Skip to content

Commit

Permalink
blackify
Browse files Browse the repository at this point in the history
  • Loading branch information
wkerzendorf committed Jul 18, 2023
1 parent b9f2fb2 commit 4ac0f43
Showing 1 changed file with 23 additions and 49 deletions.
72 changes: 23 additions & 49 deletions tardis/io/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""):
if "csvy_model" in validated_config_dict.keys():
pass
elif "model" in validated_config_dict.keys():

model_section = validated_config_dict["model"]
Configuration.validate_model_section(model_section)
# SuperNova Section Validation
Expand Down Expand Up @@ -304,12 +303,16 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""):
)

spectrum_section = validated_config_dict["spectrum"]
Configuration.validate_spectrum_section(spectrum_section, montecarlo_section["enable_full_relativity"])
Configuration.validate_spectrum_section(
spectrum_section, montecarlo_section["enable_full_relativity"]
)

return cls(validated_config_dict)

@staticmethod
def validate_spectrum_section(spectrum_section, enable_full_relativity=False):
def validate_spectrum_section(
spectrum_section, enable_full_relativity=False
):
"""
Validate the spectrum section dictionary
Expand All @@ -318,7 +321,6 @@ def validate_spectrum_section(spectrum_section, enable_full_relativity=False):
spectrum_section : dict
"""
# Spectrum Section Validation


start = spectrum_section["start"]
stop = spectrum_section["stop"]
Expand All @@ -328,26 +330,24 @@ def validate_spectrum_section(spectrum_section, enable_full_relativity=False):
f"Start : {start} \n"
f"Stop : {stop}"
)

spectrum_integrated = (
spectrum_section["method"] == "integrated"
)

spectrum_integrated = spectrum_section["method"] == "integrated"
if enable_full_relativity and spectrum_integrated:
raise NotImplementedError(
"The spectrum method is set to 'integrated' and "
"enable_full_relativity to 'True'.\n"
"The FormalIntegrator is not yet implemented for the full "
"relativity mode. "
)

@staticmethod
def validate_model_section(model_section):
"""
Parse the model section dictionary
Parameters
----------
model_section : dict
"""

Expand All @@ -361,58 +361,37 @@ def validate_model_section(model_section):
f"Stop Velocity = {stop_velocity}"
)
elif model_section["structure"]["type"] == "file":
v_inner_boundary = model_section["structure"][
"v_inner_boundary"
]
v_outer_boundary = model_section["structure"][
"v_outer_boundary"
]
v_inner_boundary = model_section["structure"]["v_inner_boundary"]
v_outer_boundary = model_section["structure"]["v_outer_boundary"]
if v_outer_boundary.value < v_inner_boundary.value:
raise ValueError(
"Outer Boundary Velocity Cannot Be Less than Inner Boundary Velocity. \n"
f"Inner Boundary Velocity = {v_inner_boundary} \n"
f"Outer Boundary Velocity = {v_outer_boundary}"
)
if "density" in model_section["structure"].keys():
if (
model_section["structure"]["density"]["type"]
== "exponential"
):
if model_section["structure"]["density"]["type"] == "exponential":
rho_0 = model_section["structure"]["density"]["rho_0"]
v_0 = model_section["structure"]["density"]["v_0"]
if rho_0.value <= 0:
raise ValueError(
f"Density Specified is Invalid, {rho_0}"
)
raise ValueError(f"Density Specified is Invalid, {rho_0}")
if v_0.value <= 0:
raise ValueError(
f"Velocity Specified is Invalid, {v_0}"
)
raise ValueError(f"Velocity Specified is Invalid, {v_0}")
if "time_0" in model_section["structure"]["density"].keys():
time_0 = model_section["structure"]["density"]["time_0"]
if time_0.value <= 0:
raise ValueError(
f"Time Specified is Invalid, {time_0}"
)
elif (
model_section["structure"]["density"]["type"] == "power_law"
):
raise ValueError(f"Time Specified is Invalid, {time_0}")
elif model_section["structure"]["density"]["type"] == "power_law":
rho_0 = model_section["structure"]["density"]["rho_0"]
v_0 = model_section["structure"]["density"]["v_0"]
if rho_0.value <= 0:
raise ValueError(
f"Density Specified is Invalid, {rho_0}"
)
raise ValueError(f"Density Specified is Invalid, {rho_0}")
if v_0.value <= 0:
raise ValueError(
f"Velocity Specified is Invalid, {v_0}"
)
raise ValueError(f"Velocity Specified is Invalid, {v_0}")
if "time_0" in model_section["structure"]["density"].keys():
time_0 = model_section["structure"]["density"]["time_0"]
if time_0.value <= 0:
raise ValueError(
f"Time Specified is Invalid, {time_0}"
)
raise ValueError(f"Time Specified is Invalid, {time_0}")
elif model_section["structure"]["density"]["type"] == "uniform":
density = model_section["structure"]["density"]["value"]
if density.value <= 0:
Expand All @@ -422,9 +401,7 @@ def validate_model_section(model_section):
if "time_0" in model_section["structure"]["density"].keys():
time_0 = model_section["structure"]["density"]["time_0"]
if time_0.value <= 0:
raise ValueError(
f"Time Specified is Invalid, {time_0}"
)
raise ValueError(f"Time Specified is Invalid, {time_0}")

@staticmethod
def validate_montecarlo_section(montecarlo_section):
Expand Down Expand Up @@ -453,8 +430,6 @@ def validate_montecarlo_section(montecarlo_section):
'convergence_strategy is not "damped" ' 'or "custom"'
)



@staticmethod
def parse_convergence_section(convergence_section_dict):
"""
Expand Down Expand Up @@ -482,7 +457,6 @@ def parse_convergence_section(convergence_section_dict):
] = convergence_section_dict[param]

return convergence_section_dict


def __init__(self, config_dict):
super(Configuration, self).__init__(config_dict)
Expand Down

0 comments on commit 4ac0f43

Please sign in to comment.