NburstFitter

class sitelle.nburst.NburstFitter(axis, spectra, error, fwhm, header, filedir, prefix, fit_name=None, force=False)

This class is a helper to fit spectra with Nburst directly from python. It stores data as expected by Nburst, configure a script with user-defined parameters, runs it and reads the results.

axis

1D ndarray – a regular wavelength axis in Angstroms

spectra

2 or 3D ndarray – spectra of shape [x,z] or [x,y,z], interpolated on the axis

error

2 or 3D ndarray – an error array of the same shape as spectra

fwhm

2 or 3D ndarray – an fwhm array of the same shape as spectra

header

str – a header describing the data. Should match spectra shape : [NAXIS1, NAXIS2, NAXIS3] <=> [x,y,z]

filedir

str – the folder where the NburstFitter data should be stored

prefix

str – a prefix for this fitter.

fit_name

str – (Optional) the fit_name, if already performed.

fit_params

dict – Parameters for the nburst fit

force

bool – (Optional) If set to True, the Nburst input data will be recomputed even if the filedir and prefix already exists. Default = False, which means than the function can have no effect if the filedir and prefix already exist.

idl_result

BinTableHDU – The table in which the parameters are found (returned by NBurst)

fitted_spectra

1, 2 or 3D ndarray – The Nburst-fitted spectra. Same dimension as input spectra

bin_table

2D ndarray – The binning scheme used by NBurst

nburst_working_dir

Path – Class attribute. The working directory for nburst, where the library are stored. This is machine dependent and can be updated with the set_env() function.

idl_binary_path

str – Class attribute. Location of the idl binary. This is machine dependent and can be updated with the set_env() function.

idl_startup_script

str – Class attribute. Path of the script to be executed at startup of IDL, to compile the right libraries. This script should always be stored at ~/.idl/start.pro.

Attributes Summary

idl_binary_path
idl_startup_script
nburst_working_dir

Methods Summary

configure_fit([fit_name]) Configurator for the Nburst fit.
extract_spectrum(binNumber) Extract the fitted spectra in a given bin.
from_previous(filedir, prefix[, fit_name]) Reload a NburstFitter that had been created previously, based on its filedir and prefix.
from_sitelle_data(axis, spectra, error, …) This function converts sitelle data to be fitted by Nburst.
from_sitelle_region(region, ORCS_cube, …) Generate the right parameters (spectra, error, fwhm) to create a Nburst fittable cube from an integrated region in a SITELLE datacube.
read_result([filename, force]) Read the raw NBurst result and convert it to a more natural format, by populating the fitted_spectra, idl_result and bin_table attributes of the NburstFitter.
run_fit([silent]) Runs the NburstFitter, once properly configured.
set_env(machine) Sets the right value for nburst_working_dir and idl_binary_path, depending on the machine.

Attributes Documentation

idl_binary_path = '/usr/local/idl/idl/bin:/usr/local/idl/idl/bin/bin.darwin.x86_64:'
idl_startup_script = '~/.idl/start.pro'
nburst_working_dir = Path(u'/Users/blaunet/Documents/M31/nburst/')

Methods Documentation

configure_fit(fit_name=None, **kwargs)

Configurator for the Nburst fit. These function writes a procedure file for IDL containing all the fitting parameters we want to be set. They are all optionals, in which case default value are used.

Parameters:
  • silent (bool) – If True, nothing is displayed during the fit (Default = False)
  • lmin (int) – The lower wavelength limit on which the fit has to be performed
  • lmax (int) – The upper wavelength limit on which the fit has to be performed
  • vorbin (bool) – If True, a voronoi tessellation is performed on the data. Only works with 3D datacubes. (Default = False) If True, SN has to be defined as well.
  • SN (int) – The signal to noise ratio to use for the voronoi tessellation. vorbin has to be set to True.
  • exclreg ('default' or list of float) – Exclusion regions to be ommitted during the fit, in Angstroms. Typically concern emission lines region. ‘default’ uses the main emission lines as defined in sitelle.constants.SN2_LINES and sitelle.constants.SN3_LINES
  • mdegree (int) – Degree of the polynomial to be used (Default = 7)
  • vsys (float) – Velocity guess in km/s. Default : -300 km/s
  • sig_guess (float) – Velocity dispersion guess in km/s. Default = 100 km/s
  • age_guess (float) – Age guess in Myr. Default = 15000
  • met_guess (float) – Metallicity guess. Default = 0.
  • fixpar (list of int) – Defines if parameters are fixed or not. The order is [vsys, sigma, age, met]. 0 standas for False (i.e. free) and 1 for True (i.e. fixed). For exmaple, to fix the velocity while letting the rest free, fixpar=[1,0,0,0]
  • lsf (str) – Line shape function to use. If ‘SINC’, a cardinal sine is used. Else, the defaulkt gauss-hermite function is used.
  • stell_lib ({'ELODIE', 'MILES'}) – The stellar library to use to create the SSP. Default = ‘ELODIE’
extract_spectrum(binNumber)

Extract the fitted spectra in a given bin.

Parameters:binNumber (int) – The number of the bin.
Returns:
  • axis (1D ndarray) – The corresponding axis, in Angstroms
  • fit (1D ndarray) – The fitted spectra
classmethod from_previous(filedir, prefix, fit_name=None)

Reload a NburstFitter that had been created previously, based on its filedir and prefix. :param filedir: the folder where the NburstFitter data should be stored :type filedir: str :param prefix: a prefix for this fitter. :type prefix: str :param fit_name: (Optional) the fit_name, if already performed. :type fit_name: str

Returns:A NburstFitter on which the fit can be performed.
Return type:NburstFitter
classmethod from_sitelle_data(axis, spectra, error, fwhm, ORCS_cube, filedir, prefix, force=False)

This function converts sitelle data to be fitted by Nburst. It interpolates a spectra onto a regular wavelength grid, and creates error and fwhm “spectra” as well (by extending maps in the spectral direction). Spectra, error and fwhm should have the same spatial dimensions (x or x,y)

Parameters:
  • axis (1D ndarray) – Axis of the spectrum [cm-1]
  • spectra (1,2 3D ndarray) – The spectra to be fitted. It can be a one dimesion ([z]), two dimensions ([x,z]) or three dimensions ([x,y,z]).
  • error (1 or 2D ndarray) – an error array of the same spatial dim as the spectra ([x,y] if spectra is [x,y,z]), i.e one error per pixel
  • fwhm (1 or 2D ndarray) – a fwhm array of the same spatial dim as the spectra ([x,y] if spectra is [x,y,z]), i.e one fwhm per pixel
  • ORCS_cube (SpectralCube) – The SpectralCube from which the spectra are exatracted
  • filedir (str) – the folder where the NburstFitter data should be stored
  • prefix (str) – a prefix for this fitter.
  • force (bool) – (Optional) If set to True, the Nburst input data will be recomputed even if the filedir and prefix already exists. Default = False, which means than the function can have no effect if the filedir and prefix already exist.
Returns:

A NburstFitter on which the fit can be performed.

Return type:

NburstFitter

classmethod from_sitelle_region(region, ORCS_cube, filedir, prefix, force=False)

Generate the right parameters (spectra, error, fwhm) to create a Nburst fittable cube from an integrated region in a SITELLE datacube. It’s a wrapper around from_sitelle_data.

Parameters:
  • region (tuple of ndarray.) – The region to study, in the same format understood by ORCS i.e. the results from np.nonzero(mask) for example.
  • ORCS_cube (SpectralCube) – The SpectralCube from which the spectra are exatracted
  • filedir (str) – the folder where the NburstFitter data should be stored
  • prefix (str) – a prefix for this fitter.
  • force (bool) – (Optional) If set to True, the Nburst input data will be recomputed even if the filedir and prefix already exists. Default = False, which means than the function can have no effect if the filedir and prefix already exist.
Returns:

A NburstFitter on which the fit can be performed.

Return type:

NburstFitter

read_result(filename=None, force=False)

Read the raw NBurst result and convert it to a more natural format, by populating the fitted_spectra, idl_result and bin_table attributes of the NburstFitter.

Parameters:
  • filename (str) – (Optional) The full path to the fitted result file. Default to ‘filedir’/’prefix’_’fit_name’_fitted.fits
  • force (bool) – (Optional) If True, we recompute the fitted_spectra, idl_result and bin_table attributes even if they are already populated. Default = False.
run_fit(silent=False)

Runs the NburstFitter, once properly configured. It spawns a subprocess and call IDL on the previously configured script.

Parameters:silent (bool) – (Optional) Default False. If True, the output of the subporocess is displayed.
classmethod set_env(machine)

Sets the right value for nburst_working_dir and idl_binary_path, depending on the machine. This has been specifically implemented for B. Launet and should be modified when used by others.

Parameters:machine (str) – hostname of the machine