exo_k.util.user_func

@author: jeremy leconte

Library of useful functions for users (only).

Functions here CANNOT be called into the library itself: importing this module in others would lead to recursive import problems.

Module Contents

exo_k.util.user_func.create_table(logpgrid=None, tgrid=None, xgrid=None, wngrid=None, wnedges=None, ggrid=None, weights=None, p_unit='Pa', kdata_unit='m^2/molecule', value=None, mol=None)[source]

Create a new table with the required dimensions padded with zeros.

The class of the object created will depend on the dimensions required.

Parameters:
  • logpgrid (array, np.ndarray) – Grid in log p

  • tgrid (array, np.ndarray) – Grid in T

  • xgrid (array, np.ndarray) – Grid in volume mixing ratio

  • wngrid (array, np.ndarray) – Grid wavenumber

  • ggrid (array, np.ndarray) – Grid g-space

  • weights (array, np.ndarray) – Grid of quadrature weights

  • p_unit (str (optional)) – Unit of pressure (default Pa)

  • kdata_unit (str (optional)) – Unit of cross section (default is m^2/molecule)

Returns:

new_table: Xtable, Ktable, or Ktable5d

A new table

exo_k.util.user_func.hires_to_ktable(filename_grid=None, xgrid=None, **kwargs)[source]

Emulates exo_k.ktable.Ktable.hires_to_ktable() and exo_k.ktable5d.Ktable5d.hires_to_ktable() as functions and not methods so that the user can call them without creating a Ktable first.

See those methods for details on the available arguments and options.

exo_k.util.user_func.hires_to_xtable(**kwargs)[source]

Emulates exo_k.xtable.Xtable.hires_to_xtable() as a function and not a method so that the user can call it without creating an Xtable first.

See hires_to_xtable() for details on the available arguments and options.

exo_k.util.user_func.convert_kspectrum_to_hdf5(file_in, file_out=None, **kwargs)[source]

Converts kspectrum like spectra to hdf5 format for speed and space. Helper function. Real work done in Hires_spectrum __init__ funtion.

Go there to see all the available arguments and options.

Parameters:
  • file_in (str) – Initial kspectrum filename.

  • file_out (str) – Name of the final hdf5 file to be created. If not provided, ‘file_in.h5’ will be used.

exo_k.util.user_func.create_fname_grid(base_string, logpgrid=None, tgrid=None, xgrid=None, p_kw=None, t_kw=None, x_kw=None)[source]

Creates a grid of filenames from an array of pressures, temperatures ( and vmr if there is a variable gas).

Parameters:
  • base_string (str) – Generic name of the spectra files with specific keywords to be replaced by the relevant numerical values

  • logpgrid (Array) – Grid in log(pressure/Pa) of the input

  • tgrid (Array) – Grid in temperature of the input

  • xgrid (Array) – Input grid in vmr of the variable gas

Warning

The result of this function is much more predictable if the values in the above arrays are given as integers or directly strings. If you want to use floats anyway, good luck.

Parameters:
  • p_kw (str)

  • t_kw (str)

  • x_kw (str) – The pattern string that will be recognized as keywords between {} in base_string (See examples).

Examples

>>> logpgrid=[1,2]
>>> tgrid=np.array([100.,150.,200.])
>>> file_grid=exo_k.create_fname_grid('spectrum_CO2_1e{logp}Pa_{t}K.hdf5',
          logpgrid=logpgrid,tgrid=tgrid,p_kw='logp',t_kw='t')
array([['spectrum_CO2_1e1Pa_100K.hdf5', 'spectrum_CO2_1e1Pa_150K.hdf5',
'spectrum_CO2_1e1Pa_200K.hdf5'],
['spectrum_CO2_1e2Pa_100K.hdf5', 'spectrum_CO2_1e2Pa_150K.hdf5',
'spectrum_CO2_1e2Pa_200K.hdf5']], dtype='<U28')
exo_k.util.user_func.finalize_LMDZ_dir(corrkname, IRsize, VIsize)[source]

Creates the right links for a LMDZ type directory to be read by the LMDZ generic GCM.

You will need to create a proper Q.dat before using with the LMDZ GCM.

Important

You must have run exo_k.ktable.Ktable.write_LMDZ() or exo_k.ktable5d.Ktable5d.write_LMDZ() for both of your IR and VI channels beforehand.

Parameters:
  • corrkname (str) – Path to the directory with the LMDZ ktable to finalize

  • IRsize (int) – Number of IR spectral bins

  • VIsize (int) – Number of VI spectral bins

exo_k.util.user_func.load_atm_evolution(pickle_filename)[source]

Load an Atm_evolution instance from a pickle file

Parameters:

pickle_filename (str) – name of pickle file