frap.model

Classes

model

class for FRAP model

observation

class for containing observation data

inference

class for inference methods

results

class for storing inference results

plot

class for plotting results

Module Contents

class frap.model.model(incl, r_out, N_GP, pa=0.0, spacing='FB', r_in=None, userdef_vis_model=None, flux_uncert=True, jitter=0.0001, hyperparameters_fixed=True)

class for FRAP model

set_parameters

method to set model parameters

set_observations

method to set observational data

set_opacity

method to set dust opacity model

set_parameter(kind, free=True, GP=True, bounds=(10, 20), mean_std=(0.0, 1.0), variance=1.0, lengthscale=0.3, mean=0.0, profile=None)

set a parameter as free or fixed.

This method allows you to define model parameters as either free (to be inferred) or fixed (with a specified profile).

Parameters:
  • kind (str) – name of the parameter

  • free (bool, optional) – whether the parameter is free. Defaults to True.

  • dust_prop (bool, optional) – whether the parameter is related to dust properties. Defaults to False.

  • GP (bool, optional) – whether to use Gaussian process for the parameter. Defaults to True.

  • bounds (tuple, optional) – (min, max) bounds for the parameter if GP is used. Defaults to (10, 20).

  • mean_std (tuple, optional) – (mean, std) for the parameter if not using GP. Defaults to (0.0, 1.0).

  • variance (float, optional) – variance for the GP kernel. Defaults to 1.0.

  • lengthscale (float, optional) – lengthscale for the GP kernel. Defaults to 0.3.

  • mean (float, optional) – mean for the GP prior. Defaults to 0.0.

  • profile (array or function, optional) – fixed profile for the parameter if not free. Defaults to None.

set_visibility(band, q, V, s, f_s, f_mean, nu, Nch, pbcor='ALMA-12m')

set observations for a given band.

This method allows you to input observational data for a specific band, including spatial frequencies, visibilities, uncertainties, flux scaling factors, and frequencies.

Parameters:
  • band (str) – name of the observation band

  • q (dict) – spatial frequencies in 1/arcsec. Should be a dictionary of arrays for each channel.

  • V (dict) – observed visibilities in Jy. Should be a dictionary of arrays for each channel.

  • s (dict) – uncertainties in Jy. Should be a dictionary of arrays for each channel.

  • f_s (float) – flux scaling factor standard deviation

  • f_mean (float) – mean flux scaling factor

  • nu (array) – frequencies in Hz

  • Nch (int) – number of channels. Shound be consistent with q, V, s.

  • pbcor (str) – ‘ALMA-12m’ for primary beam correction. Set None NOT to do it.

set_radialprofile(band, r, Tb, f_s, f_mean, nu, Nch, FWHM, Cov)
set_opacity(opac_dict, Na=1000, Nq=1000, smooth=True, log10_a_smooth=0.05, a_min=None, a_max=None)

Set dust opacity model.

This method allows you to define the dust opacity model using precomputed opacity data.

Parameters:
  • opac_dict (dict) – dictionary containing dust opacity data with keys ‘a’, ‘lam’, ‘k_abs’, ‘k_sca’, ‘g’

  • Na (int, optional) – number of dust size grid points. Defaults to 1000.

  • Nq (int, optional) – number of size distribution index grid points. Defaults to 1000.

  • smooth (bool, optional) – whether to apply smoothing to the opacity table. Defaults to True.

  • log10_a_smooth (float, optional) – smoothing scale in log10 grain size. Defaults to 0.05.

  • a_min (float, optional) – minimum grain size in microns. Defaults to the minimum grain size in the opacity data.

  • a_max (float, optional) – maximum grain size in microns. Defaults to the maximum grain size in the opacity data.

calc_model(parameters)

Compute model visibilities using the current parameters.

This method calculates the model visibilities and intensities for all observations based on the provided parameters.

Parameters:

parameters (dict) – dictionary of model parameters. Should contain keys corresponding to free and fixed parameters.

Returns:

dictionary of model visibilities for each band and observation. I_res (dict): dictionary of model intensities for each band and observation.

Return type:

V_res (dict)

calc_model_cv(MAP_results)

Compute model visibilities for cross-validation.

This method calculates the model visibilities for cross-validation using the MAP results.

Parameters:

MAP_results (results) – results object containing MAP samples and related information.

Returns:

dictionary of model visibilities for each band and observation, corrected for flux scaling.

Return type:

V_final (dict)

calc_chi2(MAP_results)

Compute chi-squared for cross-validation.

This method calculates the chi-squared value for cross-validation using the MAP results. Note that the MAP estimate should be done with the data splitted from the same dataset.

Parameters:

MAP_results (results) – results object containing MAP samples and related information.

Returns:

chi-squared value for the cross-validation.

Return type:

chi2 (float)

calc_model_tau(parameters)

Compute model optical depths

This method calculates the model optical depths for all observations based on the provided parameters.

Parameters:

parameters (dict) – dictionary of model parameters. Should contain keys corresponding to free and fixed parameters.

Returns:

dictionary of model optical depths for each band and observation.

Return type:

tau_res (dict)

class frap.model.observation(name, nu, kind='visibility')

class for containing observation data

kind = 'visibility'
class frap.model.inference(model)

class for inference methods

prior

method to show prior distributions

SVI_MAP

method to run SVI for MAP estimation

MCMC

method to run MCMC sampling

model
prior(num_samples=1, seed=None, calc_cond_num=False)

Show prior distributions for the latent parameters.

This method generates samples from the prior distributions of the latent parameters defined in the model.

Parameters:
  • num_samples (int, optional) – number of prior samples to generate. Defaults to 1.

  • seed (int, optional) – random seed for reproducibility. Defaults to None.

Returns:

results object containing prior samples and related information.

Return type:

prior (results)

SVI_MAP(num_iterations=1000, num_particles=1, adam_lr=0.01, uniform_radius=0.1, seed=None)

Run Stochastic Variational Inference (SVI) to find the Maximum A Posteriori (MAP) estimate of the latent parameters.

This method uses SVI with an AutoDelta guide to estimate the MAP of the latent parameters defined in the model.

Parameters:
  • num_iterations (int, optional) – number of SVI iterations. Defaults to 1000

  • num_particles (int, optional) – number of particles for ELBO estimation. Defaults to 1.

  • adam_lr (float, optional) – learning rate for the Adam optimizer. Defaults to 0.01.

  • uniform_radius (float, optional) – radius for uniform initialization of parameters. Defaults to 0.1.

  • seed (int, optional) – random seed for reproducibility. Defaults to None.

Returns:

results object containing MAP estimates and related information.

Return type:

svi_map_results (results)

MCMC(num_warmup, num_samples, step_size=1.0, num_chains=1, max_tree_depth=10, adapt_step_size=True, uniform_radius=0.1, seed=None)

Run MCMC sampling using the NUTS algorithm.

This method performs MCMC sampling to estimate the posterior distributions of the latent parameters defined in the model.

Parameters:
  • num_warmup (int) – number of warmup iterations.

  • num_samples (int) – number of MCMC samples to draw.

  • step_size (float, optional) – initial step size for the NUTS sampler. Defaults to 1.0.

  • num_chains (int, optional) – number of MCMC chains to run in parallel. Defaults to 1.

  • max_tree_depth (int, optional) – maximum tree depth for the NUTS sampler. Defaults to 10.

  • adapt_step_size (bool, optional) – whether to adapt the step size during warmup. Defaults to True.

  • uniform_radius (float, optional) – radius for uniform initialization of parameters. Defaults to 0.1.

  • seed (int, optional) – random seed for reproducibility. Defaults to None.

Returns:

results object containing posterior samples and related information.

Return type:

mcmc_results (results)

class frap.model.results(r, sample, logP, param_set)

class for storing inference results

r

radial grid points

sample

dictionary of samples

logP

dictionary of log probabilities

r
sample
logP
param_set
class frap.model.plot(results)

class for plotting results

sample_paths

method to plot sample paths

r
sample
sample_paths(key, nskip=100, plot_kwargs={'alpha': 0.5, 'lw': 1.0, 'color': 'royalblue'}, scatter_kwargs={'alpha': 0.5, 'color': 'royalblue'})

Plot sample paths for a given parameter key.

Parameters:
  • key (str) – parameter key to plot

  • nskip (int, optional) – number of samples to skip for plotting. Defaults to 100.

  • plot_kwargs (dict, optional) – keyword arguments for line plots. Defaults to {‘alpha’: 0.5, ‘lw’: 1.0, ‘color’:’roayalblue’}.

  • scatter_kwargs (dict, optional) – keyword arguments for scatter plots. Defaults to {‘alpha’: 0.5, ‘color’:’royalblue’}.

Returns:

None