pysme package¶
Subpackages¶
- pysme.gui package
- Submodules
- pysme.gui.plot_colors module
- pysme.gui.plot_plotly module
FinalPlot
FinalPlot.add()
FinalPlot.create_mask_points()
FinalPlot.create_plot()
FinalPlot.on_toggle_click()
FinalPlot.save()
FinalPlot.selection_fn()
FinalPlot.set_mask_bad()
FinalPlot.set_mask_continuum()
FinalPlot.set_mask_good()
FinalPlot.set_mask_line()
FinalPlot.set_mask_type()
FinalPlot.shift_mask()
FinalPlot.show()
FitPlot
- pysme.gui.plot_pyplot module
- Module contents
Submodules¶
pysme.abund module¶
Elemental abundance data handling module
- class pysme.abund.Abund(monh=0, pattern='solar', type='sme', citation_info='\n@article{loss2003atomic,\n title={Atomic weights of the elements 2001 (IUPAC Technical Report)},\n author={Loss, RD},\n journal={Pure and Applied Chemistry},\n volume={75},\n number={8},\n pages={1107--1122},\n year={2003},\n publisher={De Gruyter}\n}\n')[source]¶
Bases:
IPersist
Elemental abundance data and methods. Valid abundance pattern types are:
- ‘sme’ - For hydrogen, the abundance value is the fraction of all
nuclei that are hydrogen, including all ionization states and treating molecules as constituent atoms. For the other elements, the abundance values are log10 of the fraction of nuclei of each element in any form relative to the total for all elements in any form. For the Sun, the abundance values of H, He, and Li are approximately 0.92, -1.11, and -11.0.
- ‘n/nTot’ - Abundance values are the fraction of nuclei
of each element in any form relative to the total for all elements in any form. For the Sun, the abundance values of H, He, and Li are approximately 0.92, 0.078, and 1.03e-11.
- ‘n/nH’ - Abundance values are the fraction of nuclei
of each element in any form relative to the number of hydrogen nuclei in any form. For the Sun, the abundance values of H, He, and Li are approximately 1, 0.085, and 1.12e-11.
- ‘H=12’ - Abundance values are log10 of the fraction of nuclei of
each element in any form relative to the number of hydrogen in any form plus an offset of 12. For the Sun, the nuclei abundance values of H, He, and Li are approximately 12, 10.9, and 1.05.
- static fromtype(pattern, fromtype, raw=False)[source]¶
Return a copy of the input abundance pattern, transformed from the input type to the ‘H=12’ type. Valid abundance pattern types are ‘sme’, ‘n/nTot’, ‘n/nH’, ‘n/nFe’, and ‘H=12’.
- get_pattern(type=None, raw=False)[source]¶
Transform the specified abundance pattern from type used internally by SME to the requested type. Valid abundance pattern types are: ‘sme’, ‘n/nTot’, ‘n/nH’, ‘H=12’
- Parameters:
type (str) – The pattern format to retrieve the pattern as. Defaults to the original input format.
raw (bool) – If True will return the pattern as a numpy array, with indices as defined in elem dict. Otherwise the return value is a dictionary, with the elements as keys.
- set_pattern_by_name(pattern_name)[source]¶
Set the abundance pattern to one of the predefined options
- Parameters:
pattern_name (str) – Name of the predefined option to use. One of ‘asplund2009’, ‘grevesse2007’, ‘lodders2003’, ‘empty’
- Raises:
ValueError – If an undefined pattern_name was given
- static totype(pattern, totype, raw=False, copy=True)[source]¶
Return a copy of the input abundance pattern, transformed from the ‘H=12’ type to the output type. Valid abundance pattern types are ‘sme’, ‘n/nTot’, ‘n/nH’, and ‘H=12’.
- update_pattern(updates)[source]¶
Update the abundance pattern for several elements at once
The abundance is first converted into the initially specified format, before being converted back to the internal format
- Parameters:
updates (dict{str:float}) – the elements to update
- Raises:
KeyError – If any of the element keys is not valid
- property elem¶
Return the standard abbreviation for each element. Use property so user will not redefine elements.
- property elem_dict¶
Return the position of each element in the raw array
- property monh¶
Metallicity, the logarithmic offset added to the abundance pattern for all elements except hydrogen and helium.
- Type:
float
- property pattern¶
Abundance pattern in the initial format
- Type:
array
pysme.atmosphere module¶
pysme.broadening module¶
- pysme.broadening.apply_broadening(ipres, x_seg, y_seg, type='gauss', sme=None)[source]¶
Broaden a spectrum by instrument resolution, with a given broadening type
- Parameters:
ipres (float) – instrument resolution
x_seg (array (npoints,)) – x values (wavelength) of the spectrum to broaden
y_seg (array (npoints,)) – y values (intensities) of the spectrum to broaden
type ({str, None}, optional) – broadening type to apply. Options are “gauss”, “sinc”, “table”, None. If None, will try to use sme.iptype to determine type. “table” requires keyword sme to be passed as well. See functions the respective for details. (default: “gauss”)
sme (SME_Struct, optional) – sme structure with instrument profile data, required only for type=”table” or type=None (default: None)
- Raises:
AttributeError – if type requires SME_Struct, but its missing passed type not recognized
- Returns:
y_seg – broadened intensity spectrum
- Return type:
array (npoints,)
- pysme.broadening.gaussbroad(w, s, hwhm)[source]¶
Smooths a spectrum by convolution with a gaussian of specified hwhm.
- Parameters:
w (array[n]) – wavelength scale of spectrum to be smoothed
s (array[n]) – spectrum to be smoothed
hwhm (float) – half width at half maximum of smoothing gaussian.
- Returns:
sout – the gaussian-smoothed spectrum.
- Return type:
array[n]
- pysme.broadening.sincbroad(w, s, hwhm)[source]¶
Smooths a spectrum by convolution with a sinc function of specified hwhm.
- Parameters:
w (array of size (n,)) – wavelength scale of spectrum to be smoothed
s (array of size (n,)) – spectrum to be smoothed
hwhm (float) – half width at half maximum of smoothing gaussian.
- Returns:
sout – the sinc-smoothed spectrum.
- Return type:
array of size (n,)
- pysme.broadening.tablebroad(w, s, xip, yip)[source]¶
Convolves a spectrum with an arbitrary instrumental profile.
- Parameters:
w (array of size (n,)) – wavelength scale of spectrum to be smoothed
s (array of size (n,)) – spectrum to be smoothed
xip (array of size (m,)) – x points of the instrument profile
yip (array of size (m,)) – y points of the instrument profile
- Returns:
sout – the smoothed spectrum.
- Return type:
array[n]
pysme.config module¶
Handle the Json configuration file At the moment it is only used for the LargeFileStorage
pysme.continuum_and_radial_velocity module¶
pysme.cwrapper module¶
Wrapper for IDL style C libary code
{return_type} {func_name}(int argv, void *argc[]);
with argv - number of parameters and argc - list of pointers to those parameters
- class pysme.cwrapper.GlobalState[source]¶
Bases:
Structure
- ABUND¶
Structure/Union member
- ACOOL¶
Structure/Union member
- AH2P¶
Structure/Union member
- AHE1¶
Structure/Union member
- AHE2¶
Structure/Union member
- AHEMIN¶
Structure/Union member
- AHMIN¶
Structure/Union member
- AHOT¶
Structure/Union member
- AHYD¶
Structure/Union member
- ALMAX¶
Structure/Union member
- ALUKE¶
Structure/Union member
- ANSTEE¶
Structure/Union member
- ATOTAL¶
Structure/Union member
- AUTOION¶
Structure/Union member
- AVOIGT¶
Structure/Union member
- BNLTE_low¶
Structure/Union member
- BNLTE_upp¶
Structure/Union member
- BNU¶
Structure/Union member
- COPBLU¶
Structure/Union member
- COPRED¶
Structure/Union member
- COPSTD¶
Structure/Union member
- EHVKT¶
Structure/Union member
- ENL4¶
Structure/Union member
- ENU4¶
Structure/Union member
- EXCIT¶
Structure/Union member
- EXCUP¶
Structure/Union member
- FRACT¶
Structure/Union member
- FREQ¶
Structure/Union member
- FREQLG¶
Structure/Union member
- GAMQST¶
Structure/Union member
- GAMRAD¶
Structure/Union member
- GAMVW¶
Structure/Union member
- GF¶
Structure/Union member
- GRAV¶
Structure/Union member
- H1FRACT¶
Structure/Union member
- H2molFRACT¶
Structure/Union member
- HE1FRACT¶
Structure/Union member
- HKT¶
Structure/Union member
- IDLHEL¶
Structure/Union member
- IFOP¶
Structure/Union member
- INDX_C¶
Structure/Union member
- ION¶
Structure/Union member
- IXAL1¶
Structure/Union member
- IXC1¶
Structure/Union member
- IXCA1¶
Structure/Union member
- IXCA2¶
Structure/Union member
- IXCH¶
Structure/Union member
- IXFE1¶
Structure/Union member
- IXH1¶
Structure/Union member
- IXH2¶
Structure/Union member
- IXH2mol¶
Structure/Union member
- IXH2pl¶
Structure/Union member
- IXHE1¶
Structure/Union member
- IXHE2¶
Structure/Union member
- IXHE3¶
Structure/Union member
- IXHMIN¶
Structure/Union member
- IXMG1¶
Structure/Union member
- IXMG2¶
Structure/Union member
- IXN1¶
Structure/Union member
- IXNH¶
Structure/Union member
- IXO1¶
Structure/Union member
- IXOH¶
Structure/Union member
- IXSI1¶
Structure/Union member
- IXSI2¶
Structure/Union member
- LINEOP¶
Structure/Union member
- LTE_b¶
Structure/Union member
- MARK¶
Structure/Union member
- MOLWEIGHT¶
Structure/Union member
- MOTYPE¶
Structure/Union member
- NLINES¶
Structure/Union member
- NRHOX¶
Structure/Union member
- NRHOX_allocated¶
Structure/Union member
- NWAVE_C¶
Structure/Union member
- N_SPLIST¶
Structure/Union member
- NumberSpectralSegments¶
Structure/Union member
- PARTITION_FUNCTIONS¶
Structure/Union member
- PATH¶
Structure/Union member
- PATHLEN¶
Structure/Union member
- POTION¶
Structure/Union member
- RADIUS¶
Structure/Union member
- RAD_ATMO¶
Structure/Union member
- RHO¶
Structure/Union member
- RHOX¶
Structure/Union member
- RHO_eos¶
Structure/Union member
- SIGEL¶
Structure/Union member
- SIGH¶
Structure/Union member
- SIGH2¶
Structure/Union member
- SIGHE¶
Structure/Union member
- SPINDEX¶
Structure/Union member
- SPLIST¶
Structure/Union member
- STIM¶
Structure/Union member
- T¶
Structure/Union member
- TEFF¶
Structure/Union member
- TK¶
Structure/Union member
- TKEV¶
Structure/Union member
- TLOG¶
Structure/Union member
- VTURB¶
Structure/Union member
- VVOIGT¶
Structure/Union member
- VW_SCALE¶
Structure/Union member
- WFIRST¶
Structure/Union member
- WLAST¶
Structure/Union member
- WLCENT¶
Structure/Union member
- WLSTD¶
Structure/Union member
- Wlim_left¶
Structure/Union member
- Wlim_right¶
Structure/Union member
- XMASS¶
Structure/Union member
- XNA¶
Structure/Union member
- XNA_eos¶
Structure/Union member
- XNE¶
Structure/Union member
- XNE_eos¶
Structure/Union member
- YABUND¶
Structure/Union member
- allocated_NLTE_lines¶
Structure/Union member
- change_byte_order¶
Structure/Union member
- debug_print¶
Structure/Union member
- flagABUND¶
Structure/Union member
- flagCONTIN¶
Structure/Union member
- flagH2broad¶
Structure/Union member
- flagIONIZ¶
Structure/Union member
- flagLINELIST¶
Structure/Union member
- flagMODEL¶
Structure/Union member
- flagNLTE¶
Structure/Union member
- flagWLRANGE¶
Structure/Union member
- initNLTE¶
Structure/Union member
- lineOPACITIES¶
Structure/Union member
- result¶
Structure/Union member
- spname¶
Structure/Union member
- class pysme.cwrapper.IDL_DLL(*args, **kwargs)[source]¶
Bases:
object
- call(name, *args, raise_error=True, raise_warning=False, **kwargs)[source]¶
run idl_call_external and check for errors in the output
- Parameters:
name (str) – name of the external C function to call
args – parameters for the function
kwargs – keywords for the function
- Raises:
ValueError – If the returned string is not empty, it means an error occured in the C library
- class pysme.cwrapper.IDL_String[source]¶
Bases:
Structure
IDL strings are actually structures like this one, for correct passing of values we need to define this structure NOTE: the definition might have changed with IDL version, so make sure to use the same one as in the C code
- s¶
Structure/Union member
- slen¶
Structure/Union member
- stype¶
Structure/Union member
- pysme.cwrapper.get_dtype(type)[source]¶
Get the ctypes dtype appropiate for the passed type string
- Parameters:
type (str) – One of ‘int’, ‘short’, ‘long’, ‘float’, ‘double’, ‘unicode’ or one of the first letters ‘islfdu’
- Returns:
type – corresponding ctypes type
- Return type:
class
- pysme.cwrapper.get_typenames(arg)[source]¶
Return internal typename based on the type of the argument strings -> “unicode” floating points -> “double” integers -> “int”
- pysme.cwrapper.idl_call_external(funcname, *args, restype='str', type=None, lib=None, state=None)[source]¶
Call an external C library (here the SME lib) function that uses the IDL type interface i.e. restype func(int n, void *args[]), where n is the number of arguments, and args is a list of pointers to the arguments
Input arrays will be converted to the required datatype for the C function (see type keyword), and any changes to input arrays will be written back if possible. Input arrays that are already in the correct datatype will not be copied (and the values can therefore change in the C call)
Note that all strings are converted into IDL_String objects, even those that are in arrays
- Parameters:
funcname (str) – Name of the function to call in the library
restype (str, optional) – expected type of the return value (default: “str”)
type (str, list(str), optional) – type of the input parameters, will default to int/double for all integer/floating point values. Accepted values are (‘short’, ‘int’, ‘long’, ‘float’, ‘double’, ‘unicode’) or their respective first letters. This means one can use a string as shorthand, e.g. “iidds”
- Returns:
value – return value of the function call
- Return type:
restype
pysme.echelle module¶
Contains functions to read and modify echelle structures, just as in reduce
Mostly for compatibility reasons
- pysme.echelle.calc_1dpolynomials(ncol, poly)[source]¶
Expand a set of 1d polynomials (one per order) seperately
- Parameters:
ncol (int) – number of columns
poly (array[nord, degree]) – polynomial coefficients
- Returns:
poly – expanded polynomials
- Return type:
array[nord, ncol]
- pysme.echelle.calc_2dpolynomial(solution2d)[source]¶
Expand a 2d polynomial, where the data is given in a REDUCE make_wave format Note that the coefficients are for order/100 and column/1000 respectively, where the order is counted from order base up
- Parameters:
solution2d (array) – data in a REDUCE make_wave format: 0: version 1: number of columns 2: number of orders 3: order base, i.e. 0th order number 4-6: empty 7: number of cross coefficients 8: number of column only coefficients 9: number of order only coefficients 10: coefficient - constant 11-x: column coefficients x-y : order coefficients z- : cross coefficients (xy, xy2, x2y, x2y2, xy3, x3y), with x = orders, y = columns
- Returns:
poly – expanded polynomial
- Return type:
array[nord, ncol]
- pysme.echelle.expand_polynomial(ncol, poly)[source]¶
Checks if and how to expand data poly, then expands the data if necessary
- Parameters:
ncol (int) – number of columns in the image
poly (array[nord, ...]) – polynomial coefficients to expand, or already expanded data
- Returns:
poly – expanded data
- Return type:
array[nord, ncol]
- pysme.echelle.read(fname, extension=1, raw=False, continuum_normalization=True, barycentric_correction=True, radial_velociy_correction=True)[source]¶
Read data from an echelle file Expand wavelength and continuum polynomials Apply barycentric/radial velocity correction Apply continuum normalization
Will load any fields in the binary table, however special attention is given only to specific names: “SPEC” : Spectrum “SIG” : Sigma, i.e. (absolute) uncertainty “CONT” : Continuum “WAVE” : Wavelength solution “COLUMNS” : Column range
- Parameters:
fname (str) – filename to load
extension (int, optional) – fits extension of the data within the file (default: 1)
raw (bool, optional) – if true apply no corrections to the data (default: False)
continuum_normalization (bool, optional) – apply continuum normalization (default: True)
barycentric_correction (bool, optional) – apply barycentric correction (default: True)
radial_velociy_correction (bool, optional) – apply radial velocity correction (default: True)
- Returns:
ech – Echelle structure, with data contained in attributes
- Return type:
obj
- pysme.echelle.save(fname, header, **kwargs)[source]¶
Save data in an Echelle fits, i.e. a fits file with a Binary Table in Extension 1
The data is passed in kwargs, with the name of the binary table column as the key Floating point data is saved as float32 (E), Integer data as int16 (I)
- Parameters:
fname (str) – filename
header (fits.header) – FITS header
**kwargs (array[]) – data to be saved in the file
pysme.iliffe_vector module¶
- class pysme.iliffe_vector.Iliffe_vector(values, offsets=None, dtype=None)[source]¶
Bases:
NDArrayOperatorsMixin
,MultipleDataExtension
Illiffe vectors are multidimensional (here 2D) but not necessarily rectangular Instead the index is a pointer to segments of a 1D array with varying sizes
- property dtype¶
- property ndim¶
- property nseg¶
- property segments¶
- property shape¶
- property size¶
- property sizes¶
pysme.large_file_storage module¶
pysme.linelist module¶
pysme.nlte module¶
pysme.persistence module¶
- pysme.persistence.load(fname, sme)[source]¶
Load the SME Structure from disk
- Parameters:
fname (str) – file to load
sme (SME_Structure) – empty sme structure with default values set
- Returns:
sme – loaded sme structure
- Return type:
SME_Structure
- pysme.persistence.save(filename, sme, format='flex', _async=False)[source]¶
Create a folder structure inside a tarfile See flex-format for details
- Parameters:
filename (str) – Filename of the final file
sme (SME_Structure) – sme structure to save
compressed (bool, optional) – whether to compress the output
- pysme.persistence.save_as_idl(sme, fname)[source]¶
Save the SME structure to disk as an idl save file
This writes a IDL script to a temporary file, which is then run with idl as a seperate process. Therefore this reqires a working idl installation.
There are two steps to this. First all the fields from the sme, structure need to be transformed into simple idl readable structures. All large arrays are stored in seperate binary files, for performance. The script then reads those files back into idl.
- pysme.persistence.save_v1(filename, data, folder='', compressed=False)[source]¶
Create a folder structure inside a zipfile Add .json and .npy and .npz files with the correct names And subfolders for more complicated objects with the same layout Each class should have a save and a load method which can be used for this purpose
- Parameters:
filename (str) – Filename of the final zipfile
data (SME_struct) – data to save
folder (str, optional) – subfolder to save data to
compressed (bool, optional) – whether to compress the output
pysme.sme module¶
pysme.sme_synth module¶
pysme.solve module¶
pysme.uncertainties module¶
- pysme.uncertainties.gaussfit(x, y, nterms='none')[source]¶
Fit a simple gaussian to data
gauss(x, a, mu, sigma) = a * exp(-z**2/2) with z = (x - mu) / sigma
- Parameters:
x (array(float)) – x values
y (array(float)) – y values
- Returns:
fitted values for x, fit paramters (a, mu, sigma)
- Return type:
gauss(x), parameters