utils - VDRP utility routines

Utility functions for virus reductions

This code relies on original software from: Copyright (c) 2011-2016, Astropy Developers Copyright (c) 2012, Free Software Foundation

vdrp.utils.bindir()[source]
vdrp.utils.biweight_bin(xv, x, y)[source]

Compute the biweight location with a moving window of size “order”

vdrp.utils.biweight_filter(a, order, ignore_central=3, c=6.0, M=None, func=None)[source]
vdrp.utils.biweight_filter2d(a, Order, Ignore_central=(3, 3), c=6.0, M=None, func=None)[source]

Compute the biweight location with a moving window of size “order”

vdrp.utils.biweight_location(a, c=6.0, M=None, axis=None, eps=1e-08)[source]

Copyright (c) 2011-2016, Astropy Developers

Compute the biweight location for an array.

Returns the biweight location for the array elements. The biweight is a robust statistic for determining the central location of a distribution.

The biweight location is given by the following equation

where M is the sample mean or if run iterative the initial guess, and u_i is given by

where MAD is the median absolute deviation.

For more details, see Beers, Flynn, and Gebhardt, 1990, AJ, 100, 32B

Parameters:
a : array-like

Input array or object that can be converted to an array.

c : float, optional

Tuning constant for the biweight estimator. Default value is 6.0.

M : float, optional

Initial guess for the biweight location.

axis : tuple, optional

tuple of the integer axis values ot calculate over. Should be sorted.

Returns
——-
biweight_location : float

Returns the biweight location for the array elements.

Examples

This will generate random variates from a Gaussian distribution and return the biweight location of the distribution:

>>> from utils import biweight_location
>>> from numpy.random import randn
>>> randvar = randn(10000)
>>> cbl = biweight_location(randvar)
vdrp.utils.biweight_midvariance(a, c=15.0, M=None, axis=None, eps=1e-08, niter=1)[source]

Copyright (c) 2011-2016, Astropy Developers

Compute the biweight midvariance for an array.

Returns the biweight midvariance for the array elements. The biweight midvariance is a robust statistic for determining the midvariance (i.e. the standard deviation) of a distribution.

The biweight location is given by the following equation

where is given by

where MAD is the median absolute deviation.

is the number of data for which holds, while the summations are over all i up to n:

This is slightly different than given in the reference below, but results in a value closer to the true midvariance.

The midvariance parameter c is typically 9.0.

For more details, see Beers, Flynn, and Gebhardt, 1990, AJ, 100, 32B

Parameters:
a : array-like

Input array or object that can be converted to an array.

c : float

Tuning constant for the biweight estimator. Default value is 9.0.

M : float, optional

Initial guess for the biweight location.

axis : tuple, optional

tuple of the integer axis values ot calculate over. Should be sorted.

Returns:
biweight_midvariance : float

Returns the biweight midvariance for the array elements.

Examples

This will generate random variates from a Gaussian distribution and return the biweight midvariance of the distribution:

>>> from utils import biweight_midvariance
>>> from numpy.random import randn
>>> randvar = randn(10000)
>>> scl = biweight_midvariance(randvar)
vdrp.utils.configdir()[source]
vdrp.utils.createDir(directory)[source]

Creates a directory. Does not raise an excpetion if the directory already exists.

Args:
directory (string): Name for directory to create.
vdrp.utils.is_outlier(points, thresh=3.5)[source]

Copyright (c) 2012, Free Software Foundation

Returns a boolean array with True if points are outliers and False otherwise.

vdrp.utils.mangle_config_pathname(path)[source]
vdrp.utils.matrixCheby2D_7(x, y)[source]
vdrp.utils.median_absolute_deviation(a, axis=None)[source]

Copyright (c) 2011-2016, Astropy Developers

Compute the median absolute deviation.

Returns the median absolute deviation (MAD) of the array elements. The MAD is defined as median(abs(a - median(a))).

Parameters:
a : array-like

Input array or object that can be converted to an array.

axis : tuple, optional

Axis along which the medians are computed. The default (axis=None) is to compute the median along a flattened version of the array.

Returns:
median_absolute_deviation : ndarray

A new array holding the result. If the input contains integers, or floats of smaller precision than 64, then the output data-type is float64. Otherwise, the output data-type is the same as that of the input.

See also

numpy.median

Examples

This will generate random variates from a Gaussian distribution and return the median absolute deviation for that distribution:

>>> from utils import median_absolute_deviation
>>> from numpy.random import randn
>>> randvar = randn(10000)
>>> mad = median_absolute_deviation(randvar)
vdrp.utils.print_bindir()[source]
vdrp.utils.print_conffile()[source]
vdrp.utils.print_configdir()[source]
vdrp.utils.read_all_mch(all_mch)[source]

Reads all.mch and returns dither information.

Args:
all_mch (str): Filename, typically all.mch.
Returns:
(OrdereDict): Dictionary of float tuples, with dither offsets,
e.g. {1 : (0.,0.), 2 : (1.27,-0.73), 3 : (1.27,0.73)}
vdrp.utils.read_radec(filename)[source]

Reads radec.dat file and returns ra,dec,pa.

Args:
filename (str): Filename, typically radec.dat or radec2.dat.
Returns:
float,float,float: 3 element list with RA, DEC and PA
vdrp.utils.rm(ff)[source]

Takes a list of files names and deletes them. Does not raise an Exception if a specific file was not in place.

Args:
ff (list): List of file names to delete.
vdrp.utils.setup_logging(logger, logfile, loglevel)[source]
vdrp.utils.write_conf_file(fname)[source]
vdrp.utils.write_radec(ra, dec, pa, filename)[source]

Creates radec.dat-type file and returns ra,dec,pa.

Args:
ra (float): Right ascension dec (float): declination pa (float): position angle filename (str): Filename, typically radec.dat or radec2.dat.