pysme.atmosphere package#
Subpackages#
Submodules#
pysme.atmosphere.atmosphere module#
Handles reading and interpolation of atmopshere (grid) data
- exception pysme.atmosphere.atmosphere.AtmosphereError[source]#
Bases:
RuntimeErrorSomething went wrong with the atmosphere interpolation
- class pysme.atmosphere.atmosphere.Atmosphere(*args, **kwargs)[source]#
Bases:
CollectionAtmosphere structure contains all information to describe the solar atmosphere i.e. temperature etc in the different layers as well as stellar parameters and abundances
- property citation_info#
citation for this atmosphere
- Type:
str
- property depth#
flag that determines whether to use RHOX or TAU for calculations
- Type:
str
- property dtype#
- property geom#
the geometry of the atmopshere model
- Type:
str
- property height#
height of the spherical model
- Type:
array
- property interp#
flag that determines whether to use RHOX or TAU for interpolation
- Type:
str
- property logg#
surface gravity in log10(cgs)
- Type:
float
- property lonh#
?
- Type:
float
- property method#
whether the data source is a grid or a fixed atmosphere
- Type:
str
- property monh#
metallicity
- Type:
float
- property names#
- property ndep#
- property opflag#
opacity flags
- Type:
array of size (20,)
- property radius#
radius of the spherical model
- Type:
float
- property rho#
density profile
- Type:
array
- property rhox#
mass column density
- Type:
array
- property source#
datafile name of this data, or atmosphere grid/file
- Type:
str
- property tau#
continuum optical depth
- Type:
array
- property teff#
effective temperature in Kelvin
- Type:
float
- property temp#
temperature profile in Kelvin
- Type:
array
- property vturb#
turbulence velocity in km/s
- Type:
float
- property wlstd#
wavelength standard deviation
- Type:
float
- property xna#
number density of atoms in 1/cm**3
- Type:
array
- property xne#
number density of electrons in 1/cm**3
- Type:
array
- class pysme.atmosphere.atmosphere.AtmosphereGrid(natmo, npoints, **kwargs)[source]#
Bases:
recarrayA grid of atmospheres, used for the interpolation of model atmospheres. Each entry represents one atmosphere model.
- property abund_format#
format of the Abundance field, as defined by the Abund class
- Type:
str
- property citation_info#
Citation text to cite in your papers
- Type:
str
- property depth#
flag that determines whether to use RHOX or TAU for calculations
- Type:
str
- property geom#
the geometry of the atmopshere model
- Type:
str
- property interp#
flag that determines whether to use RHOX or TAU for interpolation
- Type:
str
- property method#
whether the data source is a grid or a fixed atmosphere
- Type:
str
- property ndep#
- property source#
datafile name of this data
- Type:
str
pysme.atmosphere.interpolation module#
Handles reading and interpolation of atmopshere (grid) data
- class pysme.atmosphere.interpolation.AtmosphereInterpolator(depth=None, interp=None, geom=None, lfs_atmo=None, verbose=0)[source]#
Bases:
object- determine_depth_scale(depth, atmo_grid)[source]#
Determine ATMO.DEPTH radiative transfer depth variable. Order of precedence:
Value of ATMO_IN.DEPTH, if it exists and is set
Value of ATMO_GRID[0].DEPTH, if it exists and is set
‘RHOX’, if ATMO_GRID.RHOX exists (preferred over ‘TAU’ for depth)
‘TAU’, if ATMO_GRID.TAU exists
Check that INTERP is valid and the corresponding field exists in ATMO.
- Parameters:
depth ({"RHOX", "TAU", None}) – requested value, or None for autoselection based in available grid
atmo_grid (AtmosphereGrid) – input atmosphere grid to interpolate on
- Returns:
depth – The chosen depth scale
- Return type:
{“TAU”, “RHOX”}
- Raises:
AtmosphereError – If an invalid value was set in atmo_in/atmo_grid
- determine_interpolation_scale(interp, atmo_grid)[source]#
Determine ATMO.INTERP interpolation variable. Order of precedence:
Value of ATMO_IN.INTERP, if it exists and is set
Value of ATMO_GRID[0].INTERP, if it exists and is set
‘TAU’, if ATMO_GRID.TAU exists (preferred over ‘RHOX’ for interpolation)
‘RHOX’, if ATMO_GRID.RHOX exists
Check that INTERP is valid and the corresponding field exists in ATMO.
- Parameters:
interp ({"RHOX", "TAU", None}) – requested interpolation axis, or None for autoselect
atmo_grid (AtmosphereGrid) – Atmosphere grid for interpolation
- Returns:
interp – the interpolation axis
- Return type:
{“RHOX”, “TAU”}
- Raises:
AtmosphereError – if a non valid parameter is set in atmo_in/atmo_grid
- find_corner_models(teff, logg, monh, atmo_grid)[source]#
Find the models in the grid that bracket the given stellar parameters
The purpose of the first major set of code blocks is to find values of [M/H] in the grid that bracket the requested [M/H]. Then in this subset of models, find values of log(g) in the subgrid that bracket the requested log(g). Then in this subset of models, find values of Teff in the subgrid that bracket the requested Teff. The net result is a set of 8 models in the grid that bracket the requested stellar parameters. Only these 8 “corner” models will be used in the interpolation that constitutes the remainder of the program.
- Parameters:
teff (float) – effective temperature
logg (float) – surface gravity
monh (float) – metallicity
atmo_grid (AtmosphereGrid) – atmosphere grid to search models in
verbose (int, optional) – determines how many debugging messages to print, by default 0
- interp_atmo_constrained(x, y, err, par, x2, y2, constraints=None, **kwargs)[source]#
Apply a constraint on each parameter, to have it approach zero
- Parameters:
x (array[n]) – x data
y (array[n]) – y data
err (array[n]) – errors on y data
par (list[4]) – initial guess for fit parameters - see interp_atmo_func
x2 (array) – independent variable for tabulated input function
y2 (array) – dependent variable for tabulated input function
kwargs (**) –
passes keyword arguments to interp_atmo_func
- ndepint
number of depth points in supplied quantities
- constraintsarray[nconstraint], optional
error vector for constrained parameters. Use errors of 0 for unconstrained parameters.
- Returns:
ret (list of floats) – best fit parameters
yfit (array of size (n,)) – best fit to data
- interp_atmo_func(x1, par, x2, y2, ndep=None, y1=None)[source]#
Apply a horizontal shift to x2. Apply a vertical shift to y2. Interpolate onto x1 the shifted y2 as a function of shifted x2.
- Parameters:
x1 (array[ndep1]) – independent variable for output function
par (array[3]) – shift parameters par[0] - horizontal shift for x2 par[1] - vertical shift for y2 par[2] - vertical scale factor for y2
x2 (array[ndep2]) – independent variable for tabulated input function
y2 (array[ndep2]) – dependent variable for tabulated input function
ndep (int, optional) – number of depth points in atmospheric structure (default is use all)
y1 (array[ndep2], optional) – data values being fitted
Note
Only pass y1 if you want to restrict the y-values of extrapolated data points. This is useful when solving for the shifts, but should not be used when calculating shifted functions for actual use, since this restriction can cause discontinuities.
- interp_atmo_grid(atmo_grid, teff, logg, monh)[source]#
General routine to interpolate in 3D grid of model atmospheres
- Parameters:
Teff (float) – effective temperature of desired model (K).
logg (float) – logarithmic gravity of desired model (log cm/s/s).
MonH (float) – metalicity of desired model.
atmo_in (Atmosphere) – Input atmosphere
verbose ({0, 1}, optional) – how much information to plot/print (default: 0)
plot (bool, optional) – wether to plot debug information (default: False)
reload (bool) – wether to reload atmosphere information from disk (default: False)
- Returns:
atmo – interpolated atmosphere data
- Return type:
- interp_atmo_pair(atmo1, atmo2, frac, interpvar='RHOX', itop=0)[source]#
Interpolate between two model atmospheres, accounting for shifts in the mass column density or optical depth scale.
How it works:
1. The second atmosphere is fitted onto the first, individually for each of the four atmospheric quantitites: T, xne, xna, rho. The fitting uses a linear shift in both the (log) depth parameter and in the (log) atmospheric quantity. For T, the midpoint of the two atmospheres is aligned for the initial guess. The result of this fit is used as initial guess for the other quantities. A penalty function is applied to each fit, to avoid excessively large shifts on the depth scale. 2. The mean of the horizontal shift in each parameter is used to construct the common output depth scale. 3. Each atmospheric quantity is interpolated after shifting the two corner models by the amount determined in step 1), rescaled by the interpolation fraction (frac).
- Parameters:
atmo1 (Atmosphere) – first atmosphere to interpolate
atmo2 (Atmosphere) – second atmosphere to interpolate
frac (float) – interpolation fraction: 0.0 -> atmo1 and 1.0 -> atmo2
interpvar ({"RHOX", "TAU"}, optional) – atmosphere interpolation variable (default:”RHOX”).
itop (int, optional) – index of top point in the atmosphere to use. default is to use all points (itop=0). use itop=1 to clip top depth point.
atmop (array[5, ndep], optional) – interpolated atmosphere prediction (for plots) Not needed if atmospheres are provided as structures. (default: None)
verbose ({0, 5}, optional) – diagnostic print level (default 0: no printing)
plot ({-1, 0, 1}, optional) – diagnostic plot level. Larger absolute value yields more plots. Negative values cause a wait for keypress after each plot. (default: 0, no plots)
old (bool, optional) – also plot result from the old interpkrz2 algorithm. (default: False)
- Returns:
atmo – interpolated atmosphere .RHOX (vector[ndep]) mass column density (g/cm^2) .TAU (vector[ndep]) reference optical depth (at 5000 Å) .temp (vector[ndep]) temperature (K) .xne (vector[ndep]) electron number density (1/cm^3) .xna (vector[ndep]) atomic number density (1/cm^3) .rho (vector[ndep]) mass density (g/cm^3)
- Return type:
- interpolate_corner_models(teff, logg, monh, icor, atmo_grid, interp='RHOX', itop=1)[source]#
Interpolate over the 8 corner models in the cube around the stellar parameters
The code below interpolates between 8 corner models to produce the output atmosphere. In the first step, pairs of models at each of the 4 combinations of log(g) and Teff are interpolated to the desired value of [M/H]. These 4 new models are then interpolated to the desired value of log(g), yielding 2 models at the requested [M/H] and log(g). Finally, this pair of models is interpolated to the desired Teff, producing a single output model.
Interpolation is done on the logarithm of all quantities to improve linearity of the fitted data. Kurucz models sometimes have very small fractional steps in mass column at the top of the atmosphere. These cause wild oscillations in splines fitted to facilitate interpolation onto a common depth scale. To circumvent this problem, we ignore the top point in the atmosphere by setting itop=1.
- Parameters:
teff (float) – effective temperature
logg (float) – surface gravity
monh (float) – metallicity
icor (array_like) – indices of the corner models
atmo_grid (AtmosphereGrid) – atmosphere grid with input models
interp (str, optional) – interpolation axis, by default “RHOX”
itop (int, optional) – index of the topmost point in the RHOX scale, by default 1
- Returns:
atmo3 – Interpolated atmosphere
- Return type:
- spherical_model_correction(atmo_grid, icor, logg)[source]#
Correct the radius of the model grids, for the stellar parameters if necessary
If all interpolated models were spherical, the interpolated model should also be reported as spherical. This enables spherical-symmetric radiative transfer in the spectral synthesis.
- Formulae for mass and radius at the corners of interpolation cube:
log(M/Msol) = log g - log g_sol - 2*log(R_sol / R) 2 * log(R / R_sol) = log g_sol - log g + log(M / M_sol)
- Parameters:
atmo_grid (AtmosphereGrid) – complete atmosphere grid
icor (array_like) – indices for the corner models that were interpolated from the atmosphere grid
- Returns:
geom ({“PP”, “SPH”}) – The geometry of the interpolated models
radius (None, array) – The corrected radius of the models, if geom == “SPH”. Otherwise None.
pysme.atmosphere.krzfile module#
- class pysme.atmosphere.krzfile.KrzFile(filename, source=None)[source]#
Bases:
AtmosphereRead .krz atmosphere files
pysme.atmosphere.savfile module#
- class pysme.atmosphere.savfile.SavFile(filename, source=None, lfs=None)[source]#
Bases:
AtmosphereGridIDL savefile atmosphere grid