MulensModel.utils module

File with general code used in other parts of MulensModel package.

Most importantly there are Utils and PlotUtils classes.

class MulensModel.utils.Utils

Bases: object

A number of small functions used in different places

static get_flux_from_mag(mag, zeropoint=None)

Transform magnitudes into fluxes.

Parameters :
mag: np.ndarray or float

Values to be transformed.

zeropoint: float

Zeropoint of magnitude scale. Defaults to 22. - double check if you want to change this.

Returns :
flux: np.ndarray or float

Calculated fluxes. Type is the same as mag parameter.

static get_flux_and_err_from_mag(mag, err_mag, zeropoint=None)

Transform magnitudes and their uncertainties into flux space.

Parameters :
mag: np.ndarray or float

Magnitude values to be transformed.

err_mag: np.ndarray or float

Uncertainties of magnitudes to be transformed.

zeropoint: float

Zeropoint of magnitude scale. Defaults to 22. - double check if you want to change this.

Returns :
flux: np.ndarray or float

Calculated fluxes. Type is the same as mag parameter.

err_flux: np.ndarray or float

Calculated flux uncertainties. Type is float if both mag and err_mag are floats and np.ndarray otherwise.

static get_mag_from_flux(flux, zeropoint=None)

Transform fluxes into magnitudes.

Parameters :
flux: np.ndarray or float

Values to be transformed.

zeropoint: float

Zeropoint of magnitude scale. Defaults to 22. - double check if you want to change this.

Returns :
mag: np.ndarray or float

Calculated fluxes. Type is the same as flux parameter.

static get_mag_and_err_from_flux(flux, err_flux, zeropoint=None)

Transform fluxes and their uncertainties into magnitude space.

Parameters :
flux: np.ndarray or float

Flux values to be transformed.

err_flux: np.ndarray or float

Uncertainties of fluxes to be transformed.

zeropoint: float

Zeropoint of magnitude scale. Defaults to 22. - double check if you want to change this.

Returns :
mag: np.ndarray or float

Calculated fluxes. Type is the same as mag parameter.

err_mag: np.ndarray or float

Calculated magnitude uncertainties. Type is float if both flux and err_flux are floats and np.ndarray otherwise.

static gamma_to_u(gamma)

Transform gamma limb darkening coefficient to u in convention introduced by An et al. 2008 (ApJ 681, 1593).

Parameters :
gamma: float

Limb darkening coefficient in gamma convention.

Returns :
u: float

Limb darkening coefficient in u convention.

static u_to_gamma(u)

Transform u limb darkening coefficient to gamma in convention introduced by An et al. 2008 (ApJ 681, 1593).

Parameters :
u: float

Limb darkening coefficient in u convention.

Returns :
gamma: float

Limb darkening coefficient in gamma convention.

static get_n_caustics(s, q)

Find number of caustics for binary lens.

Parameters :
s: float

Separation of binary lens relative to theta_E.

q: float

Mass ratio (<1).

Returns :
n_caustics: int

Number of caustics: 1, 2, or 3.

static velocity_of_Earth(full_BJD)

Calculate 3D velocity of Earth for given epoch.

If you need velocity projected on the plane of the sky, then use v_Earth_projected()

Parameters :
full_BJD: float

Barycentric Julian Data. Full means it should begin with 245… or 246…

Returns :
velocity: np.ndarray (float, size of (3,))

3D velocity in km/s. The frame follows Astropy conventions.

static complex_fsum(arguments)

Accurate floating points sum of complex numbers in iterable.

Parameters :

arguments: iterable (e.g., list or np.ndarray)

Returns :
sum: complex

Sum of arguments.

static vector_product_normalized(vector_1, vector_2)

Get vector that is perpendicular to the 2 input ones and is normalized.

Parameters :
vector_1: np.ndarray (3,)

First vector.

vector_2: np.ndarray (3,)

Second vector.

Returns :
vector_product_norm: np.ndarray (3,)

Normalized vector product of the inputs.

static dot(cartesian, vector)

Dot product of 2 vectors represented by astropy.CartesianRepresentation and np.ndarray.

Parameters :
cartesian: astropy.CartesianRepresentation

First vector.

vector: np.ndarray

Second vector (length 3).

Returns :
dot_product: astropy.Quantity

Dot product of inputs.

static date_change(text)

Change format of month in date, e.g. ‘2015-Oct-30 12:00’ -> ‘2015-10-30 12:00’

Parameters :
text: str

Date to be changed.

Returns :
out_text: str

Changed text.

static astropy_version_check(minimum)

Check if astropy package is installed at given or later version.

Parameters :
minimum: str

Minimum version, e.g., ‘3.1.2’.

Returns :
out: bool

Is the installed version later?

class MulensModel.utils.PlotUtils

Bases: object

A number of small functions related to plotting used in different places

static get_y_value_y_err(phot_fmt, flux, flux_err)

Change the format of data for Y axis.

Parameters :
phot_fmt: str

Requested format of output: ‘mag’ or ‘flux’

flux: np.ndarray

fluxes values for Y axis

flux_err: np.ndarray

flux uncertainties for Y axis

Returns :
values: np.ndarray

Values in the requested format

uncertainties: np.ndarray

Uncertainties in the requested format. Any negative uncertainties are set to zero.

static find_subtract(subtract_2450000=False, subtract_2460000=False)

Find value that is supposed to be subtracted from time vector.

Parameters :
subtract_2450000: bool

Should we subtract 2450000?

subtract_2460000: bool

Should we subtract 2460000?

Returns :
subtract: float

Value to be subtracted.

static find_subtract_xlabel(subtract_2450000=False, subtract_2460000=False)

Find string for xlabel

Parameters :
subtract_2450000: bool

Should we subtract 2450000?

subtract_2460000: bool

Should we subtract 2460000?

Returns :
xlabel: str

String to be used by pyplot.xlabel()

static get_color_differences(color_list, color)

Calculate color difference between a list of colors and a single color. Uses algorithm from Wikipedia page: https://en.wikipedia.org/wiki/Color_difference

Parameters :
color_list: list of str

list of matplotlib colors e.g., ['black', '#E9967A']

color: str

single matplotlib color

Returns :
differences: np.ndarray

differences of colors, values < 0.3 are very similar