Skip to content

Commit

Permalink
Moves non-physical input check outsode I/O module (#2923)
Browse files Browse the repository at this point in the history
* moves non-physical input check

* fixes codespell failure as in #2908

* updated mailmap

* fixes codespell failure as in #2908

* made necessary changes to path

* Revert "fixes codespell failure as in #2908"

This reverts commit aa7a3ed.

* Revert "fixes codespell failure as in #2908"

This reverts commit 1a1d8b9.

* Rename test_radiation_field.py to validate_radiation_field.py

* Update parse_radiation_field_configuration.py
  • Loading branch information
Sonu0305 authored Jan 8, 2025
1 parent 7e37d5f commit 4d9f61f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
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 <s.sim@qub.ac.uk> ssim <ssim@users.noreply.github.com>
Stuart Sim <s.sim@qub.ac.uk> Stuart Sim <ssim@mso.anu.edu.au>
Stuart Sim <s.sim@qub.ac.uk> Stuart Sim <stuartsim@bashir.pst.qub.ac.uk>

Swayam Shah <swayamshah66@gmail.com> Sonu0305 <swayamshah66@gmail.com>

TARDIS Bot <tardis.sn.bot@gmail.com>
TARDIS Bot <tardis.sn.bot@gmail.com> tardis-bot <tardis.sn.bot@gmail.com>
TARDIS Bot <tardis.sn.bot@gmail.com> TARDIS Bot <wkerzendorf+tardis@gmail.com>
Expand Down
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.radiation_field.validate_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/radiation_field/validate_radiation_field.py
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}."
)

0 comments on commit 4d9f61f

Please sign in to comment.