From 1623cc6f413d8b29156e63fac1c96caaceae439c Mon Sep 17 00:00:00 2001 From: Florian Thomas Date: Tue, 25 Oct 2022 15:51:13 +0200 Subject: [PATCH] Modify hercules dataset Standardize with fixed pickle protocol and filetype. Also rename the class. --- hercules/__init__.py | 1 + hercules/{fileindex.py => dataset.py} | 12 ++++++++---- hercules/simulation.py | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) rename hercules/{fileindex.py => dataset.py} (92%) diff --git a/hercules/__init__.py b/hercules/__init__.py index cc8fc33..542d164 100644 --- a/hercules/__init__.py +++ b/hercules/__init__.py @@ -9,3 +9,4 @@ from .simulation import KassLocustP3 from .simconfig import SimConfig from .eggreader import LocustP3File +from .dataset import Dataset diff --git a/hercules/fileindex.py b/hercules/dataset.py similarity index 92% rename from hercules/fileindex.py rename to hercules/dataset.py index 40eac06..ed55231 100644 --- a/hercules/fileindex.py +++ b/hercules/dataset.py @@ -2,7 +2,7 @@ """ Author: F. Thomas -Date: February 19, 2021 +Date: October 17, 2022 """ @@ -24,7 +24,9 @@ def __init__(self, x): def __call__(self, x): return self.x -class FileIndex: +class Dataset: + + __version = '1.0' def __init__(self, directory): @@ -70,6 +72,8 @@ def make_index(self, config_list): def interpolate_all(self): + print('Making interpolation') + self.r_int = self.interpolate(self.r) self.phi_int = self.interpolate(self.phi) self.z_int = self.interpolate(self.z) @@ -109,11 +113,11 @@ def load_sim(self, path): return np.load(self.directory / path / PY_DATA_NAME) def dump(self): - pickle.dump(self, open(self.directory/'index.p', "wb")) + pickle.dump(self, open(self.directory/'index.he', "wb"), protocol=4) @classmethod def load(cls, path): path_p = Path(path) - instance = pickle.load(open(path_p/'index.p', "rb")) + instance = pickle.load(open(path_p/'index.he', "rb")) instance.directory = path_p return instance diff --git a/hercules/simulation.py b/hercules/simulation.py index 491c06d..e62d226 100644 --- a/hercules/simulation.py +++ b/hercules/simulation.py @@ -17,7 +17,7 @@ import pickle from hercules.simconfig import SimConfig -from .fileindex import FileIndex +from .dataset import Dataset from .constants import (HEXBUG_DIR, HEXBUG_DIR_CONTAINER, OUTPUT_DIR_CONTAINER, LOCUST_CONFIG_NAME, KASS_CONFIG_NAME, SIM_CONFIG_NAME, CONFIG) @@ -193,9 +193,9 @@ def __call__(self, config_list, **kwargs): def make_index(self, config_list): - file_ind = FileIndex(self._working_dir) - file_ind.make_index(config_list) - file_ind.dump() + dataset = Dataset(self._working_dir) + dataset.make_index(config_list) + dataset.dump() @abstractmethod def run(self, config_list, **kwargs):