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

Sourcery refactored master branch #21

Closed
wants to merge 1 commit 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
48 changes: 30 additions & 18 deletions 2022/sn_radtrans_compare/run_model_DDC10.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def read_blondin_toymodel(fname):
raw_blondin_csv = pd.read_csv(fname, delim_whitespace=True, comment='#', header=None, names=columns)
raw_blondin_csv.set_index('idx', inplace=True)
blondin_csv = raw_blondin_csv.loc[:, ['vel', 'dens', 'temp', 'X_56Ni0', 'X_Ti', 'X_Ca', 'X_S', 'X_Si', 'X_O', 'X_C']]
rename_col_dict = {'vel':'velocity', 'dens':'density', 'temp':'t_rad'}
rename_col_dict.update({item:item[2:] for item in blondin_csv.columns[3:]})
rename_col_dict = {
'vel': 'velocity',
'dens': 'density',
'temp': 't_rad',
} | {item: item[2:] for item in blondin_csv.columns[3:]}
rename_col_dict['X_56Ni0'] = 'Ni56'
blondin_csv.rename(columns=rename_col_dict, inplace=True)
blondin_csv.iloc[:, 3:] = blondin_csv.iloc[:,3:].divide(blondin_csv.iloc[:,3:].sum(axis=1), axis=0)
Expand All @@ -62,18 +65,25 @@ def read_blondin_toymodel(fname):
t0_string = t0_pattern.findall(fh.read())[0]

t0 = parse_quantity(t0_string.replace('DAYS', 'day'))
blondin_dict = {}
blondin_dict['model_density_time_0'] = str(t0)
blondin_dict['description'] = 'Converted {0} to csvy format'.format(fname)
blondin_dict['tardis_model_config_version'] = 'v1.0'
blondin_dict_fields = [dict(name='velocity', unit='km/s', desc='velocities of shell outer bounderies.')]
blondin_dict_fields.append(dict(name='density', unit='g/cm^3', desc='mean density of shell.'))
blondin_dict_fields.append(dict(name='t_rad', unit='K', desc='radiative temperature.'))

for abund in blondin_csv.columns[3:]:
blondin_dict_fields.append(dict(name=abund, desc='Fraction {0} abundance'.format(abund)))
blondin_dict['datatype'] = {'fields':blondin_dict_fields}

blondin_dict_fields = [
dict(
name='velocity',
unit='km/s',
desc='velocities of shell outer bounderies.',
),
dict(name='density', unit='g/cm^3', desc='mean density of shell.'),
dict(name='t_rad', unit='K', desc='radiative temperature.'),
]
blondin_dict_fields.extend(
dict(name=abund, desc='Fraction {0} abundance'.format(abund))
for abund in blondin_csv.columns[3:]
)
blondin_dict = {
'model_density_time_0': str(t0),
'description': 'Converted {0} to csvy format'.format(fname),
'tardis_model_config_version': 'v1.0',
'datatype': {'fields': blondin_dict_fields},
}
return blondin_dict, blondin_csv


Expand All @@ -84,8 +94,10 @@ def read_blondin_toymodel(fname):
model_grid = np.array(np.empty((epochs.shape[0]*velocity_grid.shape[0], 3)))
model_grid = []
for i, epoch in enumerate(epochs):
for j, velocity in enumerate(velocity_grid):
model_grid.append((epoch, lbols[i], velocity-2000*u.km/u.s*i))
model_grid.extend(
(epoch, lbols[i], velocity - 2000 * u.km / u.s * i)
for velocity in velocity_grid
)
print(len(model_grid))


Expand All @@ -98,7 +110,7 @@ def run_tardis_model(params):
sim = Simulation.from_config(model_config)
print(sim.model.v_boundary_inner)
sim.run()
fname = 'Output/ddc10/ddc10_t{}_v{}.hdf'.format(params[0].value, params[2].value)
fname = f'Output/ddc10/ddc10_t{params[0].value}_v{params[2].value}.hdf'
with pd.HDFStore(fname) as hdf:
hdf.put('wavelength', pd.Series(sim.runner.spectrum.wavelength.value))
hdf.put('lum', pd.Series(sim.runner.spectrum_integrated.luminosity_density_lambda.value))
Expand All @@ -118,7 +130,7 @@ def run_final_models_plus_pickle(params, fname='blondin_model_compare_ddc10.yml'
print(sim.model.v_boundary_inner)
sim.run()
import pickle
dump = 'Output/ddc10/ddc10_t{}_v{}.pickle'.format(params[0].value, params[2].value)
dump = f'Output/ddc10/ddc10_t{params[0].value}_v{params[2].value}.pickle'
with open(dump, 'wb') as dumpfile:
pickle.dump(sim, dumpfile)
return 1
Expand Down
48 changes: 30 additions & 18 deletions 2022/sn_radtrans_compare/run_model_DDC25.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def read_blondin_toymodel(fname):
raw_blondin_csv = pd.read_csv(fname, delim_whitespace=True, comment='#', header=None, names=columns)
raw_blondin_csv.set_index('idx', inplace=True)
blondin_csv = raw_blondin_csv.loc[:, ['vel', 'dens', 'temp', 'X_56Ni0', 'X_Ti', 'X_Ca', 'X_S', 'X_Si', 'X_O', 'X_C']]
rename_col_dict = {'vel':'velocity', 'dens':'density', 'temp':'t_rad'}
rename_col_dict.update({item:item[2:] for item in blondin_csv.columns[3:]})
rename_col_dict = {
'vel': 'velocity',
'dens': 'density',
'temp': 't_rad',
} | {item: item[2:] for item in blondin_csv.columns[3:]}
rename_col_dict['X_56Ni0'] = 'Ni56'
blondin_csv.rename(columns=rename_col_dict, inplace=True)
blondin_csv.iloc[:, 3:] = blondin_csv.iloc[:,3:].divide(blondin_csv.iloc[:,3:].sum(axis=1), axis=0)
Expand All @@ -62,18 +65,25 @@ def read_blondin_toymodel(fname):
t0_string = t0_pattern.findall(fh.read())[0]

t0 = parse_quantity(t0_string.replace('DAYS', 'day'))
blondin_dict = {}
blondin_dict['model_density_time_0'] = str(t0)
blondin_dict['description'] = 'Converted {0} to csvy format'.format(fname)
blondin_dict['tardis_model_config_version'] = 'v1.0'
blondin_dict_fields = [dict(name='velocity', unit='km/s', desc='velocities of shell outer bounderies.')]
blondin_dict_fields.append(dict(name='density', unit='g/cm^3', desc='mean density of shell.'))
blondin_dict_fields.append(dict(name='t_rad', unit='K', desc='radiative temperature.'))

for abund in blondin_csv.columns[3:]:
blondin_dict_fields.append(dict(name=abund, desc='Fraction {0} abundance'.format(abund)))
blondin_dict['datatype'] = {'fields':blondin_dict_fields}

blondin_dict_fields = [
dict(
name='velocity',
unit='km/s',
desc='velocities of shell outer bounderies.',
),
dict(name='density', unit='g/cm^3', desc='mean density of shell.'),
dict(name='t_rad', unit='K', desc='radiative temperature.'),
]
blondin_dict_fields.extend(
dict(name=abund, desc='Fraction {0} abundance'.format(abund))
for abund in blondin_csv.columns[3:]
)
blondin_dict = {
'model_density_time_0': str(t0),
'description': 'Converted {0} to csvy format'.format(fname),
'tardis_model_config_version': 'v1.0',
'datatype': {'fields': blondin_dict_fields},
}
return blondin_dict, blondin_csv


Expand All @@ -84,8 +94,10 @@ def read_blondin_toymodel(fname):
model_grid = np.array(np.empty((epochs.shape[0]*velocity_grid.shape[0], 3)))
model_grid = []
for i, epoch in enumerate(epochs):
for j, velocity in enumerate(velocity_grid):
model_grid.append((epoch, lbols[i], velocity-2000*u.km/u.s*i))
model_grid.extend(
(epoch, lbols[i], velocity - 2000 * u.km / u.s * i)
for velocity in velocity_grid
)
print(len(model_grid))


Expand All @@ -98,7 +110,7 @@ def run_tardis_model(params):
sim = Simulation.from_config(model_config)
print(sim.model.v_boundary_inner)
sim.run()
fname = 'Output/ddc25/ddc25_t{}_v{}.hdf'.format(params[0].value, params[2].value)
fname = f'Output/ddc25/ddc25_t{params[0].value}_v{params[2].value}.hdf'
with pd.HDFStore(fname) as hdf:
hdf.put('wavelength', pd.Series(sim.runner.spectrum.wavelength.value))
hdf.put('lum', pd.Series(sim.runner.spectrum_integrated.luminosity_density_lambda.value))
Expand All @@ -118,7 +130,7 @@ def run_final_models_plus_pickle(params, fname='blondin_model_compare_ddc25.yml'
print(sim.model.v_boundary_inner)
sim.run()
import pickle
dump = 'Output/ddc25/ddc25_t{}_v{}.pickle'.format(params[0].value, params[2].value)
dump = f'Output/ddc25/ddc25_t{params[0].value}_v{params[2].value}.pickle'
with open(dump, 'wb') as dumpfile:
pickle.dump(sim, dumpfile)
return 1
Expand Down
48 changes: 30 additions & 18 deletions 2022/sn_radtrans_compare/run_model_toy01.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def read_blondin_toymodel(fname):
raw_blondin_csv.set_index('idx', inplace=True)

blondin_csv = raw_blondin_csv.loc[:, ['vel', 'dens', 'temp', 'X_56Ni0', 'X_Ti', 'X_Ca', 'X_S', 'X_Si', 'X_O', 'X_C']]
rename_col_dict = {'vel':'velocity', 'dens':'density', 'temp':'t_rad'}
rename_col_dict.update({item:item[2:] for item in blondin_csv.columns[3:]})
rename_col_dict = {
'vel': 'velocity',
'dens': 'density',
'temp': 't_rad',
} | {item: item[2:] for item in blondin_csv.columns[3:]}
rename_col_dict['X_56Ni0'] = 'Ni56'
blondin_csv.rename(columns=rename_col_dict, inplace=True)
blondin_csv.iloc[:, 3:] = blondin_csv.iloc[:,3:].divide(blondin_csv.iloc[:,3:].sum(axis=1), axis=0)
Expand All @@ -47,18 +50,25 @@ def read_blondin_toymodel(fname):
t0_string = t0_pattern.findall(fh.read())[0]

t0 = parse_quantity(t0_string.replace('DAYS', 'day'))
blondin_dict = {}
blondin_dict['model_density_time_0'] = str(t0)
blondin_dict['description'] = 'Converted {0} to csvy format'.format(fname)
blondin_dict['tardis_model_config_version'] = 'v1.0'
blondin_dict_fields = [dict(name='velocity', unit='km/s', desc='velocities of shell outer bounderies.')]
blondin_dict_fields.append(dict(name='density', unit='g/cm^3', desc='mean density of shell.'))
blondin_dict_fields.append(dict(name='t_rad', unit='K', desc='radiative temperature.'))

for abund in blondin_csv.columns[3:]:
blondin_dict_fields.append(dict(name=abund, desc='Fraction {0} abundance'.format(abund)))
blondin_dict['datatype'] = {'fields':blondin_dict_fields}

blondin_dict_fields = [
dict(
name='velocity',
unit='km/s',
desc='velocities of shell outer bounderies.',
),
dict(name='density', unit='g/cm^3', desc='mean density of shell.'),
dict(name='t_rad', unit='K', desc='radiative temperature.'),
]
blondin_dict_fields.extend(
dict(name=abund, desc='Fraction {0} abundance'.format(abund))
for abund in blondin_csv.columns[3:]
)
blondin_dict = {
'model_density_time_0': str(t0),
'description': 'Converted {0} to csvy format'.format(fname),
'tardis_model_config_version': 'v1.0',
'datatype': {'fields': blondin_dict_fields},
}
return blondin_dict, blondin_csv

blondin_dict, blondin_csv = read_blondin_toymodel('snia_toy01.dat')
Expand All @@ -80,8 +90,10 @@ def read_blondin_toymodel(fname):
model_grid = np.array(np.empty((epochs.shape[0]*velocity_grid.shape[0], 3)))
model_grid = []
for i, epoch in enumerate(epochs):
for j, velocity in enumerate(velocity_grid):
model_grid.append((epoch, lbols[i], velocity-2000*u.km/u.s*i))
model_grid.extend(
(epoch, lbols[i], velocity - 2000 * u.km / u.s * i)
for velocity in velocity_grid
)
print(len(model_grid))


Expand All @@ -94,7 +106,7 @@ def run_tardis_model(params):
sim = Simulation.from_config(model_config)
print(sim.model.v_boundary_inner)
sim.run()
fname = 'Output/Toy_01/toy01_t{}_v{}.hdf'.format(params[0].value, params[2].value)
fname = f'Output/Toy_01/toy01_t{params[0].value}_v{params[2].value}.hdf'
with pd.HDFStore(fname) as hdf:
hdf.put('wavelength', pd.Series(sim.runner.spectrum.wavelength.value))
hdf.put('lum', pd.Series(sim.runner.spectrum_integrated.luminosity_density_lambda.value))
Expand All @@ -114,7 +126,7 @@ def run_final_models_plus_pickle(params, fname='blondin_model_compare_01.yml'):
print(sim.model.v_boundary_inner)
sim.run()
import pickle
dump = 'Output/Toy_01/toy01_t{}_v{}.pickle'.format(params[0].value, params[2].value)
dump = f'Output/Toy_01/toy01_t{params[0].value}_v{params[2].value}.pickle'
with open(dump, 'wb') as dumpfile:
pickle.dump(sim, dumpfile)
return 1
Expand Down
48 changes: 30 additions & 18 deletions 2022/sn_radtrans_compare/run_model_toy06.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def read_blondin_toymodel(fname):
raw_blondin_csv.set_index('idx', inplace=True)

blondin_csv = raw_blondin_csv.loc[:, ['vel', 'dens', 'temp', 'X_56Ni0', 'X_Ti', 'X_Ca', 'X_S', 'X_Si', 'X_O', 'X_C']]
rename_col_dict = {'vel':'velocity', 'dens':'density', 'temp':'t_rad'}
rename_col_dict.update({item:item[2:] for item in blondin_csv.columns[3:]})
rename_col_dict = {
'vel': 'velocity',
'dens': 'density',
'temp': 't_rad',
} | {item: item[2:] for item in blondin_csv.columns[3:]}
rename_col_dict['X_56Ni0'] = 'Ni56'
blondin_csv.rename(columns=rename_col_dict, inplace=True)
blondin_csv.iloc[:, 3:] = blondin_csv.iloc[:,3:].divide(blondin_csv.iloc[:,3:].sum(axis=1), axis=0)
Expand All @@ -47,18 +50,25 @@ def read_blondin_toymodel(fname):
t0_string = t0_pattern.findall(fh.read())[0]

t0 = parse_quantity(t0_string.replace('DAYS', 'day'))
blondin_dict = {}
blondin_dict['model_density_time_0'] = str(t0)
blondin_dict['description'] = 'Converted {0} to csvy format'.format(fname)
blondin_dict['tardis_model_config_version'] = 'v1.0'
blondin_dict_fields = [dict(name='velocity', unit='km/s', desc='velocities of shell outer bounderies.')]
blondin_dict_fields.append(dict(name='density', unit='g/cm^3', desc='mean density of shell.'))
blondin_dict_fields.append(dict(name='t_rad', unit='K', desc='radiative temperature.'))

for abund in blondin_csv.columns[3:]:
blondin_dict_fields.append(dict(name=abund, desc='Fraction {0} abundance'.format(abund)))
blondin_dict['datatype'] = {'fields':blondin_dict_fields}

blondin_dict_fields = [
dict(
name='velocity',
unit='km/s',
desc='velocities of shell outer bounderies.',
),
dict(name='density', unit='g/cm^3', desc='mean density of shell.'),
dict(name='t_rad', unit='K', desc='radiative temperature.'),
]
blondin_dict_fields.extend(
dict(name=abund, desc='Fraction {0} abundance'.format(abund))
for abund in blondin_csv.columns[3:]
)
blondin_dict = {
'model_density_time_0': str(t0),
'description': 'Converted {0} to csvy format'.format(fname),
'tardis_model_config_version': 'v1.0',
'datatype': {'fields': blondin_dict_fields},
}
return blondin_dict, blondin_csv

blondin_dict, blondin_csv = read_blondin_toymodel('snia_toy06.dat')
Expand All @@ -79,8 +89,10 @@ def read_blondin_toymodel(fname):
model_grid = np.array(np.empty((epochs.shape[0]*velocity_grid.shape[0], 3)))
model_grid = []
for i, epoch in enumerate(epochs):
for j, velocity in enumerate(velocity_grid):
model_grid.append((epoch, lbols[i], velocity-2000*u.km/u.s*i))
model_grid.extend(
(epoch, lbols[i], velocity - 2000 * u.km / u.s * i)
for velocity in velocity_grid
)
print(len(model_grid))


Expand All @@ -93,7 +105,7 @@ def run_tardis_model(params):
sim = Simulation.from_config(model_config)
print(sim.model.v_boundary_inner)
sim.run()
fname = 'Output/Toy_06/toy06_t{}_v{}.hdf'.format(params[0].value, params[2].value)
fname = f'Output/Toy_06/toy06_t{params[0].value}_v{params[2].value}.hdf'
with pd.HDFStore(fname) as hdf:
hdf.put('wavelength', pd.Series(sim.runner.spectrum.wavelength.value))
hdf.put('lum', pd.Series(sim.runner.spectrum_integrated.luminosity_density_lambda.value))
Expand All @@ -113,7 +125,7 @@ def run_final_models_plus_pickle(params, fname='blondin_model_compare_06.yml'):
print(sim.model.v_boundary_inner)
sim.run()
import pickle
dump = 'Output/Toy_06/toy06_t{}_v{}.pickle'.format(params[0].value, params[2].value)
dump = f'Output/Toy_06/toy06_t{params[0].value}_v{params[2].value}.pickle'
with open(dump, 'wb') as dumpfile:
pickle.dump(sim, dumpfile)
return 1
Expand Down