astrolofar.spectrum

Module to extract spectral information from fits files.

Note

This module is built based on WSClean fits files, i.e. it does not support image cubes (yet). This means you need a fits file for each frequency/polarization.

You can use the module as

>>> from astrolofar import spectrum
astrolofar.spectrum.gen_mask(fitsname, rms, threshold, sigma_kernel=(0, 0), theta_kernel=0, outname='fitsname')

Generate a mask starting from a fits file. The mask has the same pixel scale and size of the input fits file, but WCS info are not stored. The mask is 0 in pixels with brightness lower than rms * threshold and 1 in pixels with brightness higher than rms * threshold. A 2D Gaussian smoothing kernel can be applied to avoid sharp pixelized features.

Parameters:
  • fitsname (str) – Name of the fits file. You may include the full path if the file is not in the directory where you ran Python.

  • rms (float) – Standard deviation or RMS value of the background/noise level. It must be in the same unit of the data stored in the fits file (e.g. mJy/beam).

  • threshold (float) – Set the minimum brightnes included in the mask as threshold * sigma.

  • sigma_kernel (tuple (float, float), default: (0, 0)) – Standard deviation of the Gaussian smoothing kernel in (x, y) before rotating by theta. Default is (0, 0), which means no smoothing is applied.

  • theta_kernel (float, default: 0) –

    Rotation angle of the Gaussian smoothing kernel in units of radians. The angle increases counter-clockwise.

  • outname (str, default: fitsname) – Name of the output mask fits file without extension. If fitsname (default) is used, the name of the output file will be the same of the input fits file plus .mask (i.e. the final name will be fitsname.mask.fits).

Returns:

  • mask (2D-array) – Mask array saved in outname.

  • outname (str) – Full name (including extension) of the mask fits file.

astrolofar.spectrum.gen_spix_map(fitslist, nterms=1, reffreq=None, maskfits=None, sigma_kernel=(0, 0), theta_kernel=0, wsclean=False, outname='spix')

Extract a pixel-by-pixel spectral index map from a set of fits files. A minimum of 2 files must be given as input. Higher order maps can also be generated if nterms>1; in this case, at least 3 files must be given in input. Spectral index (and higher order) map is saved in a fits file with the same pixel scale, size and WCS of the input fits.

Warning

Every fits file must have the same pixel scale and image size. If not, regrid the fits images into the same pixel scale and size.

Parameters:
  • fitslist (array of str) – List of fits files from which spectral index (and higher orders) will be extracted. It must contain more than 2 entries.

  • nterms (int, default: 1) – Number of spectral terms for the logaritmic polynomial function. E.g., if nterms=1 (default) only a spectral index map is extracted by fitting a standard power law; if nterms=2 also a curvature map is produced, using a second-order logarithmic polynomial.

  • reffreq (float, default: None) – Reference frequency (in MHz) at which spectral indices (or higher orders parameters) are evaluated. If None (default) is used, reffreq will be the central frequency of the fits images in fitslist.

  • maskfits (str, default: None) – Mask fits file to extract spectral indices from specific pixels. It can be generated by astrolofar.spectrum.gen_mask(). The mask must have the same pixel scale and size of the files in fitslist. If None (default) is used, spectral indices will be extracted from evry pixel of the image.

  • sigma_kernel (tuple (float, float), default: (0, 0)) –

    Standard deviation of the Gaussian smoothing kernel in (x, y) before rotating by theta. Default is (0, 0), which means no smoothing is applied.

  • theta_kernel (float, default: 0) –

    Rotation angle of the Gaussian smoothing kernel in units of radians. The angle increases counter-clockwise.

  • wsclean (bool, default: False) – It is only required when the outputs are used in the forced-spectrum fitting of WSClean. When False (dafault) is selected, pixels not selected by the mask assumes NaN values, otherwise they get arbitrary values of \(-0.7\) for the spectral index map and \(0\) for the higher orders terms, which are the average values for the synchrotron radiation. An extra label wsclean is added to the output fits file.

  • outname (str, default: 'spix') – Name of the output spectral index (and higher order) fits file without extension. A single name must be given: the generated fits file will be a cube with label SPIX-cube, where the third axis contain the spectral index map and higher orders (its dimension is the same of nterms). If spix (default) is used, the output file will be spix-SPIX-cube.fits.

Returns:

si_map – Array with spectral index (and higher order) values.

Return type:

ndarray

astrolofar.spectrum.log_pol(x, *args)

Evaluate the logarithmic polynomial using the following formula:

\[y = y_0 x^{c_1} \prod_{i=2}^{n} 10^{c_i \log_{10}^{i}(x)} \, ,\]

where \(y_0=10^{c_0}\) is the normalization factor, \(\alpha=c_1\) is the spectral index, and \(c_i\) are the higher orders coefficients (e.g. \(\beta=c_2\) is the curvature). Using \(y_0\) instad of \(10^{c_0}\) allows for the fitting of negative flux densities that could be present in real observations, e.g. because of calibration errors. The order of the logarithmic polynomial is \(n\); e.g., second-order means 3 terms are used, i.e. \(c_0,c_1,c_2\).

Parameters:
  • x (array_like) – The bases. If you are using it for spectrum fitting or other astronomycal purpose, it should be the channel frequency divided by a reference frequency: for example, x = freq/150. where the reference frequency is 150 MHz.

  • *args (float) – The coefficients \(c_i\). At least two terms must be used, i.e. \(c_0\) and \(c_1\).

Returns:

y – The logaritmic polynomial function of x of order n.

Return type:

array_like