Stack

class curie.Stack(stack, particle='p', E0=60.0, **kwargs)[source]

Foil pack for stacked target calculations

Computes the energy loss and (relative) charged particle flux through a stack of foils using the Anderson-Ziegler formulation for stopping powers.

Parameters:
stacklist of dicts, pd.DataFrame or str

Definition of the foils in the stack. The ‘compound’ for each foil in the stack must be given, and the ‘areal_density’ or some combination of parameters that allow the areal density to be calculated must also be given. Foils must also be given a ‘name’ if they are to be filtered by the .saveas(), .summarize(), and .plot() methods. By default, foils without ‘name’ are not included by these methods.

There are three acceptable formats for stack. The first is a pd.DataFrame with the columns described. The second is a list of dicts, where each dict contains the appropriate keys. The last is a str, which is a path to a file in either .csv, .json or .db format, where the headers of the file contain the correct information. Note that the .json file must follow the ‘records’ format (see pandas docs). If a .db file, it must have a table named ‘stack’.

The ‘areal_density’ can be given directly, in units of mg/cm^2, or will be calculated from the following: ‘mass’ (in g) and ‘area’ (in cm^2), ‘thickness’ (in mm) and ‘density’ (in g/cm^3), or just ‘thickness’ if the compound is a natural element, or is in ci.COMPOUND_LIST or the ‘compounds’ argument.

Also, the following shorthand indices are supported: ‘cm’ for ‘compound’, ‘d’ for ‘density’, ‘t’ for ‘thickness’, ‘m’ for ‘mass’, ‘a’ for ‘area’, ‘ad’ for ‘areal_density’, and ‘nm’ for ‘name’.

particlestr

Incident ion. For light ions, options are ‘p’ (default), ‘d’, ‘t’, ‘a’ for proton, deuteron, triton and alpha, respectively. Additionally, heavy ions can be specified either by element or isotope, e.g. ‘Fe’, ‘40CA’, ‘U’, ‘Bi-209’.For light ions, the charge state is assumed to be fully stripped. For heavy ions the charge state is handled by a Bohr/Northcliffe parameterization consistent with the Anderson-Ziegler formalism.

E0float

Incident particle energy, in MeV. If dE0 is not provided, it will default to 1 percent of E0.

Other Parameters:
compoundsstr, pandas.DataFrame, list or dict

Compound definitions for the compounds included in the foil stack. If the compounds are not natural elements, or ci.COMPOUND_LIST, or if different weights or densities are required, they can be specified here. (Note specifying specific densities in the ‘stack’ argument is probably more appropriate.) Also, if the ‘compound’ name in the stack is a chemical formula, e.g. ‘H2O’, ‘SrCO3’, the weights can be inferred and ‘compounds’ doesn’t need to be given.

If compounds is a pandas DataFrame, it must have the columns ‘compound’, ‘element’, one of ‘weight’, ‘atom_weight’, or ‘mass_weight’, and optionally ‘density’. If a str, it must be a path to a .csv, .json or .db file, where .json files must be in the ‘records’ format and .db files must have a ‘compounds’ table. All must have the above information. For .csv files, the compound only needs to be given for the first line of that compound definition.

If compounds is a list, it must be a list of ci.Element or ci.Compound classes. If it is a dict, it must have the compound names as keys, and weights as values, e.g. {‘Water’:{‘H’:2, ‘O’:1}, ‘Brass’:{‘Cu’:-66,’Zn’:-33}}

dE0float

1-sigma width of the energy distribution from which the initial particle energies are sampled, in MeV. Default is to 1 percent of E0.

Nint

Number of particles to simulate. Default is 10000.

dpfloat

Density multiplier. dp is uniformly multiplied to all areal densities in the stack. Default 1.0.

chunk_sizeint

If N is large, split the stack calculation in to multiple “chunks” of size chunk_size. Default 1E7.

accuracyfloat

Maximum allowed (absolute) error in the predictor-corrector method. Default 0.01. If error is above accuracy, each foil in the stack will be solved with multiple steps, between min_steps and max_steps.

min_stepsint

The minimum number of steps per foil, in the predictor-corrector solver. Default 2.

max_stepsint

The maximum number of steps per foil, in the predictor-corrector solver. Default 50.

Examples

>>> stack = [{'cm':'H2O', 'ad':800.0, 'name':'water'},
                        {'cm':'RbCl', 'density':3.0, 't':0.03, 'name':'salt'},
                        {'cm':'Kapton', 't':0.025},
                        {'cm':'Brass', 'm':3.5, 'a':1.0, 'name':'metal'}]
>>> st = ci.Stack(stack, compounds='example_compounds.json')
>>> st = ci.Stack(stack, compounds={'Brass':{'Cu':-66, 'Zn':-33}}, E0=60.0)
>>> print(st.stack)
    name compound  areal_density       mu_E     sig_E
0  water      H2O         800.00  55.444815  2.935233
1   salt     RbCl           9.00  50.668313  0.683532
2    NaN   Kapton           3.55  50.612543  0.683325
3  metal    Brass         350.00  49.159245  1.205481
>>> st.saveas('stack_calc.csv')
Attributes:
stackpandas.DataFrame

‘name’, ‘compound’, ‘areal_density’, mean energy ‘mu_E’, and 1-sigma energy width ‘sig_E’ for each foil in the stack (energies in MeV).

fluxespandas.DataFrame

‘flux’ as a function of ‘energy’ for each foil in the stack where ‘name’ is not None.

compoundsdict

Dictionary with compound names as keys, and ci.Compound classes as values.

Methods

get_flux(sample_name)

Returns the computed energy grid and flux for a sample

plot([filter_name])

Plots the fluxes for each foil in the stack calculation

saveas(filename[, save_fluxes, filter_name])

Saves the results of the stack calculation

summarize([filter_name])

Summarize the stack calculation

get_flux(sample_name)[source]

Returns the computed energy grid and flux for a sample

Units of energy are in MeV, and the flux is a relative flux (normalized to 1). Note that sample_name must be an exact match with the ‘name’ property in the stack specification.

Parameters:
sample_namestr

Name of the sample for which to return the flux. Must be an exact match for an element in the stack.

Returns:
(energy, flux)tuple(np.ndarray, np.ndarray)

Energy grid in MeV, and relative flux in the sample, along the energy grid.

Examples

>>> stack = [{'cm':'H2O', 'ad':800.0, 'name':'water'},
                {'cm':'RbCl', 'density':3.0, 't':0.03, 'name':'salt'},
                {'cm':'Kapton', 't':0.025},
                {'cm':'Brass','ad':350, 'name':'metal'}]
>>> st = ci.Stack(stack, compounds={'Brass':{'Cu':-66, 'Zn':-33}}, E0=60.0)
>>> print(st.get_flux('water'))
(array([47.95, 48.05, 48.15, 48.25, 48.35, 48.45, 48.55, 48.65, 48.75,
48.85, 48.95, 49.05, 49.15...
>>> rx = ci.Reaction('16O(p,x)16F')
>>> print(rx.average(*st.get_flux('water')))
1.495163043176288
plot(filter_name=None, **kwargs)[source]

Plots the fluxes for each foil in the stack calculation

Plots the flux distribution for each foil in the stack, or the filtered stack depending on the behaviour of filter_name.

Parameters:
filter_namestr, optional

Applies a filter to the fluxes before plotting. If a str, foils with a ‘name’ matching a regex search with filter_name are plotted. Default, None.

Other Parameters:
**kwargs

Optional keyword arguments for plotting. See the plotting section of the curie API for a complete list of kwargs.

Examples

>>> stack = [{'cm':'H2O', 'ad':800.0, 'name':'water'},
                {'cm':'RbCl', 'density':3.0, 't':0.03, 'name':'salt'},
                {'cm':'Kapton', 't':0.025},
                {'cm':'Brass','ad':350, 'name':'metal'}]
>>> st = ci.Stack(stack, compounds={'Brass':{'Cu':-66, 'Zn':-33}}, E0=60.0)
>>> st.plot()
>>> st.plot(filter_name='salt')
saveas(filename, save_fluxes=True, filter_name=True)[source]

Saves the results of the stack calculation

Saves the stack design, mean energies, and (optionally) the flux profile for each foil in the stack. Supported file types are ‘.csv’, ‘.db’ and ‘.json’.

Parameters:
filenamestr

Name of file to save to. Supported file types are ‘.csv’, ‘.db’ and ‘.json’. If save_fluxes=True, an additional file will be saved to ‘fname_fluxes.ftype’.

save_fluxesbool, optional

If True, an additional file will be saved with the flux profile for each foil in the stack. The foil must have a ‘name’ keyword, and can be further filtered with the filter_name argument. If false, only the stack design and mean energies are saved. Defaut, True.

filter_namebool or str, optional

Applies a filter to the stack and fluxes before saving. If True, only foils with a ‘name’ keyword will be saved. If ‘False’, foils without a ‘name’ will be saved in the stack design file, but not the fluxes file. If a str, foils with a ‘name’ matching a regex search with filter_name are saved. This applies to both files. Default, True.

Examples

>>> stack = [{'cm':'H2O', 'ad':800.0, 'name':'water'},
                {'cm':'RbCl', 'density':3.0, 't':0.03, 'name':'salt'},
                {'cm':'Kapton', 't':0.025},
                {'cm':'Brass','ad':350, 'name':'metal'}]
>>> st = ci.Stack(stack, compounds={'Brass':{'Cu':-66, 'Zn':-33}}, E0=60.0)
>>> st.saveas('example_stack.csv')
>>> st.saveas('example_stack.json', filter_name=False)
>>> st.saveas('example_stack.db', save_fluxes=False)
summarize(filter_name=True)[source]

Summarize the stack calculation

Prints out the mean energies and 1-sigma energy widths of each foil in the stack, or the filtered stack depending on the behavior of filter_name.

Parameters:
filter_namebool or str, optional

Applies a filter to the stack. If True, only foils with a ‘name’ keyword will be included. If ‘False’, a summary of all foils will be printed. If a str, foils with a ‘name’ matching a regex search with filter_name are included. Default, True.

Examples

>>> stack = [{'cm':'H2O', 'ad':800.0, 'name':'water'},
                {'cm':'RbCl', 'density':3.0, 't':0.03, 'name':'salt'},
                {'cm':'Kapton', 't':0.025},
                {'cm':'Brass','ad':350, 'name':'metal'}]
>>> st = ci.Stack(stack, compounds={'Brass':{'Cu':-66, 'Zn':-33}}, E0=60.0)
>>> st.summarize()
water: 55.45 +/- 2.94 (MeV)
salt: 50.68 +/- 0.69 (MeV)
metal: 49.17 +/- 1.21 (MeV)
>>> st.summarize(filter_name=False)
water: 55.45 +/- 2.94 (MeV)
salt: 50.68 +/- 0.69 (MeV)
Kapton-1: 50.62 +/- 0.69 (MeV)
metal: 49.17 +/- 1.21 (MeV)