Skip to content

Commit

Permalink
Adding a "weighting variable" to a Grid (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlovell authored Feb 12, 2025
2 parents fd8020b + c0117cb commit beb74c9
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/synthesizer/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def __init__(
self._axes_units = {}
self._get_axes()

# Read in the metadata
self._weight_var = None
self._model_metadata = {}
self._get_grid_metadata()

# Get the ionising luminosity (if available)
self._get_ionising_luminosity()

Expand Down Expand Up @@ -215,6 +220,20 @@ def _parse_grid_path(self, grid_dir, grid_name):
f"{self.grid_dir}/{self.grid_name}.{self.grid_ext}"
)

def _get_grid_metadata(self):
"""Unpack the grids metadata into the Grid."""
# Open the file
with h5py.File(self.grid_filename, "r") as hf:
# What component variable do we need to weight by for the
# emission in the grid?
self._weight_var = hf.attrs.get("WeightVariable", None)

# Loop over the Model metadata stored in the Model group
# and store it in the Grid object
if "Model" in hf:
for key, value in hf["Model"].attrs.items():
self._model_metadata[key] = value

def __getattr__(self, name):
"""
Return an attribute handling arbitrary axis names.
Expand Down Expand Up @@ -409,9 +428,11 @@ def _get_ionising_luminosity(self):

# Old name for backwards compatibility (DEPRECATED)
if "log10Q" in hf.keys():
self.log10Q = {}
self.log10_specific_ionising_lum = {}
for ion in hf["log10Q"].keys():
self.log10Q[ion] = hf["log10Q"][ion][:]
self.log10_specific_ionising_lum[ion] = hf["log10Q"][ion][
:
]

def _get_spectra_grid(self, spectra_to_read):
"""
Expand Down Expand Up @@ -1063,10 +1084,7 @@ def plot_specific_ionising_lum(
y = np.arange(len(self.metallicity))

# Select grid for specific ion
if hasattr(self, "log10_specific_ionising_lum"):
log10_specific_ionising_lum = self.log10_specific_ionising_lum[ion]
else:
log10_specific_ionising_lum = self.log10Q[ion]
log10_specific_ionising_lum = self.log10_specific_ionising_lum[ion]

# Truncate grid if max age provided
if max_log10age is not None:
Expand Down

0 comments on commit beb74c9

Please sign in to comment.