nugridpy.utils¶
utils.py
Utility class for holding extra methods from mesa.py, nuh5p.py
Functions
close_wins (win_min, win_max) |
close all windows in a certain window number range |
colourblind (i) |
colour pallete from http://tableaufriction.blogspot.ro/ |
colourblind2 (i) |
another colour pallete from http://www.sron.nl/~pault/ |
convert_specie_naming_from_h5_to_ppn (…) |
read isotopes names from h5 files, and convert them |
define_zip_index_for_species (…) |
This just give back cl, that is the original index as it is read from files from a data file. |
element_abund_marco (i_decay, …) |
Given an array of isotopic abundances not decayed and a similar |
get_el_from_z (z) |
Very simple Vfunction that gives the atomic number AS A STRING when given the element symbol. |
get_z_from_el (element) |
Very simple function that gives the atomic number AS A STRING when given the element symbol. |
give_zip_element_z_and_names (element_name) |
create 2 indexes that, given the name of the element/specie, give the atomic number. |
linestyle (i[, a, b]) |
provide one out of 25 unique combinations of style, color and mark |
linestylecb (i[, a, b]) |
version of linestyle function with colourblind colour scheme |
make_list (default_symbol_list, len_list_to_print) |
provide the list of symbols to use according for the list of |
solar (filename_solar, solar_factor) |
read solar abundances from filename_solar. |
species_list (what_list) |
provide default lists of elements to plot. |
stable_specie () |
provide the list of stable species, and decay path feeding stables |
strictly_monotonic (bb) |
bb is an index array which may have numerous double or triple |
symbol_list (what_list) |
provide default symbol lists |
trajectory_SgConst ([Sg, delta_logt_dex]) |
setup trajectories for constant radiation entropy. |
Classes
Utils |
This private class contains utilities that are used by methods, mostly in the ppn and mppnp classes. |
constants |
|
data_fitting ([func, coef]) |
Wrapper for the scipy method optimize.leastsq |
iniabu (filename) |
This class in the utils package reads an abundance distribution file of the type iniab.dat. |
-
class
nugridpy.utils.
Utils
¶ This private class contains utilities that are used by methods, mostly in the ppn and mppnp classes. Users whould normally not use these methods directly. Things go here when it can be imagined that they may be used not in immediate conjunction with plotting. Otherwise they would go into the superclass data_plot.
-
compar
(x, y)¶ simple comparator method
-
comparator
(x, y)¶ simple comparator method
-
decay_indexpointer
()¶ This private method provides decay indexpointers which allow to instantaneously decay an abundance vector. These are attributes are.
- decay_idp : list
- points in the iso_to_plot (i.e. the undecayed abundance vector index space) to the decay target.
- idp_to_stables_in_isostoplot : list
- points to the stable isotopes in the undecayed abundance vector index space.
Notes
For an application example see ppn.py-abu_vector-_getcycle.
-
is_stable
(species)¶ This routine accepts input formatted like ‘He-3’ and checks with stable_el list if occurs in there. If it does, the routine returns True, otherwise False.
Notes
this method is designed to work with an se instance from nugridse.py. In order to make it work with ppn.py some additional work is required.
FH, April 20, 2013.
-
-
nugridpy.utils.
close_wins
(win_min, win_max)¶ close all windows in a certain window number range
win_min/max minumum and maximum window number to close
-
nugridpy.utils.
colourblind
(i)¶ colour pallete from http://tableaufriction.blogspot.ro/ allegedly suitable for colour-blind folk
SJ
-
nugridpy.utils.
colourblind2
(i)¶ another colour pallete from http://www.sron.nl/~pault/ allegedly suitable for colour-blind folk
SJ
-
nugridpy.utils.
convert_specie_naming_from_h5_to_ppn
(isotope_names)¶ read isotopes names from h5 files, and convert them according to standard scheme used inside ppn and mppnp. Also Z and A are recalculated, for these species. Isomers are excluded for now, since there were recent changes in isomers name. As soon as the isomers names are settled, than Z and A provided here will be obsolete, and can be changed by usual Z and A.
-
class
nugridpy.utils.
data_fitting
(func='linear', coef=(1, 1))¶ Wrapper for the scipy method optimize.leastsq
Parameters: - func (string or function, optional) – If func is a string, then it must be one of the two strings ‘linear’ or ‘powerlaw’. If func is not a string it must be a custom function. The default is “linear”.
- coef (tuple or list) – A guess for the list of coeffiecients. For ‘powerlaw’ coef must have three enries. For ‘linear’ coef must have two enries. If you provide your own function, then provide as many coef entries as your function needs.
Examples
Typically you have some data y(x) and you want to fit some function to this data.
in order to test this create some sample data y(x)
>>> x=arange(0,100) >>> y=(((random_sample(100)+0.5)*50.)-50)+x # this is the data to fit
This class provides two simple fit functions: linear and power law.
Feel free to add more, or provide your custom function as an argument. For example, in order to provide an exponential fit function, first define the function.
>>> def ff(coef,x): >>> return coef[0]*sc.exp(coef[1]*x)+coef[2]
and then call the data_fitting instance.
>>> f=utils.data_fitting(ff,coef=(1,0,0))
Once you have initialized this class, the instance provides two methods; fit and plot to check the fit.
>>> f.fit(x,y) >>> f.plot() >>> plot(f.x,(y-f.func(f.fcoef,f.x))/(0.5*(y[-1]-y[0])),'o') The fit coefficients are stored in self.fcoef.
(FH)
-
fit
(x, y, dcoef='none')¶ performs the fit
- x, y : list
- Matching data arrays that define a numerical function y(x), this is the data to be fitted.
- dcoef : list or string
- You can provide a different guess for the coefficients, or provide the string ‘none’ to use the inital guess. The default is ‘none’.
Returns: Values between 1 and 4 signal success. Return type: ierr Notes
self.fcoef, contains the fitted coefficients.
-
plot
(ifig=1, data_label='data', fit_label='fit', data_shape='o', fit_shape='-')¶ plot the data and the fitted function.
Parameters: - ifig (integer) – Figure window number. The default is 1.
- data_label (string) – Legend for data. The default is ‘data’.
- fit_label (string) – Legend for fit. If fit_lable is ‘fit’, then substitute fit function type self.func_name. The default is ‘fit’.
- data_shape (character) – Shape for data. The default is ‘o’.
- fit_shape (character) – Shape for fit. The default is ‘-‘.
-
nugridpy.utils.
define_zip_index_for_species
(names_ppn_world, number_names_ppn_world)¶ This just give back cl, that is the original index as it is read from files from a data file.
-
nugridpy.utils.
element_abund_marco
(i_decay, stable_isotope_list, stable_isotope_identifier, mass_fractions_array_not_decayed, mass_fractions_array_decayed)¶ Given an array of isotopic abundances not decayed and a similar array of isotopic abundances not decayed, here elements abundances, and production factors for elements are calculated
-
nugridpy.utils.
get_el_from_z
(z)¶ Very simple Vfunction that gives the atomic number AS A STRING when given the element symbol. Uses predefined a dictionnary. Parameter : z : string or number For the other way, see get_z_from_el
-
nugridpy.utils.
get_z_from_el
(element)¶ Very simple function that gives the atomic number AS A STRING when given the element symbol. Uses predefined a dictionnary. Parameter : element : string For the other way, see get_el_from_z
-
nugridpy.utils.
give_zip_element_z_and_names
(element_name)¶ create 2 indexes that, given the name of the element/specie, give the atomic number.
-
class
nugridpy.utils.
iniabu
(filename)¶ This class in the utils package reads an abundance distribution file of the type iniab.dat. It then provides you with methods to change some abundances, modify, normalise and eventually write out the final distribution in a format that can be used as an initial abundance file for ppn. This class also contains a method to write initial abundance files for a MESA run, for a given MESA netowrk.
-
iso_abundance
(isos)¶ This routine returns the abundance of a specific isotope. Isotope given as, e.g., ‘Si-28’ or as list [‘Si-28’,’Si-29’,’Si-30’]
-
isoratio_init
(isos)¶ This file returns the isotopic ratio of two isotopes specified as iso1 and iso2. The isotopes are given as, e.g., [‘Fe’,56,’Fe’,58] or [‘Fe-56’,’Fe-58’] (for compatibility) -> list.
-
set_and_normalize
(species_hash)¶ species_hash is a hash array in which you provide abundances referenced by species names that you want to set to some particular value; all other species are then normalised so that the total sum is 1.
Examples
You can set up the argument array for this method for example in the following way.
>>> sp={} >>> sp['he 4']=0.2 >>> sp['h 1']=0.5
-
write
(outfile='initial_abundance.dat', header_string='initial abundances for a PPN run')¶ Write initial abundance file (intended for use with ppn)
Parameters: - outfile (string) – Name of output file. The default is ‘initial_abundance.dat’.
- header_string (string) – A string with header line. The default is ‘initial abundances for a PPN run’.
-
write_mesa
(mesa_isos_file='isos.txt', add_excess_iso='fe56', outfile='xa_iniabu.dat', header_string='initial abundances for a MESA run', header_char='!')¶ Write initial abundance file, returns written abundances and mesa names.
Parameters: - mesa_isos_file (string, optional) – List with isos copied from mesa network definition file in mesa/data/net_data/nets. The default is ‘isos.txt’.
- add_excess_iso (string, optional) – Add 1.-sum(isos in mesa net) to this isotope. The defualt is ‘fe56’.
- outfile (string, optional) – name of output file. The default file is ‘xa_iniabu.dat’.
- header_string (string, optional) – Srting with header line. The default is ‘initial abundances for a MESA run’.
- header_char (character, optional) – The default is ‘!’.
Examples
>>> from NuGridPy import utils >>> !ls ~/PPN/forum.astro.keele.ac.uk/frames/mppnp/USEEPP/ # find ppn initial abundance file >>> !cat ~/mesa/data/net_data/nets/agb.net # find isos needed in mesa net >>> !cat > isos.txt # paste needed isos into file >>> help(utils.iniabu) # check documentation of method >>> x=utils.iniabu('path_to_here/forum.astro.keele.ac.uk/frames/mppnp/USEEPP/iniab2.0E-02GN93.ppn') >>> x.write_mesa? >>> mnames,mabus = x.write_mesa(add_excess_iso='ne22', ... header_string='mppnp/USEEPP/iniab2.0E-02GN93.ppn for mesa/agb.net', ... outfile='xa_2.0E-02GN93.mesa')
-
-
nugridpy.utils.
linestyle
(i, a=5, b=3)¶ provide one out of 25 unique combinations of style, color and mark
use in combination with markevery=a+mod(i,b) to add spaced points, here a would be the base spacing that would depend on the data density, modulated with the number of lines to be plotted (b)
Parameters: - i (integer) – Number of linestyle combination - there are many….
- a (integer) – Spacing of marks. The default is 5.
- b (integer) – Modulation in case of plotting many nearby lines. The default is 3.
Examples
>>> plot(x,sin(x),linestyle(7)[0], markevery=linestyle(7)[1])
- 2014 FH
-
nugridpy.utils.
linestylecb
(i, a=5, b=3)¶ version of linestyle function with colourblind colour scheme
returns linetyle, marker, color (see example)
Parameters: - i (integer) –
- of linestyle combination - there are many.... (Number) –
- a (integer) –
- of marks. The default is 5. (Spacing) –
- b (integer) –
- in case of plotting many nearby lines. The default (Modulation) –
- 3. (is) –
Examples
>>> plot(x,sin(x),ls=linestyle(7)[0], marker=linestyle(7)[1], color=linestyle(7)[2],markevery=linestyle(7)[3])
- 2014 FH
-
nugridpy.utils.
make_list
(default_symbol_list, len_list_to_print)¶ provide the list of symbols to use according for the list of species/arrays to plot.
Parameters: - default_symbol_list (list) – Symbols that the user choose to use.
- len_list_to_print (integer) – len of list of species/arrays to print.
-
nugridpy.utils.
solar
(filename_solar, solar_factor)¶ read solar abundances from filename_solar.
Parameters: - filename_solar (string) – The file name.
- solar_factor (float) – The correction factor to apply, in case filename_solar is not solar, but some file used to get initial abundances at metallicity lower than solar. However, notice that this is really rude, since alpha-enahncements and things like that are not properly considered. Only H and He4 are not multiplied. So, for publications PLEASE use proper filename_solar at…solar, and use solar_factor = 1. Marco
-
nugridpy.utils.
species_list
(what_list)¶ provide default lists of elements to plot.
- what_list : string
String name of species lists provided.
If what_list is “CNONe”, then C, N, O and some other light elements.
If what_list is “s-process”, then s-process indicators.
-
nugridpy.utils.
stable_specie
()¶ provide the list of stable species, and decay path feeding stables
-
nugridpy.utils.
strictly_monotonic
(bb)¶ bb is an index array which may have numerous double or triple occurrences of indices, such as for example the decay_index_pointer. This method removes all entries <= -, then all dublicates and finally returns a sorted list of indices.
-
nugridpy.utils.
symbol_list
(what_list)¶ provide default symbol lists
Parameters: what_list (string) – String name of symbol lists provided; “list1”, “list2”, “lines1” or “lines2”.
-
nugridpy.utils.
trajectory_SgConst
(Sg=0.1, delta_logt_dex=-0.01)¶ setup trajectories for constant radiation entropy.
S_gamma/R where the radiation constant R = N_A*k (Dave Arnett, Supernova book, p. 212) This relates rho and T but the time scale for this is independent.
Parameters: - Sg (float) – S_gamma/R, values between 0.1 and 10. reflect conditions in massive stars. The default is 0.1.
- delta_logt_dex (float) – Sets interval between time steps in dex of logtimerev. The default is -0.01.