Package ComboCode :: Package cc :: Package data :: Module Data
[hide private]
[frames] | no frames]

Module Data

source code

Multiple operations on data or modeling results (e.g. aligning, convolution, ...)

Author: R. Lombaert

Functions [hide private]
(list[list[(.,.)]], list)
alignY(datalists, xmin, xmax, zeropoint=0, p0=[1, 0, 1.5, -2.5], func='power')
*** WILL BE REWRITTEN ***
source code
list
doConvolution(x_in, y_in, x_out, widths, factor=5, oversampling=1)
Perform convolution on lists with a Gaussian filter.
source code
array
convolveArray(xx, yy=None, sigma=3)
Convolves an intensity-versus-velocity profile with an instrumental Gaussian profile of width 'sigma'
source code
np.array
reduceArray(arr, stepsize, cutoff=None, mode='average')
Reduce the size of a 1d-array.
source code
float
getRMS(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)
Get the RMS of a flux array in a given wavelength range.
source code
float
getMean(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)
Get the mean of a flux array in a given wavelength range.
source code
float
getStd(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)
Get the std of a flux array in a given wavelength range.
source code
array
selectArray(flux, wave=None, wmin=None, wmax=None)
Select the sub array of a flux, given a wavelength range.
source code
array
arrayify(x)
Check whether the input value is a proper array.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.data'
Function Details [hide private]

alignY(datalists, xmin, xmax, zeropoint=0, p0=[1, 0, 1.5, -2.5], func='power')

source code 

*** WILL BE REWRITTEN ***

Align two datasets by shifting Y coordinate.

Works on multiple data lists at a time. Each dataset is shifted to match with the previous dataset AFTER the previous one has already been shifted.

e.g. for the third dataset y_new = zeropoint + shifts[1]*shifts[2]*y

The shifts between datasets are multiplicative, the first dataset is shifted additively by the keyword zeropoint.

At least 3 points of overlap are required!

Parameters:
  • datalists (list[list[(.,.)]]) - two or more 2d lists of data giving (x,y)
  • xmin (float or list) - the lower boundar(y)(ies) of the overlapping region, used for alignment. Must be 1 value for 2 datasets, n-1 values for more
  • xmax (float or list) - the upper boundar(y)(ies) of the overlapping region, used for alignment. Must be 1 value for 2 datasets, n-1 values for more
  • zeropoint (float) - The first dataset is shifted additively with this value

    (default: 0)

  • p0 (list) - initial parameters for fitting function definition

    (default: [1,0,1.5,-2.5])

Returns: (list[list[(.,.)]], list)
The datasets are returned as given, but with shifted Y-values, and the shifts used (first value additively, rest multiplicatively)

doConvolution(x_in, y_in, x_out, widths, factor=5, oversampling=1)

source code 

Perform convolution on lists with a Gaussian filter.

Reduce the input grid to the target grid by integration.

Parameters:
  • x_in (array) - The input x-values
  • y_in (array) - The input y-values
  • x_out (array) - The target x-grid
  • widths (array) - The full width/half maximum spectral resolution as a function of wavelength, i.e. the fwhm of the gaussian
  • factor (int) - the sigma factor for determining the window pushed through the gaussian filter. This avoids having to convolve the whole input grid, which takes a lot of time. Beyond sigma*factor the contribution of the y values is assumed to be negligible.

    (default: 5)

  • oversampling (int) - oversampling factor of the target x-grid with respect to the given spectral resolution.

    (default: 1)

Returns: list
The resulting y-values

convolveArray(xx, yy=None, sigma=3)

source code 

Convolves an intensity-versus-velocity profile with an instrumental Gaussian profile of width 'sigma'

by Kristof Smolders

Parameters:
  • xx (array) - x values
  • yy (array) - y values, if None, the y values are assumed to be included in xx, in its second dimension.

    (default: None)

  • sigma (float) - width of the gaussian profile

    (default: 3)

Returns: array
The new y values after convolution

reduceArray(arr, stepsize, cutoff=None, mode='average')

source code 

Reduce the size of a 1d-array.

Two modes are available:

  • average: subsequent n=stepsize elements are averaged
  • remove: keep one element every n=stepsize elements

The average mode can be used when, e.g., reading MCMax output, where the density/temperature/... grids are given for radial and angular coordinates. In case only the radial points are needed, the stepsize would then be the number of angular grid cells.

Parameters:
  • arr (np.array) - The array to be reduced
  • stepsize (int) - The number of subsequent elements to average/frequency of element removal.
  • cutoff (float) - A cutoff value below which no reduction is done. Default if the full array is to be reduced. Only relevant for mode == 'remove'.

    (default: None)

  • mode (string) - The reduction mode, either 'average' or 'remove'. If the mode is not recognized, it is assumed to be 'average'.

    (default: 'average')

Returns: np.array
The reduced array

getRMS(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)

source code 

Get the RMS of a flux array in a given wavelength range. If no wavelengths are given, the RMS of the whole array is given.

If the array used for RMS calculation is too small, None is returned.

The mean should already be subtracted!

A 1-sigma clipping of the flux array can be done by providing limits.

Parameters:
  • flux (array) - The wavelength array
  • limits ((float,float)) - Flux limits if flux clipping (1 sigma!) is needed before RMS calculation. None for both limits implies no clipping. None for one of the limits implies a half-open interval. (lower limit,upper limit)

    (default: (None,None))

  • wave (array) - The wavelength array. If default, the RMS is calculated of the whole flux array
  • wmin (float) - The minimum wavelength. If not given, the minimum wavelength is the first entry in the wave array

    (default: None)

  • wmin (float) - The maximum wavelength. If not given, the maximum wavelength is the last entry in the wave array

    (default: None)

  • minsize (int) - The minimum size of the selected array before proceeding with the noise calculation. 0 if no min size is needed.

    (default: 20)

  • wmax (float)
Returns: float
The flux RMS between given wavelengths

getMean(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)

source code 

Get the mean of a flux array in a given wavelength range. If no wavelengths are given, the mean of the whole array is given.

If the array used for mean calculation is too small, None is returned.

A 1-sigma clipping of the flux array can be done by providing limits.

Parameters:
  • flux (array) - The wavelength array
  • limits ((float,float)) - Flux limits if flux clipping (1 sigma!) is needed before Meancalculation. None for both limits implies no clipping. None for one of the limits implies a half-open interval.

    (default: (None,None))

  • wave (array) - The wavelength array. If default, the Mean is calculated of the whole flux array
  • wmin (float) - The minimum wavelength. If not given, the minimum wavelength is the first entry in the wave array

    (default: None)

  • wmin (float) - The maximum wavelength. If not given, the maximum wavelength is the last entry in the wave array

    (default: None)

  • minsize (int) - The minimum size of the selected array before proceeding with the noise calculation. 0 if no min size is needed.

    (default: 20)

  • wmax (float)
Returns: float
The flux mean between given wavelengths

getStd(flux, limits=(None, None), wave=None, wmin=None, wmax=None, minsize=20)

source code 

Get the std of a flux array in a given wavelength range. If no min/max wavelengths are given, the std of the whole array is given.

If the array used for std calculation is too small, None is returned.

A 1-sigma clipping of the flux array can be done by providing limits.

Parameters:
  • flux (array) - The wavelength array
  • limits ((float,float)) - Flux limits if flux clipping (1 sigma!) is needed before STD calculation. None for both limits implies no clipping. None for one of the limits implies a half-open interval.

    (default: (None,None))

  • wave (array) - The wavelength array. If default, the STD is calculated of the whole flux array
  • wmin (float) - The minimum wavelength. If not given, the minimum wavelength is the first entry in the wave array

    (default: None)

  • wmin (float) - The maximum wavelength. If not given, the maximum wavelength is the last entry in the wave array

    (default: None)

  • minsize (int) - The minimum size of the selected array before proceeding with the noise calculation. 0 if no min size is needed.

    (default: 20)

  • wmax (float)
Returns: float
The flux std between given wavelengths

selectArray(flux, wave=None, wmin=None, wmax=None)

source code 

Select the sub array of a flux, given a wavelength range. If no range is given, return the full array.

Parameters:
  • flux (array) - The wavelength array
  • wave (array) - The wavelength array. If default, no wavelength selection is done.
  • wmin (float) - The minimum wavelength. If not given, the minimum wavelength is the first entry in the wave array

    (default: None)

  • wmin (float) - The maximum wavelength. If not given, the maximum wavelength is the last entry in the wave array

    (default: None)

  • wmax (float)
Returns: array
The flux in given wavelengths

arrayify(x)

source code 

Check whether the input value is a proper array.

Parameters:
  • x (anything) - The input candidate array
Returns: array
an array of the input value