exo_k.util.filenames
@author: jeremy leconte
Library of useful functions for handling filenames
Module Contents
- exception exo_k.util.filenames.EndOfFile[source]
Bases:
Exception
Error for an end of file
Initialize self. See help(type(self)) for accurate signature.
- exo_k.util.filenames.select_kwargs(kwargs, filter_keys_list=None)[source]
Function to select only some keyword arguments from a kwargs dict to pass to a function afterward.
- Parameters:
- Returns:
- filtered_kwargs:
A dictionary with only the selected keys (if they were present in kwargs).
- Return type:
Examples
>>> def func(allo=None): >>> print(allo) >>> >>> def bad_global_func(**kwargs): >>> print(kwargs) >>> func(**kwargs) >>> >>> def good_global_func(**kwargs): >>> print(kwargs) >>> func(**select_kwargs(kwargs,['allo']))
>>> bad_global_func(allo=3.,yeah=None) {'allo': 3.0, 'yeah': None} TypeError: func() got an unexpected keyword argument 'yeah'
>>> good_global_func(allo=3.,yeah=None) {'allo': 3.0, 'yeah': None} 3.0
- exo_k.util.filenames.create_fname_grid_Kspectrum_LMDZ(Np, Nt, Nx=None, suffix='', nb_digit=3)[source]
Creates a grid of filenames consistent with Kspectrum/LMDZ from the number of pressure, temperatures (, and vmr) points (respectively) in the grid.
- Parameters:
Np (
int
) – Number of Pressure and temperature points.Nt (
int
) – Number of Pressure and temperature points.Nx (
int
, optional) – Number of vmr points if there is a variable gassuffix (
str
, optional) – String to add behind the ‘k001’nb_digit (
int
, optional) – Total number of digit including the zeros (‘k001’ is 3)
- Returns:
- list of str
List of the files in the right order and formating to be given to
exo_k.ktable.Ktable.hires_to_ktable()
orexo_k.xtable.Xtable.hires_to_xtable()
.
Examples
>>> exo_k.create_fname_grid_Kspectrum_LMDZ(2,3) array([['k001', 'k002', 'k003'], ['k004', 'k005', 'k006']], dtype='<U4')
>>> exo_k.create_fname_grid_Kspectrum_LMDZ(2,3,suffix='.h5') array([['k001.h5', 'k002.h5', 'k003.h5'], ['k004.h5', 'k005.h5', 'k006.h5']], dtype='<U7')
- exo_k.util.filenames.parse_filename_HELIOS(filename=None)[source]
Parse wn_range, T, P from filename and return it. Example of filename: Out_00000_67000_00500_n566.bin, where wn_range = [0, 67000] cm^{-1}, T=500K, P=1e-566 Bar.
- exo_k.util.filenames.convert_exo_transmit_to_hdf5(file_in, file_out, mol='unspecified')[source]
Converts exo_transmit like spectra to hdf5 format for speed and space.
- exo_k.util.filenames._read_array(file, Nvalue, N_per_line=5, Nline=None, revert=False)[source]
Reads an array in a .dat filestream. Assumes that the arrays are arranged N_per_line values per line.
- Parameters:
file (
file stream
) – File to be read.Nvalue (
int
) – Number of values to be read.N_per_line (
int
) – Number of values assumed per line.revert (
boolean (optional)
) – Whether or not to revert the array (because some arrays are in decreasing order).Nline (
int (optional)
) – Slightly speeds up the process if the user specifies the number of lines that will need to be read.
- Returns:
- Array
A numpy array with the values.
- exo_k.util.filenames._read_exorem_k_array(file, Nline)[source]
Reads an array in a .dat filestream. Assumes that the arrays are arranged N_per_line values per line.
- Parameters:
file (
file stream
) – File to be read.Nline (
int
) – Number of values/lines to be read.
- Returns:
- Array
A numpy array with the values.