Skip to content

Commit 35ccf43

Browse files
committed
I'm dumb, this can be so much simpler
1 parent fe121be commit 35ccf43

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

cogsworth/pop.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,6 @@ def save(self, file_name, overwrite=False):
11671167
self.kick_info.to_hdf(file_name, key="kick_info")
11681168

11691169
with h5.File(file_name, "a") as f:
1170-
f.attrs["has_pop"] = True
11711170
f.attrs["potential_dict"] = yaml.dump(potential_to_dict(self.galactic_potential),
11721171
default_flow_style=None)
11731172
self.initial_galaxy.save(file_name, key="initial_galaxy")
@@ -1232,7 +1231,7 @@ def load(file_name):
12321231

12331232
BSE_settings = {}
12341233
with h5.File(file_name, "r") as file:
1235-
if "has_pop" not in file.attrs or not file.attrs["has_pop"]:
1234+
if "numeric_params" not in file.keys():
12361235
raise ValueError((f"{file_name} is not a Population file, "
12371236
"perhaps you meant to use `cogsworth.sfh.load`?"))
12381237
numeric_params = file["numeric_params"][...]

cogsworth/sfh.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ def save(self, file_name, key="sfh"):
398398

399399
# dump it all into the file attrs using yaml
400400
with h5.File(file_name, "a") as file:
401-
file.attrs["has_sfh"] = True
402401
file[key].attrs["params"] = yaml.dump(params, default_flow_style=None)
403402

404403

@@ -966,9 +965,8 @@ def load(file_name, key="sfh"):
966965

967966
# load the parameters back in using yaml
968967
with h5.File(file_name, "r") as file:
969-
if "has_sfh" not in file.attrs or not file.attrs["has_sfh"]:
970-
raise ValueError((f"{file_name} is not a SFH file, "
971-
"perhaps you meant to use `cogsworth.pop.load`?"))
968+
if key not in file.keys():
969+
raise ValueError((f"Can't find a saved SFH in {file_name} under the key {key}."))
972970
params = yaml.load(file[key].attrs["params"], Loader=yaml.Loader)
973971

974972
# get the current module, get a class using the name, delete it from parameters that will be passed

0 commit comments

Comments
 (0)