From c227975e62c70574c805c56fd75095e25b9da97c Mon Sep 17 00:00:00 2001 From: Jason Foat Date: Sat, 5 Oct 2024 23:27:26 +0000 Subject: [PATCH] Clean up. --- stac_mjx/io.py | 17 +++++++++-------- stac_mjx/io_dict_to_hdf5.py | 17 +++++++---------- stac_mjx/main.py | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/stac_mjx/io.py b/stac_mjx/io.py index 33056c7..e27c22c 100755 --- a/stac_mjx/io.py +++ b/stac_mjx/io.py @@ -189,14 +189,15 @@ def _load_params(param_path): return params -def load_stac_tranform(save_path): - _, file_extension = os.path.splitext(save_path) - if file_extension == ".p": - with open(save_path, "rb") as file: - fit_data = pickle.load(file) - elif file_extension == ".h5": - fit_data = ioh5.load(save_path) - return fit_data +# Fly model -- decide to keep or not! +# def load_stac_ik_only(save_path): +# _, file_extension = os.path.splitext(save_path) +# if file_extension == ".p": +# with open(save_path, "rb") as file: +# fit_data = pickle.load(file) +# elif file_extension == ".h5": +# fit_data = ioh5.load(save_path) +# return fit_data def save(fit_data, save_path: Text): diff --git a/stac_mjx/io_dict_to_hdf5.py b/stac_mjx/io_dict_to_hdf5.py index 4474093..53817eb 100644 --- a/stac_mjx/io_dict_to_hdf5.py +++ b/stac_mjx/io_dict_to_hdf5.py @@ -4,10 +4,10 @@ # import os - def save(filename, dic): - """ - saves a python dictionary or list, with items that are themselves either + """Saves python dict. + + Saves a python dictionary or list, with items that are themselves either dictionaries or lists or (in the case of tree-leaves) numpy arrays or basic scalar types (int/float/str/bytes) in a recursive manner to an hdf5 file, with an intact hierarchy. @@ -17,9 +17,7 @@ def save(filename, dic): def recursively_save_dict_contents_to_group(h5file, path, dic): - """ - .... - """ + """ Todo fill this out.""" if isinstance(dic, dict): iterator = dic.items() elif isinstance(dic, list): @@ -45,7 +43,8 @@ def recursively_save_dict_contents_to_group(h5file, path, dic): def load(filename, ASLIST=False): - """ + """Loads a hdf5 file. + Default: load a hdf5 file (saved with io_dict_to_hdf5.save function above) as a hierarchical python dictionary (as described in the doc_string of io_dict_to_hdf5.save). if ASLIST is True: then it loads as a list (on in the first layer) and gives error if key's are not convertible @@ -63,9 +62,7 @@ def load(filename, ASLIST=False): def recursively_load_dict_contents_from_group(h5file, path): - """ - .... - """ + """Todo: fill this out.""" ans = {} for key, item in h5file[path].items(): if isinstance(item, h5py._hl.dataset.Dataset): diff --git a/stac_mjx/main.py b/stac_mjx/main.py index ca337ad..a2d02dd 100644 --- a/stac_mjx/main.py +++ b/stac_mjx/main.py @@ -85,7 +85,7 @@ def run_stac( with open(fit_path, "rb") as file: fit_data = pickle.load(file) # logging.info("Running transform()") - # fit_data = utils.load_stac_tranform(fit_path) + # fit_data = utils.load_stac_ik_only(fit_path) offsets = fit_data["offsets"]