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

restructure of geometry #2422

Merged
merged 23 commits into from
Oct 19, 2023
Merged
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
22 changes: 11 additions & 11 deletions tardis/io/model/model_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def transport_to_dict(transport):
"input_energy": transport.input_energy,
"input_mu": transport.input_mu,
"input_nu": transport.input_nu,
"input_r_cgs": transport.input_r,
"input_r": transport.input_r,
"j_blue_estimator": transport.j_blue_estimator,
"j_estimator": transport.j_estimator,
"last_interaction_in_nu": transport.last_interaction_in_nu,
Expand Down Expand Up @@ -296,23 +296,23 @@ def model_to_dict(model):
isotope_abundance : dict
"""
model_dict = {
"velocity_cgs": model.velocity,
"velocity_cgs": model.velocity.cgs,
"abundance": model.abundance,
"time_explosion_cgs": model.time_explosion,
"t_inner_cgs": model.t_inner,
"t_radiative_cgs": model.t_radiative,
"time_explosion_cgs": model.time_explosion.cgs,
"t_inner_cgs": model.t_inner.cgs,
"t_radiative_cgs": model.t_radiative.cgs,
"dilution_factor": model.dilution_factor,
"v_boundary_inner_cgs": model.v_boundary_inner,
"v_boundary_outer_cgs": model.v_boundary_outer,
"v_boundary_inner_cgs": model.v_boundary_inner.cgs,
"v_boundary_outer_cgs": model.v_boundary_outer.cgs,
"w": model.w,
"t_rad_cgs": model.t_rad,
"r_inner_cgs": model.r_inner,
"density_cgs": model.density,
"t_rad_cgs": model.t_rad.cgs,
"r_inner_cgs": model.r_inner.cgs,
"density_cgs": model.density.cgs,
}

for key, value in model_dict.items():
if hasattr(value, "unit"):
model_dict[key] = [value.cgs.value, value.unit.to_string()]
model_dict[key] = [value.cgs.value, value.cgs.unit.to_string()]

isotope_abundance = model.raw_isotope_abundance.__dict__

Expand Down
52 changes: 26 additions & 26 deletions tardis/io/tests/test_model_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ def test_model_to_dict(simulation_verysimple):
model_dict, isotope_abundance = model_to_dict(model)

# Check model dictionary
assert np.array_equal(model_dict["velocity_cgs"][0], model.velocity.value)
assert model_dict["velocity_cgs"][1] == model.velocity.unit.to_string()
assert np.array_equal(
model_dict["velocity_cgs"][0], model.velocity.cgs.value
)
assert model_dict["velocity_cgs"][1] == model.velocity.cgs.unit.to_string()
assert np.array_equal(model_dict["abundance"], model.abundance)
assert np.array_equal(
model_dict["time_explosion_cgs"][0], model.time_explosion.value
Expand All @@ -148,36 +150,36 @@ def test_model_to_dict(simulation_verysimple):
model_dict["time_explosion_cgs"][1]
== model.time_explosion.unit.to_string()
)
assert np.array_equal(model_dict["t_inner_cgs"][0], model.t_inner.value)
assert np.array_equal(model_dict["t_inner_cgs"][0], model.t_inner.cgs.value)
assert model_dict["t_inner_cgs"][1] == model.t_inner.unit.to_string()
assert np.array_equal(
model_dict["t_radiative_cgs"][0], model.t_radiative.value
model_dict["t_radiative_cgs"][0], model.t_radiative.cgs.value
)
assert (
model_dict["t_radiative_cgs"][1] == model.t_radiative.unit.to_string()
)
assert np.array_equal(model_dict["dilution_factor"], model.dilution_factor)
assert np.array_equal(
model_dict["v_boundary_inner_cgs"][0], model.v_boundary_inner.value
model_dict["v_boundary_inner_cgs"][0], model.v_boundary_inner.cgs.value
)
assert (
model_dict["v_boundary_inner_cgs"][1]
== model.v_boundary_inner.unit.to_string()
== model.v_boundary_inner.cgs.unit.to_string()
)
assert np.array_equal(
model_dict["v_boundary_outer_cgs"][0], model.v_boundary_outer.value
model_dict["v_boundary_outer_cgs"][0], model.v_boundary_outer.cgs.value
)
assert (
model_dict["v_boundary_outer_cgs"][1]
== model.v_boundary_outer.unit.to_string()
== model.v_boundary_outer.cgs.unit.to_string()
)
assert np.array_equal(model_dict["w"], model.w)
assert np.array_equal(model_dict["t_rad_cgs"][0], model.t_rad.value)
assert model_dict["t_rad_cgs"][1] == model.t_rad.unit.to_string()
assert np.array_equal(model_dict["r_inner_cgs"][0], model.r_inner.value)
assert model_dict["r_inner_cgs"][1] == model.r_inner.unit.to_string()
assert np.array_equal(model_dict["density_cgs"][0], model.density.value)
assert model_dict["density_cgs"][1] == model.density.unit.to_string()
assert np.array_equal(model_dict["t_rad_cgs"][0], model.t_rad.cgs.value)
assert model_dict["t_rad_cgs"][1] == model.t_rad.cgs.unit.to_string()
assert np.array_equal(model_dict["r_inner_cgs"][0], model.r_inner.cgs.value)
assert model_dict["r_inner_cgs"][1] == model.r_inner.cgs.unit.to_string()
assert np.array_equal(model_dict["density_cgs"][0], model.density.cgs.value)
assert model_dict["density_cgs"][1] == model.density.cgs.unit.to_string()


def test_store_model_to_hdf(simulation_verysimple, tmp_path):
Expand All @@ -190,26 +192,26 @@ def test_store_model_to_hdf(simulation_verysimple, tmp_path):

# Check file contents
with h5py.File(fname) as f:
assert np.array_equal(f["model/velocity_cgs"], model.velocity.value)
assert np.array_equal(f["model/velocity_cgs"], model.velocity.cgs.value)
assert np.array_equal(f["model/abundance"], model.abundance)
assert np.array_equal(
f["model/time_explosion_cgs"], model.time_explosion.value
f["model/time_explosion_cgs"], model.time_explosion.cgs.value
)
assert np.array_equal(f["model/t_inner_cgs"], model.t_inner.value)
assert np.array_equal(f["model/t_inner_cgs"], model.t_inner.cgs.value)
assert np.array_equal(
f["model/t_radiative_cgs"], model.t_radiative.value
f["model/t_radiative_cgs"], model.t_radiative.cgs.value
)
assert np.array_equal(f["model/dilution_factor"], model.dilution_factor)
assert np.array_equal(
f["model/v_boundary_inner_cgs"], model.v_boundary_inner.value
f["model/v_boundary_inner_cgs"], model.v_boundary_inner.cgs.value
)
assert np.array_equal(
f["model/v_boundary_outer_cgs"], model.v_boundary_outer.value
f["model/v_boundary_outer_cgs"], model.v_boundary_outer.cgs.value
)
assert np.array_equal(f["model/w"], model.w)
assert np.array_equal(f["model/t_rad_cgs"], model.t_rad.value)
assert np.array_equal(f["model/r_inner_cgs"], model.r_inner.value)
assert np.array_equal(f["model/density_cgs"], model.density.value)
assert np.array_equal(f["model/t_rad_cgs"], model.t_rad.cgs.value)
assert np.array_equal(f["model/r_inner_cgs"], model.r_inner.cgs.value)
assert np.array_equal(f["model/density_cgs"], model.density.cgs.value)


def test_transport_to_dict(simulation_verysimple):
Expand Down Expand Up @@ -289,9 +291,7 @@ def test_store_transport_to_hdf(simulation_verysimple, tmp_path):
assert np.array_equal(
f["transport/input_nu"], transport_data["input_nu"]
)
assert np.array_equal(
f["transport/input_r_cgs"], transport_data["input_r"].value
)
assert np.array_equal(f["transport/input_r"], transport_data["input_r"])
assert np.array_equal(
f["transport/j_blue_estimator"], transport_data["j_blue_estimator"]
)
Expand Down
2 changes: 1 addition & 1 deletion tardis/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
factor of the model used in the simulation.
"""

from tardis.model.base import *
from tardis.model.base import SimulationState
Loading
Loading