Commit 7eb821ef authored by rfetick's avatar rfetick
Browse files

use .ini instead of.yml instrument files

parent b57ce29e
[metadata]
; Tag
tag = "muse_nfm"
tag = muse_nfm
; Human readable name
name = "VLT MUSE (NFM)"
name = VLT MUSE (NFM)
[telescope]
; Primary diameter [m]
......
d: 8.0
filters: {}
fullname: VLT MUSE (NFM)
gain: 5.0
nact: 34
name: MUSE_NFM
occ: 0.14
phasemask_path: null
phasemask_shift: !!python/tuple
- 0.0
- 0.0
res: 1.1977272727272726e-07
ron: 15.0
[metadata]
; Tag
tag = "muse_wfm"
tag = muse_wfm
; Human readable name
name = "VLT MUSE (WFM)"
name = VLT MUSE (WFM)
[telescope]
; Primary diameter [m]
......
d: 8.0
filters: {}
fullname: VLT MUSE (WFM)
gain: 5.0
nact: 34
name: MUSE_WFM
occ: 0.14
phasemask_path: null
phasemask_shift: !!python/tuple
- 0.0
- 0.0
res: 9.698196540301804e-07
ron: 15.0
[metadata]
; Tag
tag = "zimpol"
tag = zimpol
; Human readable name
name = "VLT SPHERE/Zimpol"
name = VLT SPHERE/Zimpol
[telescope]
; Primary diameter [m]
......
d: 8.0
filters:
N_R: !!python/tuple
- 6.459e-07
- 5.6700000000000005e-08
V: !!python/tuple
- 5.54e-07
- 8.06e-08
fullname: VLT SPHERE/ZIMPOL
gain: 10.5
nact: 40
name: ZIMPOL
occ: 0.14
phasemask_path: null
phasemask_shift: !!python/tuple
- 0.0
- 0.0
res: 1.69683257918552e-08
ron: 20.0
......@@ -24,7 +24,7 @@ from maoppy.instrument import muse_nfm
npix = 128 # pixel size of PSF
wvl = 600*1e-9 # wavelength [m]
flux = 1e5
flux = 1e4
ron = muse_nfm.ron
bckgd = 1.0
......@@ -34,8 +34,8 @@ Pmodel = Psfao((npix,npix),system=muse_nfm,samp=samp)
#%% Generate a MUSE-NFM PSF
r0 = 0.15 # Fried parameter [m]
b = 1e-7 # Phase PSD background [rad² m²]
amp = 1.4 # Phase PSD Moffat amplitude [rad²]
b = 1e-2 # Phase PSD background [rad² m²]
amp = 3.0 # Phase PSD Moffat amplitude [rad²]
alpha = 0.1 # Phase PSD Moffat alpha [1/m]
ratio = 1.0
theta = 0.0
......@@ -49,7 +49,7 @@ noise = ron*np.random.randn(npix,npix)
image = flux*psf + bckgd + noise
#%% Fit the PSF with Psfao
guess = [0.145,2e-7,1.2,0.08,ratio,theta,1.5]
guess = [0.145,2e-2,1.2,0.08,ratio,theta,1.5]
w = np.ones_like(image)/ron**2.0
fixed = [False,False,False,False,True,True,False]
......
......@@ -32,9 +32,9 @@ from maoppy.instrument import muse_nfm
npix = 128 # pixel size of PSF
wvl = 600*1e-9 # wavelength [m]
flux = 1e6
flux = 1e4
ron = muse_nfm.ron
bckgd = 10.0
bckgd = 1.0
#%% Initialize PSF model
samp = muse_nfm.samp(wvl) # sampling (2.0 for Shannon-Nyquist)
......@@ -42,8 +42,8 @@ Pmodel = Psfao((npix,npix),system=muse_nfm,samp=samp)
#%% Generate a MUSE-NFM PSF
r0 = 0.15 # Fried parameter [m]
b = 1e-7 # Phase PSD background [rad² m²]
amp = 1.4 # Phase PSD Moffat amplitude [rad²]
b = 1e-2 # Phase PSD background [rad² m²]
amp = 3.0 # Phase PSD Moffat amplitude [rad²]
alpha = 0.1 # Phase PSD Moffat alpha [1/m]
ratio = 1.0 # Phase PSD Moffat ellipticity
theta = 0.0 # Phase PSD Moffat angle
......@@ -57,12 +57,12 @@ noise = ron*np.random.randn(npix,npix)
image = flux*psf + bckgd + noise
#%% Crop the image
ncrop = 32
ncrop = 40
im_crop = image[npix//2-ncrop//2:npix//2+ncrop//2,
npix//2-ncrop//2:npix//2+ncrop//2]
#%% Fit the cropped image with Psfao
guess = [0.145,2e-7,1.2,0.08,ratio,theta,1.5]
guess = [0.145,2e-2,1.2,0.08,ratio,theta,1.5]
w = np.ones_like(im_crop)/ron**2.0
fixed = [False,False,False,False,True,True,False]
......
......@@ -8,8 +8,7 @@ Created on Mon May 27 17:30:51 2019
import sys
import os
import yaml
from configparser import ConfigParser
from astropy.io import fits
import numpy as np
from scipy.interpolate import interp2d
......@@ -17,13 +16,6 @@ from scipy.interpolate import interp2d
from maoppy.utils import circarr as _circarr
from maoppy.utils import RAD2ARCSEC as _RAD2ARCSEC
def _get_data_folder():
folder = os.path.abspath(__file__)
folder = os.sep.join(folder.split(os.sep)[0:-1])+os.sep+'data'+os.sep
return folder
#%% INSTRUMENT CLASS
class Instrument:
"""Represents an optical system (telescope to detector)
......@@ -48,7 +40,7 @@ class Instrument:
Pixel binning factor (default=1)
"""
def __init__(self, D=None, occ=0., res=None, Nact=0, gain=1., ron=0.):
def __init__(self, D=None, occ=0., res=None, Nact=0, gain=1., ron=1.):
if D is None:
raise ValueError("Please enter keyword `D` to set Instrument's aperture diameter")
......@@ -136,42 +128,63 @@ class Instrument:
"""Returns wavelength for the given sampling"""
return samp*(self.resolution_rad*self.D)
def to_yaml(self,filename):
"""Save current instrument as YAML"""
data = {}
data['name'] = self.name
data['fullname'] = self.fullname
data['d'] = self.D
data['occ'] = self.occ
data['res'] = self.resolution_rad
data['gain'] = self.gain
data['ron'] = self.ron
data['nact'] = self.Nact
data['filters'] = self.filters
data['phasemask_path'] = self.phasemask_path
data['phasemask_shift'] = self.phasemask_shift
with open(filename,'w') as f:
yaml.dump(data,f)
#%% LOAD INSTRUMENT INSTANCES (make them attributes of this module)
# this might be clumsy, should I make something like this:
# from maoppy.instrument import load_instrument
# zimpol = load_instrument("zimpol")
def _get_data_folder():
folder = os.path.abspath(__file__)
folder = os.sep.join(folder.split(os.sep)[0:-1])+os.sep+'data'+os.sep
return folder
def _get_all_ini(pth):
return [f for f in os.listdir(pth) if f.endswith('.ini')]
def load_ini(pth):
"""Create an Instrument instance from a path to a .ini file"""
config = ConfigParser()
config.optionxform = str
try:
config.read(pth)
except:
raise FileNotFoundError("The instrument file has not been found")
# [metadata]
tag = config['metadata']['tag']
name = config['metadata']['name']
# [telescope]
d = float(config['telescope']['d'])
occ = float(config['telescope']['occ'])
# [ao]
nact = int(config['ao']['nact'])
# [camera]
res_mas = float(config['camera']['res_mas'])
# [filters]
filters = {}
if 'filters' in config.keys():
for filt in config['filters']:
s = config['filters'][filt]
wvl_central,width = s[1:-1].split(',')
filters[filt] = (float(wvl_central)*1e-9,float(width)*1e-9)
# Make instrument
res_rad = res_mas*1e-3 / _RAD2ARCSEC
instru = Instrument(D=d,occ=occ,res=res_rad,Nact=nact)
instru.name = tag
instru.fullname = name
instru.filters = filters
return instru
_this_module = sys.modules[__name__]
_d = _get_data_folder()
_l = [_f for _f in os.listdir(_d) if _f.endswith('.yml')]
for _f in _l:
with open(_d+_f,'r') as _fi:
_i = yaml.full_load(_fi)
_instru = Instrument(D=_i['d'],occ=_i['occ'],res=_i['res'],gain=_i['gain'],ron=_i['ron'],Nact=_i['nact'])
_instru.name = _i['name']
_instru.fullname = _i['fullname']
_instru.filters = _i['filters']
_instru.phasemask_path = _i['phasemask_path']
_instru.phasemask_shift = _i['phasemask_shift']
_n = _i['name'].lower().replace(" ","_") # format name
for _f in _get_all_ini(_d):
_instru = load_ini(_d+_f)
_n = _instru.name.lower().replace(" ","_") # format name
setattr(_this_module, _n, _instru)
del _this_module, _d, _l, _f, _instru, _fi, _i, _n
del _this_module, _d, _f, _instru, _n
......@@ -15,8 +15,8 @@ setup(name='maoppy',
author='Romain JL Fetick (LAM, Marseille, France)',
author_email='romain.fetick@lam.fr',
description='Modelization of the Adaptive Optics Psf in PYthon (MAOPPY)',
package_data={'maoppy': ['data/*.yml']},
package_data={'maoppy': ['data/*.ini']},
include_package_data=True,
packages=find_packages(exclude=['example','test']),
requires=['numpy','scipy','astropy','pyyaml'],
requires=['numpy','scipy','astropy'],
zip_safe=False)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment