Skip to content

Commit

Permalink
Modify hercules dataset
Browse files Browse the repository at this point in the history
Standardize with fixed pickle protocol and filetype. Also rename the class.
  • Loading branch information
MCFlowMace committed Oct 25, 2022
1 parent a6fdf81 commit 1623cc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions hercules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .simulation import KassLocustP3
from .simconfig import SimConfig
from .eggreader import LocustP3File
from .dataset import Dataset
12 changes: 8 additions & 4 deletions hercules/fileindex.py → hercules/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
Author: F. Thomas
Date: February 19, 2021
Date: October 17, 2022
"""

Expand All @@ -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):

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions hercules/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1623cc6

Please sign in to comment.