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

Moves non-physical input check outsode I/O module #2923

Merged
merged 10 commits into from
Jan 8, 2025
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Stuart Sim <[email protected]> ssim <[email protected]>
Stuart Sim <[email protected]> Stuart Sim <[email protected]>
Stuart Sim <[email protected]> Stuart Sim <[email protected]>

Swayam Shah <[email protected]> Sonu0305 <[email protected]>

TARDIS Bot <[email protected]>
TARDIS Bot <[email protected]> tardis-bot <[email protected]>
TARDIS Bot <[email protected]> TARDIS Bot <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ owner = "tardis-sn"
repo = "tardis"

[tool.codespell]
skip = "*.png,*.ggb,*.jpg,*.gif,*.ico,docs/contributing/CHANGELOG.md,docs/tardis.bib"
skip = "*.ipynb,*.png,*.ggb,*.jpg,*.gif,*.ico,docs/contributing/CHANGELOG.md,docs/tardis.bib,docs/resources/research_done_using_TARDIS/research_papers.rst"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change included?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid codespell job failure like it is mentioned in #2908 but it is not merged yet, hence included in this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PR should ideally have only one purpose, and this will lead to merge conflicts that must be resolved once #2908 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got your point, will make sure this does not repeat.

quiet-level = 3
8 changes: 2 additions & 6 deletions tardis/io/model/parse_radiation_field_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
parse_structure_from_config,
)
from tardis.plasma.radiation_field import DilutePlanckianRadiationField
from tardis.physics.radiation_field import validate_radiative_temperature

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -113,12 +114,7 @@ def parse_radiation_field_state_from_csvy(
geometry, packet_source
)

if np.any(t_radiative < 1000 * u.K):
logging.critical(
"Radiative temperature is too low in some of the shells, temperatures below 1000K "
f"(e.g., T_rad = {t_radiative[np.argmin(t_radiative)]} in shell {np.argmin(t_radiative)} in your model) "
"are not accurately handled by TARDIS.",
)
validate_radiative_temperature(t_radiative)

if hasattr(csvy_model_data, "columns") and (
"dilution_factor" in csvy_model_data.columns
Expand Down
31 changes: 31 additions & 0 deletions tardis/physics/radiation_field.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should validation be in a directory called "physics"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood the title of #2681, 'Move ... to a physics module,' as meaning to move it to a physics directory (module). Sorry if I misunderstood.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. The term was meant generically, because most of TARDIS consists of modules that calculate physics. Thus these checks should be placed in the most relevant pre-existing module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay understood, I'll make the necessary changes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
import numpy as np
from astropy import units as u

logger = logging.getLogger(__name__)

def validate_radiative_temperature(t_radiative):
"""
Validates the radiative temperature to ensure it is physically reasonable.

Parameters
----------
t_radiative : Quantity
The radiative temperature array.

Raises
------
ValueError
If any radiative temperature is below 1000 K.
"""
if np.any(t_radiative < 1000 * u.K):
min_t_rad = t_radiative[np.argmin(t_radiative)]
min_shell = np.argmin(t_radiative)
logging.critical(
"Radiative temperature is too low in some of the shells, temperatures below 1000K "
f"(e.g., T_rad = {min_t_rad} in shell {min_shell} in your model) "
"are not accurately handled by TARDIS."
)
raise ValueError(
f"Radiative temperature below 1000 K detected: T_rad = {min_t_rad} in shell {min_shell}."
)
Loading