Skip to content

Commit c7bfcbe

Browse files
Nush395Torax team
authored andcommitted
Explicit validator for IMAS core_profiles IDS.
PiperOrigin-RevId: 846714287
1 parent ac76e04 commit c7bfcbe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

torax/_src/imas_tools/input/core_profiles.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,49 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Useful functions to load IMAS core_profiles or plasma_profiles IDSs."""
15+
1516
from collections.abc import Collection, Mapping
17+
import logging
1618
from typing import Any
1719

20+
from imas import ids_structure
1821
from imas import ids_toplevel
1922
import numpy as np
2023
from torax._src import constants
2124

2225

26+
def _validate_profiles_1d(profiles_1d: ids_structure.IDSStructure):
27+
grid = profiles_1d.grid
28+
if not grid.rho_tor_norm.has_value:
29+
raise ValueError("The IDS is missing the grid.rho_tor_norm quantity.")
30+
if not grid.psi.has_value:
31+
logging.warning("The IDS is missing the grid.psi quantity.")
32+
33+
if not profiles_1d.time.has_value:
34+
logging.warning("The IDS is missing the time quantity.")
35+
36+
electrons_ids = profiles_1d.electrons
37+
if not electrons_ids.temperature.has_value:
38+
logging.warning("The IDS is missing the electrons.temperature quantity.")
39+
if not electrons_ids.density.has_value:
40+
logging.warning("The IDS is missing the electrons.density quantity.")
41+
42+
if not profiles_1d.t_i_average.has_value:
43+
logging.warning("The IDS is missing the t_i_average quantity.")
44+
45+
46+
def _validate_profiles_conditions(ids: ids_toplevel.IDSToplevel):
47+
"""Validates the profiles_conditions IDS."""
48+
for profiles_1d in ids.profiles_1d:
49+
_validate_profiles_1d(profiles_1d)
50+
51+
global_quantities = ids.global_quantities
52+
if not global_quantities.v_loop.has_value:
53+
logging.warning("The IDS is missing the v_loop quantity.")
54+
if not global_quantities.ip.has_value:
55+
logging.warning("The IDS is missing the ip quantity.")
56+
57+
2358
# pylint: disable=invalid-name
2459
def profile_conditions_from_IMAS(
2560
ids: ids_toplevel.IDSToplevel,
@@ -38,6 +73,7 @@ def profile_conditions_from_IMAS(
3873
The updated fields read from the IDS that can be used to completely or
3974
partially fill the `profile_conditions` section of a TORAX `CONFIG`.
4075
"""
76+
_validate_profiles_conditions(ids)
4177
profiles_1d, rhon_array, time_array = _get_time_and_radial_arrays(
4278
ids, t_initial
4379
)

0 commit comments

Comments
 (0)