piXedfit_fitting

piXedfit.piXedfit_fitting.SEDfit_from_binmap(fits_binmap, binid_range=None, bin_ids=None, models_spec=None, params_ranges=None, params_priors=None, fit_method='mcmc', gal_z=None, free_z=0, nrands_z=10, wavelength_range=None, smooth_velocity=True, sigma_smooth=0.0, spec_resolution=None, smooth_lsf=False, lsf_wave=None, lsf_sigma=None, poly_order=10, spec_chi_sigma_clip=4.0, del_wave_nebem=15.0, add_igm_absorption=0, igm_type=0, likelihood='gauss', dof=3.0, nwalkers=100, nsteps=600, nsteps_cut=50, nproc=10, initfit_nmodels_mcmc=100000, perc_chi2=90.0, cosmo=0, H0=70.0, Om0=0.3, store_full_samplers=1, name_out_fits=None)

Function for performing SED fitting to a photometric data cube. The data cube should has been binned using the function pixel_binning().

Parameters:
  • fits_binmap – Input FITS file of the spectrophotometric data cube that has been binned.

  • binid_range – Range of bin IDs which the SEDs are going to be fit. The accepted format is [idmin,idmax]. The ID starts from 0. If None, the SED fitting will be done to all of the spatial bins in the galaxy.

  • bin_ids – Bin IDs which the SEDs are going to be fit. The accepted format is 1D array. The ID starts from 0. Both binid_range and bin_ids can’t be None. If both of them are not None, the bin_ids will be used.

  • models_spec – Model spectral templates in the rest-frame generated prior to the SED fitting process using the function piXedfit.piXedfit_model.save_models_rest_spec(). This set of model spectra will be used in the main fitting step if fit_method=’rdsps’ or initial fitting if fit_method=’mcmc’.

  • params_ranges – Ranges of the parameter defined (i.e., outputted) using the params_ranges() in the priors class.

  • params_priors – Forms of adopted priros. The acceptable format is a list, such as params_priors=[prior1, prior2, prior3] where prior1, prior2, and prior3 are output of functions in the priors class.

  • fit_method – (default: ‘mcmc’) Choice for the fitting method. Options are: ‘mcmc’ and ‘rdsps’.

  • gal_z – Redshift of the galaxy. If gal_z=None, then redshift is taken from the header of the FITS file. If gal_z in the FITS header is negative, the redshift is set to be free in the SED fitting (i.e., photometric redshift).

  • free_z – A flag stating whether redshift would be free prameter (value: 1) or not (value: 0). If free_z=1, the gal_z input is not relevant, but the redshift range that is set when setting priors would be considered.

  • nrands_z – Number of random redshifts to be generated (within the chosen range as set in the params_range) in the main fitting if fit_method=’rdsps’ or initial fitting if fit_method=’mcmc’. This is only relevant if gal_z=None (i.e., photometric redshift will be activated).

  • wavelength_range – Range of wavelength within which the observed spectrum will be considered in the SED fitting. The accepted format is [wmin,wmax] with wmin and wmax are minimum and maximum wavelengths.

  • smooth_velocity – (default: True) The same parameter as in FSPS. Switch to perform smoothing in velocity space (if True) or wavelength space.

  • sigma_smooth – (default: 0.0) The same parameter as in FSPS. If smooth_velocity is True, this gives the velocity dispersion in km/s. Otherwise, it gives the width of the gaussian wavelength smoothing in Angstroms. These widths are in terms of sigma (standard deviation), not FWHM.

  • spec_resolution – (default: None) Spectral resolution (R) of the input spectra. This is R=c/sigma_smooth if sigma_smooth is a velocity dispersion. This parameter will be considered if smooth_velocity=True and sigma_smooth=None. The sigma_smooth will then be calculated using the above equation.

  • smooth_lsf – (default: False) The same parameter as in FSPS. Switch to apply smoothing of the SSPs by a wavelength dependent line spread function. Only takes effect if smooth_velocity is True.

  • lsf_wave – Wavelength grids for the input line spread function. This must be in the units of Angstroms, and sorted ascending.

  • lsf_sigma – The dispersion of the Gaussian line spread function at the wavelengths given by lsf_wave, in km/s. This array must have the same length as lsf_wave. If value is 0, no smoothing will be applied at that wavelength.

  • poly_order – The degree of the legendre polynomial function to be used for correcting the shape (normalization) of the model spectra.

  • spec_chi_sigma_clip – Standard deviation (sigma) to be adopted in the sigma clipping to the spectrum data points that are regarded as outliers before calculating chi-square in the SED fitting process. The sigma clipping is carried out based on the distribution of chi values (sum((D-M)/Derr)).

  • del_wave_nebem – This parameter defines the Wavelength region (+/- del_wave_nebem) around the emission lines that will be excluded in the fitting of spectral continuum between the model spectrum and the observed one.

  • add_igm_absorption – Switch for the IGM absorption. Options are: 0 for switch off and 1 for switch on.

  • igm_type – Choice for the IGM absorption model. Options are: 0 for Madau (1995) and 1 for Inoue+(2014).

  • likelihood – Choice of likelihood function for the RDSPS method. Only relevant if the fit_method=’rdsps’. Options are: ‘gauss’ for the Gaussian form and ‘student_t’ for the student’s t form.

  • dof – Degree of freedom (nu) in the Student’s t likelihood function. Only relevant if the fit_method=’rdsps’ and likelihood=’student_t’.

  • nwalkers – Number of walkers in the MCMC process. This parameter is only applicable if fit_method=’mcmc’.

  • nsteps – Number of steps for each walker in the MCMC process. Only relevant if fit_method=’mcmc’.

  • nsteps_cut – Number of first steps of each walkers that will be cut when collecting the final sampler chains. Only relevant if fit_method=’mcmc’ and store_full_samplers=1.

  • nproc – Number of processors (cores) to be used in the calculation.

  • initfit_nmodels_mcmc – Number of models to be used in the initial fitting in the MCMC method. Only relevant if fit_method=’mcmc’.

  • perc_chi2 – A percentile in the set of models sorted based on the chi-square values that will be considered in the calculation of the best-fit parameters (i.e., posterior-weighted averages) in the RDSPS fitting. This parameter is only relevant if fit_method=’rdsps’.

  • cosmo – Choices for the cosmology. Options are: (a)’flat_LCDM’ or 0, (b)’WMAP5’ or 1, (c)’WMAP7’ or 2, (d)’WMAP9’ or 3, (e)’Planck13’ or 4, (f)’Planck15’ or 5. These options are similar to the choices available in the Astropy Cosmology package.

  • H0 – The Hubble constant at z=0. Only relevant when cosmo=’flat_LCDM’ is chosen.

  • Om0 – The Omega matter at z=0.0. Only relevant when cosmo=’flat_LCDM’ is chosen.

  • store_full_samplers – Flag indicating whether full sampler models will be stored into the output FITS file or not. Options are: 1 or True for storing the full samplers and 0 or False otherwise.

  • name_out_fits – Names of output FITS files. This parameter is optional. If not None it must be in a list format with the same number of elements as the number of bins to be performed SED fitting. Example: name_out_fits = [‘bin1.fits’, ‘bin2.fits’, …, ‘binN.fits’]. If None, default names will be adopted.

piXedfit.piXedfit_fitting.get_bestfit_params(input_fits)

Function to get (i.e., read) best-fit parameters from the FITS file output of the fitting process.

Parameters:

input_fits – Input FITS file, which is an output of the fitting process.

Returns params:

The list of parameters.

Returns bfit_params:

A dictionary containing the best-fit parameters.

piXedfit.piXedfit_fitting.maps_parameters(fits_binmap, bin_ids, name_sampler_fits, fits_fluxmap=None, refband_SFR=None, refband_SM=None, refband_Mdust=None, name_out_fits=None)

Function for constructing maps of properties of a galaxy from the collectin of fitting results of the spatial bins within the galaxy.

Parameters:
  • fits_binmap – Input FITS file of the spectrophotometric data cube that has been binned.

  • bin_ids – Bin indices of the FITS files listed in name_sampler_fits input. Allowed format is a 1D array. The id starts from 0.

  • name_sampler_fits – List of the names of the FITS files containing the fitting results of spatial bins. This should have the same number of element as that of bin_ids. The number of element doesn’t necessarily the same as the number of bins. A missing bin will be ignored in the creation of the maps of properties.

  • fits_fluxmap – FITS file containing reduced maps of multiband fluxes, which is output of the flux_map() in the images_processing class in the piXedfit_images module.

  • refband_SFR – Index of band in the multiband set that is used for reference in dividing map of SFR in bin space into map of SFR in pixel space. If None, the band with shortest wavelength is selected.

  • refband_SM – Index of band in the multiband set that is used for reference in dividing map of stellar mass in bin space into map of stellar mass in pixel space. If None, the band with longest wavelength is selected.

  • refband_Mdust – Index of band/filter in the multiband set that is used for reference in dividing map of dust mass in bin space into map of dust mass in pixel space. If None, the band with longest wavelength is selected.

  • name_out_fits – Desired name for the output FITS file. If None, a default name will be used.

class piXedfit.piXedfit_fitting.priors(ranges={'dust1': [0.0, 4.0], 'dust2': [0.0, 4.0], 'dust_index': [-2.2, 0.4], 'gas_logu': [-4.0, -1.0], 'gas_logz': None, 'log_age': [-1.0, 1.14], 'log_alpha': [-2.0, 2.0], 'log_beta': [-2.0, 2.0], 'log_fagn': [-5.0, 0.48], 'log_gamma': [-4.0, 0.0], 'log_mass': [4.0, 12.0], 'log_mw_age': [-2.0, 1.14], 'log_qpah': [-3.0, 1.0], 'log_t0': [-1.0, 1.14], 'log_tau': [-1.0, 1.5], 'log_tauagn': [0.7, 2.18], 'log_umin': [-1.0, 1.39], 'logzsol': [-2.0, 0.2], 'z': [0.0, 1.0]})

Functions for defining priors to be used in the Bayesian SED fitting process. First, one need to define ranges for the parameters using params_ranges(), then define shape of the prior distribution function of each parameter. The available analytic forms for the prior are uniform, Gaussian, Student’s t, and gamma functions. User can also choose an arbitrary one, using arbitrary(). It is also possible to define a joint prior between a given parameter and stellar mass. This joint prior can be adopted from a known scaling relation, such as stellar mass vs metallicity relation. Note that it is not required to define range of all parameters to be involved in SED fitting. If range is not inputted, the default one will be used. It is also not required to define prior shape of all parameters. If not inputted, a uniform prior will be used. Due to the defined ranges, the analytical form is truncated at the edges defined by the range.

Parameters:

ranges – The ranges of the parameters. If gas_logz is None, gas-phase metallicity is set to have the same value as the stellar metallicity.

arbitrary(param, values, prob)

Function for assigning an arbitrary prior.

Parameters:
  • param – The parameter to be assigned with the arbitrary prior.

  • values – Array of values.

  • prob – Array of probability associated with the values.

Returns prior:

Output prior.

gamma(param, a, loc, scale)

Function for assigning a prior in the form of Gamma function to a parameter.

Parameters:
  • param – The parameter that will be assigned the Gamma prior.

  • a – A shape parameter in the gamma function.

  • loc – Peak location.

  • scale – Width of the distribution.

Returns prior:

Output prior.

gaussian(param, loc, scale)

Function for assigning Gaussian prior to a parameter.

Parameters:
  • param – The parameter that will be assigned the Gaussian prior.

  • loc – Peak location of the Gaussian prior.

  • scale – Width or standard deviation of the Gaussian prior.

Returns prior:

Output prior.

joint_with_mass(param, log_mass, param_values, scale)

Function for assigning a joint prior between a given parameter and stellar mass (log_mass).

Parameters:
  • param – The parameter that will share a joint prior with the stellar mass.

  • log_mass – Array of stellar mass values.

  • param_values – Array of the parameter values. In this case, the parameter that shares a joint prior with the stellar mass.

  • scale – Array of width or standard deviations of the param_value.

Returns prior:

Output prior.

params_ranges()

Function for defining ranges of the parameters.

Returns params_ranges:

Ranges of the parameters to be inputted into a SED fitting function.

studentt(param, df, loc, scale)

Function for assigning a prior in the form of Student’s t distribution.

Parameters:
  • param – The parameter that will be assigned the Student’s t prior.

  • df – The degree of freedom.

  • loc – Peak location.

  • scale – Width of the distribution.

Returns prior:

Output prior.

uniform(param)

Function for assigning uniform prior to a parameter.

Parameters:

param – The parameter that will be assigned the uniform prior.

Returns prior:

Output prior.

piXedfit.piXedfit_fitting.singleSEDfit(obs_flux=None, obs_flux_err=None, filters=None, spec_wave=None, spec_flux=None, spec_flux_err=None, gal_z=None, models_spec=None, wavelength_range=None, params_ranges=None, params_priors=None, fit_method='mcmc', nrands_z=10, add_igm_absorption=0, igm_type=0, smooth_velocity=True, sigma_smooth=0.0, spec_resolution=None, smooth_lsf=False, lsf_wave=None, lsf_sigma=None, poly_order=10, spec_chi_sigma_clip=5.0, del_wave_nebem=15.0, likelihood='gauss', dof=2.0, nwalkers=100, nsteps=600, nsteps_cut=50, nproc=10, initfit_nmodels_mcmc=100000, perc_chi2=90.0, cosmo=0, H0=70.0, Om0=0.3, store_full_samplers=1, name_out_fits=None)

Function for performing SED fitting to a single SED. The input SED can be in three forms: (1) photometry only (with input obs_flux, obs_flux_err, filters and leave spec_wave=None,spec_flux=None,spec_flux_err=None), (2) spectrum only (with input spec_wave, spec_flux, and spec_flux_err while leaving obs_flux=None,obs_flux_err=None,filters=None), and (3) spectrophotometry if all inputs are provided.

Parameters:
  • obs_flux – Input fluxes in multiple bands. The format is 1D array with a number of elements of the array should be the sama as that of obs_flux_err and filters. The fluxes should be in the unit of erg/s/cm^2/Angstrom.

  • obs_flux_err – Input flux uncertainties in multiple bands. The flux uncertainties should be in the unit of erg/s/cm^2/Angstrom.

  • filters – List of photometric filters. The list of filters recognized by piXedfit can be accesses using piXedfit.utils.filtering.list_filters(). Please see this page for information on managing filters that include listing available filters, adding, and removing filters.

  • spec_wave – 1D array of wavelength of the input spectrum.

  • spec_flux – Flux grids of the input spectrum. The fluxes should be in the unit of erg/s/cm^2/Angstrom.

  • spec_flux_err – Flux uncertainties of the input spectrum. The flux uncertainties should be in the unit of erg/s/cm^2/Angstrom.

  • gal_z – Redshift of the galaxy. If gal_z=None, redshift will be a free parameter in the fitting.

  • models_spec – Model spectral templates in the rest-frame generated prior to the SED fitting process using the function piXedfit.piXedfit_model.save_models_rest_spec(). This set of model spectra will be used in the main fitting step if fit_method=’rdsps’ or initial fitting if fit_method=’mcmc’.

  • wavelength_range – Range of wavelength within which the observed spectrum will be considered in the SED fitting. The accepted format is [wmin,wmax] with wmin and wmax are minimum and maximum wavelengths.

  • params_ranges – Ranges of the parameter defined (i.e., outputted) using the params_ranges() in the priors class.

  • params_priors – Forms of adopted priros. The acceptable format is a list, such as params_priors=[prior1, prior2, prior3] where prior1, prior2, and prior3 are output of functions in the priors class.

  • fit_method – Choice of method for the SED fitting. Options are: (a)’mcmc’ for Markov Chain Monte Carlo, and (b)’rdsps’ for Random Dense Sampling of Parameter Space.

  • nrands_z – Number of random redshifts to be generated (within the chosen range as set in the params_range) in the main fitting if fit_method=’rdsps’ or initial fitting if fit_method=’mcmc’. This is only relevant if gal_z=None (i.e., photometric redshift will be activated).

  • add_igm_absorption – Switch for the IGM absorption. Options are: 0 for switch off and 1 for switch on.

  • igm_type – Choice for the IGM absorption model. Options are: 0 for Madau (1995) and 1 for Inoue+(2014).

  • smooth_velocity – (default: True) The same parameter as in FSPS. Switch to perform smoothing in velocity space (if True) or wavelength space.

  • sigma_smooth – (default: 0.0) The same parameter as in FSPS. If smooth_velocity is True, this gives the velocity dispersion in km/s. Otherwise, it gives the width of the gaussian wavelength smoothing in Angstroms. These widths are in terms of sigma (standard deviation), not FWHM.

  • spec_resolution – (default: None) Spectral resolution (R) of the input spectra. This is R=c/sigma_smooth if sigma_smooth is a velocity dispersion. This parameter will be considered if smooth_velocity=True and sigma_smooth=None. The sigma_smooth will then be calculated using the above equation.

  • smooth_lsf – (default: False) The same parameter as in FSPS. Switch to apply smoothing of the SSPs by a wavelength dependent line spread function. Only takes effect if smooth_velocity is True.

  • lsf_wave – Wavelength grids for the input line spread function. This must be in the units of Angstroms, and sorted ascending.

  • lsf_sigma – The dispersion of the Gaussian line spread function at the wavelengths given by lsf_wave, in km/s. This array must have the same length as lsf_wave. If value is 0, no smoothing will be applied at that wavelength.

  • poly_order – The degree of the legendre polynomial function to be used for correcting the shape (normalization) of the model spectra.

  • spec_chi_sigma_clip – Standard deviation (sigma) to be adopted in the sigma clipping to the spectrum data points that are regarded as outliers before calculating chi-square in the SED fitting process. The sigma clipping is carried out based on the distribution of chi values (sum((D-M)/Derr)).

  • del_wave_nebem – This parameter defines the Wavelength region (+/- del_wave_nebem) around the emission lines that will be excluded in the fitting of spectral continuum between the model spectrum and the observed one.

  • likelihood – Choice of likelihood function for the RDSPS method. Only relevant if the fit_method=’rdsps’. Options are: ‘gauss’ for the Gaussian form and ‘student_t’ for the student’s t form.

  • dof – Degree of freedom (nu) in the Student’s t likelihood function. Only relevant if the fit_method=’rdsps’ and likelihood=’student_t’.

  • nwalkers – Number of walkers in the MCMC process. This parameter is only applicable if fit_method=’mcmc’.

  • nsteps – Number of steps for each walker in the MCMC process. Only relevant if fit_method=’mcmc’.

  • nsteps_cut – Number of first steps of each walkers that will be cut when collecting the final sampler chains. Only relevant if fit_method=’mcmc’ and store_full_samplers=1.

  • nproc – Number of processors (cores) to be used in the calculation.

  • initfit_nmodels_mcmc – Number of models to be used in the initial fitting in the MCMC method. Only relevant if fit_method=’mcmc’.

  • perc_chi2 – A percentile in the set of models sorted based on the chi-square values that will be considered in the calculation of the best-fit parameters (i.e., posterior-weighted averages) in the RDSPS fitting. This parameter is only relevant if fit_method=’rdsps’.

  • cosmo

    Choices for the cosmology. Options are: (a)’flat_LCDM’ or 0, (b)’WMAP5’ or 1, (c)’WMAP7’ or 2, (d)’WMAP9’ or 3, (e)’Planck13’ or 4, (f)’Planck15’ or 5. These options are similar to the choices available in the Astropy Cosmology package.

  • H0 – The Hubble constant at z=0. Only relevant when cosmo=’flat_LCDM’ is chosen.

  • Om0 – The Omega matter at z=0.0. Only relevant when cosmo=’flat_LCDM’ is chosen.

  • store_full_samplers – Flag indicating whether full sampler models will be stored into the output FITS file or not. Options are: 1 or True for storing the full samplers and 0 or False otherwise.

  • name_out_fits – Name of the output FITS file. This parameter is optional. If None, a default name will be adopted.