fmflow package#

Subpackages#

Module contents#

class BaseAccessor(dataarray)[source]#

Bases: object

DEMODULATED = 'DEMODULATED'#
DEMODULATED_R = 'DEMODULATED_R'#
FMARRAY = 'FMARRAY'#
FMCUBE = 'FMCUBE'#
FMSPECTRUM = 'FMSPECTRUM'#
MODULATED = 'MODULATED'#
property datacoords#

A dictionary of arrays that label full axes of the data.

dimcoords(dim)[source]#

A dictionary of values that label dim axis.

property isdemodulated#

Whether the array is demodulated (regardless of reverse).

property isdemodulated_r#

Whether the array is reverse-demodulated.

property ismodulated#

Whether the array is modulated.

property scalarcoords#

A dictionary of values that don’t label any axes.

updatecoords(coords, dim=None)[source]#
array(data, tcoords=None, chcoords=None, scalarcoords=None, attrs=None, name=None)[source]#

Create a modulated array as an instance of xarray.DataArray with FM array accessor.

Parameters:
  • data (numpy.ndarray) – A 2D (time x channel) array.

  • tcoords (dict, optional) – A dictionary of arrays that label time axis.

  • chcoords (dict, optional) – A dictionary of arrays that label channel axis.

  • scalarcoords (dict, optional) – A dictionary of values that don’t label any axes.

  • attrs (dict, optional) – A dictionary of attributes to add to the instance.

  • name (str, optional) – A string that names the instance.

Returns:

A modulated array.

Return type:

array (xarray.DataArray)

chbinning(array, size=2)[source]#

Binning an array along ch axis with given size.

Parameters:
  • array (xarray.DataArray) – An input array.

  • size (int) – Ch length of a bin.

Returns:

An output binned array.

Return type:

binarray (xarray.DataArray)

chunk(*argnames, concatfunc=None)[source]#

Make a function compatible with multicore chunk processing.

This function is intended to be used as a decorator like:

>>> @fm.chunk('array')
>>> def func(array):
...     # do something
...     return newarray
>>>
>>> result = func(array, timechunk=10)

or you can set a global chunk parameter outside the function:

>>> timechunk = 10
>>> result = func(array)
cube(data, chcoords=None, ycoords=None, xcoords=None, datacoords=None, scalarcoords=None, attrs=None, name=None)[source]#

Create a cube as an instance of xarray.DataArray with FM accessor.

Parameters:
  • data (numpy.ndarray) – A 3D (channel) array.

  • chcoords (dict, optional) – A dictionary of arrays that label channel axis.

  • ycoords (dict, optional) – A dictionary of arrays that label y axis.

  • xcoords (dict, optional) – A dictionary of arrays that label x axis.

  • datacoords (dict, optional) – A dictionary of values that label all axes.

  • scalarcoords (dict, optional) – A dictionary of values that don’t label any axes.

  • attrs (dict, optional) – A dictionary of attributes to add to the instance.

  • name (str, optional) – A string that names the instance.

Returns:

A cube.

Return type:

cube (xarray.DataArray)

demodulate(array, reverse=False)[source]#

Create a demodulated array from the modulated one.

This function is only available when the array is modulated.

Parameters:
  • array (xarray.DataArray) – A modulated array.

  • reverse (bool, optional) – If True, the array is reverse-demodulated (i.e. -1 * fmch is used for demodulation). Default is False.

Returns:

A demodulated array.

Return type:

array (xarray.DataArray)

empty(shape, dtype=None, **kwargs)[source]#

Create a modulated array of given shape and type, without initializing entries.

Parameters:
  • shape (sequence of ints) – 2D shape of the array.

  • dtype (data-type, optional) – The desired data-type for the array.

  • kwargs (optional) – Other arguments of the array (*coords, attrs, and name).

Returns:

A modulated array without initializing entries.

Return type:

array (xarray.DataArray)

empty_like(array, dtype=None, keepmeta=True)[source]#

Create an array of empty with the same shape and type as the input array.

Parameters:
  • array (xarray.DataArray) – The shape and data-type of it define these same attributes of the output array.

  • dtype (data-type, optional) – If spacified, this function overrides the data-type of the output array.

  • keepmeta (bool, optional) – Whether *coords, attrs, and name of the input array are kept in the output one. Default is True.

Returns:

An array without initializing entries.

Return type:

array (xarray.DataArray)

fromcube(cube, array)[source]#

Create an array filled with the cube.

Parameters:
  • cube (xarray.DataArray) – A cube to be cast.

  • array (xarray.DataArray) – An array whose shape the cube is cast on.

Returns:

An array filled with the cube.

Return type:

array (xarray.DataArray)

fromspectrum(spectrum, array)[source]#

Create an array filled with the spectrum.

Parameters:
  • spectrum (xarray.DataArray) – A spectrum to be cast.

  • array (xarray.DataArray) – An array whose shape the spectrum is cast on.

Returns:

An array filled with the spectrum.

Return type:

array (xarray.DataArray)

full(shape, fill_value, dtype=None, **kwargs)[source]#

Create a modulated array of given shape and type, filled with fill_value.

Parameters:
  • shape (sequence of ints) – 2D shape of the array.

  • fill_value (scalar or numpy.ndarray) – Fill value or array.

  • dtype (data-type, optional) – The desired data-type for the array.

  • kwargs (optional) – Other arguments of the array (*coords, attrs, and name).

Returns:

A modulated array filled with fill_value.

Return type:

array (xarray.DataArray)

full_like(array, fill_value, dtype=None, keepmeta=True)[source]#

Create an array of fill_value with the same shape and type as the input array.

Parameters:
  • array (xarray.DataArray) – The shape and data-type of it define these same attributes of the output array.

  • fill_value (scalar or numpy.ndarray or xarray.DataArray) – Fill value or array.

  • dtype (data-type, optional) – If spacified, this function overrides the data-type of the output array.

  • keepmeta (bool, optional) – Whether *coords, attrs, and name of the input array are kept in the output one. Default is True.

Returns:

An array filled with fill_value.

Return type:

array (xarray.DataArray)

load(filename, copy=True)[source]#

Load a dataarray from a NetCDF file.

Parameters:
  • filename (str) – A file name (*.nc).

  • copy (bool) – If True, dataarray is copied in memory. Default is True.

Returns:

A loaded dataarray.

Return type:

dataarray (xarray.DataArray)

mad(array, dim=None, axis=None)[source]#

Compute the median absolute deviation (MAD) along the given dim or axis.

Only one of the dim and axis arguments can be supplied. If neither are supplied, then mad will be calculated over axes.

Parameters:
  • array (xarray.DataArray) – An input array.

  • dim (str, optional) – Dim along which the MADs are computed.

  • axis (int, optional) – Axis along which the MADs are computed.

Returns:

An array of the MAD.

Return type:

mad (xarray.DataArray)

modulate(array)[source]#

Create a modulated array from the demodulated one.

This function is only available when the array is demodulated.

Parameters:

array (xarray.DataArray) – A demodulated array.

Returns:

A modulated array.

Return type:

array (xarray.DataArray)

ones(shape, dtype=None, **kwargs)[source]#

Create a modulated array of given shape and type, filled with ones.

Parameters:
  • shape (sequence of ints) – 2D shape of the array.

  • dtype (data-type, optional) – The desired data-type for the array.

  • kwargs (optional) – Other arguments of the array (*coords, attrs, and name).

Returns:

A modulated array filled with ones.

Return type:

array (xarray.DataArray)

ones_like(array, dtype=None, keepmeta=True)[source]#

Create an array of ones with the same shape and type as the input array.

Parameters:
  • array (xarray.DataArray) – The shape and data-type of it define these same attributes of the output array.

  • dtype (data-type, optional) – If spacified, this function overrides the data-type of the output array.

  • keepmeta (bool, optional) – Whether *coords, attrs, and name of the input array are kept in the output one. Default is True.

Returns:

An array filled with ones.

Return type:

array (xarray.DataArray)

save(dataarray, filename=None)[source]#

Save a dataarray to a NetCDF file.

Parameters:
  • dataarray (xarray.DataArray) – A dataarray to be saved.

  • filename (str) – A filename (used as <filename>.nc). If not spacified, random 8-character name will be used.

class setlogger(level=None, filename=None, overwrite=False, encoding='utf-8')[source]#

Bases: object

static sethandlers(filename, overwrite, encoding)[source]#
static setlevel(level)[source]#
spectrum(data, chcoords=None, scalarcoords=None, attrs=None, name=None)[source]#

Create a spectrum as an instance of xarray.DataArray with FM spectrum accessor.

Parameters:
  • data (numpy.ndarray) – A 1D (channel) array.

  • chcoords (dict, optional) – A dictionary of arrays that label channel axis.

  • scalarcoords (dict, optional) – A dictionary of values that don’t label any axes.

  • attrs (dict, optional) – A dictionary of attributes to add to the instance.

  • name (str, optional) – A string that names the instance.

Returns:

A spectrum.

Return type:

spectrum (xarray.DataArray)

tocube(array, weights=None, reverse=False, gridsize=10, gridunit='arcsec', gcf='besselgauss')[source]#

Create a cube from an array.

Parameters:
  • array (xarray.DataArray) – An array.

  • weights (xarray.DataArray, optional) – A weight array.

  • reverse (bool, optional) – If True, the array is reverse-demodulated (i.e. -1 * fmch is used for demodulation). Default is False.

  • gridsize (float, optional) – Grid size in units of gridunit.

  • gridunit (str, optional) – Grid unit of gridsize.

  • gcf (str, optional) – Grid convolution function.

Returns:

A cube.

Return type:

cube (xarray.DataArray)

tospectrum(array, weights=None, reverse=False)[source]#

Create a spectrum from an array.

Parameters:
  • array (xarray.DataArray) – An array.

  • weights (xarray.DataArray, optional) – A weight array.

  • reverse (bool, optional) – If True, the array is reverse-demodulated (i.e. -1 * fmch is used for demodulation). Default is False.

Returns:

A spectrum.

Return type:

spectrum (xarray.DataArray)

xarrayfunc(func)[source]#

Make a function compatible with xarray.DataArray.

This function is intended to be used as a decorator like:

>>> @fm.xarrayfunc
>>> def func(array):
...     # do something
...     return newarray
>>>
>>> result = func(array)
Parameters:

func (function) – A function to be wrapped. The first argument of the function must be an array to be processed.

Returns:

A wrapped function.

Return type:

wrapper (function)

zeros(shape, dtype=None, **kwargs)[source]#

Create a modulated array of given shape and type, filled with zeros.

Parameters:
  • shape (sequence of ints) – 2D shape of the array.

  • dtype (data-type, optional) – The desired data-type for the array.

  • kwargs (optional) – Other arguments of the array (*coords, attrs, and name).

Returns:

A modulated array filled with zeros.

Return type:

array (xarray.DataArray)

zeros_like(array, dtype=None, keepmeta=True)[source]#

Create an array of zeros with the same shape and type as the input array.

Parameters:
  • array (xarray.DataArray) – The shape and data-type of it define these same attributes of the output array.

  • dtype (data-type, optional) – If spacified, this function overrides the data-type of the output array.

  • keepmeta (bool, optional) – Whether *coords, attrs, and name of the input array are kept in the output one. Default is True.

Returns:

An array filled with zeros.

Return type:

array (xarray.DataArray)