pyFIT3D.common package
pyFIT3D.common.auto_ssp_tools module
- class pyFIT3D.common.auto_ssp_tools.ConfigAutoSSP(config_file, redshift_set=None, sigma_set=None, AV_set=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, mask_list=None, elines_mask_file=None, sigma_inst=None, verbose=False)
Bases:
objectReads, stores and process the configuration of AutoSSP script. Also, load masks and SSP models. This class
- args
- Type
ReadArgumentsAutoSSP class
- filename
- _load :
- _load_ssp_fits :
- _multi_AV :
- _load_masks :
- pyFIT3D.common.auto_ssp_tools.auto_ssp_desegmentation_main(wavelength, cube_flux, cube_eflux, output_files, ssp_file, config_file, out_file, seg_map, rss_nl_pars, rss_coeffs, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, elines_mask_file=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, R_V=None, extlaw=None, plot=None, fit_sigma_rnd=True, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, kdtree_nodes=4, store_models=True, store_el=True, store_results=False, store_coeffs=False)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_rnd(spec_file, ssp_file, out_file, config_file, plot=None, error_file=None, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, elines_mask_file=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, seed=None, ratio=None, fit_sigma_rnd=True, variance_error_column=False, fit_gas=True)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_rnd_cube(spec_file, ssp_file, out_file, config_file, plot=None, error_file=None, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, elines_mask_file=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, seed=None, is_guided_sigma=False, ratio=None, guided_nl_file=None, fit_sigma_rnd=True, R_V=None, extlaw=None, fit_gas=True, losvd_rnd_medres_merit=False, verbose=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True, store_models=True, store_el=True, store_results=False, store_coeffs=False)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_rnd_cube_main(wavelength, cube_flux, cube_eflux, output_files, ssp_file, config_file, out_file, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, elines_mask_file=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, R_V=None, extlaw=None, plot=None, is_guided_sigma=False, ratio=True, spec_id=None, input_guided=None, input_guided_errors=None, fit_sigma_rnd=True, fit_gas=True, losvd_rnd_medres_merit=False, verbose=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True, store_models=True, store_el=True, store_results=False, store_coeffs=False)
Returns the model spectra, results and coefficient the analysis of a data CUBE. Also, returns the maps of the emission lines analysis.
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_rnd_rss(spec_file, ssp_file, out_file, config_file, plot=None, error_file=None, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, elines_mask_file=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, seed=None, is_guided_sigma=False, ratio=None, guided_nl_file=None, fit_sigma_rnd=True, R_V=None, extlaw=None, fit_gas=True, losvd_rnd_medres_merit=False, verbose=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_rnd_rss_main(wavelength, rss_flux, rss_eflux, output_files, ssp_file, config_file, out_file, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, elines_mask_file=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, R_V=None, extlaw=None, plot=None, is_guided_sigma=False, ratio=True, spec_id=None, input_guided=None, input_guided_errors=None, fit_sigma_rnd=True, fit_gas=True, losvd_rnd_medres_merit=False, verbose=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True)
Returns the model spectra, results and coefficient the analysis of a RSS. Also, returns the maps of the emission lines analysis.
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_single(spec_file, ssp_file, out_file, config_file, plot=None, error_file=None, variance_error_column=False, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, elines_mask_file=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, seed=None, ratio=None, fit_sigma_rnd=True, fit_gas=True)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_elines_single_main(wavelength, flux, eflux, ssp_file, config_file, out_file, ssp_nl_fit_file=None, sigma_inst=None, mask_list=None, elines_mask_file=None, min=None, max=None, w_min=None, w_max=None, nl_w_min=None, nl_w_max=None, input_redshift=None, delta_redshift=None, min_redshift=None, max_redshift=None, input_sigma=None, delta_sigma=None, min_sigma=None, max_sigma=None, input_AV=None, delta_AV=None, min_AV=None, max_AV=None, R_V=None, extlaw=None, plot=None, single_ssp=False, is_guided_sigma=False, ratio=True, spec_id=None, y_ratio=None, guided_errors=None, fit_sigma_rnd=True, fit_gas=True, losvd_rnd_medres_merit=False, verbose=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True)
- pyFIT3D.common.auto_ssp_tools.auto_ssp_spec(spec_file, ssp_models_file, out_file, config_file, error_file=None, variance_error_column=False, nl_ssp_models_file=None, instrumental_dispersion=None, wl_range=None, nl_wl_range=None, mask_list=None, elines_mask_file=None, redshift_set=None, losvd_set=None, losvd_in_AA=False, AV_set=None, fit_gas=True, fit_sigma_rnd=True, single_ssp=False, plot=None, min=None, max=None, seed=None, ratio=None, losvd_rnd_medres_merit=False, verbose=0, R_V=None, extlaw=None, sps_class=<class 'pyFIT3D.modelling.stellar.StPopSynt'>, SN_window_reference_wavelength=None, SN_window_half_range=45, norm_window_reference_wavelength=None, norm_window_half_range=45, gas_fit_subtrcont_ratio_range=None, gas_fit_subtrcont_ratio_std=None, gas_fit_half_range_sysvel=None, gas_fit_correct_wl_range=0, gas_fit_guide_vel=True)
- pyFIT3D.common.auto_ssp_tools.create_auto_ssp_el_output(config_file, shape, return_config=False)
- pyFIT3D.common.auto_ssp_tools.cube_ssp_output_to_maps(name, out_file, auto_ssp_output_dir, dump_elines=False, config_file=None)
- pyFIT3D.common.auto_ssp_tools.dump_auto_ssp_el_output(output_el_models, config_file, prefix)
- pyFIT3D.common.auto_ssp_tools.dump_fits_output(out_file_fit, wavelength, model_spectra)
Dump the models into a FITS
- pyFIT3D.common.auto_ssp_tools.dump_rss_output(out_file_fit, wavelength, model_spectra)
Dump the RSS models into a FITS
- pyFIT3D.common.auto_ssp_tools.load_cube(spec_file, error_file=None, output_seds=False)
Return the RSS from the given filename in the parsed command line arguments
- pyFIT3D.common.auto_ssp_tools.load_rss(spec_file, error_file=None, output_seds=False)
Return the RSS from the given filename in the parsed command line arguments
- pyFIT3D.common.auto_ssp_tools.read_auto_ssp_el_output_from_file(input_elines, config_file, prefix, shape)
pyFIT3D.common.constants module
pyFIT3D.common.gas_tools module
- class pyFIT3D.common.gas_tools.ConfigEmissionModel(filename=None, chi_goal=0.5, chi_step=0.1, verbose=False)
Bases:
objectConstructor for a configuration of one emission line system.
This class takes one config filename compliant with the FIT3D formating and builds an object containing
- n_models
Number of models found in the given config file.
- Type
int
- chi_goal
The maximum chi square to admit during the fit.
- Type
float
- chi_step
The size of the step in the chi square.
- Type
float
- model_types
A list of the types of models to apply during the emission line fitting.
- Type
array like
- guess
A list of initial values for the parameters.
- Type
array like
- to_fit
Whether the given parameter will be fitted (1) or left fixed at initial value (0).
- Type
boolean array like
- ea
MISSING DOC
- Type
array like
- ranges
The ranges to explore in the parameter space during the fitting
- Type
tuple of array like
- links
The list of link types in config file:
-1: no linking 0: the guess value of the current parameter should be *added* by the corresponding fitted parameter in the previous model 1: the guess value of the current parameter should be *multiplied* by the corresponding fitted parameter in the previous model
- Type
array like
- fitting_chain
The most important attribute. This is a list of all parameters stages during the fitting procedure. This attribute is meant to be updated using the self.updated_pars method, taking into account the fixed parameters and the links from the configuration of the system.
- Type
array like
- _load :
Loads the configuration for an emission line system from a config file.
- _correct_guess :
Fixes the messed up guess parameters out of the given ranges.
- _set_linkings :
Return a copy of the given parameters with links parsed also updating the boundadies accordingly.
- get_tofit :
Gets a filtered version of the parameters to fit.
- randomize_guess :
Returns a random perturbation of the initial guess parameters.
- update_ranges :
Updates the values of the parameters ranges also updating boundaries.
- get_updated_guess :
Returns a version of self.guess updated by new_guess fixed by masks and links.
- vectorize_pars :
Returns a vectorized (flattened np.array) version of the given parameters list.
- list_pars :
Returns a list version of the given parameter vector
- check_par_fit :
Returns True if a choosen parameter should be fitted.
- print :
Produces a config file using the present config.
- add_model(model_type, guess, to_fit, pars_0, pars_1, links, n_pars=9)
- check_par_fit(model_type, i_par)
Check if a parameter needs to be fitted.
- Parameters
model_type (str) – The model type of the checked parameter. E.g., eline or poly1d.
i_par (int) – The parameter position in configuration file (a.k.a. the index of the model array).
- Returns
True if parameter should be fitted. False otherwise.
- Return type
boolean
- get_tofit(parameters=None)
Return a copy of the parameters to be fitted
If a list of parameters are given, this method will filter the parameters to be fitted. If no parameters are given, returns a filtered copy of self.latest_fit.
- Parameters
parameters (array like) – A list of the parameters to be filtered. Defaults to self.latest_fit.
- Returns
filtered_parameters – A copy of the original parameters containing only parameters to be fitted.
- Return type
array like
- get_updated_guess(new_guess, placeholder=None, inplace=False)
Returns a version of self.guess updated by new_guess fixed by masks and links.
- Parameters
new_guess (array like) – A list of the parameter arrays to update the current values in self.guess parameters to be fitted (e.g. self.get_tofit(self.guess)).
placeholder (array like, optional) – A list of parameters like parameters to be used as the initial values to the updated parameters instead self.guess. Default value is None.
inplace (boolean) – if True updates self.guess with the updated values.
- Returns
A version of self.guess updated by new_guess fixed by masks and links.
- Return type
array like
- list_pars(vector_parameters)
Return a list copy of the given vectorized parameters
- Parameters
vector_parameters (array like) – A vectorized version of the parameters. It can either contain all the parameters or only those meant to be fitted.
- Returns
list_pars – A list of arrays in the same format of self.guess.
- Return type
array like
- print(list_parameters=None, filename=None, verbose=1)
Produces a config file using the present config.
- Parameters
list_parameters (array like, optional) – A list of parameters to be printed. If None, uses self.guess as the parameters list.
filename (str, optional) – Output filename. If None, the filename is /dev/stdout.
verbose (int, optional) – Print information. Defaults to 1.
- randomize_guess(parameters=None)
Return a copy of the initial guess parameters randomly perturbed
- update_ranges(min_values=None, max_values=None)
Updates the values of the parameters ranges also updating boundaries.
- Parameters
min_values (array like, optional) – Array updating the values of self.pars_0. Should have the same dimension of it. If None it uses self.pars_0.
max_values (array like, optional) – Array updating the values of self.pars_1. Should have the same dimension of it. If None it uses self.pars_1.
- vectorize_pars(list_parameters, only_tofit=True)
Return a copy of the parameters squeezed into a one-dimensional array
This method makes a copy of the given list-formatted parameters and turns it into an array of one dimenssion taking into account the fixed parameters. By default, only fitting parameters are returned in the vector.
- Parameters
list_parameters (array like) – A list containing the parameters to be vectorized.
only_tofit (boolean) – If True (default), only parameters to be fitted are returned. If False, all parameters are returned.
- Returns
vectorized_pars – A vectorized array with the parameters to be fitted (default) or all the parameters in the given list.
- Return type
array like
- pyFIT3D.common.gas_tools.append_emission_lines_parameters(EL, output_models, current_spaxel)
Appends the result parameters of a fit to the output_models structure.
- Parameters
EL (EmissionLines class) – The instance of the EmissionLines class with the fit results.
output_models (dict) – The dict outputted by create_emission_lines_parameters.
curret_spaxel (int or tuple) – If int it will be consider as the spectra id of a RSS run (see kin_rss_elines_main). If a tuple, it will be consider as (ix, iy), the coordinates of the fitted spectrum in the cube run (see kin_cube_elines_main).
See also
None,None,None
- pyFIT3D.common.gas_tools.create_ConfigEmissionModel(wave_guess_list, flux_guess_list, sigma_guess_list, v0_guess_list, flux_boundaries=None, sigma_boundaries=None, v0_boundaries=None, sort_by_flux=False, config_filename=None, polynomial_order=None, polynomial_coeff_guess=None, polynomial_coeff_boundaries=None, output_path=None, verbose=0)
Creates a ConfigEmissionModel.
- Parameters
wave_guess_list (array like) – Wavelengths guesses list.
flux_guess_list (array like) – Flux guesses list.
sigma_guess_list (array like) – Sigma guesses list.
v0_guess_list (array like) – Velocity guesses list.
flux_boundaries (array like, optional) – Defaults to None.
sigma_boundaries (array like, optional) – Defaults to None.
v0_boundaries (array like, optional) – Defaults to None.
sort_by_flux (bool, optional) – Defaults to False
polynomial_order (int, optional) – Defaults to None.
polynomial_coeff_guess (array like, optional) – Defaults to None.
polynomial_coeff_boundaries (array like, optional) – Defaults to None.
output_path (str, optional) – Defaults to os.getcwd().
verbose (int, optional) – Defaults to 0.
- Returns
array like – List of config filenames generated.
array like – List of wavelength intervals of the configs.
- pyFIT3D.common.gas_tools.create_emission_lines_parameters(config, shape)
Creates the output maps and associated metadata for a cube or RSS run of fit_elines_main. Used in kin_rss_elines_main and kin_cube_elines_main.
- Parameters
config (
ConfigEmissionModel) – Configuration file of the Emission Line system.shape (int or tuple) – The shape of the input spectra (RSS or cube). If the run is over a RSS shape should be an integer
(i_spec). In the case of a cube, should be a tuple(iy, ix).
- Returns
output_models – The keys depends on the models parameters present in the config (_EL_MODELS dict is defined in pyFIT3D.common.constants). Each parameter has a e_par key also.
- Example:
A config has 2 eline models and 1 poly1d model:
output_models it will have keys
_EL_MODELS['eline'].keys()and_EL_MODELS['poly1d'].keys()with their respective errors hashed ase_{key}. The output_models parameters from eline models will have shape (2, shape). The poly1d parameters have (1, shape).- E.g.:
output_models['v0'][0]is the map of the v0 parameter of the first eline model.
- Return type
dict
See also
None,None,None
- pyFIT3D.common.gas_tools.detect_create_ConfigEmissionModel(wave, flux, sigma_guess=2.5, redshift=0, chunks=5, flux_boundaries_fact=None, sigma_boundaries_fact=None, v0_boundaries_add=None, polynomial_order=None, polynomial_coeff_guess=None, polynomial_coeff_boundaries=None, peak_find_nsearch=1, peak_find_threshold=2, peak_find_dmin=1, plot=0, output_path=None, label=None, crossmatch_list_filename=None, crossmatch_absdmax_AA=4, crossmatch_redshift_search_boundaries=None, crossmatch_redshift_search_step=0.001, sort_by_flux=False, verbose=0)
Detect peaks from a spectrum and creates a ConfigEmissionModel file.
- Parameters
wave (array like) – Wavelengths array.
flux (array like) – Flux array.
sigma_guess (float, optional) – Sigma guess. Defaults to 2.5.
redshift (float, optional) – Input redshift. Defaults to 0.s
chunks (int or sequence of pairs of scalars of floats, optional) – If
chunksis an int, it defines the number of divisions of the input spectrum to be analyzed. Ifchunksis a sequence of pairs of scalars, each pair defines a chunk interval to be analyzed. Defaults to 1.flux_boundaries_fact (pair of scalars, optional) – Mutiplyer factor of the flux guess to define the flux boundaries. Defaults to (0.001, 1000).
sigma_boundaries_fact (pair of scalars, optional) – Mutiplyer factor of
sigma_guessto define the flux boundaries. Defaults to (0.1, 2)v0_boundaries_add (pair of scalars, optional) – Additive factor of the v0 guess to define the v0 boundaries. Defaults to (-50, 50).
polynomial_order (int, optional) – If it is different than None adds a polynomial model of order
polynomial_orderto all generated ConfigEmissionModel. Defaults to None.polynomial_coeff_guess (scalar or a sequence of scalars, optional) – If is a scalar defines the guess of the coefficient guess of the polynomial model added to all generated ConfigEmissionModel files. If is a sequence defines the guesses of the
polynomial_ordercoefficients. Should be of dimensionpolynomial_order. Defaults to None.polynomial_coeff_boundaries (pair of scalars or sequence of pairs or scalars, optional) – Defines the boundaries of the coefficients of the polynomial model. Should be a pair of scalar or a sequence of pairs of scalars. Defaults to None.
peak_find_nsearch (int, optional) – Defaults to 1.
peak_find_threshold (float, optional) – Defaults to 2.0.
peak_find_dmin (int, optional) – Defaults to 1.
plot (int, optional) – Defaults to 0.
output_path (str, optional) – Defaults to os.getcwd().
label (str, optional) – label to prepend to config file names. Defaults to None.
crossmatch_list_filename (str, optional) – Defaults to None.
crossmatch_absdmax_AA (float, optional) – Defaults to 4 AA.
crossmatch_redshift_search_boundaries (pair of scalars, optional) – Defaults to None.
crossmatch_redshift_search_step (float, optional) – Defaults to 0.001.
sort_by_flux (bool, optional) – Sort emission lines to be fitted decreasingly by flux at each chunk config. Defaults to False.
verbose (int, optional) – Defaults to 0.
- Returns
array like – List of config filenames generated.
array like – List of wavelength intervals of the configs.
array like – List of wavelengths peaks detected.
array like – List of wavelengths peaks detected and corrected by
redshift.
See also
None,None,None
- pyFIT3D.common.gas_tools.fit_elines(spec_file, config_file, w_min, w_max, out_file=None, mask_file=None, run_mode='RND', n_MC=50, n_loops=15, scale_ini=0.15, fine_search=None, redefine_max=False, plot=0, out_mod_res_final=None, seed=None, check_stats=True)
The fit_elines script (i.e. a well prepared wrap of fit_elines_main).
It will run the run_mode fit the the emission models defined by the config_file on the spectrum in spec_file masked by mask_file, inside the define wavelength range (w_min, w_max).
If run_mode is:
'RND': mimics fit_elines_rnd script. 'LM': mimics fit_elines_LM script. 'both': It will run the 'RND' first and inputs the results of the fit in the 'LM' fit.
- Parameters
spec_file (str) – The filename of the file containing the wavelengths, observed flux and optionally the error in observed flux.
config_file (str) – The filename of the
ConfigEmissionModelinput file.w_min (int) – The minimun (bluer) wavelength which defines the fitted wavelength range.
w_max (int) – The maximum (redder) wavelength which defines the fitted wavelength range.
out_file (str, optional) – The name of the output results of the fit. If None it will be defined by basename(sys.argv[0]).
mask_file (str, optional) – If mask_file is a valid file it will mask the wavelengths.
run_mode (str {'RND', 'LM', 'both'}, optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to the RND method.n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
fine_search (boolean, optional) – The fine_search parameter of RND method. Defaults to __ELRND_fine_search_option__ defined in pyFIT3D.common.constants.
redefine_max (int or boolean, optional) – The redefine_max parameter of the fit. Defaults to 0.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
out_mod_res_final (str, optional) – The filename of output the result spectra of the fit. Defaults to out.fit_spectra.
seed (int, optional) – It will define the input seed. Defaults to the
int(time.time()).check_stats (bool, optional) – Sets up the stats check in EmissionLinesRND fit. Defaults to True.
See also
- pyFIT3D.common.gas_tools.fit_elines_main(wavelength, flux, sigma_flux, config, run_mode='RND', n_MC=50, n_loops=15, scale_ini=0.15, fine_search=None, redefine_max=False, flux_max=None, max_factor=2, redefine_min=False, min_factor=0.012, plot=0, randomize_flux=False, vel_guide=None, vel_mask=None, vel_fixed=2, vel_guide_half_range=30, sigma_guide_half_range_frac=0.2, sigma_guide=None, sigma_fixed=2, check_stats=True, rnd_redshift_flux_threshold=True, rnd_sigma_flux_threshold=False, oversize_chi=True, update_config_frac_range=0.25)
The main function of the fit_elines script. It will run the fit of the emission models defined by the config. At the end, outputs the results to the screen.
- Parameters
wavelength (array like) – The observed wavelengths.
flux (array like) – The observed flux.
sigma_flux – The error in flux.
config (
ConfigEmissionModel) – TheConfigEmissionModelinstance that will configure the fit.run_mode (str {'RND', 'LM', 'both'}, optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to the RND method.n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
fine_search (boolean, optional) – The fine_search parameter of RND method. Defaults to __ELRND_fine_search_option__ defined in pyFIT3D.common.constants.
redefine_max (int, boolean, optional) – The redefine_max parameter of the fit. Defaults to 0.
flux_max (float, optional) – If redefine_max is True or 1 it will set force the flux_max on redefine_max.
max_factor (float, optional) – Set up the max flux factor when redefine_max is on. Defaults to 2.
redefine_min (boolean, optional) – If redefine_max is on, it will also redefine the min flux. Defaults to False.
min_factor (float, optional) – Set up the min flux factor when redefine_max is on. Defaults to 0.012.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
randomize_flux (boolean, optional.) –
If true it will randomize the input flux of RND method:
flux_fit = flux + rand()*sqrt(sigma_flux)
if None it defaults to False.
vel_guide (float, optional) – Sets up the guide velocity of the fit run. (see: guide_vel).
vel_mask (int, boolean.) – Sets up the mask of the guide velocity of the fit run. (see: guide_vel).
vel_fixed (int, boolean, optional) – Sets up the to_fit parameter of the guide velocity of the fit run. (see: guide_vel).
vel_guide_half_range (float, optional) – Sets up the range of the guided velocity of the fit run. (see: guide_vel).
sigma_guide (float, optional) – Sets up the guide sigma of the fit run. (see: guide_sigma).
sigma_fixed (int, optional) – Sets up the to_fit parameter of the guide sigma of the fit run. (see: guide_sigma).
sigma_guide_half_range_frac (float, optional) – Sets up the range of the guided sigma of the fit run. (see: guide_sigma).
check_stats (bool, optional) – Sets up the stats check in EmissionLinesRND fit. Defaults to True.
rnd_redshift_flux_threshold (bool, optional) – Keep flux inside limits during redshift search in RND mode. Defaults to True.
rnd_sigma_flux_threshold (bool, optional) – Keep flux inside limits during sigma search in RND mode. Defaults to False.
oversize_chi (bool, optional) – if True, will triplify the first chi of each MC round in RND mode. Defaults to True.
update_config_frac_range (float, optional) – Configures the range of the free parameters in when run_mode = ‘BOTH’. Defaults to 0.25.
- Returns
if run_mode is ‘RND’ it will return
EmissionLinesRNDinstance. if run_mode is ‘LM’ it will returnEmissionLinesLMinstance. if run_mode is ‘BOTH’ it will returnEmissionLinesRNDorEmissionLinesLMinstance depending if theEmissionLinesLMrun find a best fit.- Return type
class:EmissionLines class like
- pyFIT3D.common.gas_tools.guide_sigma(config, sigma, mask, fit, half_range_frac=0.2)
Guide the sigma parameter of the eline model in a ConfigEmissionModel instance.
- Parameters
config (
ConfigEmissionModel) – ConfigEmissionModel instance.sigma (float) – The guided sigma (sigma parameter in eline model).
mask (int or boolean) – The input mask value of the sigma.
fit (int or boolean) – It will set if config.to_fit parameters. If True or 1 it will search for the best sigma inside the defined range (see half_range_frac). If False or 0 it will set the sigma parameter fixed.
half_range_frac (float) – If fit is 1 or True, it will set the sigma parameter fit range: [sigma*(1 - half_range_frac), sigma*(1 + half_range_frac)]
- pyFIT3D.common.gas_tools.guide_vel(config, vel, mask, fit, half_range=30)
Guide the v0 parameter of the eline model in a ConfigEmissionModel instance.
- Parameters
config (
ConfigEmissionModel) – ConfigEmissionModel instance.vel (float) – The guided velocity (v0 parameter in eline model).
mask (int or boolean) – The input mask value of the velocity.
fit (int or boolean) – It will set if config.to_fit parameters. If True or 1 it will search for the best v0 inside the defined range (see half_range). If False or 0 it will set the v0 parameter fixed.
half_range (float) – If fit is 1 or True, it will set the v0 parameter fit range (+/- half_range).
- pyFIT3D.common.gas_tools.kin_cube_elines(spec_file, config_file, w_min, w_max, out_file=None, mask_file=None, error_file=None, prefix=None, run_mode='RND', memo=False, vel_map_file=None, vel_mask_file=None, vel_fixed=2, sigma_map_file=None, sigma_fixed=2, sigma_val=None, n_MC=50, n_loops=15, scale_ini=0.15, redefine_max=True, max_factor=2, redefine_min=False, min_factor=0.012, plot=0, seed=None)
The kin_cube_elines script (i.e. a well prepared wrap of kin_cube_elines_main).
It will run the run_mode fit the the emission models defined by the config_file on the cube of spectra in spec_file masked by mask_file, inside the define wavelength range (w_min, w_max).
If run_mode is:
'RND': mimics fit_elines_rnd script. 'LM': mimics fit_elines_LM script. 'both': It will run the 'RND' first and inputs the results of the fit in the 'LM' fit.
- Parameters
spec_file (str) – The filename of the FITS file containing the wavelengths and observed flux spectra.
config_file (str) – The filename of the
ConfigEmissionModelinput file.w_min (int) – The minimun (bluer) wavelength which defines the fitted wavelength range.
w_max (int) – The maximum (redder) wavelength which defines the fitted wavelength range.
out_file (str, optional) – The name of the output results of the fit. Defaults to
basename(sys.argv[0]).replace('py', 'out').mask_file (str, optional) – If mask_file is a valid file it will mask the wavelengths.
error_file (str) – The filename of the FITS file containing the errors in observed flux spectra.
prefix (str, optional) – It will define the prefix used in output_emission_lines_parameters and output_emission_lines_spectra. Defaults to basename of out_file.
run_mode (str {'RND', 'LM', 'both'}, optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to the RND method.memo (boolean, optional) – While fitting the cube, memorizes the last result and inputs to the next spectrum in the loop.
vel_map_file (str, optional) – The filename of the guide velocity map. (see: guide_vel).
vel_mask_file (array like, optional) – The filename of the mask map of the guide velocity. (see: guide_vel).
vel_fixed (int or boolean, optional) – Sets up the to_fit parameter of the guide velocity. (see: guide_vel).
sigma_map_file (array like, optional) – The filename of the guide sigma map. (see: guide_sigma).
sigma_fixed (int or boolean) – Sets up the to_fit parameter of the guide sigma map. (see: guide_sigma).
sigma_val (float, optional) – Rewrites the sigma_map using a single value for the guide sigma map. (see: guide_sigma)
n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
redefine_max (int or boolean, optional) – The redefine_max parameter of the fit. Defaults to True.
max_factor (float, optional) – Set up the max flux factor when redefine_max is on. Defaults to 2.
redefine_min (boolean, optional) – If redefine_max is on, it will also redefine the min flux. Defaults to False.
min_factor (float, optional) – Set up the min flux factor when redefine_max is on. Defaults to 0.012.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
seed (int, optional) – It will define the input seed. Defaults to the
int(time.time()).
See also
ConfigEmissionModel,None,None,None,None
- pyFIT3D.common.gas_tools.kin_cube_elines_main(wavelength, cube_flux, config, out_file=None, cube_eflux=None, run_mode='RND', vel_map=None, vel_mask_map=None, vel_fixed=2, sigma_map=None, sigma_fixed=2, memo=False, n_MC=50, n_loops=15, scale_ini=0.15, redefine_max=True, max_factor=2, redefine_min=True, min_factor=0.012, plot=0, oversize_chi=False)
The main function of the kin_cube_elines script. It will run the fit_elines_main over all observed spectra cube_flux, with shape
(NW, NY, NX). All spectra has to be sampled over the same wavelength with shape(NW).- Parameters
wavelength (array) – The observed wavelengths.
cube_flux (array like) – The observed flux spectra with shape
(NW, NY, NX).config (
ConfigEmissionModel) – TheConfigEmissionModelinstance that will configure the fit.out_file (str, optional) – The filename of the file where the output of
EmissionLinesresult will be recorded.cube_eflux (array like, optional) – The error in flux with shape
(NW, NY, NX).run_mode ('RND', 'LM', 'both', optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to RND method.vel_map (array like, optional) – Sets up the guide velocity map. (see: guide_vel).
vel_mask_map (array like, optional) – Sets up the mask map of the guide velocity. (see: guide_vel).
vel_fixed (int or boolean, optional) – Sets up the to_fit parameter of the guide velocity. (see: guide_vel).
sigma_map (array like, optional) – Sets up the guide sigma map. (see: guide_sigma).
sigma_fixed (int or boolean) – Sets up the to_fit parameter of the guide sigma map. (see: guide_sigma).
memo (boolean, optional) – While fitting the cube, memorizes the last result and inputs to the next spectrum in the loop.
n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
redefine_max (int or boolean, optional) – The redefine_max parameter of the fit. Defaults to True.
max_factor (float, optional) – Set up the max flux factor when redefine_max is on. Defaults to 2.
redefine_min (boolean, optional) – If redefine_max is on, it will also redefine the min flux. Defaults to True.
min_factor (float, optional) – Set up the min flux factor when redefine_max is on. Defaults to 0.012.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
oversize_chi (bool, optional) – if True, will triplify the first chi of each MC round in RND mode. Defaults to False.
- Returns
Constructed as:
list of array like Observed spectra, model spectra and residual spectra, all with same shape as `cube_flux`. dict Output maps of fitted parameters (see: `create_emission_lines_parameters`, `append_emission_lines_parameters` and `output_emission_lines_parameters`).- Return type
tuple
- pyFIT3D.common.gas_tools.kin_rss_elines(spec_file, config_file, w_min, w_max, out_file=None, mask_file=None, error_file=None, prefix=None, run_mode='RND', guided=False, memo=False, vel_map_file=None, vel_mask_file=None, vel_fixed=None, sigma_map_file=None, sigma_fixed=None, n_MC=50, n_loops=15, scale_ini=0.15, fine_search=None, redefine_max=False, plot=0, seed=None)
The kin_rss_elines script (i.e. a well prepared wrap of kin_rss_elines_main)
It will run the run_mode fit the the emission models defined by the config_file on the rss of spectra in spec_file masked by mask_file, inside the define wavelength range (w_min, w_max).
If run_mode is:
'RND': mimics fit_elines_rnd script. 'LM': mimics fit_elines_LM script. 'both': It will run the 'RND' first and inputs the results of the fit in the 'LM' fit.
- Parameters
spec_file (str) – The filename of the FITS file containing the wavelengths and observed flux spectra.
config_file (str) – The filename of the
ConfigEmissionModelinput file.w_min (int) – The minimun (bluer) wavelength which defines the fitted wavelength range.
w_max (int) – The maximum (redder) wavelength which defines the fitted wavelength range.
out_file (str, optional) – The name of the output results of the fit. Defaults to
basename(sys.argv[0]).replace('py', 'out').mask_file (str, optional) – If mask_file is a valid file it will mask the wavelengths.
error_file (str) – The filename of the FITS file containing the errors in observed flux spectra.
prefix (str, optional) – It will define the prefix used in output_emission_lines_parameters and output_emission_lines_spectra. Defaults to basename of out_file.
run_mode (str {'RND', 'LM', 'both'}, optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to the RND method.guided (boolean, optional) – It will redefine the max and the min flux parameter of the eline models.
memo (boolean, optional) – While fitting the rss, memorizes the last result and inputs to the next spectrum in the loop.
vel_map_file (str, optional) – The filename of the guide velocity map. (see: guide_vel).
vel_mask_file (array like, optional) – The filename of the mask map of the guide velocity. (see: guide_vel).
vel_fixed (int or boolean, optional) – Sets up the to_fit parameter of the guide velocity. (see: guide_vel).
sigma_map_file (array like, optional) – The filename of the guide sigma map. (see: guide_sigma).
sigma_fixed (int or boolean) – Sets up the to_fit parameter of the guide sigma map. (see: guide_sigma).
n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
fine_search (boolean, optional) – The fine_search parameter of RND method. Defaults to __ELRND_fine_search_option__ defined in pyFIT3D.common.constants.
redefine_max (int or boolean, optional) – The redefine_max parameter of the fit. Defaults to 0.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
seed (int, optional) – It will define the input seed. Defaults to the
int(time.time()).
See also
ConfigEmissionModel,None,None,None,None
- pyFIT3D.common.gas_tools.kin_rss_elines_main(wavelength, rss_flux, config, out_file=None, rss_eflux=None, run_mode='RND', guided=False, memo=False, vel_map=None, vel_mask_map=None, vel_fixed=2, sigma_map=None, sigma_fixed=2, n_MC=50, n_loops=15, scale_ini=0.15, fine_search=None, redefine_max=False, max_factor=2, redefine_min=False, min_factor=0.012, plot=0)
The main function of the kin_rss_elines script. It will run the fit_elines_main over all observed spectra rss_flux, with shape
(NW, NS). All spectra has to be sampled over the same wavelength with shape(NW).- Parameters
wavelength (array) – The observed wavelengths.
rss_flux (array like) – The observed flux spectra with shape (NW, NS).
config (
ConfigEmissionModel) – TheConfigEmissionModelinstance that will configure the fit.out_file (str, optional) – The filename of the file where the output of
EmissionLinesresult will be recorded. Defaults tobasename(sys.argv[0]).replace('py', 'out').rss_eflux (array like, optional) – The error in flux with shape
(NW, NY, NX).run_mode ('RND', 'LM', 'both', optional) – It will configure which
EmissionLinesit will run. ‘RND’: The RND algorithm of fit. ‘LM’: Levemberg-Marquadt algorithm of fit. ‘both’: It will run first the ‘RND’ method and inputs the final_fit_params of ‘RND’ at the ‘LM’ method. Defaults to RND method.guided (boolean, optional) – It will redefine the max and the min flux parameter of the eline models.
memo (boolean, optional) – While fitting the rss, memorizes the last result and inputs to the next spectrum in the loop.
vel_map (array like, optional) – Sets up the guide velocity map. (see: guide_vel).
vel_mask_map (array like, optional) – Sets up the mask map of the guide velocity. (see: guide_vel).
vel_fixed (int or boolean, optional) – Sets up the to_fit parameter of the guide velocity. (see: guide_vel).
sigma_map (array like, optional) – Sets up the guide sigma map. (see: guide_sigma).
sigma_fixed (int or boolean) – Sets up the to_fit parameter of the guide sigma map. (see: guide_sigma).
n_MC (int, optional) – Number of Monte-Carlo iterations in the fit. Defaults to 50.
n_loops (int, optional) – Number of loops of the fit. Defaults to 15.
scale_ini (float, optional) – The scale_ini parameter of fit. Defaults to 0.15
fine_search (boolean, optional) – The fine_search parameter of RND method. Defaults to __ELRND_fine_search_option__ defined in pyFIT3D.common.constants.
redefine_max (int or boolean, optional) – The redefine_max parameter of the fit. Defaults to 0.
max_factor (float, optional) – Set up the max flux factor when redefine_max is on. Defaults to 2.
redefine_min (boolean, optional) – If redefine_max is on, it will also redefine the min flux. Defaults to False.
min_factor (float, optional) – Set up the min flux factor when redefine_max is on. Defaults to 0.012.
plot (int, optional) – If 1 it will plot fit. If 2 it will plot to a file. None it will be set as 0, i.e. do not plot.
- Returns
list of array like – Observed spectra, model spectra and residual spectra, all with same shape as rss_flux.
dict – Output maps of fitted parameters (see: create_emission_lines_parameters, append_emission_lines_parameters and output_emission_lines_parameters).
- pyFIT3D.common.gas_tools.load_spec(filename, wave_axis=3, error_filename=None, error_extension=0)
Loads the rss or the cube with an entire galaxy.
- Parameters
filename (str) – The filename of the fits file with the cube or row-stacked spectra.
wave_axis (int) – The axis of the wavelengths in the FITS file. It defaults to 3.
error_filename (str, optional) – The filename of the fits file with the errors in observed flux.
error_extension (int, optional) – The number of the extesion where the error is in
error_filenameFITS file.
- Returns
- array like
The wavelengths.
- array like
The flux
astropy.io.fits.header.HeaderinstanceThe header of the cube or RSS fits file.
- array like:
The error of the flux.
- Return type
tuple of array like
- pyFIT3D.common.gas_tools.output_emission_lines_parameters(prefix, config, output_models)
Outputs the maps of parameters fit by kin_cube_elines_main or kin_rss_elines_main.
- Parameters
prefix (str) – The output prefix of the map files.
config (
ConfigEmissionModel) – Config used in the run.output_models (dict) – The dictionary created by create_emission_lines_parameters.
See also
None,None,None,None,None
- pyFIT3D.common.gas_tools.output_emission_lines_spectra(wave, spectra, header, prefix='kin_back_cube', wave_axis=3)
Outputs the spectra from the fit by kin_cube_elines_main or kin_rss_elines_main to 3 FITS files (flux, model flux and residuals).
- Parameters
wave (array like) – Wavelengths.
spectra (3 elements list) – Observed flux, modeled flux and residual flux of the fit.
header (dict or
astropy.io.fits.header.Header) – Header to be recorded in output FITS file.prefix (str, optional) – The output prefix of the spectra files.
wave_axis (int, optional) – The wavelength axis which will be recorded in FITS files.
See also
None,None,None
- pyFIT3D.common.gas_tools.read_fit_elines_output(filename, verbose=0)
Reads the output file of a fit_elines_main run. Outputs a dict with the fitted parameters.
- Parameters
filename (str) – The filename of the output file of a fit_elines_main run.
verbose (int, optional) – Verbosity level. Defaults to 0.
- Returns
array like – number of models of each emission lines system fit
array like – Resultant chi-sq (goodness) of the fit of each emission lines system.
array of dicts – An array of
output_modelsdicts. The keys of the dicts depends on the models parameters present in the config (_EL_MODELS dict is defined in pyFIT3D.common.constants). Each parameter has a e_par key also.Example with a config containing 2 eline models and 1 poly1d model:
output_models it will have keys
_EL_MODELS['eline'].keys()and_EL_MODELS['poly1d'].keys()with their respective errors hashed ase_{key}.The output_models parameters from eline models will have shape (2, shape).
The poly1d parameters have (1, shape)
E.g,
output_models['v0'][0]is the map of the v0 parameter of the first eline).
See also
None,None
pyFIT3D.common.io module
- class pyFIT3D.common.io.ReadArguments(args_list=None, verbose=False)
Bases:
objectArgument parser for the FIT3D echo-system
- verbose
Initialize the argument list received and other helper variables
- pyFIT3D.common.io.array_to_fits(filename, arr, new_card=False, header=None, overwrite=False, sort_dict_header=True)
- pyFIT3D.common.io.call_cmnd(cmnd, logfile=None, verbose=True, logfilemode='a', timeout=None)
- pyFIT3D.common.io.clean_preview_results(args)
Remove output files from older runs
- Parameters
args (
ReadArguments) –
- pyFIT3D.common.io.clean_preview_results_files(out_file, out_file_elines, out_file_single, out_file_coeffs, out_file_fit)
Remove output files from older runs
- Parameters
args (
ReadArguments) –
- pyFIT3D.common.io.collapse_badpixels_mask(mask__wyx, threshold_fraction=1, mask_value=1)
Performs the bad pixels mask collapse, i.e., generates a 2D map from a 3D (wavelengths, y, x) masking spaxels with a fraction of masked pixels equal or above threshold.
- Parameters
mask__wyx (array like) – Bad pixels mask cube (3 dimensions, NWAVE, NY, NX).
threshold_fraction (float) – Sets the threshold to be considered a bad spaxel, i.e. spaxels with a fraction of masked pixels equal or above this threshold will be masked. threshold = NWAVE * threshold_fraction.
- Returns
2D bad spaxels map.
- Return type
array like
- pyFIT3D.common.io.create_ConfigAutoSSP_from_lists(list_chunks, list_systems_config, output_path=None, label=None)
- pyFIT3D.common.io.create_emission_lines_file_from_list(wave_list, output_path=None, label=None)
- pyFIT3D.common.io.create_emission_lines_mask_file_from_list(wave_list, eline_half_range=16, output_path=None, label=None)
- pyFIT3D.common.io.get_data_from_fits(filename, extension=0, header=None, return_n_extensions=False)
Retrieve the data from the HDU extension in a FITS file. If header is True, also, retrieves the header from the HDU extension. if filename is not a existent file or astropy.io.fits.open(filename) raises an OSError, returns the filename. if header is True, returns None.
- Parameters
filename (str) – FITS file name.
extension (int) – The retrieved HDU extension. Default is 0.
header (bool or None) – Also retrieves the HDU extension header.
return_n_extensions (bool or None) – Also returns the number of extensions of the FITS file.
- Returns
array like – The data from HDU extension.
astropy.io.fits.header.Header– If header is True also returns the header from HDU extension.int – If return_n_extensions is True also returns the number of extensions.
- pyFIT3D.common.io.get_num_col_file(filename, sep=None, maxsplit=- 1)
Reads the number of columns of file using str.split.
- Parameters
filename (str) – Filename of the inspected file.
sep (None or char, optional) – If sep is given uses as the column delimiter. Default is None.
maxsplit (int, optional) – If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).
- Returns
Number of columns in filename separated by sep.
- Return type
int
- pyFIT3D.common.io.get_wave_from_header(header, wave_axis=None)
Generates a wavelength array using header, a
astropy.io.fits.header.Headerinstance, at axis wave_axis.wavelengths = CRVAL + CDELT*([0, 1, …, NAXIS] + 1 - CRPIX)
- Parameters
header (
astropy.io.fits.header.Header) – FITS header with spectral data.wave_axis (int, optional) – The axis where the wavelength information is stored in header, (CRVAL, CDELT, NAXIS, CRPIX). Defaults to 1.
- Returns
Wavelengths array.
wavelengths = CRVAL + CDELT*([0, 1, …, NAXIS] + 1 - CRPIX)
- Return type
array like
- pyFIT3D.common.io.output_spectra(w, v, filename)
A wrapper to np.savetxt() creating a column with an ID.
- pyFIT3D.common.io.plot_spectra_ax(ax, wave_list, spectra_list, title='', labels_list=None, color=None, cmap=None, ylim=None, xlim=None, alpha=None, lw=None)
Print spectra provided by wave_list and spectra_list.
- Parameters
ax (matplotlib.axis) – Axis to plot spectra.
wave_list (list) – List of spectra_list wavelengths.
spectra_list (list) – List of spectra.
title (str, optional) – Title to the axis. Default value is ‘’.
labels_list (list or None) – List of labels, if None no labels are shown.
color (str, list or None) – A color, a list of colors or None. If None automatically generates the colors for spectra_list by using the cmap colormap.
cmap (str) – The colormap to generate the colors for spectra if color is None. Default colormap is viridis.
xlim (list or None) – Plot boudaries of the x-axis. Default value is None (i.e., define automatically the x-limits).
ylim (list or None) – Plot boudaries of the y-axis. Default value is None (i.e., define automatically the y-limits).
alpha (float, list or None) – An alpha, a list of alphas or None. If None automatically uses alpha=1.
lw (float, list or None) – A line width (lw), a list of lw or None. If None automatically uses defaul matplotlib lw.
- pyFIT3D.common.io.print_block_init(message, print_seed=False)
- pyFIT3D.common.io.print_done(time_ini, message=None)
- pyFIT3D.common.io.print_time(print_seed=True, time_ini=None, get_time_only=False)
Return the local timestamp
- Parameters
print_seed (boolean) – Whether to print or not a formatted version of the local time
- Returns
The rounded current timestamp
- Return type
int
- pyFIT3D.common.io.print_verbose(text, verbose=0, level=1)
Print text if verbose is True.
- Parameters
text (str) – Text to be printed.
verbose (int, bool, optional) – If verbose is greater than level prints text. If is True forces the print of text. Defaults to 0.
level (int, optional) – Configures the print level of the verbosity. Default level is 1.
- pyFIT3D.common.io.probe_method_time_consumption(**kwargs)
Function created as a wrapper to cProfile Python Profilers, a set of statistics that describes how often and how long various parts of the program (or any call of method/functions) executed.
Example
def f_sum_xy_ntimes(x, y, n=100): for i in range(n): s = x + y return s a = np.random.normal(10, 0.3, 100) b = np.random.normal(3, 0.1, 100) a_plus_b = probe_method_time_consumption(f=f_sum_xy_ntimes, f_args=dict(x=a, y=b, n=10000)) # 2 function calls in 0.011 seconds # # Ordered by: cumulative time # # ncalls tottime percall cumtime percall filename:lineno(function) # 1 0.011 0.011 0.011 0.011 <ipython-input-32-389c091e3289>:1(f_sum_xy_ntimes) # 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} # ...
- Parameters
f (function) – Function that will be probed.
f_args (dict) – A dictionary with the arguments for f call.
- Returns
The return from f.
- Return type
ret_f
- class pyFIT3D.common.io.readFileArgumentParser(*args, **kwargs)
Bases:
argparse.ArgumentParser- convert_arg_line_to_args(line)
- pyFIT3D.common.io.read_datacube(filename, badpix_extension=None, badpix_val=1, badpix_coll_threshold_frac=0.75, badpix_outmask_value=1)
- pyFIT3D.common.io.read_first_line(filename)
Return the first record of the given filename
- Parameters
filename (str) – The name of the file for which to get the first record
- Returns
The first not commented record found in the given filename
- Return type
str
- pyFIT3D.common.io.read_masks_file(filename)
Read the masks file and returns an array with the ranges to be masked.
- Parameters
filename (str) – Masks filename.
- Returns
array like – An array that saves in each position the range to be masked.
int – The number of intervals to be masked.
Example
A typical mask file filename:
5800 6080 5550 5610 7100 15000
should return:
- array([5800., 6808.],
[5500., 5610.], [7100., 15000.]),
- pyFIT3D.common.io.read_spectra(filename, f_error=None, variance_column=True)
Return the wavelength, and the flux and error spectra from a given filename
If the given filename contains only 2 columns or less an error will be raised. If there are only 3 columns, the error will be computed as follow:
0.002 * abs(flux)
- Parameters
filename (str) – Filename of the spectra.
f_error (function, optional) – Function that defines the error when it is not present in the spectrum file. It defaults to 0.002 * abs(flux).
variance_column (bool, optional) – When True treats the error column as variance and takes the square-root of the values.
- Returns
{wave, flux, eflux} – The wavelength, and the flux and the error flux stored in the given file.
- Return type
array like
- pyFIT3D.common.io.remove_isfile(filename)
- pyFIT3D.common.io.sel_waves(masks, wave)
Return the mask for the given wavelength array
For a given observed wavelength for which it is intended to extract physical information, this function returns a boolean selection of wavelength ranges to consider during the fitting. The selections are computed such that for any i-mask:
masks[i, 0] <= wave <= masks[i, 1]
- Parameters
masks (array like) – A Nx2 array containing the masks for the emission lines
wave (array like) – A one-dimensional array of the observed wavelength
- Returns
A boolean array with True for the non-masked wavelengths.
- Return type
array like
See also
- pyFIT3D.common.io.trim_waves(wave, wave_range)
Return a mask for the trimmed version of the wavelength range
For a given observed wavelength for which it is intended to extract physical information, this function returns a boolean selection of the wavelength range to consider during the fitting. The selection is computd such that:
wave_range[0] <= wave <= wave_range[1]
In the case where wave_range is None or wave_range[0] = wave_range[1], returns the entire wavelength range.
- Parameters
wave (array like) – A one-dimensional array of the observed wavelength
- pyFIT3D.common.io.write_img_header(input_fits, keyword, value, comment=None, before=None, after=None, output=None, overwrite=True)
pyFIT3D.common.stats module
- pyFIT3D.common.stats.WLS_invmat(y_obs, y_mod__m, dy=None)
Fit y_obs with linear combination of y_mod__m using Weighted Least Squares (WLS). An error dy (e.g. 1/sigma^2) could be set.
TODO: Math stuff…
- Parameters
y_obs (array like) – Data to be fitted.
y_mod__m (array like) – Set of models to fit y_obs.
dy (array like, optional) – Error of y_obs. Default is None.
- Returns
array like – Best model of y_obs.
array like – Best coefficients of y_mod__m.
- pyFIT3D.common.stats.calc_chi_sq(f_obs, f_mod, ef_obs, ddof=0)
Calculates the Chi Square of a fitted model.
- Parameters
f_obs (array like) – Observed spectrum
f_mod (array like) – Modeled spectrum
ef_obs (array like) – Error of observed spectrum.
- Returns
float – The Chi Square of the fit.
int – The number of observations.
- pyFIT3D.common.stats.convolve(wl, sed, kernel, nx=100)
- pyFIT3D.common.stats.convolve_sigma(flux, sigma, side_box=None)
Convolves flux using a Gaussian-kernel with standard deviation sigma. The kernel have dimension 2*`side_box` + 1.
- Parameters
flux (array like) – Spectrum to be convolved.
sigma (float) – Sigma of the Gaussian-kernel.
N_side (float) – Will define the range size of the Gaussian-kernel.
- Returns
Convolved flux by the weights defined by the Gaussian-kernel.
- Return type
array like
- pyFIT3D.common.stats.hyperbolic_fit_par(x, y, verbose=False)
Calculates the parameter x considering y with an hyperbolic model function fit. This function assumes that the three last values of x and y are forming an hyperbole.
- Parameters
x (array like) – The x values.
y (array like) – The y(x) values.
verbose (bool, optional) – Print output errors. Default is False.
- pyFIT3D.common.stats.median_box(box_init, x)
Creates a box with spans the same range of x evenly spaced with a median box. The box size is 2*`box_init`. If box_init is even, it will be rewritten to the next odd integer.
- Parameters
box_init (int) – The pixel where the box begins.
x (array like) – The array which will be ‘boxed’.
- Returns
Evenly spaced box with approximately the same range of x.
- Return type
array like
- pyFIT3D.common.stats.median_filter(box, x, verbose=False)
Apply a median filter to x with box size box.
- Parameters
box (int) – Box size of the median filter.
x (array like) – Array to be filtered.
- Returns
x input array filtered
- Return type
array like
- pyFIT3D.common.stats.pdl_stats(x, ddof=1, bad=nan)
- pyFIT3D.common.stats.round_up_to_odd(n)
Rounds up n to the next odd integer.
- Parameters
n (float) – A number to be rounded to the next odd integer.
- Returns
n rounded to the next odd integer.
- Return type
int
- pyFIT3D.common.stats.shift_convolve(wave_obs, wave_in, flux_in, redshift, sigma, sigma_inst=None)
Shift and convolve spectrum.
Shift the spectrum flux_in at wave_obs wavelenghts to wave_in corrected in redshift. Also convolves the spectrum to sigma + sigma_inst. If sigma_inst is None, the shift + convolution of flux_in is simplier and faster.
- Parameters
wave_obs (array like) – Observed wavelenghts.
wave_in (array like) – Input wavelengts of SSP models at observed frame.
flux_in (array like) – Flux in wave_obs wavelenghts.
redshift (float) – Input redshift.
sigma (float) – Velocity dispersion of data in km/s.
sigma_inst (float, optional) – Instrumental velocity dispersion in Angstrom. Defaults to None.
- Returns
The flux_in convolved by sigma + sigma_int and shifted (interpoled) to wave_in wavelenghts.
- Return type
array like
See also
None,None
- pyFIT3D.common.stats.smooth_ratio(flux_ratio, sigma, kernel_size_factor=None)
Create a smooth factor using the ratio r = flux_a/flux_b through a median filter.
- Parameters
flux_ratio (array like) – The flux_ratio which will be passed through a median_filter
sigma (float) – Sigma in angstroms.
kernel_size_factor (float) –
Will define, together with sigma, the kernel_size.
kernel_size = next odd integer from int(kernel_size_factor * sigma)
- Returns
The smooth ratio.
- Return type
array like
- pyFIT3D.common.stats.std_m(data)
pyFIT3D.common.tools module
- class pyFIT3D.common.tools.ReadDatacubes(name, input_dir=None, filename_SSP=None, filename_ELINES=None, filename_SFH=None, filename_flux_elines=None, filename_flux_elines_long=None, filename_indices=None)
Bases:
objectThis class groups the results from the entire analysis of pyFIT3D.
For now is reading output datacubes:
NAME.SSP.cube.fits.gz NAME.ELINES.cube.fits.gz NAME.SFH.cube.fits.gz flux_elines.NAME.cube.fits.gz indices.CS.NAME.cube.fits.gz
If available, it will read also the file:
flux_elines_long.NAME.cube.fits.gz
- name
Object name.
- Type
str
- input_dir
Location of the needed files.
- Type
str
- ELINES
The data from NAME.ELINES.cube.fits.gz FITS file.
The keys are build automatically. Example:
self.ELINES.keys() # dict_keys(['v_Halpha', 'disp_Halpha', '[OII]3727', '[OIII]5007', # '[OIII]4959', 'Hbeta', 'Halpha', '[NII]6583', '[NII]6548', # '[SII]6731', '[SII]6717'])
Each element is an 2D numpy array with galaxy image dimension (ny, nx).
- Type
dict
- SSP
The data from NAME.SSP.cube.fits.gz FITS file.
The keys are build automatically. Example:
self.SSP.keys() # dict_keys(['V', 'cont_seg', 'scale_seg', 'flux_ssp', 'e_flux_ssp', 'log_age_yr_ssp', 'log_age_yr_mass_ssp', 'e_log_age_yr_ssp', 'et_ZH_ssp', 'et_ZH_mass_ssp', 'e_met_ZH_ssp', 'Av_ssp', 'e_Av_ssp', 'vel_ssp', 'e_vel_ssp', 'disp_ssp', 'e_disp_ssp', 'ML_ssp', 'Mass_ssp', 'Mass_dust_cor_ssp', 'eMass_ssp']) Each element is an 2D numpy array with galaxy image dimension (ny, nx).
- Type
dict
- SFH
The data from NAME.SFH.cube.fits.gz FITS file.
The keys are build automatically. Example:
self.SFH.keys() # dict_keys(['models', 'age', 'met'])
models: Luminosity fraction (grouped by age-met) 3D array (n_models, ny, nx) age: Luminosity fraction (grouped by age) 3D array (n_age, ny, nx) met: Luminosity fraction (grouped by met) 3D array (n_met, ny, nx)
- Type
dict
- n_models
The number of SSP models used in the SFH derivation.
- Type
int
- age_models
Ages of SSP models.
- Type
array like
- met_models
Metallicities of SSP models.
- Type
array like
- age_met_models
Age-Met of each SSP model.
- Type
array like
- age_met_models_index
Each position saves a tuple with (i_age, i_met), the indexes of age_models and met_models of each model.
- Type
array like
- n_age
The number of different ages in SSP models used in the SFH derivation.
- Type
int
- n_met
The number of different metallicities in SSP models used in the SFH derivation.
- Type
int
- flux_elines
The data from flux_elines.NAME.cube.fits.gz FITS file.
The keys are build automatically. Example:
self.flux_elines.keys() # dict_keys(['H10', 'H11', 'H12', 'H8', 'H9', 'Ha', 'Hb', 'Hd', 'He', 'HeI3819', 'HeI4026', 'HeI4471', 'HeI4713', 'HeI4922', 'HeI5876', 'HeI6678', 'HeII', 'Hg', 'OI', 'SiII', '[ArIII]', '[ClIII]', '[FeIII]', '[FeII]', '[NII]', '[NII]6548', '[NII]6584', '[NI]', '[NeIII]', '[OIII]4363', '[OIII]4959', '[OIII]5007', '[OII]', '[OII]3727', '[OI]', '[SIII]', '[SII]', '[SII]6717', '[SII]6731'])
Each line has a dict with the derivated properties as keys:
flux_elines['Ha'].keys() # dict_keys(['EW', 'disp', 'e_EW', 'e_disp', 'e_flux', 'e_vel', 'flux', 'vel'])
Each element is an 2D numpy array with galaxy image dimension (ny, nx).
- Type
dict
- flux_elines_long
The data from flux_elines_long.NAME.cube.fits.gz FITS file.
- Type
dict
- indices
The data from indices.CS.NAME.cube.fits.gz FITS file.
The keys are build automatically. Example:
self.indices.keys() # dict_keys(['Hd', 'Hb', 'Mgb', 'Fe5270', 'Fe5335', 'D4000', 'Hdmod', 'Hg', 'SN', 'e_Hd', 'e_Hb', 'e_Mgb', 'e_Fe5270', 'e_Fe5335', 'e_D4000', 'e_Hdmod', 'e_Hg', 'e_SN'])
Each element is an 2D numpy array with galaxy image dimension (ny, nx).
- Type
dict
- header
The headers of each loaded FITS file.
The keys are build automatically. Example:
self.headers.keys() # dict_keys(['ELINES', 'SSP', 'SFH', 'flux_elines', 'flux_elines_long', 'indices'])
- Type
dict of astropy.io.fits.header.Header
- units
The units of each available data of each loaded FITS file. The keys are the main datacubes keys.
- Type
dict
- ids
The original id (INDEX) of each available data of each loaded FITS file. The keys are the main datacubes keys.
- Type
dict
- signal
Image selecting valid spaxels. By default is True where self.SSP[‘V’] != 0.
- Type
array like
- pa
Position Angle. By default, the ellipcity is derived based on second moments by the derivation of the Stokes parameters. The image used is self.SSP[‘V’]. See self.get_ellipse_pars().
- Type
float
- ba
Ellipse axis ratio. By default, the ellipcity is derived based on second moments by the derivation of the Stokes parameters. The image used is self.SSP[‘V’]. See self.get_ellipse_pars().
- Type
float
- x0
The x coordinate of the central spaxel. By default x0 and y0 are defined by the pixel where self.SSP[‘V’] is max. See self.get_central_spaxel().
- Type
int
- y0
The y coordinate of the central spaxel. By default x0 and y0 are defined by the pixel where self.SSP[‘V’] is max. See self.get_central_spaxel().
- Type
int
- pixel_distance__yx
The distance of each pixel in pixels.
- Type
array like
- HLR_pix
The radial scale of the HLR in bins. I. e., the radius of 1 HLR in pixels. The HLR is derived from self.SSP[‘V’].
- Type
float
- pixel_distance_HLR__yx
The distance of each pixel in units of HLR.
- Type
array like
- desc
The description of each property when disponible at the FITS header with the keyword UNITS_.
- Type
dict
- get_signal :
Get the galaxy selection of good pixels.
- get_central_spaxel :
Get central spaxel coordinates.
- get_ellipse_pars :
Get the ellipcity of the galaxy based on the Stokes parameters derivation.
- set_central_spaxel :
Set the central spaxel coordinates. Will recalculate ellipcity, distances and the HLR.
- set_ellipse_pars :
Set the ellipcity parameters, i. e., position angle and the axis ratio. Will recalculate distances and the HLR.
- get_half_radius :
Find the half radius of the desired property.
- radial_profile :
Calculate the radial profile of an N-D image.
- plot_maps :
Plot all maps stored in a datacube (or all datacubes).
- get_central_spaxel(image=None)
- get_ellipse_pars(image=None, x0=None, y0=None, mask=None)
- get_half_radius(prop, mask=None)
Find the half radius of the desired property. Using radial bins of 1 pixel, calculate the cumulative sum of
prop. The “half prop radius” is the radius where the cumulative sum reaches 50% of its peak value.- Parameters
prop (array) – Image to get the half radius.
mask (array(bool), optional) – Boolean array with the valid data. Defaults to
qMask.
- Returns
HXR – The half
propradius, in pixels.- Return type
float
Notes
This value should be close to $dfrac{HLR_{circular}}{sqrt{b/a}}$ if the isophotes of the galaxy are all ellipses with parameters p.a. and b/a.
- get_pixel_distance(use_HLR_units=False, pixel_scale=None, x=None, y=None, pa=None, ba=None)
Return an image (
numpy.ndarrayof same shape as :attr`qSignal`) of the distance from the center of the galaxy(x0, y0)in HLR units (default), assuming a projected disk.- Parameters
use_HLR_units (boolean, optional) – Whether to use units of half light radius or pixels.
pixel_scale (float, optional) – Pixel distance scale, used if
use_HLR_unitsisFalse. If not set, do not scale the distance.x (array, optional) – X coordinates to calculate the distance. If not set, the coordinates of the core images will be used.
y (array, optional) – Y coordinates to calculate the distance. Must have the same length as
x. If not set, the coordinates of the core images will be used.pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis.
ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).
- Returns
pixel_distance – Array (or image) containing the pixel distances.
- Return type
array
See also
- get_signal(image=None)
- plot_maps(datacube=None)
Plot all maps from desired datacube. If
datacubeis None, will plot the maps from all datacubes.- Parameters
datacube (str, optional) – The name of the datacube, e.g. ELINES, SFH. Defaults to None, i.e., print all maps.
- radial_profile(prop, bin_r, rad_scale=1.0, mask=None, mode='mean', return_npts=False)
- set_central_spaxel(x0, y0, image=None)
Sets the central spaxel coordinates. Will change all the relative properties such as distances, ellipse parameters and HLR_pix.
- Parameters
x0 (int) – The x-coordinate of the central spaxel.
y0 (int) – The y-coordinate of the central spaxel.
See also
- set_ellipse_pars(pa, ba, image=None)
Sets the ellipse parameters (position angle and axis ratio). Will change all the relative properties such as distances and HLR_pix.
- Parameters
pa (float) – Position angle.
ba (float) – Minor-to-major axis ratio.
- pyFIT3D.common.tools.SN_map_seg(SN__s, seg_map__yx)
- pyFIT3D.common.tools.check_max(ix, iy, ixp, iyp, Ha_map__yx, seg_map__yx, frac_peak)
- pyFIT3D.common.tools.check_near(ix, iy, seg_map__yx)
- pyFIT3D.common.tools.check_point(ix, iy, ixp, iyp, Ha_map__yx, seg_map__yx, mask_map__yx, Ha_peaks, NR, max_dist_peak, min_flux, frac_peak)
- pyFIT3D.common.tools.check_point_SN(ix, iy, ixp, iyp, area, Ha_map__yx, seg_map__yx, mask_map__yx, SN__yx, Ha_peaks, NR, max_dist, min_SN, min_flux, frac_peak)
- pyFIT3D.common.tools.clean_Ha_map(v__yx, mask__yx, max_vel, min_vel)
- pyFIT3D.common.tools.clean_map(map__yx, vel_map__yx, max_vel, min_vel)
- pyFIT3D.common.tools.clean_nan(in_file, badval)
- pyFIT3D.common.tools.cont_seg_all(signal_fits, flux_limit_peak, max_dist_peak, frac_peak, min_flux, segmentation_fits, diffuse_mask_fits)
- pyFIT3D.common.tools.cont_seg_all_SN(map__yx, e_map__yx, flux_limit_peak, target_SN, min_SN, frac_peak, min_flux)
- pyFIT3D.common.tools.correct_vel_map_cube_rot(input_fits, velocity_map_fits, output_fits, final_velocity=None)
- pyFIT3D.common.tools.create_SSP_from_spectra(ssp_library, coeffs, redshift=0, sigma=0, AV=0, sigma_inst=0, RV=3.1, extlaw='CCM', output_filename=None)
- pyFIT3D.common.tools.create_mask_map(input_file, cut, output_file)
- pyFIT3D.common.tools.csv_to_map_seg(csvfile, column, seg_file_fits, map_fits)
- pyFIT3D.common.tools.flux_elines_cube_EW(flux__wyx, input_header, n_MC, elines_list, vel__yx, sigma__yx, eflux__wyx=None, flux_ssp__wyx=None)
- pyFIT3D.common.tools.gen_frac_radius(X, r, r_max=None, frac=0.5)
Evaluate radius where the cumulative value of X reaches FRAC of its value.
- Parameters
X (array like) – The property whose FRAC radius will be evaluated.
r (array like) – Radius associated to each value of X. Must be the same shape as X.
r_max (int) – Integrate up to r_max. Defaults to np.max(r).
frac (float) – Fraction of X where the radius will be evaluated
- Returns
FXR – The “frac X radius”. If frac is 0.5 (default), will return HXR (half X radius).
- Return type
float
Examples
Find the radius containing half of the volume of a gaussian.
>>> import numpy as np >>> xx, yy = np.indices((100, 100)) >>> x0, y0, A, a = 50.0, 50.0, 1.0, 20.0 >>> z = A * np.exp(-((xx-x0)**2 + (yy-y0)**2)/a**2) >>> r = np.sqrt((xx - 50)**2 + (yy-50)**2) >>> gen_frac_radius(z, r, f=0.5) 16.786338066912215
- pyFIT3D.common.tools.gen_rebin(a, e, bin_e, mean=True)
Rebinning function. Given the value array a, with generic positions e such that e.shape == a.shape, return the sum or the mean values of a inside the bins defined by bin_e.
- Parameters
a (array like) – The array values to be rebinned.
e (array like) – Generic positions of the values in a.
bin_e (array like) – Bins of e to be used in the rebinning.
mean (boolean) – Divide the sum by the number of points inside the bin. Defaults to True.
- Returns
a_e – An array of length len(bin_e)-1, containing the sum or mean values of a inside each bin.
- Return type
array
- pyFIT3D.common.tools.get_CS_slice(input_name)
- pyFIT3D.common.tools.get_Ha(input_fits, redshift, output_fits)
- pyFIT3D.common.tools.get_SN_cube(org_cube__wyx, wave__w, wmin=None, wmax=None)
Generates the SN, the mean and the standard deviation maps of
org_cube__wyxwithinwminandwmax.- Parameters
org_cube__wyx (array) – The cube spectra. Dimensions are \((NW, NY, NX)\), where \(NW\) is the number of wavelengths, and \((NY, NX)\) the 2D-image dimension.
wave__w (array) – The wavelengths with dimension NW
wmin (int, optional) – Blue-side border (leftmost) of the wavelength range to generate the outputted maps. Defaults to None.
wmax (int, optional) – Red-side border (rightmost) of the wavelength range to generate the outputted maps. Defaults to None.
- Returns
SN__yx (array) – The signal-to-noise map (\(NX, NY\)) within [
wmin,wmax] wavelength range.mean_flux__yx (array) – The mean flux map (\(NX, NY\)) within [
wmin,wmax] wavelength range.sigma_flux__yx (array) – The standard deviation of the flux map (\(NX, NY\)) within [
wmin,wmax] wavelength range.
- pyFIT3D.common.tools.get_SN_rss(org_rss__sw, wave__w, wmin=None, wmax=None)
Generates the SN, the mean and the standard deviation maps of
org_rss__swwithinwminandwmax.- Parameters
org_rss__sw (array) – The row-stacked spectra (RSS). Dimensions are \((NS, NW)\), where NS the RSS dimension and \(NW\) is the number of wavelengths
wave__w (array) – The wavelengths with dimension NW.
wmin (int, optional) – Blue-side border (leftmost) of the wavelength range to generate the outputted maps. Defaults to None.
wmax (int, optional) – Red-side border (rightmost) of the wavelength range to generate the outputted maps. Defaults to None.
- Returns
SN__s (array) – The signal-to-noise for the RSS within [
wmin,wmax]wavelength range.mean_flux__s (array) – The mean flux of the RSS within [
wmin,wmax] wavelength range.sigma_flux__s (array) – The standard deviation of the flux of the RSS within [
wmin,wmax] wavelength range.
- pyFIT3D.common.tools.get_cosmo(z, h, om, ol)
- pyFIT3D.common.tools.get_distance(x, y, x0, y0, pa=0.0, ba=1.0)
Return an image (
numpy.ndarray) of the distance from the center(x0, y0)in pixels, assuming a projected disk.- Parameters
x (array) – X coordinates to get the pixel distances.
y (array) – y coordinates to get the pixel distances.
x0 (float) – X coordinate of the origin.
y0 (float) – Y coordinate of the origin.
pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis.
ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).
- Returns
pixel_distance – Pixel distances.
- Return type
array
- pyFIT3D.common.tools.get_ellipse_pars(image, x0, y0, mask=None)
Estimate ellipticity and orientation of the galaxy using the “Stokes parameters”, as described in Sec. 4.4.6.5 at: http://adsabs.harvard.edu/abs/2002AJ….123..485S
The image used is
signal.- Parameters
image (array) – Image to use when calculating the ellipse parameters.
x0 (float) – X coordinate of the origin.
y0 (float) – Y coordinate of the origin.
mask (array, optional) – Mask containing the pixels to take into account.
- Returns
pa (float) – Position angle in radians, counter-clockwise relative to the positive X axis.
ba (float) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).
- pyFIT3D.common.tools.get_image_distance(shape, x0, y0, pa=0.0, ba=1.0)
Return an image (
numpy.ndarray) of the distance from the center(x0, y0)in pixels, assuming a projected disk.- Parameters
shape ((float, float)) – Shape of the image to get the pixel distances.
x0 (float) – X coordinate of the origin.
y0 (float) – Y coordinate of the origin.
pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis. Defaults to
0.0.ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)). Defaults to
1.0.
- Returns
pixel_distance – Image containing the distances.
- Return type
2-D array
See also
- pyFIT3D.common.tools.get_index(wave__w, flux_ssp__sw, res__sw, redshift__s, n_sim, plot=0, wl_half_range=200, seg__yx=None)
- pyFIT3D.common.tools.get_slice(data__wyx, wave__w, prefix, config_file)
- pyFIT3D.common.tools.imarith(in1_file, operator, in2_file, out_file)
- pyFIT3D.common.tools.img2spec_e(input_fits, index_image, output)
- pyFIT3D.common.tools.index_seg_cube(indices_file, segmentation_fits, indices_cube_fits)
- pyFIT3D.common.tools.indices_spec(wave__w, flux_ssp__w, res__w, redshift, n_sim, plot=0, wl_half_range=200, verbose=False)
- pyFIT3D.common.tools.list_eml_compare(wave_list, filename_list_ref, redshift, abs_max_dist_AA=4, plot=0, verbose=0)
Compare a list of emission lines central wavelengths of detected automatically with a theoretical list of emission lines central wavelengths.
- Parameters
wave_list (array like) –
filename_list_ref (str) –
redshift (float) –
abs_max_dist_AA (float, optional) – Defaults to 4 AA.
plot (int, optional) – Defaults to 0.
verbose (int, optional) – Defaults to 0.
- Returns
array like – Final list of detected emission lines.
array like – Indexes from
wave_listfor the peaks associated to each final list of detected emission lines.array like – Final list of
wave_listpeaks associated to the detected emission lines.if
filename_list_refpresents a second column with the names of theemission lines –
- array like
The names of the emission lines if
- pyFIT3D.common.tools.map_auto_ssp_AGE_MET_rnd_seg(auto_ssp_output_filename, segmentation_fits, output_prefix, central_wavelength, inst_disp)
- pyFIT3D.common.tools.map_auto_ssp_rnd_seg(input_elines, segmentation_fits, output_prefix, inst_disp=None, wave_norm=None)
- pyFIT3D.common.tools.med2df(input_fits, output_fits, x_width, y_width)
- pyFIT3D.common.tools.momana_spec_wave(gas_flux__w, wave, vel, sigma, crval, cdelt, n_MC=10, egas_flux__w=None, flux_ssp__w=None)
It will proceed the moment analysis of emission line centered at wave. The parameters crval and cdelt are required in order to generate wavelength interval to proceed the analysis.
NW = len(gas_flux__w) wavelengths = crval + cdelt*[0, 1, ..., NW],
TODO: create wavelength intervals withoud crval and cdelt, i.e., set intervals using wave and a defined interval in Angstroms.
- Parameters
gas_flux__w (array like) – Gas spectrum.
wave (float) – Emission line central wavelength to be analyzed.
vel (float) – Ha velocity
sigma (float) – Ha sigma.
crval (float) – The wavelength attributed to the flux at position 0.
cdelt (float) – The step which the wavelengths varies.
n_MC (int, optional) – Number of Monte-Carlo iterations. Defaults to 10.
egas_flux__w (array like or None) – Error in gas_flux__w used to randomize the gas flux value at each MC iteration. If None the gas flux value is not randomized. Defaults to None.
flux_ssp__w (array like or None) – Stellar population spectrum used to the EW computation. If None, the EW will be 0. Defaults to None.
- Returns
The result of the moment analysis of emission line centered in wave.
[ integrated flux [10^-16 erg/s/cm^2], velocity [km/s], dispersion [km/s], equivalent width [Angstroms], sigma(integrated flux), sigma(velocity), sigma(dispersion), sigma(equivalent width), ]
- Return type
array like
- pyFIT3D.common.tools.nearest(ix, iy, ix_peaks, iy_peaks, NR, seg_map__yx)
- pyFIT3D.common.tools.pack_NAME(name, ssp_pack_filename=None, elines_pack_filename=None, sfh_pack_filename=None, mass_out_filename=None)
- pyFIT3D.common.tools.pack_results_name(name, pack_filename, prefix)
- pyFIT3D.common.tools.peak_finder(wave, flux, nsearch, peak_threshold=2, dmin=2, plot=False, verbose=0)
Search for peaks in a spectrum (a.k.a. emission lines finder).
flux_filtered = median_filter(flux) probable peaks = flux_filtered > median(flux_filtered) + peak_threshold*std(flux_filtered)
Ther final peak list do not include peaks closer than
dminpixels.- Parameters
wave (array like) – Wavelengths array.
flux (array like) – Fluxes array.
nsearch (int) –
- A peak will have the highest flux around the interval (in pixels):
(peak - nsearch, peak + nsearch)
peak_threshold (float, optional) – Defines the standard deviation multiplicative factor for the probable peak threshold calculation. Defaults to 2.
dmin (int, optional) – Defines the minimal distance between peaks (in pixels). Defaults to 2.
plot (bool, str, optional) – If True plots the result. If is a string, it configures plot as True and uses the string as the plot filename. Defaults to False.
verbose (int, optional) – Print detect information at
verboselevel. Defaults to 0.
- Returns
array like – The indices of the peaks in wave/flux arrays.
array like – The probable peaks (in wavelengths).
array like – The hyperbolic fit of the wavelength associated to each peak.
array like – The flux associated to each peak.
- pyFIT3D.common.tools.proceed_loop(ixp, iyp, is_point, tmp_Ha_map__yx, Ha_map__yx, seg_map__yx, mask_map__yx, Ha_peaks, NR, flux_limit_peak, max_dist_peak, min_flux, frac_peak)
- pyFIT3D.common.tools.proceed_loop_SN(ixp, iyp, area, is_point, tmp_Ha_map__yx, Ha_map__yx, seg_map__yx, mask_map__yx, SN__yx, Ha_peaks, NR, flux_limit_peak, max_dist, min_SN, min_flux, frac_peak)
- pyFIT3D.common.tools.radial_profile(prop, bin_r, x0, y0, pa=0.0, ba=1.0, rad_scale=1.0, mask=None, mode='mean', return_npts=False)
Calculate the radial profile of an N-D image.
- Parameters
prop (array) – Image of property to calculate the radial profile.
bin_r (array) – Semimajor axis bin boundaries in units of
rad_scale.x0 (float) – X coordinate of the origin.
y0 (float) – Y coordinate of the origin.
pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis.
ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).
rad_scale (float, optional) – Scale of the bins, in pixels. Defaults to 1.0.
mask (array, optional) – Mask containing the pixels to use in the radial profile. Must be bidimensional and have the same shape as the last two dimensions of
prop. Default: no mask.mode (string, optional) –
- One of:
'mean': Compute the mean inside the radial bins (default).'median': Compute the median inside the radial bins.'sum': Compute the sum inside the radial bins.'var': Compute the variance inside the radial bins.'std': Compute the standard deviation inside the radial bins.
return_npts (bool, optional) – If set to
True, also return the number of points inside each bin. Defaults toFalse.
- Returns
radProf ([masked] array) – Array containing the radial profile as the last dimension. Note that
radProf.shape[-1] == (len(bin_r) - 1)Ifpropis a masked aray, this andnptswill be a masked array as well.npts ([masked] array, optional) – The number of points inside each bin, only if
return_nptsis set toTrue.
See also
- pyFIT3D.common.tools.radial_sum_cube_e(cube__wyx, delta_R, x0, y0, input_mask=None, input_error=None, plot=False)
- pyFIT3D.common.tools.read_ELINES(filename)
- pyFIT3D.common.tools.read_SFH(filename)
- pyFIT3D.common.tools.read_SSP(filename)
- pyFIT3D.common.tools.read_coeffs_CS(filename)
Reads the output coefficients file of the AutoSSP RSS run and returns a dictionary with each output as a key. The dimensions of each array stored in the dictionay has shape (NC, NS), where NC is the number max of coefficients and NS is the number of spectra.
- Parameters
filename (str) – The coefficients output filename from AutoSSP RSS run.
- Returns
- keys:
shape : a tuple with NC, NS age__cs : ages met__cs : metallicities coeffs__cs : coefficients norm__cs : normalized coefficients e_norm__cs : error in normalized coefficients ml__cs : mass-to-light Av__cs : dust extinction parameters A_V coeff_mass__cs : coeffs*10**(ml__cs)
- Return type
dict
- pyFIT3D.common.tools.read_flux_elines(filename, filename_lines=None, cube=True)
- pyFIT3D.common.tools.read_img_header(input_fits, header_cards, filename=None)
- pyFIT3D.common.tools.read_indices(filename)
- pyFIT3D.common.tools.read_indices_file(indices_file)
- pyFIT3D.common.tools.redshift_config(input_config, redshift, output_config=None)
- pyFIT3D.common.tools.rss_seg2cube(rss__sw, seg__yx)
- pyFIT3D.common.tools.smooth_spec_clip_cube(cube__wyx, wavebox_width, sigma, wavepix_min, wavepix_max)
- pyFIT3D.common.tools.spec_extract_cube(input_fits, segmentation_fits, output_rss_fits, diffuse_output=None)
- pyFIT3D.common.tools.spec_extract_cube_error(error__wyx, seg__yx, badpix__wyx=None, fov_selection__yx=None)
- pyFIT3D.common.tools.spec_extract_cube_mean(data__wyx, seg__yx, badpix__wyx=None)
- pyFIT3D.common.tools.spec_extract_diffuse(input_fits, Ha_map_fits, segmentation_diffuse_fits, output_rss_fits, lower_limit=None)
- pyFIT3D.common.tools.sum_mass_age(name, output_csv_filename=None)
- pyFIT3D.common.tools.vel_eline(flux, wave, nsearch, imin, wave_ref, set_first_peak=True)