Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jf514 committed Oct 5, 2024
1 parent c09971f commit c227975
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
17 changes: 9 additions & 8 deletions stac_mjx/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 7 additions & 10 deletions stac_mjx/io_dict_to_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion stac_mjx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down

0 comments on commit c227975

Please sign in to comment.