cassis_lte_python.LTEmodel#

Classes#

Functions#

generate_lte_model_func(config)

Function to generate the model function using information provided in config.

Module Contents#

cassis_lte_python.LTEmodel.generate_lte_model_func(config: dict)#

Function to generate the model function using information provided in config. The generated function depends on the frequency in MHz and on a set of lmfit parameters.

Parameters:

config

a dictionary containing :

  • the following frequency-dependent functions:

    • tc : continuum values ; no default

    • beam_sizes : 1-D equivalent beam size ; no default

    • tmb2ta : conversion factor from Tmb to Ta* scale ; default to 1

    • jypb2k : conversion factor from Jy/beam to K ; default to 1

    • noise : rms noise values ; default to 0

  • line_list : list of transitions to be modeled

  • cpt_list : list of components

Returns:

The model function to be minimized.

class cassis_lte_python.LTEmodel.ModelSpectrum(configuration: dict, str, cassis_lte_python.sim.model_setup.ModelConfiguration, **kwargs)#

Bases: object

LOGGER#
model_config#
log = False#
normalize = False#
model = None#
model_fit = None#
model_fit_cpt = []#
figure = None#
tag_colors = None#
tag_other_sp_colors = None#
cpt_cols = None#
thresholds_other = None#
save_config_dict()#
save_config(filename, dirname=None)#
update_configuration(config)#
model_info(cpt=None)#
get_tc(x_mod)#
get_rms_cal(fmhz)#
param_names()#
generate_lte_model(normalize=False)#
do_modeling()#
do_minimization(print_report: short | long | None = None, report_kws=None)#
do_savings()#
do_plots()#
fit_model(max_nfev=None, fit_kws=None)#

Computes weights and perform the fit.

Parameters:
  • max_nfev – maximum number of iterations (default value depends on the algorithm)

  • fit_kws – keywords for the fit function

Returns:

fit_report(report_kws=None)#
eval_uncertainties_components(fmhz, sigma=1)#

From lmfit.model

compute_model_intensities(params=None, x_values=None, line_list=None, line_center_only=False, cpt=None)#
compute_model(params=None, x_values=None, line_list=None, line_center_only=False)#

For backward compatibility.

Parameters:
  • params

  • x_values

  • line_list

  • line_center_only

Returns:

integrated_intensities()#
setup_plot_fus()#

Plot in full spectrum mode (self.bandwidth is None)

Returns:

setup_plot_la(win_list: list, verbose=True, other_species_dict: dict | None = None, **kwargs)#

Prepare all data to do the plots in line analysis mode

Parameters:
  • win_list – the list of windows

  • verbose

  • other_species_dict – a dictionary of other species and their thresholds

Returns:

get_lines_plot_params(line_list: pandas.DataFrame, vlsr: float, f_ref: float, tag_colors: dict)#
select_windows(**kwargs)#

Determine windows to plot

Parameters:
  • tag – tag selection if do not want all the tags

  • display_all – if False, only display windows with fitted data

  • windows – a dictionary of the windows to be plotted (keys=tags, vals=window numbers)

Returns:

select_windows_other_lines(other_species_win_selection: str)#

Select windows with other lines from this tag

Parameters:

other_species_win_selection – desired tag

Returns:

setup_plot()#

Prepare all data to do the plot(s), using provided keywords. Possible keywords are :

  • tag: tag selection if do not want all the tags

  • basic: do not plot other species

  • other_species: list or dictionary or file with other species ; dictionary and file can contain their thresholds

  • other_species_plot: list of other species to plot ; if None, other_species is used ; if other_species is provided, only these species are kept

  • other_species_win_selection: select only windows with other lines from this tag.

  • display_all: if False, only display windows with fitted data

Returns:

Notes :

  • other_species_selection is deprecated, use other_species_win_selection

make_plot(plot_type)#

Do the plot(s).

Parameters:

plot_type – gui or file

Returns:

set_filepath(filename, dirname=None, ext=None)#
abstract use_ref_pixel(tag_list=None)#
save_model(filename, dirname=None, ext='txt', full_spectrum=True)#

Save the model spectrum from self.model.

Parameters:
  • filename – the name of the file

  • dirname – the directory where to save the file

  • ext – extension of the file : txt (default) or fits

  • full_spectrum – save the model for the entire observed spectrum ; if false, only save the model spectrum for the windows in self.win_list

Returns:

None

save_spectrum(filename, dirname=None, ext='txt', spec: None | tuple = None, spectrum_type: typing_extensions.Literal[observed, continuum, synthetic] = '', vlsr: None | float | int = None, yunit: None | str = None, comment: None | str = None)#

Write a spectrum (continuum, data or model, depending on the provided parameters) on a file.

Parameters:
  • filename

  • dirname

  • ext

  • spec – tuple of x and y values to be written ; if not provided and continuum is false, stored model is written

  • spectrum_type – ‘continuum’, ‘observed’, ‘synthetic’ or empty string ‘’ (default)

  • vlsr

  • yunit

  • comment

Returns:

the path to the file

save_stick_spectrum(filename, dirname=None, ext='fits')#
save_line_list_cassis(filename, dirname=None, snr_threshold=None)#

Writes the list of lines for display in CASSIS. To be used when fitting the entire spectrum.

Parameters:
  • filename

  • dirname

Returns:

save_fit_results(filename, dirname=None)#
write_cassis_file(filename, ext: str, dirname=None, datafile=None)#
write_ltm(filename, dirname=None)#

Writes a LTE model configuration file for CASSIS

Parameters:
  • filename – the name of the file

  • dirname – the directory where to save the file

Returns:

None

write_lam(filename, dirname=None)#

Writes a line analysis configuration file for CASSIS

Parameters:
  • filename – the name of the file

  • dirname – the directory where to save the file

Returns:

None

class cassis_lte_python.LTEmodel.ModelCube(configuration, verbose=False)#

Bases: object

LOGGER#
output_dir#
output_dir_spectra#
output_dir_images#
log_file_loop#
cubeshape#
hdr#
wcs#
fmhz_ranges = []#
ref_pixel_info = None#
latest_valid_params#
tags#
param_names#
user_params#
parameters_array#
array_dict#
err_dict#
cont_info#
get_beams()#
read_frequencies(fits_list=None)#
pixels_line(xref, yref, xmax, xmin, step=1)#
pixels_gradient_loop(xref, yref, xmax, ymax, xmin=0, ymin=0, step=1)#
pixel_infos(mdl)#
save_latest_valid_params(params: dict)#
use_ref_pixel(mdl, tag_list=None)#
parameters_at_pix(pix)#
do_minimization(pix_list=None)#
make_maps(keep_all_pix=True, png_all=False, ntot_scaling='sqrt')#

Creates the fits images for the varying parameters.

Parameters:

keep_all_pix – if False, use NaNs for parameters that are at boundary.

Returns:

print_infos()#
property log_path#
property yunit#