# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Run MCFOST and examine its outputs

# +
import glob, getpass, sys, os
sys.path.append('../library/')

import numpy as np
import matplotlib.pyplot as plt
from mcfost_dust   import Dust   as McDust
from mcfost_polimg import ImgPol as McImg
# -

wave   = 0.5 # default, this valus is overwritten if MCFOST is executet
RUN_MC = False

# ## Execute MCFOST

# MCFOTS terminal messages are print in the terminal where this Notebook is executed
if RUN_MC:
    para = '../para_files/test_21_10_2019.para'
    wave = np.float(input('Introduce wavelength [microms]: '))
    text = f'Executing MCFOST for wavelength {wave} [microns]'
    print('=' * len(text))
    print(text)
    print('=' * len(text))
    os.system(f'sh doit.sh {para} {wave}')

# By default the code examine the latest directory
mcdirs = glob.glob('mcfostout_*')
mcdirs.sort()
newest_run = mcdirs[-1] + '/'

# ## Examine DUST Phase Function & Polarisation properties 

# +
# Read MCFOST OUTPUT: DUST PROPERTIES ===================
# mcfost_out = McDust(newest_run)
# mcfost_out.read_all()
# mcfost_out.plot_scat()
# -

# ## Examine Polarised Images

imgs = McImg(newest_run, wave)
imgs.read_fitscube()
imgs.get_dims()
imgs.get_imgs()
imgs.make_PSF(gauss_kernel = 2)
imgs.convolve()
imgs.add_noise(SN = 3)
imgs.make_pol()
imgs.plot_pol_imgs() # From Left to right: Disc in Intensity (total scattered light), Stokes Q, Stokes U, P_I = sqrt(Q*Q + U*U)

# +
# TO DO (after Francois explains me/us how to load the experimental matrices to MCFOST):
# 1) Add image labels, create option to save images in pdf, remove/change axes, etc etc                 >>>>> DONE
# 2) Convolve with Gaussian to emulate real observations                                                >>>>> DONE
# 3) Add photon/gaussian noise to emulate real observations                                             >>>>> DONE
# 4) Zoom-in images (I zooom-in afterwards to not lose spatial resolution when MCFOST computes the grid)

StarcoderdataJupyterScriptsDedupFiltered