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

Marcs model ingestion bugfix #147

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
28 changes: 9 additions & 19 deletions stardis/io/model/marcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,18 @@

num_of_chemicals_in_model = len(marcs_chemical_mass_fractions.columns)

if atom_data.atom_data.index.max() < final_atomic_number:
if (
len(marcs_chemical_mass_fractions.columns)
> atom_data.atom_data.index.max()
):
logging.warning(
f"Final model chemical number is {num_of_chemicals_in_model} while final atom data chemical number is {atom_data.atom_data.index.max()} and final atomic number requested is {final_atomic_number}."
)
if atom_data.atom_data.index.max() < final_atomic_number and (
len(marcs_chemical_mass_fractions.columns) > atom_data.atom_data.index.max()
):
logging.warning(

Check warning on line 74 in stardis/io/model/marcs.py

View check run for this annotation

Codecov / codecov/patch

stardis/io/model/marcs.py#L74

Added line #L74 was not covered by tests
f"Final model chemical number is {num_of_chemicals_in_model} while final atom data chemical number is {atom_data.atom_data.index.max()} and final atomic number requested is {final_atomic_number}."
)

for atom_num, col in enumerate(marcs_chemical_mass_fractions.columns):
if atom_num < len(atom_data.atom_data):
marcs_chemical_mass_fractions[atom_num + 1] = (
10 ** marcs_chemical_mass_fractions[col]
) * atom_data.atom_data.mass.iloc[atom_num]
else:
for atoms_not_in_atom_data in range(
atom_num, marcs_chemical_mass_fractions.shape[1]
):
marcs_chemical_mass_fractions[atoms_not_in_atom_data + 1] = np.nan
break

# Remove scaled log number columns - leaves only masses
dropped_cols = [
Expand Down Expand Up @@ -225,7 +217,7 @@
with open(fpath, "rt") as file:
contents = file.readlines(BYTES_THROUGH_METADATA)

lines = [line for line in contents]
lines = list(contents)

for i, line in enumerate(lines):
metadata_re_match = metadata_re[i].match(line)
Expand All @@ -235,14 +227,12 @@

# clean up metadata dictionary by changing strings of numbers to floats and attaching parsed units where appropriate
keys_to_remove = []
for i, key in enumerate(metadata.keys()):
for key in metadata:
if "_units" in key:
quantity_to_add_unit = key.split("_units")[0]
metadata[quantity_to_add_unit] *= u.Unit(metadata[key])
keys_to_remove.append(key)
elif key == "fname":
pass
else:
elif key != "fname":
metadata[key] = float(metadata[key])
metadata = {key: metadata[key] for key in metadata if key not in keys_to_remove}

Expand Down
Loading