pytmosph3r.util.util

Module Contents

get_attributes(obj, attr=None)[source]

Returns attributes of an object if they do not start nor end with an underscore.

get_methods(obj)[source]

Returns methods of an object.

retrieve_name(var, up=0)[source]
Retrieve the name of a variable var as a string. For example if var is named ‘temperature’, the function will return “temperature”. Example::
def test(hello, up=0):

return retrieve_name(hello, up)

bonjour = “bonjour” test(bonjour) # returns “hello” test(bonjour, up=1) # returns “bonjour”

Parameters:
  • var – Variable

  • up – context to retrieve from (default is the current context, i.e., the function in which the function has been called)

to_radians(array, units='deg')[source]

Convert an array from ‘units’ to rad.

to_SI(obj: object, unit: astropy.units.Unit | str = None)[source]

Convert astropy quantity to ‘units’ (SI by default).

get_altitude_index(altitude: Literal[surface, middle, top], n_vertical: int)[source]

Return altitude index associated with keyword altitude (within “surface”,”top”,”middle”). If not among this keyword, return as is.

get_latitude_index(latitude: Literal[north, equator, south], n_latitudes: int)[source]

Return latitude index associated with keyword latitude (within “north”,”pole”,”equator”).

get_longitude_index(longitude: Literal[day, night, terminator], n_longitudes=None)[source]

Return longitude index associated with keyword longitude (within “day”,”night”, “terminator”). The keywords refer to the position of the star if the direction of the rays has been defined as (latitude, longitude) = (0,0).

get_index(array, location, dim: Literal[altitude, latitude, longitude] = 'altitude')[source]

Return the index of location in array at the dimension dim (altitude/latitude/longitude). For example, if dim is ‘altitude’ and location is ‘surface’, it will return 0.

get_2D(array, location, dim: Literal[altitude, latitude, longitude] = 'altitude')[source]

Return a 2D slice of array array at the dimension dim (among altitude, latitude and longitude). For example if dim is ‘altitude’, it will return the 2D array of all latitudes and longitudes at this altitude.

get_column(array, latitude, longitude)[source]

Return a vertical column of array array at the position (latitude, longitude).

convert_log(array, units: Literal[log, ln] | None = None)[source]

Convert array from log space to normal space. units determines if the space is log or ln.

mol_key(mol_dict, mol, mol_type='vap', data='')[source]

Returns the key corresponding to mol in mol_dict.

aerosols_array_iterator(dictionary)[source]

Returns an iterator over arrays of an aerosols dictionary. For example, if the dictionary looks like this: {'H2O':{'mmr':np.array([1, 2]), 'reff':1e-5}}. The code will iterate over the mmr (array) but not reff (float).

arrays_to_zeros(dictionary, shape)[source]

Returns a copy of dictionary of which subarrays are initialized as an array of shape shape filled with zeros. Used for aerosols, to initialize the arrays before interpolating.

init_array(obj, size)[source]

Returns obj if float, else array of size size.

get(obj, i)[source]

Returns obj if float, else return the value of obj at i

update_dict(d, u)[source]

Recursive update of nested dictionaries.

merge_attrs(obj, other)[source]

Merge attributes from other into obj if they do not exist/are None.

spectral_chunks(k_database, n)[source]
get_chunk(i, n, size)[source]

Get i-th chunk out n chunks dividing size.

get_chunk_size(chunk, chunk_size, total_size)[source]
get_wls(array, wls, array_wls)[source]

Get subset of array at wavelengths wls when the wavelengths of array are array_wls

make_array(lis)[source]

Get array from a list of lists. Missing data is replaced with -1.

timer(f)[source]

A decorator to time a function in debug mode.

query_yes_no(question, default='yes')[source]

Ask a yes/no question via raw_input() and return their answer.

“question” is a string that is presented to the user. “default” is the presumed answer if the user just hits <Enter>.

It must be “yes” (the default), “no” or None (meaning an answer is required of the user).

The “answer” return value is True for “yes” or False for “no”.