diff options
-rw-r--r-- | szilagyi/_dataset/__init__.py | 21 | ||||
-rw-r--r-- | szilagyi/nomogram.py | 20 | ||||
-rw-r--r-- | szilagyi/plots.py | 2 |
3 files changed, 26 insertions, 17 deletions
diff --git a/szilagyi/_dataset/__init__.py b/szilagyi/_dataset/__init__.py index e91251e..18eaee8 100644 --- a/szilagyi/_dataset/__init__.py +++ b/szilagyi/_dataset/__init__.py @@ -4,12 +4,21 @@ import re class Vector(complex): - def __getitem__(self, index): - if index == 0: - return self.real - if index == 1: - return self.imag - raise IndexError + @property + def x(self): + return self.real + + @x.setter + def x(self, value): + self.real = value + + @property + def y(self): + return self.imag + + @y.setter + def y(self, value): + self.imag = value def _load_from(root): diff --git a/szilagyi/nomogram.py b/szilagyi/nomogram.py index 55276ae..8c567d7 100644 --- a/szilagyi/nomogram.py +++ b/szilagyi/nomogram.py @@ -6,7 +6,7 @@ from . import _dataset def look_downwards(data, x, start): for i in range(start, 0, -1): - if data[i - 1][0] < x: + if data[i - 1].x < x: break else: raise IndexError @@ -15,7 +15,7 @@ def look_downwards(data, x, start): def look_upwards(data, x, start): for i in range(start, len(data)): - if data[i + 1][0] > x: + if data[i + 1].x > x: break else: raise IndexError @@ -23,10 +23,10 @@ def look_upwards(data, x, start): def find_segment(data, x): - width = data[-1][0] - data[0][0] - relative = x - data[0][0] + width = data[-1].x - data[0].x + relative = x - data[0].x candidate = math.floor(relative / width * len(data)) - look = look_downwards if data[candidate][0] > x else look_upwards # May raise IndexError + look = look_downwards if data[candidate].x > x else look_upwards # May raise IndexError candidate = look(data, x, candidate) return candidate, candidate + 1 @@ -35,20 +35,20 @@ def find_boundary_curves(swis, x, y): segments = deque() for index, data in swis: i, j = find_segment(data, x) - if data[i][1] > y and data[j][1] > y: + if data[i].y > y and data[j].y > y: segments.append((index, data, i, j)) break - if data[i][1] < y and data[j][1] < y: + if data[i].y < y and data[j].y < y: if segments: segments.popleft() segments.append((index, data, i, j)) if len(segments) == 3: middle = segments[1][1] - run = middle[j][0] - middle[i][0] + run = middle[j].x - middle[i].x if run == 0: raise RuntimeError # tidy up dataset - slope = (middle[j][1] - middle[i][1]) / run - intercept = middle[j][1] - slope * middle[j][0] + slope = (middle[j].y - middle[i].y) / run + intercept = middle[j].y - slope * middle[j].x value = slope * x + intercept if value == y: raise RuntimeError # Exactly on point; SWI == index diff --git a/szilagyi/plots.py b/szilagyi/plots.py index b38b99e..44782d6 100644 --- a/szilagyi/plots.py +++ b/szilagyi/plots.py @@ -31,5 +31,5 @@ if __name__ == "__main__": C.append(row) plot.pcolormesh(X, Y, C, cmap='viridis', vmin=-10, vmax=10, rasterized=True) for _, data in _dataset.INDICES: - plot.plot([x[0] for x in data], [x[1] for x in data]) + plot.plot([x.x for x in data], [x.y for x in data]) plot.show() |