Skip to content

utils

Miscellaneous utility functions that may be of use throughout MeshiPhi

convert_decimal_days(decimal_days, mins=False)

Convert decimal days to more readable Days, Hours and (optionally) Minutes Args: decimal_days (float): Number of days as a decimal mins (bool): Determines whether to return minutes or decimal hours Returns: new_time (str): The time in the new format

fftind(size)

Creates a numpy array of shifted Fourier coordinates.

Parameters:

Name Type Description Default
size int

The size of the coordinate array to create

required

Returns:

Type Description

np.array: Numpy array of shifted Fourier coordinates (k_x, k_y). Has shape (2, size, size), with:

array[0,:,:] = k_x components

array[1,:,:] = k_y components

gaussian_random_field(size, alpha)

Creates a gaussian random field with normal (circular) distribution Code from https://github.com/bsciolla/gaussian-random-fields/blob/master/gaussian_random_fields.py

Parameters:

Name Type Description Default
size int

Default = 512; The number of datapoints created per axis in the GRF

required
alpha float

Default = 3.0; The power of the power-law momentum distribution

required

Returns:

Type Description

np.array: 2D Array of datapoints, shape (size, size)

longitude_distance(long_a, long_b)

Calculates the angular distance between two longitude values

longitude_domain(long)

Converts any longitude degree value into one between -180:180

round_to_sigfig(x, sigfig=5)

Rounds numbers to some number of significant figures

Parameters:

Name Type Description Default
x float or array

Value(s) to round to sig figs

required
sigfig int

Number of significant figures desired

5

Returns:

Type Description

np.array: Values rounded to the desired number of significant figures

setup_logging(func, log_format='[%(asctime)-17s :%(levelname)-8s] - %(message)s')

Wraps a CLI endpoint and sets up logging for it

This is probably not the smoothest implementation, but it's an educational one for people who aren't aware of decorators and how they're implemented. In addition, it supports a nice pattern for CLI endpoints

TODO: start handling level configuration from logging yaml config

:param func: :param log_format: :return: