@@ -26,8 +26,17 @@ 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
30- rhoAsh = 0
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+
38+ rho = data ["boxlib" , "density" ]
39+ rhoAsh = rho * 0.0
3140 for f in field_list :
3241 # If the first two letters are "X(", then we're dealing with species massfractions
3342 if f [1 ][:2 ] == "X(" :
@@ -36,8 +45,8 @@ def _ash(field, data):
3645 nuc = pyna .Nucleus (speciesName )
3746
3847 # Include elements beyond oxygen but don't include Ni56
39- if nuc .Z > 8.0 and nuc .Z != 56 :
40- rhoAsh += data [ "boxlib" , "density" ] * data [f ]
48+ if nuc .Z > 8.0 and nuc .Z != 28 :
49+ rhoAsh += rho * data [f ]
4150
4251 return rhoAsh
4352
@@ -319,9 +328,10 @@ def slice(fnames:list[str], fields:list[str],
319328 show_full_star = show_full_star )
320329
321330 #add rhoX_ash as a derived field
322- ds .add_field (("gas" , "ash" ), function = _ash ,
323- display_name = r"\rho X\left(ash\right)" ,
324- 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" )
325335
326336 for i , field in enumerate (fields ):
327337 # Plot each field parameter
0 commit comments