:py:mod:`exo_k.util.filenames` ============================== .. py:module:: exo_k.util.filenames .. autoapi-nested-parse:: @author: jeremy leconte Library of useful functions for handling filenames Module Contents --------------- .. py:exception:: EndOfFile Bases: :py:obj:`Exception` Error for an end of file Initialize self. See help(type(self)) for accurate signature. .. py:function:: select_kwargs(kwargs, filter_keys_list = None) Function to select only some keyword arguments from a kwargs dict to pass to a function afterward. :param kwargs: Dictionary of keyword arguments and values. :param filter_keys_list: Names of the keys to select. :returns: filtered_kwargs: A dictionary with only the selected keys (if they were present in kwargs). .. rubric:: 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 .. py:function:: create_fname_grid_Kspectrum_LMDZ(Np, Nt, Nx=None, suffix='', nb_digit=3) Creates a grid of filenames consistent with Kspectrum/LMDZ from the number of pressure, temperatures (, and vmr) points (respectively) in the grid. :param Np: Number of Pressure and temperature points. :type Np: :class:`int` :param Nt: Number of Pressure and temperature points. :type Nt: :class:`int` :param Nx: Number of vmr points if there is a variable gas :type Nx: :class:`int`, *optional* :param suffix: String to add behind the 'k001' :type suffix: :class:`str`, *optional* :param nb_digit: Total number of digit including the zeros ('k001' is 3) :type nb_digit: :class:`int`, *optional* :returns: list of str List of the files in the right order and formating to be given to :func:`exo_k.ktable.Ktable.hires_to_ktable` or :func:`exo_k.xtable.Xtable.hires_to_xtable`. .. rubric:: Examples >>> exo_k.create_fname_grid_Kspectrum_LMDZ(2,3) array([['k001', 'k002', 'k003'], ['k004', 'k005', 'k006']], dtype='>> 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='