Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate simulation metadata from (sxs) metadata #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nrcatalogtools/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def get(self, sim_name, quantity="waveform"):
metadata = self.get_metadata(sim_name)
if type(metadata) is not dict and hasattr(metadata, "to_dict"):
metadata = metadata.to_dict()
elif isinstance(metadata, dict):
metadata = dict(metadata.items())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused why this check is needed. Wouldn't metadata before and after this action be the same thing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a quick fix for another small issue. Tbh, I think it could be addressed more appropriately from the sxs side.

The issue is that somehow the type of metadata becomes the sxs.Metadata, and the update method of which supports syntax like: metadata.update(new_meta), but not metadata.update(**new_data).

But then the latter syntax is used in here. Since I am not sure whether sxs expects the metadata there has to be a pure dict or that they are not aware of this issue, I opt for this simple fix here.

Going back to the original question, the sxs.Metadata is a subclass from OrderedDict, so the isinstance and items() methods work, and converting it to a simple dict revert the update method back to the usual one.


if quantity.lower() == "waveform":
filepath = self.waveform_filepath_from_simname(sim_name)
Expand Down
14 changes: 6 additions & 8 deletions nrcatalogtools/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def load_from_h5(cls, file_path_or_open_file, metadata={}, verbosity=0):

# If _metadata is not already a set attribute, then set it here.
try:
cls._metadata
cls._sim_metadata
except AttributeError:
cls._metadata = metadata
cls._sim_metadata = metadata

ell_min, ell_max = 99, -1
LM = []
Expand Down Expand Up @@ -164,7 +164,6 @@ def load_from_h5(cls, file_path_or_open_file, metadata={}, verbosity=0):
data[:, idx] = amp_interp(times) * np.exp(1j * phase_interp(times))

w_attributes = {}
w_attributes["metadata"] = metadata
w_attributes["history"] = ""
w_attributes["frame"] = quaternionic.array([[1.0, 0.0, 0.0, 0.0]])
w_attributes["frame_type"] = "inertial"
Expand All @@ -177,7 +176,6 @@ def load_from_h5(cls, file_path_or_open_file, metadata={}, verbosity=0):
)
w_attributes["r_is_scaled_out"] = True
w_attributes["m_is_scaled_out"] = True
# w_attributes["ells"] = ell_min, ell_max

return cls(
data,
Expand Down Expand Up @@ -361,17 +359,17 @@ def filepath(self):
@property
def sim_metadata(self):
"""Return the simulation metadata dictionary"""
return self._metadata["metadata"]
return self._sim_metadata

@property
def metadata(self):
"""Return the simulation metadata dictionary"""
return self.sim_metadata
return self._metadata

@property
def label(self):
"""Return a Latex label that summarizes key simulation details"""
md = self.metadata
md = self.sim_metadata

return (
f"$q{md['relaxed_mass_ratio_1_over_2']:0.3f}\\_"
Expand Down Expand Up @@ -402,7 +400,7 @@ def get_parameters(self, total_mass=1.0):
dict: Initial binary parameters with names compatible with PyCBC.
"""

metadata = self.metadata
metadata = self.sim_metadata
parameters = md.get_source_parameters_from_metadata(
metadata, total_mass=total_mass
)
Expand Down