spectuner.config
- spectuner.config.load_config(fname: str) Config[source]
Load the config.
- Parameters:
fname – Path to the config file. It can be a pickle file stored using
spectuner.save_configor a HDF file obtained from pixel-level fitting. In addition, if this is a directory, it will load the config defined by the YAML files.- Returns:
Loaded
Configinstance.
- spectuner.config.load_default_config() Config[source]
Load the default config.
- Returns:
Default config.
- spectuner.config.save_config(config: Config, fname: str)[source]
Save the config to a pickle file.
- Parameters:
config – Config to save.
fname – Saving name.
- class spectuner.config.Config[source]
A subclass of dict with user-friendly methods to update the config.
- append_spectral_window(spec: ndarray, beam_info: float | tuple, noise: float, T_bg: float = 0.0, need_cmb: bool = True)[source]
Add a spectral window to
obs_info.- Parameters:
spec – The observed spectrum given by a 2D array, with the first column being the frequency in MHz and the second column being the intensity in K.
beam_info – For single disk telescopes, this should be a float indicating the telescope diameter in meter. For interferometers, this should be (
BMAJ,BMIN) indicating the beam size in degree.noise – RMS noise in K.
T_bg – Background temperature in K.
need_cmb – If
true, additionally add 2.726 K to the background temperature.
- append_spectral_window_simple(freq: ndarray, beam_info: float | tuple, T_bg: float = 0.0, need_cmb: bool = True)[source]
Add a spectral window to
obs_info.This may be used for generating model spectra. For any fitting-related tasks, please use
append_spectral_windowinstead.- Parameters:
freq – Frequency grid in MHz.
beam_info – For single disk telescopes, this should be a float indicating the telescope diameter in meter. For interferometers, this should be (
BMAJ,BMIN) indicating the beam size in degree.T_bg – Background temperature in K.
need_cmb – If
true, additionally add 2.726 K to the background temperature.
- set_fname_db(fname_db: str)[source]
Set the path to the spectroscopic database.
- Parameters:
fname_db – Path to the spectroscopic database.
- set_n_process(n_process: int)[source]
Set the number of processes for the multiprocessing pool.
- Parameters:
n_process – Number of processes.
- set_param_info(param_name: Literal['theta', 'T_ex', 'N_tot', 'delta_v', 'v_offset'], is_log: bool, bound: Tuple[float, float] | None = None, is_shared: bool = False, special: str | None = None)[source]
Update the settings of a parameter.
- Parameters:
param_name – Parameter name.
is_log – Whether to use log-scale during fitting for this parameter.
bound –
Lower and upper limits used by optimizers for fitting. If
is_log=True, the limits should be in log-scale. For example, ifis_log=True,bound=(12, 20)means that the parameter is between \(10^{12}\) and \(10^{20}\). The unit of the limits follows:theta: arcsec
T_ex: K
N_tot: cm^-2
delta_v: km/s
v_offset: km/s
is_shared – Whether the parameter is shared in joint fitting of different states and isotopologues.
special – Special parametrization. Now, this can only be used for
theta. If setspecial="eta",thetashould be treated as the filling factor \(\eta\), with \(\eta = \theta^2/(\theta^2 + \theta_{\rm maj} \theta_{\rm min})\).
- set_optimizer(method: str, **kwargs)[source]
Set the optimizer for the fitting.
- Parameters:
method (str) –
Name of the optimizer.
Use ‘pso’ (particle swarm optimization) for line identification.
Use ‘slsqp’ (sequential least squares programming implemented in
scipy.minimize), for pixel-by-pixel fitting with a nerual network.
**kwargs –
Additional arguments for the optimizer.
n_trial (int): Number of trials for ‘pso’. The optimizer will be run for n_trial times, and the best fit will be selected among all trials. Defaults to 1.
n_swarm (int): Number of particles for ‘pso’. Defaults to 28.
n_draw (int): Number of samples drawed by the neural network. This only works for local optimizers such as ‘slsqp’. The code will compute the fitness for each sample and select the best one as the initial guess. Defaults to 50.
- set_ident_species(species: list | None, collect_iso: bool = True, combine_iso: bool = False, combine_state: bool = False, version_mode: Literal['default', 'all'] = 'default', include_hyper: bool = False, exclude_list: list | None = None, rename_dict: dict | None = None)[source]
Set species for line identification.
- Parameters:
species – List of species to include. If
None, inlcude all possible species in the given frequency ranges.collect_iso – If
True, collect isotopologues of molecules inspecies.combine_iso – If
True, combine isotopologues and fitting them jointly.combine_state – If
True, combine states and fitting them jointly.version_mode – If set to
'all', include all versions of the species in the indiviudal fitting phase. Then, during the combining phase, the best fit among the versions is used. Bothcombine_isoandcombine_statemust beFalsefor this option to work. Defaults to'default'.include_hyper – If
True, include hyperfine states.exclude_list – List of species to exclude.
rename_dict – A dict to rename species.
- set_modificaiton_lists(exclude_id_list: list | None = None, exclude_name_list: list | None = None, include_id_list: list | None = None)[source]
Set modification lists.
- Parameters:
exclude_id_list – List of IDs to be removed from the combined result.
exclude_name_list – List of molecule names to be removed from the combined result.
include_id_list – List of IDs to be added to the combined result.
- set_previous_result(fname: str, exclude_identified: bool = True)[source]
Set previous identification result.
- Parameters:
fname – Path to the previous identification result.
exclude_identified – Whether to exclude the identified species in the previous result.
- set_pixel_by_pixel_fitting(species: list, loss_fn: Literal['pm', 'chi2'] = 'pm', need_spectra: bool = True)[source]
Set pixel-by-pixel fitting.
- Parameters:
species – List of species to fit. The species will be fit jointly.
loss_fn –
Loss function for fitting.
"pm": Peak matching."chi2": Chi-square.
need_spectra – Whether to save the best-fitting model spectrum.
- set_inference_model(ckpt: str, device: str = 'cuda:0', batch_size: int = 64, num_workers: int = 2)[source]
Set AI model related parameters.
- Parameters:
ckpt – Path to the checkpoint file.
device – Device to use. Set
device="cpu"if no GPU is available. Defaults to"cuda:0".batch_size – Batch size of inference. Reduce this number if GPU memory is not enough. Defaults to 64.
num_workers – Number of workers for the data loader.