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

Cleanup of the config_reader module. #623

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 7 additions & 7 deletions tardis/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,25 +680,25 @@ def plot_model(self):
self.graph.cb = self.graph.figure.colorbar(t_rad_color_map)
self.graph.cb.set_label('T (K)')
self.graph.normalizing_factor = 0.2 * (
self.model.tardis_config.structure.r_outer.value[-1] -
self.model.tardis_config.structure.r_inner.value[0]) / (
self.model.tardis_config.structure.r_inner.value[0])
self.model.tardis_config.model.structure.r_outer.value[-1] -
self.model.tardis_config.model.structure.r_inner.value[0]) / (
self.model.tardis_config.model.structure.r_inner.value[0])

#self.graph.normalizing_factor = 8e-16
for i, t_rad in enumerate(self.model.t_rads.value):
r_inner = (self.model.tardis_config.structure.r_inner.value[i] *
r_inner = (self.model.tardis_config.model.structure.r_inner.value[i] *
self.graph.normalizing_factor)
r_outer = (self.model.tardis_config.structure.r_outer.value[i] *
r_outer = (self.model.tardis_config.model.structure.r_outer.value[i] *
self.graph.normalizing_factor)
self.shells.append(Shell(i, (0,0), r_inner, r_outer,
facecolor=t_rad_color_map.to_rgba(t_rad),
picker=self.graph.shell_picker))
self.graph.ax2.add_patch(self.shells[i])
self.graph.ax2.set_xlim(0,
self.model.tardis_config.structure.r_outer.value[-1] *
self.model.tardis_config.model.structure.r_outer.value[-1] *
self.graph.normalizing_factor)
self.graph.ax2.set_ylim(0,
self.model.tardis_config.structure.r_outer.value[-1] *
self.model.tardis_config.model.structure.r_outer.value[-1] *
self.graph.normalizing_factor)
self.graph.figure.tight_layout()
self.graph.draw()
Expand Down
334 changes: 1 addition & 333 deletions tardis/io/config_reader.py

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions tardis/io/tests/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def test_abundances(self):

def test_velocities(self):
assert_almost_equal(self.yaml_data['model']['structure']['velocity']['start'].cgs.value,
self.config.structure.v_inner[0].cgs.value)
self.config.model.structure.v_inner[0].cgs.value)
assert_almost_equal(self.yaml_data['model']['structure']['velocity']['stop'].cgs.value,
self.config.structure.v_outer[-1].cgs.value)
assert len(self.config.structure.v_outer) == (self.yaml_data['model']['structure']['velocity']['num'])
self.config.model.structure.v_outer[-1].cgs.value)
assert len(self.config.model.structure.v_outer) == (self.yaml_data['model']['structure']['velocity']['num'])

def test_densities(self):
assert_almost_equal(self.config['structure']['mean_densities'][0].cgs.value,
assert_almost_equal(self.config['model']['structure']['mean_densities'][0].cgs.value,
(7.542803599143591e-14 * u.Unit('g/cm^3')).value)
assert_almost_equal(self.config['structure']['mean_densities'][-1].cgs.value,
assert_almost_equal(self.config['model']['structure']['mean_densities'][-1].cgs.value,
(1.432259798833509e-15 * u.Unit('g/cm^3')).value)


Expand Down Expand Up @@ -150,8 +150,8 @@ def setup(self):


def test_velocities(self):
assert self.config.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.structure.v_inner[0].value, 1e4 * 1e5)
assert self.config.model.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.model.structure.v_inner[0].value, 1e4 * 1e5)

def test_abundances(self):
oxygen_abundance = self.yaml_data['model']['abundances']['O']
Expand All @@ -169,8 +169,8 @@ def setup(self):


def test_velocities(self):
assert self.config.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.structure.v_inner[0].value, 1.259375e+03 * 1e5)
assert self.config.model.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.model.structure.v_inner[0].value, 1.259375e+03 * 1e5)

def test_abundances(self):
oxygen_abundance = self.yaml_data['model']['abundances']['O']
Expand All @@ -196,8 +196,8 @@ def setup(self):


def test_velocities(self):
assert self.config.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.structure.v_inner[0].value, 1.259375e+03 * 1e5)
assert self.config.model.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.model.structure.v_inner[0].value, 1.259375e+03 * 1e5)

def test_abundances(self):
assert_almost_equal(self.config.abundances.ix[14, 54], 0.21864420000000001)
Expand All @@ -220,8 +220,8 @@ def setup(self):


def test_velocities(self):
assert self.config.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.structure.v_inner[0].to(
assert self.config.model.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.model.structure.v_inner[0].to(
u.km / u.s).value, 9000)

def test_abundances(self):
Expand All @@ -241,7 +241,7 @@ def setup(self):
config_dirname=data_path(''))

def test_density(self):
assert_array_almost_equal(self.config.structure.mean_densities.to(u.Unit('g / cm3')).value,
assert_array_almost_equal(self.config.model.structure.mean_densities.to(u.Unit('g / cm3')).value,
1.e-14)

class TestParseConfigTinner:
Expand Down Expand Up @@ -277,8 +277,8 @@ def setup(self):


def test_velocities(self):
assert self.config.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.structure.v_inner[0].to(
assert self.config.model.structure.v_inner.unit == u.Unit('cm/s')
assert_almost_equal(self.config.model.structure.v_inner[0].to(
u.km / u.s).value, 11000)

def test_abundances(self):
Expand All @@ -298,13 +298,13 @@ def test_abundances(self):
assert_almost_equal(self.config.abundances.ix[6, 6], 0.5)

def test_densities(self):
assert_almost_equal(self.config.structure.mean_densities[0].to(u.Unit('g/cm3')).value, 9.7656229e-11 / 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[1].to(u.Unit('g/cm3')).value, 4.8170911e-11/ 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[2].to(u.Unit('g/cm3')).value, 2.5600000e-11/ 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[3].to(u.Unit('g/cm3')).value, 1.4450533e-11/ 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[4].to(u.Unit('g/cm3')).value, 8.5733893e-11/ 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[5].to(u.Unit('g/cm3')).value, 5.3037103e-11/ 13.0**3 )
assert_almost_equal(self.config.structure.mean_densities[6].to(u.Unit('g/cm3')).value, 3.3999447e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[0].to(u.Unit('g/cm3')).value, 9.7656229e-11 / 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[1].to(u.Unit('g/cm3')).value, 4.8170911e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[2].to(u.Unit('g/cm3')).value, 2.5600000e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[3].to(u.Unit('g/cm3')).value, 1.4450533e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[4].to(u.Unit('g/cm3')).value, 8.5733893e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[5].to(u.Unit('g/cm3')).value, 5.3037103e-11/ 13.0**3 )
assert_almost_equal(self.config.model.structure.mean_densities[6].to(u.Unit('g/cm3')).value, 3.3999447e-11/ 13.0**3 )


def test_ascii_reader_power_law():
Expand All @@ -320,7 +320,7 @@ def test_ascii_reader_power_law():
v_outer = yaml_data['model']['structure']['velocity']['stop']
my_conf = config_reader.Configuration.from_yaml(data_path('tardis_configv1_density_power_law_test.yml'),
test_parser=True)
structure = my_conf['structure']
structure = my_conf['model']['structure']

expected_densites = [3.29072513e-14, 2.70357804e-14, 2.23776573e-14,
1.86501954e-14, 1.56435277e-14, 1.32001689e-14, 1.12007560e-14,
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_ascii_reader_exponential_law():
v_outer = yaml_data['model']['structure']['velocity']['stop']
my_conf = config_reader.Configuration.from_yaml(data_path('tardis_configv1_density_exponential_test.yml'),
test_parser=True)
structure = my_conf['structure']
structure = my_conf['model']['structure']

expected_densites = [5.18114795e-14, 4.45945537e-14, 3.83828881e-14, 3.30364579e-14, 2.84347428e-14, 2.44740100e-14, 2.10649756e-14, 1.81307925e-14, 1.56053177e-14, 1.34316215e-14, 1.15607037e-14, 9.95038990e-15, 8.56437996e-15, 7.37143014e-15, 6.34464872e-15, 5.46088976e-15, 4.70023138e-15, 4.04552664e-15, 3.48201705e-15, 2.99699985e-15]
expected_unit = 'g / (cm3)'
Expand Down
14 changes: 7 additions & 7 deletions tardis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def __init__(self, tardis_config):

self.t_inner = tardis_config.plasma.t_inner

self.v_inner = tardis_config.structure.v_inner
self.v_outer = tardis_config.structure.v_outer
self.v_inner = tardis_config.model.structure.v_inner
self.v_outer = tardis_config.model.structure.v_outer
self.v_middle = 0.5 * (self.v_inner + self.v_outer)

self.ws = self.calculate_geometric_w(
tardis_config.structure.r_middle,
tardis_config.structure.r_inner[0])
tardis_config.model.structure.r_middle,
tardis_config.model.structure.r_inner[0])

if tardis_config.plasma.t_rads is None:
self.t_rads = self._init_t_rad(
Expand Down Expand Up @@ -177,14 +177,14 @@ def t_inner(self, value):
self._t_inner = value
self.luminosity_inner = (
4 * np.pi * constants.sigma_sb.cgs *
self.tardis_config.structure.r_inner[0] ** 2
self.tardis_config.model.structure.r_inner[0] ** 2
* self.t_inner ** 4).to('erg/s')

self.time_of_simulation = (1.0 * u.erg / self.luminosity_inner)
self.j_blues_norm_factor = (
constants.c.cgs * self.tardis_config.supernova.time_explosion /
(4 * np.pi * self.time_of_simulation *
self.tardis_config.structure.volumes))
self.tardis_config.model.structure.volumes))



Expand Down Expand Up @@ -227,7 +227,7 @@ def calculate_j_blues(self, init_detailed_j_blues=False):
index=self.atom_data.lines.index,
columns=np.arange(len(self.t_rads)))

for i in xrange(self.tardis_config.structure.no_of_shells):
for i in xrange(self.tardis_config.model.structure.no_of_shells):
zero_j_blues = self.j_blues[i] == 0.0
self.j_blues[i][zero_j_blues] = (
w_epsilon * intensity_black_body(
Expand Down
4 changes: 2 additions & 2 deletions tardis/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1,last_run
:return:
"""
self.time_of_simulation = model.time_of_simulation
self.volume = model.tardis_config.structure.volumes
self.volume = model.tardis_config.model.structure.volumes
self._initialize_estimator_arrays(self.volume.shape[0],
model.plasma.tau_sobolevs.shape)
self._initialize_geometry_arrays(model.tardis_config.structure)
self._initialize_geometry_arrays(model.tardis_config.model.structure)

self._initialize_packets(model.t_inner.value,
no_of_packets)
Expand Down
2 changes: 1 addition & 1 deletion tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def estimate_t_inner(self, input_t_inner, luminosity_requested,
def get_convergence_status(self, t_rad, w, t_inner, estimated_t_rad, estimated_w,
estimated_t_inner):
convergence_section = self.tardis_config.montecarlo.convergence_strategy
no_of_shells = self.tardis_config.structure.no_of_shells
no_of_shells = self.tardis_config.model.structure.no_of_shells

convergence_t_rad = (abs(t_rad - estimated_t_rad) /
estimated_t_rad).value
Expand Down
4 changes: 2 additions & 2 deletions tardis/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None):


#raise Exception("there's a problem here with units what units does synpp expect?")
yaml_reference['opacity']['v_ref'] = float((radial1d_mdl.tardis_config.structure.v_inner[0].to('km/s') /
yaml_reference['opacity']['v_ref'] = float((radial1d_mdl.tardis_config.model.structure.v_inner[0].to('km/s') /
(1000. * u.km / u.s)).value)
yaml_reference['grid']['v_outer_max'] = float((radial1d_mdl.tardis_config.structure.v_outer[-1].to('km/s') /
yaml_reference['grid']['v_outer_max'] = float((radial1d_mdl.tardis_config.model.structure.v_outer[-1].to('km/s') /
(1000. * u.km / u.s)).value)

#pdb.set_trace()
Expand Down