Full documentation of cripticpy

cripticpy.Tp(p, ptype)[source]

Compute a kinetic energy from a momentum for a given particle type

Parameters
pastropy.Quantity

momentum

ptypeint, string, or array of int or string

particle type(s); can be specified by number as used internally in criptic, or by name; known names are ‘proton’, ‘electron’, ‘positron’, ‘boron10’, ‘boron11’, ‘carbon12’, ‘nitrogen14’, ‘oxygen16’

Returns
Tastropy.Quantity

kinetic energies

cripticpy.heatscatter(x, y, aspect='equal', ax=None, cmap=matplotlib.rcParams.image.cmap, log=True, nxbin=50, nybin=50, scale='density', scat_alpha=0.5, scat_color=None, scat_size=5, vmax=None, vmin=None, vmin_contour=False, vmin_contour_alpha=1.0, vmin_contour_color=None, vmin_frac=0.999, w=None, xlim=None, ylim=None)[source]

Makes a 2d heatmap plus scatter plot, where data in high-density regions are shown using a heatmap, and data in low-density regions are shown using scatter points.

Parameters:
xarray or astropy.Quantity, shape (N,)

x coordinates of points

yarray or astropy.Quantity, shape (N,)

y coordinates of points

aspect‘auto’ | ‘equal’ | num

aspect ratio of the central panel; effects are identical to calling set_aspect on the central panel axes

axmatplotlib.Axes

axes into which to draw plot; defaults to the currently active axes

cmapstr | Colormap

color map to use for heatmap

logbool

if True, use a logarithmic scale for the heatmap

nxbinint or arraylike, shape (N,)

number of bins in x direction

nybinint or arraylike, shape (N,)

number of bins in y direction

scale‘total’ | ‘max’ | ‘frac’ | ‘density’ | ‘normed’

method used to scale bin values; ‘total’ means that the quantity shown is the unscaled sum of the weights of all points in that bin; ‘max’ means that bins are normalized so the value in the largest bin is unity; ‘frac’ means that the value shown is the fraction of the weight in each bin; ‘density’ means that the bins are normalized so that the quantity shown is the sum of weights divided by the size / area of the bin; ‘normed’ means that bins are normalized so that the area integral is unity

scat_alphafloat

alpha value for scatter plot points; setting this to zero suppresses scatter points entirely

scat_colorstring

color to use for scatter points

scat_sizefloat

size of marker for scatter points; equivalent to s parameter in matplotlib.pyplot.scatter

vmaxfloat or astropy.Quantity

maximum value for heatmap; equivalent to the vmax keyword for matplotlib.pyplot.imshow

vminfloat or astropy.Quantity

minimum value for heatmap; points in regions where the heatmap value is < vmin are shown as scatter points; if left as None, a value will be computed from vmin_frac

vmin_contourbool

if True, draw a contour at the boundary between the heat mapped region and the scatter point region

vmin_contour_alphafloat

alpha value of the threshold contour

vmin_contour_colorstring

color of the threshold contour

vmin_fracfloat

fraction of the sum of the weights at which to switch from showing the data as a heatmap to showing individual scatter points; used to compute vmin

warray or astropy.Quantity, shape (N,)

weights of individual points; if None, all points have weight 1

xlim, ylimarraylike, shape (2,)

plotting limits in x and y directions

Returns:
imgmatplotlib.image.AxesImage

a callback to the heatmap, created by imshow

cripticpy.pT(T, ptype)[source]

Compute a momentum from a kinetic energy for a given particle type

Parameters
Tastropy.Quantity

kinetic energy

ptypeint, string, or array of int or string

particle type(s); can be specified by number as used internally in criptic, or by name; known names are ‘proton’, ‘electron’, ‘positron’, ‘boron10’, ‘boron11’, ‘carbon12’, ‘nitrogen14’, ‘oxygen16’

Returns
pastropy.Quantity

momentum

cripticpy.parseinput(fname='criptic.in', units='cgs')[source]

Parse a criptic input file

Parameters
fnamestring

name of input file to parse

units“cgs” | “mks” | None

unit system to use when assigning units to quantities; if None, then quantities are not assigned units

Returns
paramsdict

A dict containing the input parameters, with the parameter names as keys

cripticpy.readchk(chkname, units=True, ke=True, ndot=True, sort=False, meta=False, sources_only=False)[source]

Read a CRIPTIC checkpoint

Parameters

chknamestring

The name of the checkpoint to read

unitsbool

If True, all quantities are returned as astropy.Quantity objects with appropriate units; if False data are returned as flat numpy arrays.

kebool

If True, energies will be computed for all momentum quantities; only allowed if units is also True

ndotbool

If True, compute number of CRs injected per unit time for each source

sortbool

If True, all packets, deleted packets, and sources will be sorted in order of unique ID

metabool

If True, only the metadata are read and returned

sources_onlybool

If True, only sources are returned, not packets

Returns
outdict

a dict containing the following entries (some optional, may or may not be included depending on contents of the checkpoint file being read and the keywords provided)

“t”float or astropy.Quantity

time of output

“dt”float or astropy.Quantity

size of next time step

“step”int

next step number

“uid”int

value of the unique ID counter

“part_names”list of string

names of particles that correspond to each particle type

“packets”dict

a dict containing information on packets, with the following entries:

“x”ndarray or astropy.Quantity, size (n,3)

positions of all packets

“ptype”ndarray, size (n)

particle type numbers of all packets

“uid”ndarray, size (n)

unique IDs of all packets

“source”ndarray, size (n)

unique IDs of sources of all packets

“p”ndarray or astropy.Quantity, size (n)

momenta of all packets

“w”ndarray, size (n)

statistical weights of all packets

“tinj”ndarray or astropy.Quantity, size (n)

times at which each packet was injected

“wgtinj”ndarray or astropy.Quantity, size (n)

statistical weights of each packet at injection

“gr”ndarray or astropy.Quantity, size (n)

grammage traversed by each packet

“mu “ndarray, size(n)

pitch angles of CR packets

“sec”ndarray, size (n)

boolean that is true if packet is a secondary, false if not

“lossmech”list of string

names of loss mechanisms

“T”ndarray or astropy.Quantity, size (n)

CR packet kinetic energies

“pres”ndarray or astropy.Quantity, size(n)

CR pressure divided by k_B at position of each packet; pressures only include packets with gyroradii >= the gyroradius of this packet

“presGrad”ndarray or astropy.Quantity, size (n,3)

gradient of pres

“eden”ndarray or astropy.Quantity, size(n)

CR energy density at position of each packet, including only CRs with gyroradii >= the gyroradius of this packet

“edenGrad”ndarray or astropy.Quantity, size(n,3)

gradient of eden

“nden”ndarray or astropy.Quantity, size(n)

CR number density at position of each packet, including only CRs with gyroradii >= the gyroradius of this packet

“ndenGrad”ndarray or astropy.Quantity, size(n,3)

gradient of nden

delpacketsdict
a dict containing information on packets that were deleted

ce the last checkpoint, with the following entries:

“x”ndarray or astropy.Quantity, size (m,3)

positions of all packets

“ptype”ndarray, size (m)

particle types of all packets

“uid”ndarray, size (m)

unique IDs of all packets

“source”ndarray, size (m)

unique IDs of sources of all packets

“p”ndarray or astropy.Quantity, size (m)

momenta of all packets

“w”ndarray, size (m)

statistical weights of all packets

“tinj”ndarray or astropy.Quantity, size (m)

times at which each packet was injected

“wgtinj”ndarray, size (m)

statistical weights of each packet at injection

“gr”ndarray or astropy.Quantity, size (m)

grammage traversed by each packet

“mu “ndarray, size(n)

pitch angles of CR packets

“T”ndarray or astropy.Quantity, size (n)

CR packet kinetic energies

sourcesdict

a dict containing information on sources, with the following entries:

“x”ndarray or astropy.Quantity, size (i,3)

positions of all sources

“ptype”ndarray, size(i)

particle types produced by sources

“uid”ndarray, size (i)

unique IDs of all sources

“p0”ndarray or astropy.Quantity, size (i)

lower limit of momentum of packets injected by each source

“p1”ndarray or astropy.Quantity, size (i)

upper limit of momentum of packets injected by each source

“q”ndarray, size (i)

index of source momentum distribution

“mu0 “ndarray, size(n)

minimum pitch angle of packets injected by each source

“mu1 “ndarray, size(n)

maximum pitch angle of packets injected by each source

“coef”ndarray or astropy.Quantity, size (i)

coefficient of source momentum distribution

“ndot”ndarray or astropy.Quantity, size (i)

number of CRs injected per unit time by source

lossesdict

a dict containing information on losses, with the following entries:

“lossrate”ndarray or astropy.Quantity, size(n,m)

rate of catastrophic loss for all loss processes

“dpdt”ndarray or astropy.Quantity, size(n,m)

rate of continuous momentum loss for all loss processes

photonsdict

a dict containing information on photon emission, with the following entries:

“en”ndarray or astropy.Quantity, size(j)

energies at which photon emission is calculated

“freq”ndarray or astropy.Quantity, size(j)

frequencies at which photon emission is calculated; equal to en / h

“dLdE”ndarray or astropy.Quantity, size(n,m,j)

array giving the specific luminosity dL/dE (units of erg s^-1 GeV^-1 or J s^-1 GeV^-1 if criptic was run in MKS mode) of each of the n packets produced via each of the m loss mechanisms at each of the j energies

“dLdE_sum”ndarray or astropy.Quantity, size(u,v,m,j)

array giving the specific luminosity dL/dE (units of erg s^-1 GeV^-1 or J s^-1 GeV^-1 if criptic was run in MKS mode) produced by different mechanisms and particle populations; the index u runs from 0 to number of distinct particle types, and gives emission produced by that type; the index v is 0 (for primary particles) or 1 (for secondary particles); the index m runs over all the emission mechanisms (in the same orders as lossmech); finally, the index j runs over the j energies in en

ionizationdict

a dict containing information on ionization rates, with the following entries:

“targets”list of string

names of the ionization targets included in the file

“rate”ndarray or astropy.Quantity, size(n,m)

array of size number of packets x number of ionization targets, giving the ionization rate (units of 1/time) for each packet for each target species

dpdt_transportdict

a dict containing information on rates of momentum change by transport (as opposed to loss) processes, with the following entries:

“Fermi2”ndarray or astropy.Quantity, size(n)

rate of momentum change due to 2nd order Fermi acceleration

“adiabatic”ndarray or astropy.Quantity, size(n)

rate of momentum change due to adiabatic gain or loss

“streaming”ndarray or astropy.Quantity, size(n)

rate of momentum change due to streaming gain or loss

cripticpy.readlastchk(dirname='.', chkname='criptic_', units=True, ke=True, ndot=True, sort=False, meta=False, sources_only=False)[source]

Read the most recent CRIPTIC checkpoint in a specified directory

Parameters
dirnamestring

The name of the directory in which to find the checkpoint

chknamestring

Base name for checkpoint files; checkpoint files are files with names of the form basenameNNNNN.hdf5, where NNNNN is the checkpoint number

unitsbool

If True, all quantities are returned as astropy.Quantity objects with appropriate units; if False data are returned as flat numpy arrays.

kebool

If True, energies will be computed for all momentum quantities; only allowed if units is also True

ndotbool

If True, compute number of CRs injected per unit time for each source

sortbool

If True, all packets, deleted packets, and sources will be sorted in order of unique ID

metabool

If True, only the metadata are read and returned

sources_onlybool

If True, only sources are returned, not packets

Returns
outdict

a dict containing the following entries (some optional, may or may not be included depending on contents of the checkpoint file being read and the keywords provided)

“t”float or astropy.Quantity

time of output

“dt”float or astropy.Quantity

size of next time step

“step”int

next step number

“uid”int

value of the unique ID counter

“part_names”list of string

names of particles that correspond to each particle type

“packets”dict

a dict containing information on packets, with the following entries:

“x”ndarray or astropy.Quantity, size (n,3)

positions of all packets

“ptype”ndarray, size (n)

particle type numbers of all packets

“uid”ndarray, size (n)

unique IDs of all packets

“source”ndarray, size (n)

unique IDs of sources of all packets

“p”ndarray or astropy.Quantity, size (n)

momenta of all packets

“w”ndarray, size (n)

statistical weights of all packets

“tinj”ndarray or astropy.Quantity, size (n)

times at which each packet was injected

“wgtinj”ndarray or astropy.Quantity, size (n)

statistical weights of each packet at injection

“gr”ndarray or astropy.Quantity, size (n)

grammage traversed by each packet

“sec”ndarray, size (n)

boolean that is true if packet is a secondary, false if not

“lossmech”list of string

names of loss mechanisms

“T”ndarray or astropy.Quantity, size (n)

CR packet kinetic energies

“pres”ndarray or astropy.Quantity, size(n)

CR pressure divided by k_B at position of each packet; pressures only include packets with gyroradii >= the gyroradius of this packet

“presGrad”ndarray or astropy.Quantity, size (n,3)

gradient of pres

“eden”ndarray or astropy.Quantity, size(n)

CR energy density at position of each packet, including only CRs with gyroradii >= the gyroradius of this packet

“edenGrad”ndarray or astropy.Quantity, size(n,3)

gradient of eden

“nden”ndarray or astropy.Quantity, size(n)

CR number density at position of each packet, including only CRs with gyroradii >= the gyroradius of this packet

“ndenGrad”ndarray or astropy.Quantity, size(n,3)

gradient of nden

delpacketsdict

a dict containing information on packets that were deleted since the last checkpoint, with the following entries:

“x”ndarray or astropy.Quantity, size (m,3)

positions of all packets

“ptype”ndarray, size (m)

particle types of all packets

“uid”ndarray, size (m)

unique IDs of all packets

“source”ndarray, size (m)

unique IDs of sources of all packets

“p”ndarray or astropy.Quantity, size (m)

momenta of all packets

“w”ndarray, size (m)

statistical weights of all packets

“tinj”ndarray or astropy.Quantity, size (m)

times at which each packet was injected

“wgtinj”ndarray, size (m)

statistical weights of each packet at injection

“gr”ndarray or astropy.Quantity, size (m)

grammage traversed by each packet

“T”ndarray or astropy.Quantity, size (n)

CR packet kinetic energies

sourcesdict

a dict containing information on sources, with the following entries:

“x”ndarray or astropy.Quantity, size (i,3)

positions of all sources

“ptype”ndarray, size(i)

particle types produced by sources

“uid”ndarray, size (i)

unique IDs of all sources

“p0”ndarray or astropy.Quantity, size (i)

lower limit of momentum of packets injected by each source

“p1”ndarray or astropy.Quantity, size (i)

upper limit of momentum of packets injected by each source

“q”ndarray, size (i)

index of source momentum distribution

“coef”ndarray or astropy.Quantity, size (i)

coefficient of source momentum distribution

“ndot”ndarray or astropy.Quantity, size (i)

number of CRs injected per unit time by source

lossesdict

a dict containing information on losses, with the following entries:

“lossrate”ndarray or astropy.Quantity, size(n,m)

rate of catastrophic loss for all loss processes

“dpdt”ndarray or astropy.Quantity, size(n,m)

rate of continuous momentum loss for all loss processes

photonsdict

a dict containing information on photon emission, with the following entries:

“en”ndarray or astropy.Quantity, size(j)

energies at which photon emission is calculated

“freq”ndarray or astropy.Quantity, size(j)

frequencies at which photon emission is calculated; equal to en / h

“dLdE”ndarray or astropy.Quantity, size(n,m,j)

array giving the specific luminosity dL/dE (units of erg s^-1 GeV^-1 or J s^-1 GeV^-1 if criptic was run in MKS mode) of each of the n packets produced via each of the m loss mechanisms at each of the j energies

“dLdE_sum”ndarray or astropy.Quantity, size(u,v,m,j)

array giving the specific luminosity dL/dE (units of erg s^-1 GeV^-1 or J s^-1 GeV^-1 if criptic was run in MKS mode) produced by different mechanisms and particle populations; the index u runs from 0 to number of distinct particle types, and gives emission produced by that type; the index v is 0 (for primary particles) or 1 (for secondary particles); the index m runs over all the emission mechanisms (in the same orders as lossmech); finally, the index j runs over the j energies in en

ionizationdict

a dict containing information on ionization rates, with the following entries:

“targets”list of string

names of the ionization targets included in the file

“rate”ndarray or astropy.Quantity, size(n,m)

array of size number of packets x number of ionization targets, giving the ionization rate (units of 1/time) for each packet for each target species

dpdt_transportdict

a dict containing information on rates of momentum change by transport (as opposed to loss) processes, with the following entries:

“Fermi2”ndarray or astropy.Quantity, size(n)

rate of momentum change due to 2nd order Fermi acceleration

“adiabatic”ndarray or astropy.Quantity, size(n)

rate of momentum change due to adiabatic gain or loss

“streaming”ndarray or astropy.Quantity, size(n)

rate of momentum change due to streaming gain or loss

cripticpy.vp(p, ptype)[source]

Compute a velocity from a momentum for a given particle type

Parameters
pastropy.Quantity

momentum

ptypeint, string, or array of int or string

particle type(s); can be specified by number as used internally in criptic, or by name; known names are ‘proton’, ‘electron’, ‘positron’, ‘boron10’, ‘boron11’, ‘carbon12’, ‘nitrogen14’, ‘oxygen16’

Returns
vastropy.Quantity

velocities