Skip to content

Commit

Permalink
Reformat using Ruff and Black
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva-2001 committed Aug 21, 2024
1 parent 6cae852 commit bcb47d8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion tardis/spectrum/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def spectrum_integrated(self):
np.array([np.nan]) * u.erg / u.s,
)
return self._spectrum_integrated

@property
def integrator(self):
if self._integrator is None:
Expand Down
116 changes: 60 additions & 56 deletions tardis/tests/test_tardis_full_formal_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from astropy.tests.helper import assert_quantity_allclose

from tardis.io.configuration.config_reader import Configuration
from tardis.simulation.base import Simulation
from tardis.io.util import HDFWriterMixin
from tardis.simulation.base import Simulation
from tardis.tests.fixtures.regression_data import RegressionData


config_line_modes = ["downbranch", "macroatom"]
interpolate_shells = [-1, 30]

Expand All @@ -30,65 +29,70 @@ def base_config(request, example_configuration_dir: Path):

return config


@pytest.fixture(scope="module", params=interpolate_shells)
def config(base_config, request):
base_config["spectrum"]["integrated"]["interpolate_shells"] = request.param
return base_config


class SimulationContainer(HDFWriterMixin):
hdf_properties = ["spectrum_solver", "transport"]

def __init__(self, simulation):
self.spectrum_solver = simulation.spectrum_solver
self.transport = simulation.transport
hdf_properties = ["spectrum_solver", "transport"]

def __init__(self, simulation):
self.spectrum_solver = simulation.spectrum_solver
self.transport = simulation.transport


class TestTransportSimpleFormalIntegral:
"""
Very simple run with the formal integral spectral synthesis method
"""

_name = "test_transport_simple_integral"

@pytest.fixture(scope="class")
def simulation(self, config, atomic_data_fname ):
config.atom_data = atomic_data_fname

self.name = self._name + f"_{config.plasma.line_interaction_type:s}"
if config.spectrum.integrated.interpolate_shells > 0:
self.name += "_interp"

simulation = Simulation.from_config(config)
simulation.run_convergence()
simulation.run_final()
simulation.spectrum_solver.hdf_properties = [
"spectrum_real_packets",
"spectrum_integrated",
]
simulation.transport.hdf_properties = ["transport_state"]

return simulation

def test_simulation(self, simulation, request):
regression_data = RegressionData(request)
container = SimulationContainer(simulation)
regression_data.sync_hdf_store(container)

def test_j_blue_estimators(self, simulation, request):
regression_data = RegressionData(request)
j_blue_estimator = simulation.transport.transport_state.radfield_mc_estimators.j_blue_estimator
expected = regression_data.sync_ndarray(j_blue_estimator)
npt.assert_allclose(j_blue_estimator, expected)

def test_spectrum(self, simulation, request):
regression_data = RegressionData(request)
luminosity = simulation.spectrum_solver.spectrum_real_packets.luminosity
expected = regression_data.sync_ndarray(luminosity.cgs.value)
expected = u.Quantity(expected, "erg /s")
assert_quantity_allclose(luminosity, expected)

def test_spectrum_integrated(self, simulation, request):
regression_data = RegressionData(request)
luminosity = simulation.spectrum_solver.spectrum_integrated.luminosity
expected = regression_data.sync_ndarray(luminosity.cgs.value)
expected = u.Quantity(expected, "erg /s")
assert_quantity_allclose(luminosity, expected)
"""
Very simple run with the formal integral spectral synthesis method
"""

_name = "test_transport_simple_integral"

@pytest.fixture(scope="class")
def simulation(self, config, atomic_data_fname):
config.atom_data = atomic_data_fname

self.name = self._name + f"_{config.plasma.line_interaction_type:s}"
if config.spectrum.integrated.interpolate_shells > 0:
self.name += "_interp"

simulation = Simulation.from_config(config)
simulation.run_convergence()
simulation.run_final()
simulation.spectrum_solver.hdf_properties = [
"spectrum_real_packets",
"spectrum_integrated",
]
simulation.transport.hdf_properties = ["transport_state"]

return simulation

def test_simulation(self, simulation, request):
regression_data = RegressionData(request)
container = SimulationContainer(simulation)
regression_data.sync_hdf_store(container)

def test_j_blue_estimators(self, simulation, request):
regression_data = RegressionData(request)
j_blue_estimator = (
simulation.transport.transport_state.radfield_mc_estimators.j_blue_estimator
)
expected = regression_data.sync_ndarray(j_blue_estimator)
npt.assert_allclose(j_blue_estimator, expected)

def test_spectrum(self, simulation, request):
regression_data = RegressionData(request)
luminosity = simulation.spectrum_solver.spectrum_real_packets.luminosity
expected = regression_data.sync_ndarray(luminosity.cgs.value)
expected = u.Quantity(expected, "erg /s")
assert_quantity_allclose(luminosity, expected)

def test_spectrum_integrated(self, simulation, request):
regression_data = RegressionData(request)
luminosity = simulation.spectrum_solver.spectrum_integrated.luminosity
expected = regression_data.sync_ndarray(luminosity.cgs.value)
expected = u.Quantity(expected, "erg /s")
assert_quantity_allclose(luminosity, expected)

0 comments on commit bcb47d8

Please sign in to comment.