nugridpy.grain

grain.py is a collection of routines to analyze presolar grain data (and can probably be extended to observational data at a later stage).

This class load the current version of the presolar grain database for further processing. A private databse can be given as well as described later. Several routines (see below and NuGrid book) can be used to filter, plot, and retrieve grain data. The presolar grain database is supported by the group at Washington University, mainly Frank Gyngard. The database can be found at http://presolar.wustl.edu/PGD/Presolar_Grain_Database.html

Important note: This script assumes that you have a full SVN tree checked out (or actually, that you have at least the utils folder and the validation folder on the same level checked out.

Usage of these tools

For questions, bug reports, please contact trappitsch@uchicago.edu Reto Trappitsch for the NuGrid collaboration

Developing notes

data header should be safed lowercase always -> use .lower() argument also for comparison w/ user input therefore! if updating the database with new files creates a utf16 error while reading in the database, open it in excel, save the file, and try again. if this does not work, good luck…

Functions

get_svnpath() This subroutine gives back the path of the whole svn tree installation, which is necessary for the script to run.
iso_name_converter(iso) Converts the name of the given isotope (input), e.g., ‘N-14’ to 14N as used later to compare w/ grain database.
preprocessor(fname, gdbdir, gdbload[, wb_sic])
style_creator(desc, descdict)

Classes

gdb([fname, gdbdir, gdbload, iniabufile]) This class provides easy access to the presolar grain databse, as described in the header The databse is read in by default, however you can choose a private database and if you do so, if you want to use the private database exclusively or together with the whole database.
class nugridpy.grain.gdb(fname=None, gdbdir=None, gdbload=True, iniabufile='frames/mppnp/USEEPP/iniab2.0E-02GN93.ppn')

This class provides easy access to the presolar grain databse, as described in the header The databse is read in by default, however you can choose a private database and if you do so, if you want to use the private database exclusively or together with the whole database.

If you use a private datafile, make sure it is in the same structure as the presolar grain database. The most important thing is that you have a column named ‘Notes’ before the data start. Everything on the right there is data, on the left description of the data. You don’t have to have all the data columns if you don’t have data, but the header of the data columns needs to be exactly the same as the in the database. Look at validation/grain_data xls files if you want to see an example of the formatting / or use it as a template.

Parameters:
  • fname (string) – filename to your private database, if not in the main tree structure with other databse, give full path.
  • gdbdir (string) – In case you have not a full svn tree installed, choose the correct path to all the data here
  • gdbload (boolean, optional) – True or False: Do you want to load the grain database or not? The default is True.
  • iniabufile (string, optional) – Which initial abundances should be used to calculate delta values. Here we assume complete SVN tree (need USEEPP). Give absolute path otherwise. The default is ‘frames/mppnp/USEEPP/iniab2.0E-02GN93.ppn’.
check_availability(isos)

This routine checks if the requested set of isotopes is available in the dataset.

Parameters:isos (list) – set of isotopes in format [‘Si-28’,’Si-30’].
Returns:[index, delta_b, ratio_b]. index: where is it. delta_b: is it a delta value or not? ratio_ib: True if ratio is inverted, false if not
Return type:list
delta_to_ratio(isos_ss, delta, oneover=False)

Transforms a delta value into an isotopic ratio

Parameters:
  • isos_ss (list or float) – list w/ isotopes, e.g., [‘N-14’,’N-15’] OR the solar system ratio.
  • delta (float) – delta value of the isotopes to transform.
  • oneover (boolean) – take the inverse of the ratio before returning it (never of the delta value!). The default is False.
Returns:

delta value

Return type:

float

filter_data(isos, limit, delta=True)

This subroutine filters isotopic values according to the limit you give. You can filter in ratio or in delta space.

Parameters:
  • isos (list) – isotopes you want to filter for, e.g., give as [‘Si-28’, ‘Si-30’] for the 28/30 ratio.
  • limit (string) – what do you want to filter for, e.g., ratio or delta > 100, then give ‘>100’.
  • delta (boolean, optional) – do you wanna filter in delta space, then set to True, otherwise to False. The default is True.
filter_desc(graintype=None, group=None, reference=None, size=None, phase=None)

This routine is to filter for description elements. You can check what is available in the description by running,

>>> i.header_desc()

where i is the instance you loaded.

You can run the filter multiple times! You can filter for the following types:

Parameters:
  • graintype (string or list) – Give graintypes as either ‘M’ for only mainstream or more than one [‘M’,’Z’].
  • group (integer or list) – Group of graintypes, important for oxides and silicates, since they are split into groups and not into types. Example 1, or give a list [1,3].
  • reference (string or list) – Give the reference you want to filter for, try an i.info() to pick the right name! You can select a single referennce as string or multiple references in as a list.
  • size (string) – Filter for grain sizes, give ‘<5.0’ or ‘>5.0’ as a string for larger or smaller than a given grainsize in um. Only data with known grainsizes are chosen. Often grain sizes are given in a times b, where a and b are the minumum and maximum measurements from an image. If you give a >5.0 then grains with the smaller dimension >5um are taken into account. If you want <5.0 then grains with the upper dimension <5um are taken into account.
filter_single_grain()

This subroutine is to filter out single grains. It is kind of useless if you have tons of data still in the list. To work on there, you have other filters (filter_desc and filter_data) available! This filter gives an index to every grain, plots the most important information, and then asks you to pick a filter. No input necessary, input is given during the routine

filter_uncertainty(isos, limit, delta=True)

This subroutine filters isotopic values according to the limit you give. You can filter in ratio or in delta space. This routine is based on the uncertainties, e.g., if you want to select only high quality data.

Parameters:
  • isos (list) – Isotopes you want to filter for, e.g., give as [‘Si-28’, ‘Si-30’] for the 28/30 ratio.
  • limit (string) – What do you want to filter for, e.g., ratio or delta > 100, then give ‘>100’.
  • delta (boolean, optional) – Do you wanna filter in delta space, then set to True, otherwise to False. The default is True.
info(graintype=True, group=True, reference=False, phase=True)

This routine gives you informations what kind of grains are currently available in your filtered version. It gives you the type of grains available. More to be implemented upon need.

Parameters:group, references, phase (graintype,) – What do you wanna print for information. There can be a lot of references, hence references default is False.
plot_pattern_return(isos, delta=True)

This routine returns data isotopic data to plot from the filtered list of data.

Parameters:
  • isos (list) – Isotopes for x axis in standard format [[‘Si-30’,’Si-28’],[‘Si-29’,’Si-30’],…]
  • isoy (list) – Same as isox but for y axis.
  • deltay (boolean, optional) – Same as for x-axis but for y-axis. The default is True.
Returns:

  • grpl_data – grain plot x-axis data.
  • grpl_err – x-axis error bars.
  • grpl_style – style data for the different symbols.

plot_ratio_return(isox, isoy, deltax=True, deltay=True)

This routine returns data isotopic data to plot from the filtered list of data.

Parameters:
  • isox (list) – Isotopes for x axis in standard format [‘Si-28’,’Si-30’].
  • isoy (list) – Same as isox but for y axis.
  • deltax (boolean, optional) – If true then x-axis values are in delta format. The default is True.
  • deltay (boolean, optional) – Same as for x-axis but for y-axis. The default is True.
Returns:

  • grpl_xdata – grain plot x-axis data.
  • grpl_xerr – x-axis error bars.
  • grpl_ydata – grain plot y-axis data.
  • grpl_yerr – y-axis error bars.
  • grpl_style – style data for the different symbols.

ratio_to_delta(isos_ss, ratio, oneover=False)

Transforms an isotope ratio into a delta value

Parameters:
  • isos_ss (list or float) – list w/ isotopes, e.g., [‘N-14’,’N-15’] OR the solar system ratio.
  • ratio (float) – ratio of the isotopes to transform.
  • oneover (boolean) – take the inverse of the ratio before transforming (never inverse of delta value!). The default is False.
Returns:

delta value

Return type:

float

reset_filter()

Resets the filter and goes back to initialized value. This routine also resets the style if you have changed it.

style_chg_label(type, symb=None, edc=None, fac=None, smbsz=None, edw=None, lab=None)

This routine changes the plotting style that is set by default. The style is changed according the the label that you choose. Changing according to reference, use style_chg_ref() function! You can change it back to default by resetting the filter using g.reset_filter() routine, assuming that g is your instance. The format that is used here is:

[‘Symbol’, ‘Edge color’, ‘Face color’, ‘Symbol size’, ‘Edge width’ ,’Label’]

You can see the current styles by running

Attention: You have to give values to all variables that are compatible with the python mathplotlib. If not, it’s your fault if nothing works.

g.style

Parameters:
  • type (string) – Select the label of the grains you want to change.
  • symb (string, optional) – Select new symbol. None for no change.
  • edc (string, optional) – Select new edge color. None for no change.
  • fac (string, optional) – Select new face color. None for no change.
  • smbsz (string, optional) – Select new symbol size. None for no change.
  • edw (string, optional) – Select new edge width. None for no change.
  • lab (string, optional) – Select new label. None for no change. Watch out, if you want to do more specifications later, the type will have changed to the new label.
style_chg_ref(ref, symb=None, edc=None, fac=None, smbsz=None, edw=None, lab=None)

This routine changes the plotting style that is set by default. The style is changed according the the reference of the paper as given in the grain database. For change according to type of grain, use the routine syle_chg_label().

[‘Symbol’, ‘Edge color’, ‘Face color’, ‘Symbol size’, ‘Edge width’ ,’Label’]

You can see the current styles by running

Attention: You have to give values to all variables that are compatible with the python mathplotlib. If not, it’s your fault if nothing works.

g.style

Parameters:
  • ref (string) – Select the reference of the grains you want to change.
  • symb (string, optional) – Select new symbol. None for no change.
  • edc (string, optional) – Select new edge color. None for no change.
  • fac (string, optional) – Select new face color. None for no change.
  • smbsz (string, optional) – Select new symbol size. None for no change.
  • edw (string, optional) – Select new edge width. None for no change.
  • lab (string, optional) – Select new label. None for no change.
nugridpy.grain.get_svnpath()

This subroutine gives back the path of the whole svn tree installation, which is necessary for the script to run.

nugridpy.grain.iso_name_converter(iso)

Converts the name of the given isotope (input), e.g., ‘N-14’ to 14N as used later to compare w/ grain database.