From 07b0fb8ef544dbf007068b5b23dd7ec989ac8017 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 3 Sep 2022 00:10:41 +0200 Subject: Moved dataset loading function to dataset module --- szilagyi/_dataset/__init__.py | 27 +++++++++++++++++++++++++++ szilagyi/nomogram.py | 22 ---------------------- szilagyi/plots.py | 3 ++- 3 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 szilagyi/_dataset/__init__.py diff --git a/szilagyi/_dataset/__init__.py b/szilagyi/_dataset/__init__.py new file mode 100644 index 0000000..cfa1aee --- /dev/null +++ b/szilagyi/_dataset/__init__.py @@ -0,0 +1,27 @@ +import csv +import os +import re + +from ..nomogram import Vector + + +ROOT = os.path.dirname(os.path.abspath(__file__)) + + +def load(): + def _read(iterable): + for x, y in iterable: + yield Vector(float(x), float(y)) + + def _load(filename): + with open(filename) as fd: + reader = csv.reader(fd) + return list(_read(reader)) + + def _files(directory): + for filename in os.listdir(directory): + match = re.match(r"SWI_(-?\d+)\.csv", filename) + if match: + yield int(match.group(1)), os.path.join(directory, filename) + + return [(x, _load(y)) for x, y in sorted(_files(ROOT), key=lambda x: x[0])] diff --git a/szilagyi/nomogram.py b/szilagyi/nomogram.py index 9d76127..91d75c2 100644 --- a/szilagyi/nomogram.py +++ b/szilagyi/nomogram.py @@ -1,7 +1,4 @@ -import csv import math -import os -import re from collections import deque @@ -15,25 +12,6 @@ class Vector(complex): raise IndexError -def load(directory): - def _read(iterable): - for x, y in iterable: - yield Vector(float(x), float(y)) - - def _load(filename): - with open(filename) as fd: - reader = csv.reader(fd) - return list(_read(reader)) - - def _files(directory): - for file in os.listdir(directory): - match = re.match(r"SWI_(-?\d+)\.csv", file) - if match: - yield int(match.group(1)), os.path.join(directory, file) - - return [(x, _load(y)) for x, y in sorted(_files(directory), key=lambda x: x[0])] - - def look_downwards(data, x, start): for i in range(start, 0, -1): if data[i - 1][0] < x: diff --git a/szilagyi/plots.py b/szilagyi/plots.py index 8b325d6..9e0c2c5 100644 --- a/szilagyi/plots.py +++ b/szilagyi/plots.py @@ -2,6 +2,7 @@ import os import matplotlib.pyplot as plot +from . import _dataset from .nomogram import * @@ -14,7 +15,7 @@ def grid(start, end, steps): if __name__ == "__main__": - swis = load(os.path.join(os.path.dirname(__file__), "_dataset")) + swis = _dataset.load() def _swi(x, y): # dt, depth segments = find_boundary_curves(swis, x, y) -- cgit v1.1