@@ -164,10 +164,10 @@ def plasma_composition_from_IMAS(
164164 # value set to hydrogenic ions.
165165 if main_ions_symbols is None :
166166 main_ions_symbols = constants .HYDROGENIC_IONS
167- validate_main_ions = False
167+ # main_ions_symbols explicitly provided: validate ions presence in IDS.
168168 else :
169- validate_main_ions = True
170- _validate_ids_ions (parsed_ions , main_ions_symbols , validate_main_ions )
169+ _validate_main_ions_presence ( parsed_ions , main_ions_symbols )
170+ _validate_ids_ions (parsed_ions )
171171
172172 Z_eff = (
173173 time_array ,
@@ -233,11 +233,8 @@ def _get_time_and_radial_arrays(
233233
234234def _validate_ids_ions (
235235 parsed_ions : list [str ],
236- main_ion_symbols : Collection [str ],
237- validate_main_ions : bool ,
238236) -> None :
239- """Check if all ions are recognized and expected_main_ions present in the IDS."""
240- # Check if IDS ion symbol is valid.
237+ """Checks if all parsed ions are recognized."""
241238 for ion in parsed_ions :
242239 # ion is casted to str to avoid issues with imas string types.
243240 if str (ion ) not in constants .ION_PROPERTIES_DICT .keys ():
@@ -247,21 +244,26 @@ def _validate_ids_ions(
247244 "typing or add the ion to the excluded_impurities."
248245 )
249246 )
250- # Check presence of main_ion_symbols in the IDS if explicitly provided.
251- if validate_main_ions :
252- for ion in main_ion_symbols :
253- if ion not in constants .ION_PROPERTIES_DICT .keys ():
254- raise (
255- KeyError (
256- f"{ ion } is not a valid symbol of a TORAX valid ion. Please"
257- " check typing of main_ion_symbols."
258- )
259- )
260- if ion not in parsed_ions :
261- raise (
262- ValueError (
263- f"The expected main ion { ion } cannot be found in the input"
264- " IDS or has no valid data. \n Please check that the IDS is"
265- " properly filled"
266- )
267- )
247+
248+
249+ def _validate_main_ions_presence (
250+ parsed_ions : list [str ],
251+ main_ion_symbols : Collection [str ],
252+ ) -> None :
253+ """Checks that items in main_ion_symbols are present in the IDS."""
254+ for ion in main_ion_symbols :
255+ if ion not in constants .ION_PROPERTIES_DICT .keys ():
256+ raise (
257+ KeyError (
258+ f"{ ion } is not a valid symbol of a TORAX valid ion. Please"
259+ " check typing of main_ion_symbols."
260+ )
261+ )
262+ if ion not in parsed_ions :
263+ raise (
264+ ValueError (
265+ f"The expected main ion { ion } cannot be found in the input"
266+ " IDS or has no valid data. \n Please check that the IDS is"
267+ " properly filled"
268+ )
269+ )
0 commit comments