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

[TEP005][CONFIG] Prevent incompatible configurations #746

Merged
merged 1 commit into from
Jun 20, 2017
Merged
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
67 changes: 41 additions & 26 deletions scripts/tardis
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,46 @@ if args.packet_log_file:
tardis_config = config_reader.Configuration.from_yaml(args.config_fname)
simulation = Simulation.from_config(tardis_config)


def get_integrated_spectrum():
if (
tardis_config.plasma.disable_electron_scattering and
tardis_config.plasma.line_interaction_type == 'downbranch'
):
return simulation.runner.integrator.calculate_spectrum(
simulation.runner.spectrum_frequency[:-1],
1000)
else:
raise config_reader.ConfigurationError(
'The formal integral module currently works only for '
'plasma settings "downbranch" and disabled electron scattering'
'.\nWe got: {}'.format(str(tardis_config.plasma)))


def get_virtual_spectrum():
# Catch warning when acessing invalid spectrum_virtual
with warnings.catch_warnings(record=True) as w:
spectrum = simulation.runner.spectrum_virtual

if len(w) > 0 and w[-1]._category_name == 'UserWarning':
print(
'Virtual spectrum is not available, using the '
'real packet spectrum instead.')
spectrum = simulation.runner.spectrum
return spectrum

print('Saving the {} spectrum.'.format(tardis_config.spectrum.method))

# Believe it or not, that is a fancy switch-case statement
# We need functions so that only one spectrum is accessed so we can catch
# the warning properly
spectrum = {
'real': lambda: simulation.runner.spectrum,
'virtual': get_virtual_spectrum,
'integrated': get_integrated_spectrum,
}[tardis_config.spectrum.method]


if args.gdb:
import os; print(os.getpid()); raw_input() # Workaround to attach gdb
if args.profile:
Expand All @@ -75,29 +115,4 @@ if args.profile:
else:
simulation.run()


def get_integrated_spectrum():
return simulation.runner.integrator.calculate_spectrum(
simulation.runner.spectrum_frequency[:-1],
1000)

# Catch warning when acessing invalid spectrum_virtual
with warnings.catch_warnings(record=True) as w:
print('Saving the {} spectrum.'.format(tardis_config.spectrum.method))

# Believe it or not, that is a fancy switch-case statement
# We need functions so that only one spectrum is accessed so we can catch
# the warning properly
spectrum = {
'real': lambda: simulation.runner.spectrum,
'virtual': lambda: simulation.runner.spectrum_virtual,
'integrated': get_integrated_spectrum,
}[tardis_config.spectrum.method]()

if len(w) > 0 and w[-1]._category_name == 'UserWarning':
print(
'Virtual spectrum is not available, using the '
'real packet spectrum instead.')
spectrum = simulation.runner.spectrum

spectrum.to_ascii(args.spectrum_fname)
spectrum().to_ascii(args.spectrum_fname)