clevar.utils module

class clevar.utils.LowerCaseDict(*args, **kwargs)[source]

Bases: dict

Dictionary with lowercase keys

get(key, *args, **kwargs)[source]

Return the value for key if key is in the dictionary, else default.

pop(k[, d]) v, remove specified key and return the corresponding value.[source]

If key is not found, default is returned if given, otherwise KeyError is raised

setdefault(key, *args, **kwargs)[source]

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

class clevar.utils.NameList(iterable=(), /)[source]

Bases: list

List without case consideration in in function

clevar.utils.autobins(values, bins, log=False)[source]

Get bin values automatically from bins, values

Parameters
  • values (array) – Data

  • bins (int, array) – Bins/Number of bins

  • log (bool) – Logspaced bins (used if bins is int)

Returns

Bins based on values

Return type

ndarray

clevar.utils.binmasks(values, bins)[source]

Get corresponding masks for each bin. Last bin is inclusive.

Parameters
  • values (array) – Data

  • bins (array) – Bins

Returns

bin_masks – List of masks for each bin

Return type

list

clevar.utils.deep_update(dict_base, dict_update)[source]

Update a multi-layer dictionary.

Parameters
  • dict_base (dict) – Dictionary to be updated

  • dict_update (dict) – Dictionary with the updates

Returns

dict_base – Updated dictionary (the input dict is also updated)

Return type

dict

clevar.utils.gaussian(value, mean, std)[source]

Gaussian function.

Parameters
  • value (float, array) – Point(s) to compute the distribution.

  • mean (float, array) – Mean (“centre”) of the distribution.

  • std (float, array) – Standard deviation (spread or “width”) of the distribution. Must be non-negative.

Returns

Value of the gaussian distribution at input value.

Return type

float, array

clevar.utils.neighbors_of_pixels(nside, pixels, nest=False)[source]

Get all neighbors of a pixel list

Parameters
  • nside (int) – Healpix nside

  • pixels (array) – Array of pixel indices

  • nest (bool) – If ordering is nested

Returns

Neighbor pixels

Return type

array

clevar.utils.none_val(value, none_value)[source]

Set default value to be returned if input is None

Parameters
  • value – Input value

  • none_value – Value to be asserted if input is None

Returns

Value if value is not None else none_value

Return type

type(value), type(none_value)

clevar.utils.pack_mmt_col(col)[source]
clevar.utils.pack_mt_col(col)[source]
clevar.utils.pix2map(nside, pixels, values, null)[source]

Convert from pixels, values to map

Parameters
  • nside (int) – Healpix nside

  • pixels (array) – Array of pixel indices

  • values (Array) – Value of map in each pixel

  • null (obj) – Value for pixels outside the map

clevar.utils.smooth_line(x, y, n_increase=10, scheme=[1, 2, 1])[source]

Make smooth line using pixar’s algorithm.

Parameters
  • x (array) – x values.

  • y (array) – y values.

  • n_increase (int) – Number of loops for the algorithm.

  • scheme (list) – Scheme to be used for smoothening. Newton’s binomial coefficients work better.

Returns

xsmooth, ysmooth – Smoothened line

Return type

array

Note

Good description of the method can be found at https://www.youtube.com/watch?v=mX0NB9IyYpU&ab_channel=Numberphile

clevar.utils.smooth_loop(x, y, scheme=[1, 1])[source]

Loop for smooth line using pixar’s algorithm.

Parameters
  • x (array) – x values.

  • y (array) – y values.

  • scheme (list) – Scheme to be used for smoothening. Newton’s binomial coefficients work better.

Returns

xsmooth, ysmooth – Smoothened line

Return type

array

Note

Good description of the method can be found at https://www.youtube.com/watch?v=mX0NB9IyYpU&ab_channel=Numberphile

clevar.utils.str2dataunit(input_str, units_bank, err_msg='')[source]

Convert a string to a float with unit. ex: ‘1mpc’ -> (1, ‘mpc’)

Parameters
  • input_str (str) – Input string

  • unit_bank (list) – Bank of units available.

clevar.utils.unpack_mmt_col(col)[source]
clevar.utils.unpack_mt_col(col)[source]
clevar.utils.updated_dict(*dict_list)[source]

Returns an dictionary with updated values if new dictionaries are not none

Parameters

*dict_list (positional arguments) – Lists of dictionary with updated values

Returns

Updated dictionary

Return type

dict