ChiantiPy.model package¶
Submodules¶
ChiantiPy.model.Maker module¶
classes and methods to analyze observations of astrophysical spectra
- ChiantiPy.model.Maker.doDemGofntQ(inQueue, outQueue)¶
helper for multiprocessing with maker.mgofnt()
- ChiantiPy.model.Maker.emPlot(matchDict, vs='T', loc='upper right', fs=10, lw=2, adjust=None, position='both', legend=True, verbose=0)¶
to plot line intensities divided by gofnt adjust is to provide an adjustment to the position of the labels position : one of ‘both’, ‘right’, ‘left’, or ‘none’
- Keyword Arguments:
vs (str, either ‘T’, or ‘D’) – whether to plot the emission measure vs temperature or density
loc (str) – matplotlib argument for plt.legend
fs (int) – the fontsize for the legend
lw (int) – set the line width of the plot, default = 2
adjust (list) – a list of multiplicative adjustments to the labels to the plot lines must be the same length as the number of lines
position (str) –
- where the labels to the lines should be placed, both for both ends, left for the left size
only, ‘right’ for the right side only, or None for no labels
label (bool) – whether to apply
legend (bool) – whether to include a matplotlib legend
fontsize (int) – fontsize for the matplotlib xlabel and ylabel
tscale (float) – scale the temperature by dividing by tscale
verbose (bool) – if True, additional output is sent to the terminal
- class ChiantiPy.model.Maker.maker(specData, temperature=None, eDensity=None, elementList=[], ionList=[], allLines=False, abundanceName=None, minAbund=10.0, wghtFactor=None, verbose=False)¶
Bases:
ionTrails
,specTrails
a class matching observed lines to lines in the CHIANTI database
- Parameters:
specData (dict) – contains the following keys intensity - a list of observed line intensities wvlObs - a list of observed wavelengths, usually in Angstroms dwvl the expected wavelength different between the observed wvl and CHIANTI
- Keyword Arguments:
temperature (float, list, ndarray) – the temperature(s) in K, default is None
eDensity (float, ndarray) – eDensity: electron density in \(\mathrm{cm^{-3}}\), default is None
elementList (list) – a list of elements, such as fe, to be searched, default = []
ionList (list) – a list of ions, such as fe_14, to be searched, default = []
allLines (bool) – if true, unobserved lines in CHIANTI are included in the search, default = False
abundanceName (str) – the name of the elemental abundance file to be used, the defaul t is None if not set, the default abundance file is used
minAbund (float) – sets the minimum abundance for an element to be included in the search, default = 10. to include all elements
verbose (bool) – if True, additional output is sent to the terminal, default is False
- argCheck(temperature=None, eDensity=None, pDensity='default', verbose=False)¶
to check the compatibility of the three arguments and put them into numpy arrays of atleast_1d
- Keyword Arguments:
temperature (float, list, ndarray) – the temperature(s) in K
eDensity (float, ndarray) – eDensity: electron density in \(\mathrm{cm^{-3}}\)
pDensity (str, float, ndarray) – pDensity: proton density in \(\mathrm{cm^{-3}}\) defaults to ‘default’
verbose (bool) – if True, additional output is sent to the terminal
- diff(sort=None, verbose=False)¶
calculates the weighted and straight differences between observed and predicted creates an attribute self.Dict, a dict with the following keys: ‘wvl’ = observed wavelength (A) ‘relDiff’ = (I_obs - I_pred)/(I_obs) ‘ionS’ the CHIANTI type name for an ion sort be either of none, ‘wvl’, or ‘ion’
- Keyword Arguments:
sort (str or None) – whether the output should be sorted by wvl or ion or not
- diffPlot(ratio='diffOverInt', title=False, loc='upper right', fontsize=16, figsize=[7.0, 5.0])¶
- Parameters:
ratio (str) – determines which Y values to print can be ‘diffOverInt’ (default), or ‘intOverPred’, or ‘predOverInt’
title (bool) – whether to plot the title or not
fontsize (int) – fontsize for matplotlib plots
figsize (2d list, ndarray) – the figure size for the plot
- Variables:
DiffPlot (dict) – contains the fig, ax matplotlib objects created
- diffPrint(filename='diffPrint.txt', sort=None)¶
calculates the weighted and straight differences between observed and predicted prints the values and saves to a file also created a attribute self.Dict, a dict with the following keys: ‘wvl’ = observed wavelength (A) ‘relDiff’ = (I_obs - I_pred)/(I_obs) ‘ionS’ the CHIANTI type name for an ion
- Keyword Arguments:
filename (str) – the filename where the text should be output
sort (str, can be wvl, ion, or None) – whether the output should be sorted by wvl or ion or not
- emFitPlot()¶
to plot the emission measures derived from a chi-squared search over temperature
- emPlot(vs='T', loc='upper right', fs=10, lw=2, adjust=None, position='both', label=True, legend=True, fontsize=16, tscale=1.0, verbose=True)¶
to plot line intensities divided by gofnt adjust is to provide an adjustment to the position of the labels position : one of ‘both’, ‘right’, ‘left’, or ‘none’
- Keyword Arguments:
vs (str, either ‘T’, or ‘D’) – whether to plot the emission measure vs temperature or density
loc (str) – matplotlib argument for plt.legend
fs (int) – the fontsize for the legend, default = 10
lw (int) – set the line width of the plot, default = 2
adjust (list) – a list of multiplicative adjustments to the labels to the plot lines must be the same length as the number of lines, default = None
position (str) – where the labels to the lines should be placed, both for both ends, left for the left size only, ‘right’ for the right side only, or None for no labels, default is ‘both’
label (bool) – whether to apply, default = True
legend (bool) – whether to include a matplotlib legend, default =True
fontsize (int) – fontsize for the matplotlib xlabel and ylabel, default=16
tscale (float) – scale the temperature by dividing by tscale, default = 1.
verbose (bool) – if True, additional output is sent to the terminal, default = True
- emPlotObj(vs='T', loc='upper right', fs=10, lw=2, adjust=None, position='both', label=True, legend=True, fontsize=16, figsize=[7.0, 5.0], tscale=1.0, verbose=True)¶
the emPlot using the object oriented version of matplotlib - a figure and axis objects are returned to plot line intensities divided by gofnt adjust is to provide an adjustment to the position of the labels position : one of ‘both’, ‘right’, ‘left’, or ‘none’ this uses the modern object interface fig, ax = plt.subplots(figsize=figsize) fig, ax are in returned in the self.EmPlotOjb dict
- Keyword Arguments:
vs (str, either ‘T’, or ‘D’) – whether to plot the emission measure vs temperature or density
loc (str) – matplotlib argument for plt.legend, default = ‘upper right’
fs (int) – the fontsize for the legend, default = 10
lw (int) – set the line width of the plot, default = 2
adjust (list) – a list of multiplicative adjustments to the labels to the plot lines must be the same length as the number of lines, default = None
position (str) – where the labels to the lines should be placed, both for both ends, left for the left size only, ‘right’ for the right side only, or None for no labels, default = ‘both’
label (bool) – whether to apply, default = True
legend (bool) – whether to include a matplotlib legend, default = True
fontsize (int) – fontsize for the matplotlib xlabel and ylabel, default = 16
figsize (two element list or ndarray) – sets the figure size when using matplotlib subplots to initiate the object style plotting, default = [7., 5.]
tscale (float) – scale the temperature by dividing by tscale, default = 1.
verbose (bool) – if True, additional output is sent to the terminal, default = True
- emSet(value)¶
sets the EM values for a N temperature EM distribution
- Parameters:
value (list, ndarray) – the values of the emission measure to be used when the intensities are predicted
- emSetIndices(indices, add=1.0, verbose=0)¶
to set the indices of the N temperature/density EM distribution can increase the number of paramaters if additional parameters have been used
- Parameters:
indices (list, ndarray) – the indices of the temperature/density arrays for which a set of intensities will be predicted
- Keyword Arguments:
add (float) – to increase the number of parameters used in the calculation of the reduced chi-squared
verbose (bool) – if True, additional output is sent to the terminal
- emWrite(filename, directory, reference)¶
to make a CHIANTI style emission measure file outName does not need the suffix .em reference should be a list of references
- Parameters:
filename (str) – the name of the em file to be produced
reference (list) – a list of strings providing a reference at the end of the em file
- findMinMaxIndices(verbose=0)¶
to find the minimum and maximum indices where all match[‘intensitySum’] are greater than 0
- Keyword Arguments:
verbose (bool) – if True, additional output is sent to the terminal
- fit1t(initialValue, maxfev=0)¶
calls leastsq to fit the 1t (single temperature) model used in search1dspace
- Parameters:
initialValue (float) – the initial value to start the leastsq process
Todo
see if this can be replaced by fitFunct1t or fitNt
- fitFunc1t(em)¶
the fitting function for the isothermal model to be called by leastsq called by fit1t
- Parameters:
em (number) – the log10 value of the emission measure
- Returns:
weighted chisquared
- Return type:
float
Todo
see if this can be replaced by fitFuncNt
- fitFuncNt(value)¶
the fitting function for the multiple temperature model to be called by leastsq called by fitNt
- Parameters:
value (list) – the initial values for the em fit
- fitNt(initialValue, maxfev=0)¶
calls leastsq to fit the multi temperature models called by search2tSpace, search3tSpace etc
- Parameters:
initialValue (list) – the initial trial value for the emission measure (log1))
- Keyword Arguments:
maxfev (int) – not sure it is needed
- getChisq()¶
return the weighted chi-squared
- getNormalizedChisq()¶
return normalized chisq: chi-squared divided by the number of observed lines
- getWeightedDiff()¶
to calculated the weighted difference of each of the intensities returns a 1D array
- gofnt(temperature, density, verbose=1)¶
calculate the gofnt function for each of the matched lines do each ion only once
- Parameters:
temperature (float, list, ndarray) – the temperature(s) in K
density (float, list, ndarray) – density: electron density in \(\mathrm{cm^{-3}}\)
- loadMatch(filename)¶
to open a pickle file, return the match data and make it an attribute
- loadSearchData(filename)¶
to load the pickled search data as an attribute self.SearchData
- Keyword Arguments:
filename (str) – the filename of the pickle file where the search data has been created
- makeMatch(verbose=False)¶
to match the CHIANTI lines with the input specdata uses ionTrails.ionGate to sort through ions
- Keyword Arguments:
verbose (bool) – if True, additional output is sent to the terminal
- matchPrint(filename='matchPrint.txt', sort=None, verbose=False)¶
to print out the data for the matches to the observed lines sort can be ‘wvl’ or ‘ion’, otherwise, there is no sorting done does not require predicted values
- Keyword Arguments:
filename (str) – the filename where the text should be output
sort (str, can be wvl, ion, or None) – whether the output should be sorted by wvl or ion or not
verbose (bool) – if True, additional output is sent to the terminal
- mgofnt(temperature, density, proc=6, timeout=0.1, verbose=False)¶
calculate the gofnt function for each of the matched lines this is the multiprocessing version does each ion only once
- Parameters:
temperature (float, list, ndarray) – the temperature(s) in K
density (float, list, ndarray) – density: electron density in \(\mathrm{cm^{-3}}\)
- Keyword Arguments:
proc (int) – the number of cores to be used
timeout ('float') – may not actually be necessary
verbose (bool) – if True, additional output is sent to the terminal
- predict()¶
to predict the intensities of the observed lines from an emission measure the emission measure is already specified as self.Em which is an ndarray the temperatures are set by emSetIndices
- predictPrint(minContribution=0.1, filename='predictPrint.txt', sort=None, verbose=0)¶
to predict the intensities of the observed lines from an emission measure the emission measure is already specified as self.Em which is an np array sort can be ‘wvl’ or ‘ion’, otherwise, there is no sorting done
- Keyword Arguments:
minContribution (float) – the minimum contribution a blend must supply to be included in the text output
filename (str) – the filename where the text should be output
sort (str, can be wvl, ion, or None) – whether the output should be sorted by wvl or ion or not
verbose (bool) – if True, additional output is sent to the terminal
- predictPrint1d(minContribution=0.1, filename='predictPrint1d.txt', verbose=False)¶
to predict the intensities of the observed lines from an emission measure the emission measure is already specified as self.Em which is an np array
to be used after a 1d search over density
- Keyword Arguments:
minContribution (float) – the minimum contribution a blend must supply to be included in the text output
filename (str) – the filename where the text should be output
verbose (bool) – if True, additional output is sent to the terminal
- saveMatch(filename)¶
to save the attribute Match to a pickle file so that it can be reloaded later
- Keyword Arguments:
filename (str) – the filename where the text should be output
- saveSearchData(filename)¶
to save the attribute SearchData to a pickle file
- Keyword Arguments:
filename (str) – the filename of the pickle file where the search data is to be created
- search1dSpace(initialEm, indxlimits=None, verbose=False, log=False, maxfev=0)¶
to conduct a brute force search over electron density for an isothermal-space and find the best fit to the em and density indxlimits give the range of indices to fit over can use self.MinIndex and self.MaxIndex+1 initialEm = log value of the emission measure to begin the searching
- Parameters:
initialEm (float) – the initial trial value for the log10 emission measure
- Keyword Arguments:
indxlimits (list, None) – the range of indices of the density array to search if None is specified, the whole range is searched
verbose (bool) – if True, additional output is sent to the terminal
log (bool) – if True, a log file is created - ‘search1d.raw’
- search1tEmSpace(verbose=False)¶
to find the value of chisq as a function of Em with T = best-fit
- Keyword Arguments:
verbose (bool) – if True, additional output is sent to the terminal
- search1tSpace(initialEM, indexLimits=None, logname=None, verbose=False, maxfev=0)¶
- conduct a brute force search of 2 temperature space and find the
best fit
- initialEm: float
the initial trial value for the log10 emission measure
- indexLimits: 2 dimensional array type
the lower an upper limits of the temperature to be searched the default is None and them the whole temperature array is searched
- logname: str
the name of the file were the search log is written the default is None and no log will be written
- verbose: bool
if True, additional output is sent to the terminal
- search2tSpace(initialEM, indexLimits=None, verbose=False, log=False, maxfev=0)¶
to conduct a brute force search of 2 temperature space and find the best fit indexLimits give the range of indices to fit over
- Parameters:
initialEM (list) – the initialEM trial values (2) for the log10 emission measure
- Keyword Arguments:
indexLimits (list, None) – the range of indices of the density array to search if None is specified, the whole range is searched
verbose (bool) – if True, additional output is sent to the terminal
log (bool) – if True, a log file is created - ‘search1d.raw’
- search3tSpace(initialEM, indexLimits=None, verbose=0, log=0)¶
to conduct a brute force search of 3 temperature space and find the best fit
- Parameters:
initialEM (list) – the initialEM trial values (3) for the log10 emission measure
- Keyword Arguments:
indexLimits (list, None) – the range of indices of the density array to search if None is specified, the whole range is searched
verbose (bool) – if True, additional output is sent to the terminal
log (bool) – if True, a log file is created - ‘search1d.raw’
- search4tSpace(initialEM, indexLimits=None, verbose=0, log=0)¶
to conduct a brute force search of 4 temperature space and find the best fit set log to create a log file of the iterations rather that outputting to the jupyter/ipython session
- Parameters:
initialEM (list) – the initialEM trial values (4) for the log10 emission measure
- Keyword Arguments:
indexLimits (list, None) – the range of indices of the density array to search if None is specified, the whole range is searched
verbose (bool) – if True, additional output is sent to the terminal
log (bool) – if True, a log file is created - ‘search1d.raw’