diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 30518e8b1be..90543314387 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -317,6 +317,7 @@ 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 Validation # Only Valid for Tardis Config File # Not Valid for CSVY File Config @@ -344,36 +345,58 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""): f"Inner Boundary Velocity = {v_inner_boundary} \n" f"Outer Boundary Velocity = {v_outer_boundary}" ) - - if model_section["structure"]["density"]["type"] == "exponential": - time_0 = model_section["structure"]["density"]["time_0"] - rho_0 = model_section["structure"]["density"]["rho_0"] - v_0 = model_section["structure"]["density"]["v_0"] - if not time_0.value > 0: - raise ValueError(f"Time Specified is Invalid, {time_0}") - if not rho_0.value > 0: - raise ValueError(f"Density Specified is Invalid, {rho_0}") - if not v_0.value > 0: - raise ValueError(f"Velocity Specified is Invalid, {v_0}") - elif model_section["structure"]["density"]["type"] == "power_law": - time_0 = model_section["structure"]["density"]["time_0"] - rho_0 = model_section["structure"]["density"]["rho_0"] - v_0 = model_section["structure"]["density"]["v_0"] - if not time_0.value > 0: - raise ValueError(f"Time Specified is Invalid, {time_0}") - if not rho_0.value > 0: - raise ValueError(f"Density Specified is Invalid, {rho_0}") - if not v_0.value > 0: - raise ValueError(f"Velocity Specified is Invalid, {v_0}") - elif model_section["structure"]["density"]["type"] == "uniform": - time_0 = model_section["structure"]["density"]["time_0"] - value = model_section["structure"]["density"]["value"] - if not time_0.value > 0: - raise ValueError(f"Time Specified is Invalid, {time_0}") - if not value.value > 0: - raise ValueError( - f"Density Value Specified is Invalid, {value}" - ) + if "density" in model_section["structure"].keys(): + if ( + model_section["structure"]["density"]["type"] + == "exponential" + ): + rho_0 = model_section["structure"]["density"]["rho_0"] + v_0 = model_section["structure"]["density"]["v_0"] + if not rho_0.value > 0: + raise ValueError( + f"Density Specified is Invalid, {rho_0}" + ) + if not v_0.value > 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 not time_0.value > 0: + 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 not rho_0.value > 0: + raise ValueError( + f"Density Specified is Invalid, {rho_0}" + ) + if not v_0.value > 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 not time_0.value > 0: + raise ValueError( + f"Time Specified is Invalid, {time_0}" + ) + elif model_section["structure"]["density"]["type"] == "uniform": + value = model_section["structure"]["density"]["value"] + if not value.value > 0: + raise ValueError( + f"Density Value Specified is Invalid, {value}" + ) + if "time_0" in model_section["structure"]["density"].keys(): + time_0 = model_section["structure"]["density"]["time_0"] + if not time_0.value > 0: + raise ValueError( + f"Time Specified is Invalid, {time_0}" + ) # SuperNova Section Validation supernova_section = validated_config_dict["supernova"]