nugridpy.nugridse

nugridse is a collection of plots of data in se-type h5 files.

Usage

start by loading the module,

>>> import nugridse as mp

you can get help,

>>> help mp

next, initiate a se class instance,

>>> pt=mp.se('path/to/dir/with/se-files')

which would read all h5 files from the current directory; again, do help(mp.se) or mp.se? To get info for more options, as for example how to specify a match pattern to select only certain files in the directory; this may be useful if there are very many files and you want only every 10th. For example,

>>> pt =mp.se('.','M1.65Z0.020.00')
Note: Initializing an instance with 120 files with 1000 packets each may take 3-4 minutes, which is too long for many people, therefore the initialization module will generate and write an index file. If such an index file is present initialization will take less then a second. The initialization module will automatically detect various situations in which the index file needs to be rewritten, for example if there is a new file.

look at the data that is available in your instance,

>>> pt.sedir
>>> pt.sefiles

The actual data is in pt.se and the following commands give you access to header and cycle attributes as well as the cycle profile data:

>>> pt.se.cattrs
>>> pt.se.hattrs
>>> pt.se.dcols

Available cycles can be viewed with,

>>> pt.se.cycles

You can get any of the quantities via the ‘get’ method, which is relatively smart to give you things in various ways.

>>> pt.get('rho')

would give you all rho vectors for all cycles, which is maybe more than you want, so try

>>> pt.get(300,'rho')

to get the rho vector for cycle 300. Instead of one cycle you may also supply a cycle list for the first argument.

Use help(pt) (or whatever you instance is) for a full description of what else your instance has to offer, which includes methods to work with data.

Note: A particularly nice feature is that you can work with instances of different types of data in a very flexible way, for example in lists:

>>> cases=[pt1,pt2,pt3]
>>> for this_case in cases:
...    do something with this_case

There are various plotting methods, including plotting abundance charts (abu_chart), isotopic abundance distributions and the generic ‘plot’ method that lets you plot every quantity against any other quantity that can possibly be plotted. Some of the methods (including the three just mentioned) are available via the super class data_plot, and are equally available in other python modules, as for example mesa.py or ppn.py. Several methods accept lists of cycles which implies to create a series of frames to be written to disk in order to make movies.

>>> pt.plot('mass','rho',fname=3000)

whereas,

>>> pt.plot('mass','rho',fname=[3000,4000])

will produce two png files, one for each cycle, do help(m.plot) for a full list of options.

mppnp output allows to do plots with abundances:

>>> pt.iso_abund(23500)
>>> pt.abu_chart(23500)

Also for iso_abund and abu_chart: if instead of a single cycle the user inputs a list of cycles, the method will then, instead of plotting them, will then save a .png for each cycle. Also if you just want a singular plot saved, the user can input their cycle, in a list like [0]. And that will save their plot.

Functions

set_nice_params()
set_nugrid_path(path) This function sets the path to the NuGrid VOSpace directory as a global variable, so that it need only be set once during an inter- active session.

Classes

se([sedir, pattern, rewrite, mass, Z, type, …]) This class provides easy access to h5 files from the NuGrid project, along with some standard plots.
class nugridpy.nugridse.se(sedir='.', pattern='.h5', rewrite=False, mass=None, Z=None, type='ppd_wind', output='out', code_source='MES', exp_type='delay', data_set='set1ext', verbose=False)

This class provides easy access to h5 files from the NuGrid project, along with some standard plots.

Parameters:
  • sedir (string, optional) – The directory on which the h5 files can be found. The default is ‘.’.
  • pattern (string, optional) – A string pattern that the file names have to contain in order to be read. The default is “.h5”.
  • rewrite (boolean, optional) – Would the user like to rewrite the preprocessor file. The default is False.
  • mass (integer or float, optional) – The user may select a mass and metallicity instead of providing the sedir explicitly, if they are using the VOSpace data. If mass is provided then Z should also be provided. The default is None (i.e. user gives sedir explicitly)
  • Z (float, optional) – See ‘mass’ above. The default is None (i.e. user gives sedir explicitly)
  • type (string, optional) – If the user gives mass and metallicity instead of giving sedir explicitly, then the type of data should also be given here. For example, type=’ppd_wind’, ‘see_wind’, see_exp’ or ‘ppd_exp’ The default is ‘ppd_wind’.
  • output (string, optional) – If the user gives mass and metallicity instead of giving sedir explicitly, then the type of data should also be given here. For example, out=’restart’, ‘out’ or ‘surf’ The default is ‘out’.
  • data_set (string, optional) – Coose your data of ‘set1’ or ‘set1ext’. The default is ‘set1ext’.
  • exp_type – If type is ‘see_exp’ or ‘ppd_exp’ runs of exp_type are selected. For example ‘delay’ and ‘rapid’ would be choices for Set1.
  • verbose (boolean, optional) – If True, print more output

Examples

>>> f=nu.plot_tools('.','260')

reads all h5 files with the string 260 in the name in the present directory.

abund_at_masscoordinate(ini, mass_coo, online=False)

Create a file with distribution at a given mass coord, and at a given time step.

This for instance may be used as intial distribution for function trajectory, to reproduce local conditions in ppn.

Parameters:
  • ini (integer) – Initial model, inital cycle number.
  • mass_coo (float or 1x2 list) – Mass coordinate for the traj. If list, return mass-averaged abundances for the region spanned by the list.
  • online (boolean, optional) – are you working online in the ipython notebook? If so, you will be given an HTML link to download the file.
abup_se_plot(mod, species)

plot species from one ABUPP file and the se file.

You must use this function in the directory where the ABP files are and an ABUP file for model mod must exist.

Parameters:
  • mod (integer) – Model to plot, you need to have an ABUPP file for that model.
  • species (string) – The species to plot.

Notes

The species is set to ‘C-12’.

average_iso_abund_marco(mass_range, cycle, stable, i_decay)

Interface to average over mass_range.

Parameters:
  • mass_range (list) – A 1x2 array required to plot data in a certain mass range. Needed for _read_iso_abund_marco.
  • cycle (integer) – which cycle from the h5 file?. Needed for _read_iso_abund_marco
  • stable (boolean) – Do you want to plot only stable or not.
  • i_decay (integer) – If i_decay is 1, then plot not decayed. If i_decay is 2, then plot decayed. Make sense only if stable is true.

See also

_read_iso_abund_marco()

burnstage(**keyw)

This function calculates the presence of burning stages and outputs the ages when key isotopes are depleted and uses them to calculate burning lifetimes.

Parameters:keyw (dict) – A dict of key word arguments.
Returns:A list containing the following information: burn_cycles, burn_ages, burn_abun, burn_type and burn_lifetime.
Return type:list

Notes

The following keywords can also be used:

Keyword Argument Default Value
abund “iso_massf”
isoa “A”
isoz “Z”
mass “mass”
cycle “cycle”
cyclefin 0

All arguments change the name of fields used to read data from HDF5 files, other than cyclefin. Cyclefin is the last timestep to use when reading files.

Cycles contain the cycle numbers for the various points where the abundance is abun. The age of the star at each point and the type of burning is indicated by those arrays. The lifetimes are calculated by.

burnstage_upgrade(**keyw)

This function calculates the presence of burning stages and outputs the ages when key isotopes are depleted and uses them to calculate burning lifetimes.

Parameters:keyw (dict) – A dict of key word arguments.
Returns:A list containing the following information: burn_cycles, burn_ages, burn_abun, burn_type and burn_lifetime.
Return type:list

Notes

The following keywords can also be used:

Keyword Argument Default Value
abund “iso_massf”
isoa “A”
isoz “Z”
mass “mass”
cycle “cycle”
cyclefin 0

All arguments change the name of fields used to read data from HDF5 files, other than cyclefin. Cyclefin is the last timestep to use when reading files.

Cycles contain the cycle numbers for the various points where the abundance is abun. The age of the star at each point and the type of burning is indicated by those arrays. The lifetimes are calculated by.

cores(incycle, **keyw)

This function uses the abundances as a function of time to return core masses.

Parameters:
  • incycle (integer) – incycle is the cycle to choose where to take the core masses.
  • keyw (dict) – A dict of key word arguments.
Returns:

[cores, core_type, core_info] cores contains the core masses for the types found in core_type. Core_info stores a variety of information about the abundances at certain mass coordinates.

Return type:

list

Notes

These core masses are:

M_alpha mass of the helium core
M_CO mass of the carbon-oxygen core
M_si mass of the silicon core
M_fe mass of the iron core
M_rem mass of the remnant star post-supernova

The following keywords can also be used:

Keyword Argument Default Value
abund “iso_massf”
isoa “A”
isom “isomeric_state”
isoz “Z”
mass “mass”
core_opt 1

All arguments change the name of fields used to read data from HDF5 files, other than core_opt. core_opt controls which scheme to use for calculating the core masses.

If core_opt is 0, then cores uses alpha-isotopes to calculate the silicon and iron cores. Use this for stellar evolution output.

Si_core = Si28+S32+Ar36+Ca40+Ti44

Fe_core = Cr48+Fe52+Ni56

If core_opt is 1, then cores uses all elements in a network with proton number Z=23 as a boundary. Use this for MPPNP output.

Si_core = Sum of all isotopes with 14 <= Z <= 22

Fe_core = Sum of all isotopes with 23 <= Z <= 28

decay(mass_frac)

this module simply calculate abundances of isotopes after decay.

It requires that before it is used a call is made to _read_iso_abund_marco and _stable_species.

Parameters:mass_frac (list) – alist of mass_frac dicts.

See also

_read_iso_abund_marco(), nuutils.Utils._stable_species()

ernst_table_exporter(cycle, outfname='table_out', sheetname='Sheet 1')

This routine takes NuGrid data (model output) for a given cycle and writes it into an Excel sheet.

This is one format as requested by Ernst Zinner in June 2013 (through Marco). If you want all radioactive isotopes, start from the restart file. Empty columns are not written out and you will get a message how many were empty. Please note that only one cycle is written out.

Parameters:
  • cycle (integer) – Number of the cycle to consider.
  • outfname (string, optional) – File name to write it to, .xlsx is appended automatically. The default is ‘table_out’.
  • sheetname (string, optional) – Name of the sheet in the excel file. The default is ‘Sheet 1’.
get(cycle_list, dataitem=None, isotope=None, sparse=1)

Simple function that simply calls h5T.py get method. There are three ways to call this function.

Parameters:
  • cycle_list (string, list) –

    If cycle_list is a string, then get interpates the argument cycle_list as a dataitem and fetches the dataitem for all cycles.

    If cycle_list is a list, then get fetches the dataitem for the cycles in the list.

  • dataitem (string, optional) –

    fetches the dataitem from the list of cycles. If dataitem is None, then cycle_list must be a string and will be used as dataitem. If dataitem is an isotope in the form ‘H-2’, it then returns the result of,

    >>> self.get(cycle_list,'iso_massf',dataitem)
    

    The default is None.

  • isotope (string, optional) – The name of the isotope to fetch, it must be in the form ‘H-2’. If isotope is None, then cycle_list or dataitem must be a string. The default is None.
  • sparse (integer, optional) – Implements a sparsity factor on the fetched data. The default is 1.

Notes

Calling the get method directly in the form,

>>> self.get(cycle_list,'iso_massf',dataitem)

is depricated, and only included for compatibility.

get_abundance_elem(cycle)

returns the undecayed element profile (all elements that are in elem_names).

Parameters:cycle (integer) – The cycle number
get_abundance_iso_decay(cycle)

returns the decayed stable isotopes.

Parameters:cycle (integer) – The cycle.
get_decayed(cycle_list, dataitem=None, isotope=None, sparse=1)

This function gives back the fully decayed isotope.

By default, it wants to beta-decays every isotope, however, it then checks if this is okay or not. If not it actually goes into a database (see routine below) to do the proper decay. This database might not be complete, so pay attention to the chart of the nuclides.

Standard input is as in regular get function.

Parameters:
  • cycle_list (string, list) –

    If cycle_list is a string, then get interpates the argument cycle_list as a dataitem and fetches the dataitem for all cycles.

    If cycle_list is a list, then get fetches the dataitem for the cycles in the list.

  • dataitem (string, optional) –

    fetches the dataitem from the list of cycles. If dataitem is None, then cycle_list must be a string and will be used as dataitem. If dataitem is an isotope in the form ‘H-2’, it then returns the result of,

    >>> self.get(cycle_list,'iso_massf',dataitem)
    

    The default is None.

  • isotope (string, optional) – The name of the isotope to fetch, it must be in the form ‘H-2’. If isotope is None, then cycle_list or dataitem must be a string. The default is None.
  • sparse (integer, optional) – Implements a sparsity factor on the fetched data. The default is 1.

Notes

Additional features are:

IN PROGRESS: CONTACT RETO: trappitsch@uchicago.edu

Calling the get method directly in the form,

>>> self.get_decayed(cycle_list,'iso_massf',dataitem)

is depricated, and only included for compatibility.

get_elemental_abunds(cycle, index=None)

returns the elemental abundances for one cycle, either for the whole star or a specific zone depending upon the value of ‘index’.

Parameters:
  • cycle (string or integer) – Model to get the abundances for.
  • index (integer or list, optional) – zone number for which to get elemental abundances. If None the entire abundance profile is returned. If a 1x2 list, the abundances are returned between indices of index[0] and index[1]. The default is None.
kip_cont(modstart, modstop, dcoeff_thresh=1000000000000.0, xres=1000, ylims=[0.0, 0.0], xlims=[0.0, 0.0], yres=2000, ixaxis='log_time_left', outfile='', landscape_plot=False, codev='KEP', kepswitch=12555, outlines=False, write_preproc=False, hatching=False)

This function creates a Kippenhahn diagram as a contour plot of the se output using a convection flag or diffusion coefficient threshold.

Parameters:
  • modstop (modstart,) – First and last cycle numbers to plot.
  • dcoeff_thresh (float, optional) – Diffusion coefficient threshold, above which assume convection is present (only for MESA, where convection_indicator is not there)). The default is 1.e12.
  • yres (xres,) – x and y resolution. The default for xres is 1000, the default for yres is 2000.
  • ylims (xlims,) – x and y plot limits. The default is [0., 0.].
  • ixaxis (string, optional) – Choose one of ‘age’, ‘model_number’ or ‘log_time_left’. The default is ‘log_time_left’.
  • outfile (string, optional) – Name of output file including extension, which will be saved in 300 dpi. The default is ‘’.
  • landscape_plot (boolean, optional) – For a landscape plot. The default is False.
  • codev (string, optional) – Coose one of ‘KEP’, ‘MES’ or ‘GNV’. The default is ‘KEP’.
  • kepswitch (integer, optional) – The default is 12555.
  • outlines (boolean, optional) – The default is False.
  • write_preproc (boolean, optional) – The default is False.
  • hatching (boolean, optional) – The default if False.

Examples

>>> pt.kip_cont(0, -1, xres=1000, yres=1000, ixaxis='log_time_left')

Notes

Unfortunately, although the implicit do loops are faster, I cannot implement a % bar, but this example call should not take more than 1 minute.

plot4(num)

Plots the abundances of H-1, He-4, C-12 and O-16.

plot4_nolog(num)

Plots the abundances of H-1, He-4, C-12 and O-16.

plot_prof_1(mod, species, xlim1, xlim2, ylim1, ylim2, symbol=None)

plot one species for cycle between xlim1 and xlim2

Parameters:
  • mod (string or integer) – Model to plot, same as cycle number.
  • species (list) – Which species to plot.
  • xlim2 (xlim1,) – Mass coordinate range.
  • ylim2 (ylim1,) – Mass fraction coordinate range.
  • symbol (string, optional) – Which symbol you want to use. If None symbol is set to ‘-‘. The default is None.
plot_prof_2(mod, species, xlim1, xlim2)

Plot one species for cycle between xlim1 and xlim2

Parameters:
  • mod (string or integer) – Model to plot, same as cycle number.
  • species (list) – Which species to plot.
  • xlim2 (xlim1,) – Mass coordinate range.
plot_prof_sparse(mod, species, xlim1, xlim2, ylim1, ylim2, sparse, symbol)

plot one species for cycle between xlim1 and xlim2.

Parameters:
  • species (list) – which species to plot.
  • mod (string or integer) – Model (cycle) to plot.
  • xlim2 (xlim1,) – Mass coordinate range.
  • ylim2 (ylim1,) – Mass fraction coordinate range.
  • sparse (integer) – Sparsity factor for points.
  • symbol (string) – which symbol you want to use?
presnyields(*cycles, **keyw)

This function calculates the presupernova yields of a full structure profile from a remnant mass, mrem, to the surface.

Parameters:
  • cycles (variadic tuple) – cycle[0] is the cycle to perform the presupernova yields calculations on. If cycle[1] is also specified, the yields are outputted using ‘initial’ abundances from cycle[1], otherwise the ejected masses are outputted.
  • keyw (dict) – A dict of key word arguments.

Notes

The following keywords can be used:

Keyword Argument Default Value
abund “iso_massf”
xm “mass”
mrem 0

abund and xm are used when the variables within the input file differ in their names. The default values are set to the output typically found in an MPPNP output file. For example, if the table for the abundances is called “abundances” instead of the default value, use abund = “abundances” as a keyword argument.

mrem is specified using a keyword argument and tells the program where to begin integrating.

trajectory(ini, end, delta, mass_coo, age_in_sec=False, online=False)

create a trajectory out of a stellar model

Parameters:
  • ini (integer) – Initial model, inital cycle number.
  • end (integer) – Final model, final cycle number.
  • delta (integer) – Sparsity factor of the frames.
  • mass_coo (float) – Mass coordinate for the traj.
  • age_in_sec (boolean, optional) – Set to True if age in se file is in seconds (like in MESA). The default is False.
Returns:

radius_at_mass_coo, density_at_mass_coo, temperature_at_mass_coo, age_all

Return type:

float

Notes

plus writes a file with the trajectory information to be used with ppn.

Warning: remove the old trajectory, if you have any for the same mass coordinate. You are appending data, not overwriting.

Update: this method works for output types with indexes going from the outside in (MESA) or the other way around. Also the requested quantities are linearly interpolated in the mass shell. online: boolean, optional are you working online in the ipython notebook? If so, you will be given an HTML link to download the file.

windyields(ini, end, delta, **keyw)

This function returns the wind yields and ejected masses.

X_i, E_i = data.windyields(ini, end, delta)

Parameters:
  • ini (integer) – The starting cycle.
  • end (integer) – The finishing cycle.
  • delta (integer) – The cycle interval.
  • keyw (dict) – A dict of key word arguments.
Returns:

The function returns a list of the wind yields(X_i) and a list of the ejected masses(E_i) in the mass units that were used (usually solar masses).

Return type:

list

Notes

The following keywords cand also be used:

Keyword Argument Default Value
abund “iso_massf”
tmass “mass”
cycle “cycle”

The keyword arguments are used when the variables within the input file differ in name from their default values typically found in an MPPNP output file. If the data table differs in name, use these keywords. For example, if the table for the abundances is called “abundances” instead of “iso_massf”, then use abund = “abundances” as a keyword argument.

write_deltatable(filename='default', decayed=True, dcycle=500, iniabufile='../../frames/mppnp/USEEPP/iniab2.0E-02GN93.ppn')

This subroutine is to write out tables with delta values for cosmochemists to use in comparison with their data.

No options are necessarily needed to load this routine, however, it might be useful to specify a filename. This file furthermore searches for thermal pulses, hence, it’s only useful for non-explosive TP-AGB stars!

Parameters:
  • filename (string, optional) – Choose the filename you want. The default is “default”.
  • decayed (boolean, optional) – Value if decayed massfractions of isotope should be taken or not. The default is False.
  • dcycle (integer, optional) – Difference between cycles to search for thermal pulses. The default is 500.
  • iniabufile (string, optional) – File with initial abundances. As a standard value, the GN93 file is used (in USEEPP folder). Important, input file has to be USEEPP conforming, see NuGrid book! The default is ‘../../frames/mppnp/USEEPP/iniab2.0E-02GN93.ppn’.

Notes

Regardless of what value is used as filename it will be replaced with ‘delta_outfile.txt’.

nugridpy.nugridse.set_nugrid_path(path)

This function sets the path to the NuGrid VOSpace directory as a global variable, so that it need only be set once during an inter- active session.