Core module

ORCS Core library.

Note

ORCS is built over ORB so that ORB must be installed.

class orcs.core.DataFiles

Bases: object

Manage data files (files in orcs/data)

__init__()

Init class

__weakref__

list of weak references to the object (if defined)

get_dirname()

Return absolute data directory path

get_path(file_name)

Return the path to a file in ORCS data folder: orb/data/file_name

Parameters

file_name – Name of the file in ORCS data folder.

class orcs.core.LineMaps(*args: Any, **kwargs: Any)

Bases: orb.core.

Manage line parameters maps

__init__(dimx, dimy, lines, wavenumber, binning, div_nb, wcs_header=None, **kwargs)

Init class

Parameters
  • dimx – X dimension of the unbinned data

  • dimy – Y dimension of the unbinned data

  • lines – tuple of the line names

  • wavenumber – True if the data is in wavenumber, False if it is in wavelength.

  • binning – Binning of the data.

  • div_nb – Number of divisions if the data is binned in quadrant mode.

  • wcs_header – (Optional) Unbinned WCS header passed to the written frames (default None).

  • kwargs – Kwargs are __init__() kwargs.

_get_hdf5_path()

Return the path to the hdf5 bundle

_get_map_path(line_name, param, binning=None)

Return the path to a map of one gaussian fit parameter for one given emission line.

Parameters
  • line_name – Name of the emission line

  • param – Parameter name

  • binning – (Optional) Binning of the map. If not given instance binning is used (default None).

get_map(param, x_range=None, y_range=None)

Get map values

Parameters
  • param – Parameter

  • x_range – (Optional) Data range along X axis (default None)

  • y_range – (Optional) Data range along Y axis (default None)

get_spectrum(cube, x, y, fmodel='sinc')

Reconstruct the fitted vector from the mapped parameters. :param cube: a SpectralCube instance :param x: x position in pixels (unbinned) :param y: y position in pixels (unbinned) :param fmodel: line model

save()

save class as an HDF5 file

set_map(param, data_map, x_range=None, y_range=None)

Set map values.

Parameters
  • param – Parameter

  • data_map – Data

  • x_range – (Optional) Data range along X axis (default None)

  • y_range – (Optional) Data range along Y axis (default None)

write_maps()

Write all maps to disk in fits format.

class orcs.core.SpectralCube(*args: Any, **kwargs: Any)

Bases: orb.cube.

Extension of orb.cube.SpectralCube

Core class which gives access to an HDF5 cube. The child class SpectralCube may be prefered in general for its broader functionality.

See also

orb.cube.SpectralCube

__init__(cube_path, debug=False, **kwargs)
Parameters
  • cube_path – Path to the HDF5 cube.

  • kwargs – Kwargs are orb.cube.SpectralCube() properties.

_extract_wrapper(f, args, kwargs)

General wrapper around get_spectrum* methods for backward compatibility

_get_data_prefix()

Return data prefix

extract_integrated_spectrum(*args, **kwargs)
Parameters
  • region – A ds9-like region file or a list of pixels having the same format as the list returned by np.nonzero(), i.e. (x_positions_1d_array, y_positions_1d_array).

  • median – If True, a median is used instead of a mean to combine spectra. As the resulting spectrum is integrated, the median value of the combined spectra is then scaled to the number of integrated pixels.

  • mean_flux – If True, the mean spectrum (ie per pixel flux) is returned.

Note

the region must not have a size greater than 400x400 pixels. If you really need a larger region, you can split you region into smaller ones and combines the resulting spectra.

extract_spectrum(*args, **kwargs)

Return a spectrum extracted at x, y and integrated over a circular aperture or radius r.

Parameters
  • x – x position

  • y – y position

  • r – (Optional) If r > 0, vector is integrated over a circular aperture of radius r. In this case the number of pixels is returned as a parameter: pixels

  • median – If True, a median is used instead of a mean to combine spectra. As the resulting spectrum is integrated, the median value of the combined spectra is then scaled to the number of integrated pixels.

  • mean_flux – If True, the mean spectrum (ie per pixel flux) is returned.

  • subtract_spectrum – Subtract given spectrum. Must be a vector of the same size as the extracted spectrum.

Returns

axis, spectrum

extract_spectrum_bin(*args, **kwargs)

Return a spectrum extracted at x, y and integrated over a binned region.

Parameters
  • x – X position of the bottom-left pixel

  • y – Y position of the bottom-left pixel

  • b – Binning. If 1, only the central pixel is extracted

  • median – If True, a median is used instead of a mean to combine spectra. As the resulting spectrum is integrated, the median value of the combined spectra is then scaled to the number of integrated pixels.

  • mean_flux – If True, the mean spectrum (ie per pixel flux) is returned.

Returns

axis, spectrum

extract_spectrum_in_annulus(*args, **kwargs)

Return a. orb.fft.RealSpectrum extracted at x, y and integrated over a circular annulus of min radius rmin and max radius rmax.

Parameters
  • x – x position

  • y – y position

  • rmin – rmin of the annulus

  • rmax – rmax of the annulus

  • median – If True, a median is used instead of a mean to combine spectra. As the resulting spectrum is integrated, the median value of the combined spectra is then scaled to the number of integrated pixels.

  • mean_flux – If True, the mean spectrum (ie per pixel flux) is returned.

get_flux_uncertainty()

Return the uncertainty on the flux (1 sigma) of the spectrum in a given channel in counts/s.

get_radial_velocity_correction(kind='heliocentric', date=None, silent=False)
Return heliocentric or barycentric velocity correction to apply on

the observed target in km/s

Parameters
  • kind – (Optional) ‘heliocentric’ or ‘barycentric’ (default ‘heliocentric’).

  • date – (Optional) Corrected date for the observation. Must be a string with the following format YYYY-MM-DDTHH:MM:SS.S (default None).

For m/s precision the returned float should simply be added. But more care must be taken if a better precision is needed. Please see http://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord.radial_velocity_correction for more informations.

Returns

(heliocentric or barycentric) velocities.

See also

This is based on the astropy methods. See

http://docs.astropy.org/en/stable/coordinates/velocities.html for more information on how to use the returned quantities.

get_spectrum_from_region(*args, **kwargs)

Wrapper around the extract_spectrum_from_region method to apply flux calibration by default when extracting spectra (the real data is in counts) when cube is flux calibrated.

process_by_pixel(func, args=[], modules=[], out={}, kwargs={}, mask=None, binning=1, timeout=None)

Parallelize a function taking binned spectra of the cube as an input. All pixels are gone through unless a mask is passed which indicates the pixels that must be processed. The typical results returned are maps.

Parameters
  • func – The parallelized function. Must be func(spectrum, *args, kwargs_dict) which returns a dict of floating values (e.g. {a:1.9, b:5.6, …}) or a 1d array of floats. If it returns a dict out must be set to dict(), its default value. If a 1d array of size N is returned, the out param must be set to a 3d array of shape (cube.dimx, cube.dimy, N). If supplied, kwargs are passed to the function as the last argument in a dict object. Note also that velocity will not be corrected on the fly at data extraction so that the called function must handle it.

  • args – List of arguments passed to the function. arguments can be a function in which case the function must be f(x,y), x and y being the pixel coordinates. Note that x and y can also be lists of coordinates in which case the function must return a list of data.

  • modules – Modules to import to run the function.

  • out – depends on the returned values of func. See param func.

  • kwargs – kwargs of the function func. If supplied, kwargs are passed to the function as the last argument in a dict object.

  • mask – a 2d array of bool. Ones giving the pixels on which the function must be applied.

  • binning – On-the-fly data binning.

Note

Any argument with a shape equal to the x,y shape of the cube (or the binned x,y shape) will be mapped, i.e., the argument passed to the vector function will be the value corresponding to the position of the extracted spectrum. (works also for 3d shaped arguments, the 3rd dimension can have any size)

process_by_region(func, regions, subtract, args=[], modules=[], depfuncs=[])

Parallelize a function applied to a list of integrated regions extracted from the spectral cube.

the function must be defined as func(spectrum_bundle, *args)

theta_orig is the mean original incident angle in the integrated region.

reproject()

Reproject data cube in a distorsion-less WCS.

Warning

The amount of available RAM must be larger than the cube size on disk.