Skip to content

Commit

Permalink
modifications towards FDR version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Orban de Xivry committed Jul 7, 2022
1 parent 5e9aaee commit 9c32585
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 99 deletions.
73 changes: 19 additions & 54 deletions config/config_demo_metis_compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,62 +43,34 @@
# # updates of pupil stops:
# # CVC L-band: ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits
# # CVC N2-band: ls_CVC_N2_119_dRext=0.0268_dRint=0.09_dRspi=0.0357.fits
# # RAVC L-band: ls_RAVC_L_285_dRext=0.0477_dRint=0.02_dRspi=0.0249.fits
# # RAVC L-band: ls_RAVC_L_285_dRext=0.0477_dRint=0.04_dRspi=0.0249.fits

# f_lyot_stop = _tmp_dir + 'pupil/ls_CVC_L_285_dRext=0.0291_dRint=0.08_dRspi=0.0317.fits', # lyot stop file
f_lyot_stop = _tmp_dir + 'pupil/ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits',

# RAVC LS L-band:
f_lyot_stop = _tmp_dir + 'pupil/ls_RAVC_L_285_dRext=0.0477_dRint=0.04_dRspi=0.0249.fits',

# RAVC amptlidue apodization
f_apodizer = _tmp_dir + 'pupil/apo_ring_r=0.5190_t=0.7909.fits',


# ======
# Photometry
# ======
noise = 2 , # 0: no noise, 1: photon noise only, 2: photon noise + background noise
# add_bckg = False, # true means background flux and photon noise are added
noise = 2 , # 0: no noise,
# 1: photon noise only,
# 2: photon noise + background noise
mag = 3, # star magnitude at selected band
# mag_ref = 0, # reference magnitude for star and background fluxes
wavelength = 3.81e-6 , # [m] wavelength
wavelength = 3.81e-6 , # [m] wavelength
flux_zpt = 8.999e+10, # [e-/s] zeropoint HCI-L long, mag 0 (Jan 21, 2020)
flux_bckg = 8.878e+4, # [e-/s/pix]
flux_bckg = 8.878e+4, # [e-/s/pix]
dit = 0.1, # [s] science detector integration time

#bands = 'L', #, 'M', 'N1', 'N2'],

# [GOX] this should be somewhere else: this is METIS default value and not supposed to be modified
# -> move to a 'constants.py' file or something of the like
# NB: 'band_specs' is not used by the code. Here for reference
band_specs = {
'L': {'lam': 3.81e-6,
# 'pscale': 5.47,
'flux_star': 8.999e+10, # HCI-L long
'flux_bckg': 8.878e+04},
'M': {'lam': 4.79e-6,
# 'pscale': 5.47,
'flux_star': 2.452e+10, # CO ref
'flux_bckg': 6.714e+05},
'N1': {'lam': 8.70e-6,
# 'pscale': 6.79,
'flux_star': 3.684e+10, # GeoSnap N1
'flux_bckg': 4.725e+07},
'N2': {'lam': 11.33e-6,
# 'pscale': 6.79,
'flux_star': 3.695e+10, # GeoSnap N2
'flux_bckg': 1.122e+08},
'N1a': {'lam': 8.67e-6,
# 'pscale': 10.78,
'flux_star': 2.979e+10, # Aquarius N1
'flux_bckg': 9.630e+07},
'N2a': {'lam': 11.21e-6,
# 'pscale': 10.78,
'flux_star': 2.823e+10, # Aquarius N2
'flux_bckg': 2.142e+08}
},

# ======
# AO parameters
# ======
ao_framerate = 1000 , # [Hz] framerate of the AO loop
ao_frame_decimation = 10, # Decimation of the WFS telemetry use by PSI, e.g. if =10, we use 1 every 10 WF frame
ao_frame_decimation = 10, # Decimation of the WFS telemetry use by PSI,
# e.g. if =10, we use 1 every 10 WF frame


# =========
Expand All @@ -111,30 +83,28 @@
# 1. all : no projection or filtering
# 2. zern : projection on theoretical Zernike mode (circ ap.) and modal control
# 3. dh : disk harmonics

psi_correction_mode = 'zern',
psi_nb_modes = 100, # (if modal) nb of modes
psi_start_mode_idx = 4, # (if modal) index of first mode. with Zernike, 4 means no piston and tip/tilt
psi_nb_modes = 100, # (if modal) nb of modes
psi_start_mode_idx = 4, # (if modal) index of first mode. with Zernike,
# 4 means no piston and tip/tilt


# Focal plane filtering
psi_filt_sigma = 0.05,
psi_filt_radius = 15, # [lbda/D]
psi_filt_radius = 15, # [lbda/D]

ncpa_expected_rms = 100, # expected NCPA in [nm]

# ============
# NCPA
# Only in simulation (CompassSimInstrument and HcipySimInstrument)
# ============
ncpa_dynamic = False ,
ncpa_sampling = 100, # [s] Dyn NCPA sampling
ncpa_scaling = 1, # scaling factor, if want to increase level
ncpa_expected_rms = 100, # expected NCPA in [nm]
ncpa_scaling = 1, # scaling factor, if want to increase level

ncpa_folder = './data/phase_screens/',
ncpa_prefix = "DIFF_rep_1_field_", # NB assumes units are in mm
# ncpa_suffix = '.fits'


# =============
# Residual turbulence
Expand All @@ -155,12 +125,7 @@
save_phase_screens = True,
save_basedir = './psi_results/',

check_psi_convergence = False,

)
# sort alphabetically
conf = {k: v for k, v in sorted(conf.items())}
conf = SimpleNamespace(**conf)
# from attrdict import AttrDict
# conf = AttrDict(conf)
# return conf
54 changes: 35 additions & 19 deletions config/config_metis_compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

conf = dict(

npupil = 256, # number of pixels of the pupil
det_size = 15, # [lam/D] size of the detector plane array
det_res = 4, # [px/ (lbda/D)] number of pixels per resolution element
npupil = 256, #285, # number of pixels of the pupil
det_size = 15, #14.875, # [lam/D] size of the detector plane array

# det_res should be None by default and computed based on the band_specs provdied below
# this in order to have the correct sampling wrt to the background noise.
det_res = 9.3, # [px/ (lbda/D)] number of pixels per resolution element

# --- Which type of instrument to use --
# Must be a class present in ``instruments.py``
Expand All @@ -30,7 +33,7 @@
# 1. mode = 'CVC' for Classical Vortex Coronagraph
# (2. mode = 'RAVC' for Ring Apodized Vortex Coronagraph)
# (3. mode = 'APP' for Apodizing Phase Plate)
inst_mode = 'ELT', # HCI instrument mode
inst_mode = 'CVC', # HCI instrument mode
vc_charge = 2, # (CVC and RAVC only) vortex topological charge
vc_vector = False, # (CVC and RAVC only) simulate a vector vortex instead of a scalar one

Expand All @@ -43,10 +46,17 @@
# # updates of pupil stops:
# # CVC L-band: ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits
# # CVC N2-band: ls_CVC_N2_119_dRext=0.0268_dRint=0.09_dRspi=0.0357.fits
# # RAVC L-band: ls_RAVC_L_285_dRext=0.0477_dRint=0.02_dRspi=0.0249.fits
# # RAVC L-band 20/05: ls_RAVC_L_285_dRext=0.0477_dRint=0.02_dRspi=0.0249.fits
# # RAVC L-band 22/06: ls_RAVC_L_285_dRext=0.0477_dRint=0.02_dRspi=0.0249.fits

# f_lyot_stop = _tmp_dir + 'pupil/ls_CVC_L_285_dRext=0.0291_dRint=0.08_dRspi=0.0317.fits', # lyot stop file
f_lyot_stop = _tmp_dir + 'pupil/ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits',
# f_lyot_stop = _tmp_dir + 'pupil/ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits',
# CVC LS L-band:
# f_lyot_stop = _tmp_dir+'pupil/ls_CVC_L_285_dRext=0.0209_dRint=0.09_dRspi=0.0245.fits',
f_lyot_stop = _tmp_dir+'pupil/ls_CVC_N2_119_dRext=0.0268_dRint=0.09_dRspi=0.0357.fits',

# RAVC LS L-band:
# f_lyot_stop = _tmp_dir + 'pupil/ls_RAVC_L_285_dRext=0.0477_dRint=0.04_dRspi=0.0249.fits',

# RAVC amptlidue apodization
f_apodizer = _tmp_dir + 'pupil/apo_ring_r=0.5190_t=0.7909.fits',
Expand All @@ -56,18 +66,22 @@
# ======
noise = 2 , # 0: no noise, 1: photon noise only, 2: photon noise + background noise
# add_bckg = False, # true means background flux and photon noise are added
mag = 3, # star magnitude at selected band
mag = -1.5, # star magnitude at selected band
# mag_ref = 0, # reference magnitude for star and background fluxes
wavelength = 3.81e-6 , # [m] wavelength
flux_zpt = 8.999e+10, # [e-/s] zeropoint HCI-L long, mag 0 (Jan 21, 2020)
flux_bckg = 8.878e+4, # [e-/s/pix]
dit = 0.1, # [s] science detector integration time

#bands = 'L', #, 'M', 'N1', 'N2'],
# --- the 3 following parameters should be replaced by the 'band_specs provided below'
wavelength = 11.33e-6, #3.81e-6 , # [m] wavelength
flux_zpt = 3.695e10, #8.999e+10, # [e-/s] zeropoint HCI-L long, mag 0 (Jan 21, 2020)
flux_bckg = 1.122e8, #8.878e+4, # [e-/s/pix]

dit = 0.04, # [s] science detector integration time

# TODO METIS photometry should be defined in a separate file and the user should not have
# to provide 'wavelength', 'flux_zpt', 'flux_bckg', but just 'METIS-L' or 'METIS-N' for example.
# [GOX] this should be somewhere else: this is METIS default value and not supposed to be modified
# -> move to a 'constants.py' file or something of the like
# NB: 'band_specs' is not used by the code. Here for reference
#bands = 'L', #, 'M', 'N1', 'N2'],
band_specs = {
'L': {'lam': 3.81e-6,
# 'pscale': 5.47,
Expand Down Expand Up @@ -106,7 +120,7 @@
# PSI
# =========
psi_framerate = 1, # [Hz] framerate of the psi correction
psi_nb_iter = 30, # number of iterations.
psi_nb_iter = 60, # number of iterations.

# How is the PSI estimate process before correction:
# 1. all : no projection or filtering
Expand All @@ -124,15 +138,16 @@
psi_filt_sigma = 0.05,
psi_filt_radius = 10, # [lbda/D]

# PSI scaling --- because of unknown scaling factor of NCPA
ncpa_expected_rms = 50, #250, # expected NCPA in [nm]

# ============
# NCPA
# Only in simulation (CompassSimInstrument and HcipySimInstrument)
# ============
ncpa_dynamic = True ,
ncpa_dynamic = False ,
ncpa_sampling = 100, # [s] Dyn NCPA sampling
ncpa_scaling = 1, # scaling factor, if want to increase level
ncpa_expected_rms = 100, # expected NCPA in [nm]
ncpa_scaling = 1., # scaling factor, if want to increase level

ncpa_folder = '/Users/orban/Projects/METIS/4.PSI/legacy_TestArea/NCPA_Tibor/',
ncpa_prefix = "DIFF_rep_1_field_", # NB assumes units are in mm
Expand All @@ -153,13 +168,14 @@
# Water vapour seeing
wv = False,
wv_folder = '/Users/orban/Projects/METIS/4.PSI/legacy_TestArea/WaterVapour/phases/',
wv_cubename = 'cube_Cbasic_20210504_600s_100ms_0piston_meters_scao_only_285_WVLonly_qacits.fits', # NB assume units are in meters
#'cube_Cbasic_20210504_600s_100ms_0piston_meters_scao_only_285_WVLonly_qacits.fits'
wv_cubename = 'cube_Cbasic_20210504_600s_100ms_0piston_meters_scao_only_285_WVNonly_qacits.fits', #'cube_Cbasic_20210504_600s_100ms_0piston_meters_scao_only_285_WVLonly_qacits.fits', # NB assume units are in meters
wv_sampling = 100, #[ms] sampling of the cube
wv_scaling = 1, # scale factor, if want to change the level
wv_scaling = 1, #1/100, # scale factor, if want to change the level
# =============
# Saving results
save_loop_statistics = True,
save_phase_screens = True,
save_phase_screens = False,
save_basedir = '/Users/orban/Projects/METIS/4.PSI/psi_results/',

check_psi_convergence = False,
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Welcome to PSI's documentation!
:maxdepth: 3
:caption: Contents:

psiSensor.rst
instruments.rst
configParser.rst
psiSensor
instruments
configParser


Indices and tables
Expand Down
22 changes: 21 additions & 1 deletion psi/configParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,32 @@ def readfile(self):
self.params = conf

def check_parameters(self):
# TODO had a check that the Lyot stop is for the correct mode and band
# look at the file name and search for strings

# check, based on the band, that the zeropoint is according to defined 'constants'
# otherwise print a 'warning'
if self.params.inst_mode == 'CVC':
# if self.params.band == 'L':
if os.path.basename(self.params.f_lyot_stop)[0:8] != 'ls_CVC_L':
self.logger.warn(('Lyot stop fname does not seem to match for {0}'
'Please check the filename').format(self.params.inst_mode))
# if self.params.band == 'N':
# if os.path.basename(self.params.f_lyot_stop)[0:8] != 'ls_CVC_N':
# self.logger(('Lyot stop fname does not seem to match for {0}.'
# ' Please check the filename').format(self.params.inst_mode))
elif self.params.inst_mode == 'RAVC':
# if self.params.band == 'L':
if os.path.basename(self.params.f_lyot_stop)[0:9] != 'ls_RAVC_L':
self.logger.warn(('Lyot stop fname does not seem to match for {0}'
' Please check the filename').format(self.params.inst_mode))
# if self.params.band == 'N':
# if os.path.basename(self.params.f_lyot_stop)[0:8] != 'ls_RAVC_N':
# self.logger(('Lyot stop fname does not seem to match for {0}.'
# ' Please check the filename').format(self.params.inst_mode))

assert self.params.det_size >= self.params.psi_filt_radius


# PSI correction mode checks
if self.params.psi_correction_mode == 'zern':
if hasattr(self.params, 'psi_nb_modes') is False:
Expand Down
23 changes: 12 additions & 11 deletions psi/helperFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
import shutil
import datetime
import getpass
import colored
# import colored
from colorama import Fore

class LazyLogger(object):
def __init__(self, name=''):
self._name = name
pass

def debug(self, msg):
print(("{0} - " + colored.fg("blue") +
"[Debug]: " + colored.fg("black")).format(self._name) , msg)
print(("{0} - " + Fore.CYAN +
"[Debug]: " + Fore.RESET).format(self._name) , msg)

def notice(self, msg):
print(("{0} - " + colored.fg("green") +
"[Info]: " + colored.fg("black")).format(self._name) , msg)
print(("{0} - " + Fore.GREEN +
"[Info]: " + Fore.RESET).format(self._name) , msg)

def info(self, msg):
self.notice(msg)

def warning(self, msg):
print(("{0} - " + colored.fg("orange_1") +
"[Warning]: " + colored.fg("black")).format(self._name) , msg)
print(("{0} - " + Fore.YELLOW +
"[Warning]: "+ Fore.RESET).format(self._name) , msg)

def warn(self, msg):
print(("{0} - " + colored.fg("orange_1") +
"[Warning]: " + colored.fg("black")).format(self._name) , msg)
print(("{0} - " + Fore.YELLOW +
"[Warning]: " + Fore.RESET).format(self._name) , msg)

def error(self, msg):
print(("{0} - " + colored.fg("red") +
"[Error]: " + colored.fg("black")).format(self._name) , msg)
print(("{0} - " + Fore.RED +
"[Error]: " + Fore.RESET).format(self._name) , msg)


def timeit(func):
Expand Down
10 changes: 10 additions & 0 deletions psi/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, conf):

self.phase_ncpa = hcipy.Field(0.0, self.pupilGrid) # knowledge only in Simulation
self.phase_wv = hcipy.Field(0.0, self.pupilGrid) # knowledge only in Simulation
self.phase_wv_integrated = hcipy.Field(0.0, self.pupilGrid) # knowledge only in Simulation
self.phase_ncpa_correction = hcipy.Field(0.0, self.pupilGrid) # NCPA correction applied

pass
Expand Down Expand Up @@ -329,6 +330,7 @@ def _initialize_water_vapour(self):
size_pupil_grid,
self.aperture, rotate=True)
self.phase_wv *= self.wv_scaling
self.phase_wv_integrated = self.phase_wv
# folder_wv = '/Users/orban/Projects/METIS/4.PSI/legacy_TestArea/WaterVapour/phases/'
# file_wv = "cube_Cbasic_20210504_600s_100ms_0piston_meters_scao_only_285_WVLonly_qacits.fits"
# wave_vapour_cube = fits.getdata(os.path.join(folder_wv, file_wv)) * \
Expand Down Expand Up @@ -366,8 +368,14 @@ def grabScienceImages(self, nbOfPastSeconds):
# re-initialize timer of single dit
self._start_time_last_sci_dit = np.copy(self._start_time_sci_buffer)
self._end_time_last_sci_dit = np.copy(self._start_time_sci_buffer)

if self.include_water_vapour :
self.phase_wv_integrated = 0
self.nb_wv_integrated = 0
for i in range(self.nbOfSciImages):
image_buffer[i] = self._grabOneScienceImage()
if self.include_water_vapour :
self.phase_wv_integrated /= self.nb_wv_integrated

self._end_time_sci_buffer = np.copy(self._end_time_last_sci_dit)
return image_buffer
Expand Down Expand Up @@ -429,6 +437,8 @@ def _grabOneScienceImage(self):
# Update water vapour phase
if self.include_water_vapour :
self._update_water_vapour(self._start_time_last_sci_dit + timeIdxInMs[i])
self.phase_wv_integrated += self.phase_wv
self.nb_wv_integrated += 1

# Update NCPA phase
if self.ncpa_dynamic :
Expand Down
Loading

0 comments on commit 9c32585

Please sign in to comment.