h3ppy
- class h3ppy.h3p.h3p(line_list_file='', **kwargs)[source]
Bases:
objectSetting model parameters
The
set(),model(), andfit()methods accepts the following inputs:wavelength,wave,w- the wavelength scale on which to produce the model.data- the observed \(H_3^+\) spectrumtemperature,T- the intensity of the \(H_3^+\) spectral lines are an exponential function of the temperature. Typical ranges for the ionosphere’s of the giant planets are 400 (Saturn) to 1500 K (Jupiter).density,N- the column integrated \(H_3^+\) density, this is the number of ions along the line of sight vector.sigma_n- the nth polynomial constant of the spectral line width (sigma)offset_n- the nth polynomial constant of the wavelength offset from the rest wavelength. Doppler shift and wavelength calibration errors can offset the wavelength scale.background_n- the nth polynomial constant of the displacement from the zero intensity level of the spectrumnsigma- the number of polynomial constant used for the sigma.noffset- the number of polynomial constant used for the offset.nbackground- the number of polynomial constant used for the background.R- the spectral resolving power of the instrument. This is converted in the code to asigmaparameter.
- calculate_line_intensities(**kwargs)[source]
Calculate the individual line intensities per molecule at a particlar temperature. See Spectral Function for details.
- Returns
The intensity of each individual line.
- model(**kwargs)[source]
Generate a model \(H_3^+\) spectrum given a set of parameters.
Hint
The parameters required for this function can also be set using the
setmethod.- Parameters
**kwargs – Physical parameters to pass to the model calculation.
- Returns
A spectrum of units of spectral radiance (\(W m^{-2} sr^{-1} \mu m^{-1}\)).
- Q(**kwargs)[source]
Calculate the \(H_3^+\) partition function, \(Q(T)\).
- Returns
The evaluated partition function (Miller et al., 2013) at a particular temperature.
- set(temperature: float = None, T: float = None, density: float = None, N: float = None, wavelength: ndarray = None, wave: ndarray = None, w: ndarray = None, R: float = None, **kwargs)[source]
Use set() to set the model parameters that you require.
h3p = h3ppy.h3p() h3p.set(temperature = 900, density = 1e15)
- Parameters
temperature (float) – The temperature (in \(K\)).
T (float) – Alias for temperature.
density (float) – The column integrated density (in \(m^{-2}\)).
N (float) – Alias for density.
wavelength (np.ndarray) – The wavelength scale (in \(\mu m\)).
wave (np.ndarray) – Alias for wavelength.
w (np.ndarray) – Alias for wavelength.
R – The spectral resolution (FWHM)
- fit(params_to_fit='', verbose=False, niter=14, **kwargs)[source]
Fit a \(H_3^+\) spectrum.
Hint
The parameters required for this function can also be set using the
setmethod.- Parameters
params_to_fit – Specify the parameters you want to fit, e.g., if you only want to fit temperature and density
params_to_fit = ['temperature', 'density']. By defailt it fits temperature, density, background, wavelngth offset, and line width.verbose – Print more detailed information.
niter – How may iterations of the fitting are we going to do.
- Returns
The best fit model spectrum to the data in units of spectral radiance (\(W m^{-2} sr^{-1} \mu m^{-1}\)).
- wavegen(wstart, wend, wnbr)[source]
Generate a wavelength scale using start and end wavelengths and the number of wavelength elements.
- Parameters
wstart – The wavelength at which the range should start.
wend – The wavelength at which the range should end.
wnbr – The number of wavelength bins.
- Returns
An array containing a wavelength range.
- total_emission(**kwargs)[source]
Calculate the total emitted energy by H3+ as given by Miller et al., (2013)
- get_results(verbose=False)[source]
Return the results of the spectral fit. Note that if the fit fails, the it returns
(False, False).- Returns
A dictionary containing the best fit parameters errs: A dictionary containing the uncertainty on the best fit parameters
- Return type
vars
- ylabel(label='Radiance', prefix='')[source]
- Returns
The LaTeX formatted radiance ylabel for matplotlib.
- guess_density(verbose=True, **kwargs)[source]
Based on the peak value of the provided data, calculate the column density to provide a better inital guess for use in the fitting.
- Returns
The modelled spectrum with the new estimated column denisty.
- guess_offset(verbose=True, **kwargs)[source]
Based on the peak value of the provided data and the initial guess model, calculate the wavelength shift.
- Returns
The modelled spectrum with the wavelength offset applied.
- get_rest_wavelength()[source]
- Returns
The offset wavelength scale where the \(H_3^+\) lines are at rest (i.e. lab) wavelenghts.
- add_noise(snr=0.0, absolute=0.0, percent=0.0)[source]
Generate a \(H_3^+\) model with nosie added. There are three keyword parameters that can be used to describe the level of noise. The default level is 10%.
- Parameters
snr – Signal-to-noise ratio of the noise level
absolute – The absolute intensity value of the noise
percent – The percentage of the maximum model value of the noise
- Returns
The modeled spectrum with the noise added to it.
- class h3ppy.h2.h2(line_list_file='', **kwargs)[source]
Bases:
h3pThis is an example of how to creat a
h3ppychild class to extend the modelling and fitting functionality to other molecules. Here, we use H2 line lists from Roueff et al. (2019), which is included in the package.In order for this to work, we need to override some of the
h3ppyclasses:The
__init__function needs to read the correct line list. Alternatively, use theline_list_filekeyword.Q: Different molecules have different partition functions, so a new one must be provided. The easiest way to do this is to a polynomial fit to, e.g., an ExoMol or HITRAN provided partition function.Q_constants: Store the polynomial coefficients here.dQdT: Since the partition function changes, its temperature derivative also changes. The easiest approach is to use thenp.poly1D.deriv()function.total_emission: The total emission calculation will also change. The simplest way to approach this is to sum the entire spectrum.