Base Model¶
- class rapoc.models.model.Model(input_data)[source]¶
Base model class.
- Variables:
input_data (str or dict) – data file name or data dictionary
model_name (str) – model name
band (tuple) – investigated band. Is initialised only after the use of
map()
selected_grid (astropy.units.Quantity) – investigated grid. Is initialised only after the use of
map()
mol (str) – molecule name
mol_mass (astropy.units.Quantity) – molecular mass
pressure_grid (astropy.units.Quantity) – data pressure grid in si units
temperature_grid (astropy.units.Quantity) – data temperature grid in si units
wavenumber_grid (astropy.units.Quantity) – data wavenumber grid
opacities (astropy.units.Quantity) – data opacities grid in si units
frequency_grid (astropy.units.Quantity) – data frequency grid
wavelength_grid (astropy.units.Quantity) – data wavelength grid
- Parameters:
input_data (str or dict) – data file name or input_data dictionary. If the input is a str, the correspondent loader is used (
ExoMolFileLoader
) if the file format is supported. If is dict, thenDictLoader
is used.- Raises:
IOError – if data format is not supported:
Examples
For the sake of semplicity let’s assume we use an ExoMol file as input
>>> from rapoc.models import Model >>> exomolFile = 'example.TauREx.h5' >>> model = Model(input_data=exomolFile)
- opacity_model(opacities, nu, T_input)[source]¶
Computes the mean opacity in the investigated range.
- Parameters:
opacities (np.array) – opacity array. Has the same dimension of the frequency grid nu
nu (np.array) – frequency grid
T_input (float) – temperature
- Returns:
mean opacity computed from the model
- Return type:
float
- extract_opacities(T_input, band, P_input=None, units='si')[source]¶
Returns the input_data opacities for given pressure, temperature and band.
- Parameters:
T_input (float or np.array) – temperature to use for the estimation. This should be a astropy.units.Quantity with specified units, if not K are assumed as units. Can either be a single value or an array.
band (tuple) – this should be a tuple of astropy.units.Quantity indicating the edges of the band to use in the estimation. The units used reveal the intention to work in wavelengths, wavenumbers or frequencies.
P_input (float or np.array) – pressure to use for the estimation. This should be a astropy.units.Quantity with specified units, if not Pa are assumed as units. Can either be a single value or an array. It can be None in the case of data not depending on pressure, as Rayleigh scattering. Default is None.
units (str or astropy.units, optional) – indicates the output units system. If si the opacity is returned as \(m^2/kg\), if cgs is returned as \(cm^2/g\). Instead of a string, you can also indicate the units using astropy.units. Units is si by default.
- Returns:
astropy.units.Quantity – returns the estimated opacity for the pressures and temperatures indicated. If only one pressure and temperature are indicated, it returns a single Quantity. If n pressures and m temperatures are indicated, it return a Quantity array of dimensions (n,m)
list – list of wavenumber (or wavelength or frequency) index relative to the investigated band
- estimate(T_input, band, P_input=None, mode='closest', units='si')[source]¶
It estimates the model opacity in the indicated pressure and temperature grid for the indicated band, using the
opacity_model()
.- Parameters:
T_input (float or np.array) – temperature to use for the estimation. This should be a astropy.units.Quantity with specified units, if not K are assumed as units. Can either be a single value or an array.
band (tuple) – this should be a tuple of astropy.units.Quantity indicating the edges of the band to use in the estimation. The units used reveal the intention to work in wavelengths, wavenumbers or frequencies.
P_input (float or np.array) – pressure to use for the estimation. This should be a astropy.units.Quantity with specified units, if not Pa are assumed as units. Can either be a single value or an array. It can be None in the case of data not depending on pressure, as Rayleigh scattering. Default is None.
mode (str, optional) – indicates the estimation mode desired. If closest the output will be the opacity computed from the data at the nearest pressure on the data grid to the indicated one, and at the nearest temperature on the data grid to the indicated one. If {‘linear’, ‘loglinear’} it’s used the
scipy.interpolate.griddata()
with the indicated kind. To interpolate a map of opacities over the data grid is computed first usingmap()
. Mode is closest by default.units (str or astropy.units, optional) – indicates the output units system. If si the opacity is returned as \(m^2/kg\), if cgs is returned as \(cm^2/g\). Instead of a string, you can also indicate the units using astropy.units. Units is si by default.
- Returns:
returns the estimated opacity for the pressures and temperatures indicated. If only one pressure and temperature are indicated, it returns a single Quantity. If n pressures and m temperatures are indicated, it return a Quantity array of dimensions (n,m)
- Return type:
astropy.units.Quantity
- Raises:
NotImplementedError: – if the indicated mode is not supported
astropy.units.UnitConversionError: – if the input units cannot be converted to si
AttributeError: – if the band cannot be interpreted as wavelength, wavenumber or frequency
- estimate_plot(T_input, band, P_input=None, mode='closest', force_map=False, fig=None, ax=None, yscale='log', xscale='linear', grid='wavelength')[source]¶
Produces a plot of the estimates (produced with
estimate()
), comparing the raw data with the result. If a single estimate is to be plotted, this method produces a plot of raw opacities vs wavelength from the opacities (in grey) and the mean opacity estimated. If multiple estimates are be plotted, it produces a 3D plot, with the surface of mean opacity vs temperature and pressure from the data grid (usingmap_plot()
) and the interpolated data superimposed.- Parameters:
T_input (float or np.array) – temperature to use for the estimation. This should be a astropy.units.Quantity with specified units, if not K are assumed as units. Can either be a single value or an array.
band (tuple) – this should be a tuple of astropy.units.Quantity indicating the edges of the band to use in the estimation. The units used reveal the intention to work in wavelengths, wavenumbers or frequencies.
P_input (float or np.array) – pressure to use for the estimation. This should be a astropy.units.Quantity with specified units, if not Pa are assumed as units. Can either be a single value or an array. It can be None in the case of data not depending on pressure, as Rayleigh scattering. Default is None.
mode (str, optional) – indicates the estimation mode desired. If closest the output will be the opacity computed from the data at the nearest pressure on the data grid to the indicated one, and at the nearest temperature on the data grid to the indicated one. If {‘linear’, ‘loglinear’} it’s used the
scipy.interpolate.griddata()
with the indicated kind. Mode is closest by default.force_map (bool) – If True a 3D map plot is generate even for a single estimate. Default is False.
fig (matplotlib.pyplot.figure, optional) – indicates the figure to use. If None a new figure is produced. Default is None
ax (matplotlib.pyplot.axis, optional) – indicates the axis of the figure to use. If None a new axis is produced. Default is None
yscale (str) – y-axis scale to use. Default is log
xscale (str) – x-axis scale to use. Default is linear
grid (str) – x-axis grid format. {wavelength, frequency, wavenumber} are supported. Default is wavelength.
- Returns:
matplotlib.pyplot.figure, optional – figure containing the plot
matplotlib.pyplot.axis, optional – axis containing the plot
- Raises:
KeyError: – if the indicated grid is not supported
- map(band)[source]¶
Returns the mean opacity map for the indicated model.
- Parameters:
band (tuple) – this should be a tuple of astropy.units.Quantity indicating the edges of the band to use in the estimation. The units used reveal the intention to work in wavelengths, wavenumbers or frequencies.
- Returns:
mean opacity map in si units
- Return type:
np.array
Notes
If the map has been already built for the indicated band, then the method returns the previous map. This speeds up the use of the code in external functions.
- map_plot(band, fig=None, ax=None)[source]¶
Produces a 3D-plot of the model mean opacity map built with
map()
.- Parameters:
band (tuple) – this should be a tuple of astropy.units.Quantity indicating the edges of the band to use in the estimation. The units used reveal the intention to work in wavelengths, wavenumbers or frequencies.
fig (matplotlib.pyplot.figure, optional) – indicates the figure to use. If None a new figure is produced. Default is None
ax (matplotlib.pyplot.axis, optional) – indicates the axis of the figure to use. If None a new axis is produced. Default is None
- Returns:
matplotlib.pyplot.figure, optional – figure containing the plot
matplotlib.pyplot.axis, optinal – axis containing the plot