One observation : AB Pic b

This tutorial is intended as a quick start when using a single observation.

We will use medium resolution VLT/SINFONI K-band data of AB Pic b. These observations and example model were published in P. Palma-Bifani et al (2023).

Imports

[1]:
# Generic packages
import time, os
import matplotlib.pyplot as plt

# ForMoSA modules
# For the interpolation & sampling
from ForMoSA.global_file import GlobFile
from ForMoSA.adapt.adapt_obs_mod import launch_adapt
from ForMoSA.nested_sampling.nested_sampling import launch_nested_sampling
# For the plots
from ForMoSA.plotting.plotting_class import PlottingForMoSA

0. Setup

You need to create a config file with extension .ini and modify the parameters. Learn more about our config files in it’s specific tutorial.

To initialize ForMoSA we need to read the config.ini file and setup the outputs directory and global parameters as follows.

Here we also create a sub-directory. This can be usefull when doing multiple tests on the same target.

[ ]:
base_path = '/home/mravet/Documents/These/FORMOSA/OUTPUTS/Channel1/'

# CONFIG_FILE
# reading and defining global parameters
config_file_path = base_path + 'config_ABPicb.ini'
global_params = GlobFile(config_file_path)

# Optional: Add "time_now" and "save_name" to avoid overwriting results
time_now = time.strftime("%Y%m%d_%H%M%S")
save_name = 'test'

# Create directory to save the outputs
global_params.result_path = global_params.result_path+ save_name+'_t' + time_now+'/'
os.makedirs(global_params.result_path)

# Overwrite some parameters
global_params.config.filename = global_params.result_path + 'config_used.ini'
global_params.config['config_path']['result_path']=global_params.result_path
global_params.config.write()

1. Interpolate the grid

Once everything is setup, we start by adapting the models and observations.

The grid of models is interpolated for this, but you don’t need to repeat this step once you’ve adapted the grid for a specific dataset.

(Answer ‘no’ only the first time)

[ ]:
# Have you already interpolated the grids for this data?
t_f_par = False
#t_f_par = True # Only answer True the first time, then comment to save time

launch_adapt(global_params, adapt_grid=t_f_par)

2. Lunch Nested Sampling

Once the grid is interpolated, we proceed with the nested sampling. For this case we are using the Python package nestle.

[5]:
launch_nested_sampling(global_params)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-> Likelihood functions check-ups

test_data_ABPicb will be computed with chi2

Done !

it=  2169 logz=-788.68245842
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-> Nestle

The code spent 34.9 min to run.
niter: 2170
ncall: 46932
nsamples: 2270
logz: -788.170 +/-  0.440
h: 19.343


3. Plotting the outcomes

ForMoSA has been designed with a plotting class. Bellow we show 4 main features:

  • Plotting corner-plots

  • Plotting spectra and residuals

  • Plotting chains

  • Plotting radar

  • Plotting PT and vmr (if you have the corresponding grids !!)

  • Accessing the different parameters

All plotting functions return the fig object. Therefore you can edit the axes, overplot text/curves, save, etc…

We need to start by initializing the plotting class as follows.

[6]:
# Path to output file created in the first step
config_file_path_pl = base_path + '/test_t20250423_225135'

# Initialize the plotting class and set the color
plotForMoSA = PlottingForMoSA(config_file_path_pl+'/config_used.ini', 'red')
plotForMoSA._get_posteriors(burn_in=0) # Burn in controls how much of the convergence chain you keep to estimate your final values

Plot Corner

[7]:
fig = plotForMoSA.plot_corner(levels_sig=[0.997, 0.95, 0.68], bins=100, quantiles=(0.16, 0.5, 0.84))
plt.show()
ForMoSA - Corner plot
../_images/tutorials_demoabpic_11_1.png

Plot Spectrum and Residuals

[10]:
fig, ax, axr, axr2 = plotForMoSA.plot_fit(figsize=(10, 5), uncert='no', trans='no', logy='no', logx='no', norm='no')

# You can modify the different axes and includ further plotting features
axr.set_ylim(-5,5)

#plt.savefig('')
plt.show()
ForMoSA - Best fit and residuals plot
../_images/tutorials_demoabpic_13_1.png

Plot Chains of posteriors

[11]:
fig, axs = plotForMoSA.plot_chains(figsize=(10,6))
plt.show()
ForMoSA - Posteriors chains for each parameter
../_images/tutorials_demoabpic_15_1.png

Plot Radar

[12]:
fig = plotForMoSA.plot_radar([(1000, 2000),
                        (3., 5.),
                        (-0.5, 1.0),
                        (0.1, 0.8),
                        (-50, 50),
                        (0,100)])
ForMoSA - Radar plot
/home/mravet/ForMoSA/ForMoSA/plotting/plotting_class.py:420: UserWarning: No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
  radar.ax.legend(loc='center', bbox_to_anchor=(0.5, -0.20),frameon=False, ncol=2)
../_images/tutorials_demoabpic_17_2.png

Access information

You can access different parametes since we are working with a class

[ ]:
posteriors_chains = plotForMoSA.posterior_to_plot
posteriors_names = plotForMoSA.posteriors_names