Skip to content

Commit 50b5b7b

Browse files
committed
add runtime error if no X(...) found in plotfile
1 parent 51c3fd9 commit 50b5b7b

File tree

1 file changed

+13
-4
lines changed
  • Exec/science/xrb_spherical/analysis

1 file changed

+13
-4
lines changed

Exec/science/xrb_spherical/analysis/slice.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ def _ash(field, data):
2626
if ("boxlib", "X(ash)") in field_list:
2727
return data["boxlib", "X(ash)"] * data["boxlib", "density"]
2828

29-
# If we cannot find X(ash) as a available field then compute manually
29+
# If we cannot find X(ash) as a available field then compute manually.
30+
# First check if the plotfile has massfractions -- i.e. using plt not smallplt
31+
has_species = any(f[1].startswith("X(") for f in field_list)
32+
if not has_species:
33+
raise RuntimeError(
34+
"Derived field 'ash' requires species mass fractions X(nuc), "
35+
"but no X(...) fields were found in this plotfile."
36+
)
37+
3038
rho = data["boxlib", "density"]
3139
rhoAsh = rho * 0.0
3240
for f in field_list:
@@ -320,9 +328,10 @@ def slice(fnames:list[str], fields:list[str],
320328
show_full_star=show_full_star)
321329

322330
#add rhoX_ash as a derived field
323-
ds.add_field(("gas", "ash"), function=_ash,
324-
display_name=r"\rho X\left(ash\right)",
325-
units="auto", sampling_type="cell")
331+
if "ash" in fields:
332+
ds.add_field(("gas", "ash"), function=_ash,
333+
display_name=r"\rho X\left(ash\right)",
334+
units="auto", sampling_type="cell")
326335

327336
for i, field in enumerate(fields):
328337
# Plot each field parameter

0 commit comments

Comments
 (0)