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

exponential density profile hotfix #83

Closed
wants to merge 8 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
54 changes: 50 additions & 4 deletions tardis/io/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,21 @@ def parse_spectral_bin(spectral_bin_boundary_1, spectral_bin_boundary_2):
return spectrum_start_wavelength, spectrum_end_wavelength


def calc_exponential_density(velocities, velocity_0, rho0, a):
"""
This function computes the exponential density profile.

def calculate_exponential_densities(velocities, velocity_0, rho_0, exponent):
:param velocities: Array like velocity profile.
:param rho0: rho at v0
:param velocity_0: the velocity at the inner shell
:param a: proportionality constant
:return: Array like density profile
"""
densities = a * rho0 * np.exp(-(velocities / velocity_0))
return densities


def calc_power_law_density(velocities, velocity_0, rho_0, exponent):
"""

This function computes a descret exponential density profile.
Expand Down Expand Up @@ -387,14 +400,18 @@ def parse_branch85(density_dict, v_inner, v_outer, time_explosion):

density_parser['branch85_w7'] = parse_branch85

def parse_exponential(density_dict, v_inner, v_outer, time_explosion):
def parse_power_law(density_dict, v_inner, v_outer, time_explosion):
time_0 = density_dict.pop('time_0', 19.9999584)
if isinstance(time_0, basestring):
time_0 = parse_quantity(time_0).to('s').value
else:
logger.debug('time_0 not supplied for density branch85 - using sensible default %g', time_0)
try:
rho_0 = float(density_dict.pop('rho_0'))
rho_0 = density_dict.pop('rho_0')
if isinstance(rho_0, basestring):
rho_0 = parse_quantity(rho_0).to('g/cm^3').value
else:
raise KeyError
except KeyError:
rho_0 = 1e-2
logger.warning('rho_o was not given in the config! Using %g', rho_0)
Expand All @@ -405,10 +422,39 @@ def parse_exponential(density_dict, v_inner, v_outer, time_explosion):
logger.warning('exponent was not given in the config file! Using %f', exponent)

velocities = 0.5 * (v_inner + v_outer)
densities = calculate_exponential_densities(velocities, v_inner[0], rho_0, exponent)
densities = calc_power_law_density(velocities, v_inner[0], rho_0, exponent)
densities = u.Quantity(densities, 'g/cm^3')

return densities

density_parser['power_law'] = parse_power_law

def parse_exponential(density_dict, v_inner, v_outer, time_explosion):
time_0 = density_dict.pop('time_0', 19.9999584)
if isinstance(time_0, basestring):
time_0 = parse_quantity(time_0).to('s').value
else:
logger.debug('time_0 not supplied for density branch85 - using sensible default %g', time_0)
try:
rho_0 = density_dict.pop('rho_0')
if isinstance(rho_0, basestring):
rho_0 = parse_quantity(rho_0).to('g/cm^3').value
else:
raise KeyError
except KeyError:
rho_0 = 1e-2
logger.warning('rho_o was not given in the config! Using %g', rho_0)
try:
a = density_dict.pop('proportionality_constant')
except KeyError:
a = 2
logger.warning('The proportionality constant was not given in the config file! Using %f', a)

velocities = 0.5 * (v_inner + v_outer)
densities = calc_exponential_density(velocities, v_inner[0], rho_0, a)
densities = u.Quantity(densities, 'g/cm^3')
return densities

density_parser['exponential'] = parse_exponential

try:
Expand Down
74 changes: 74 additions & 0 deletions tardis/io/default_conf_test/conf_def.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
value_test:
integer:
property_type: int
default: 99.1
mandatory: True
help: integer value for testing
float:
property_type: float
default: 99.99
mandatory: True
help: float value for testing
string:
property_type: string
default: DEFAULT
mandatory: True
help: string for testing
quantity:
property_type: quantity
default: 99.99 cm
mandatory: True
help: quantity for testing
range:
property_type: range
default: [0,10] #[Start,End]
mandatory: False
help: range for testing
range_sampled:
property_type: range_sampled
default: [0,10,1] #[Start,End,Nsample]
mandatory: False
help: range for testing





supernova:
luminosity_requested:
property_type: quantity ### log_lbol to be discussed
default: 2 m
mandatory: True
help: requested luminosity for simulation
time_explosion:
property_type: quantity
default: 10 cm
mandatory: False
help: time since explosion
test:
structure:
property_type : container-property
type:
property_type: container-declaration
containers: ['file', 'specific']
_file: ['file_property']
file_property:
filename:
property_type: string
default: None
mandatory: True
help: file name (with path) to atomic data HDF5 file
file_container:
property_type : container-property
type:
property_type: container-declaration
containers: ['bla','blub']
_bla: ['subset']
subset:
subvalue:
property_type: string
default: blabla
mandatory: False
help: very helpful


21 changes: 21 additions & 0 deletions tardis/io/default_conf_test/conf_tes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
value_test:
integer: 10
float: 10.5
string: bla bla
quantity: 10 cm
list: ['bla','blub']

supernova:
luminosity_requested: 1 cm
time_explosion: 12 d
test:
structure:
type: file
file_property:
filename: bla
file_container:
type: bla
subset:
subvalue: TEST


7 changes: 7 additions & 0 deletions tardis/io/default_conf_test/default_test_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__author__ = 'michi'
import yaml

f = open('default_conf_test/conf_def.yaml')
default = yaml.safe_load(f)
f = open('default_conf_test/conf_tes.yaml')
config = yaml.safe_load(f)
Loading