Skip to content
Snippets Groups Projects
Commit 4ac10797 authored by rfetick's avatar rfetick
Browse files

instruments are defined in .yml files

parent fe0b6f21
No related branches found
No related tags found
No related merge requests found
d: 8.0
filters: {}
fullname: VLT MUSE (NFM)
gain: 5.0
nact: 39
name: MUSE_NFM
occ: 0.14
phasemask_path: null
res: 1.1977272727272726e-07
ron: 15.0
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
res: 1.69683257918552e-08
ron: 20.0
...@@ -13,11 +13,13 @@ import matplotlib.pyplot as plt ...@@ -13,11 +13,13 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
from maoppy.psfmodel import Psfao from maoppy.psfmodel import Psfao
from maoppy.instrument import MUSE_NFM from maoppy.instrument import load
Npix = 128 # pixel size of PSF Npix = 128 # pixel size of PSF
wvl = 600*1e-9 # wavelength [m] wvl = 600*1e-9 # wavelength [m]
MUSE_NFM = load('muse_nfm')
#%% Initialize PSF model #%% Initialize PSF model
samp = MUSE_NFM.samp(wvl) # sampling (2.0 for Shannon-Nyquist) samp = MUSE_NFM.samp(wvl) # sampling (2.0 for Shannon-Nyquist)
Pmodel = Psfao((Npix,Npix),system=MUSE_NFM,samp=samp) Pmodel = Psfao((Npix,Npix),system=MUSE_NFM,samp=samp)
......
...@@ -18,7 +18,9 @@ import matplotlib.pyplot as plt ...@@ -18,7 +18,9 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
from maoppy.psfmodel import Psfao, psffit, rmserror from maoppy.psfmodel import Psfao, psffit, rmserror
from maoppy.instrument import MUSE_NFM from maoppy.instrument import load
MUSE_NFM = load('muse_nfm')
npix = 128 # pixel size of PSF npix = 128 # pixel size of PSF
wvl = 600*1e-9 # wavelength [m] wvl = 600*1e-9 # wavelength [m]
......
...@@ -26,7 +26,9 @@ from matplotlib.patches import Rectangle ...@@ -26,7 +26,9 @@ from matplotlib.patches import Rectangle
import numpy as np import numpy as np
from maoppy.psfmodel import Psfao, psffit, rmserror from maoppy.psfmodel import Psfao, psffit, rmserror
from maoppy.instrument import MUSE_NFM from maoppy.instrument import load
MUSE_NFM = load('muse_nfm')
npix = 128 # pixel size of PSF npix = 128 # pixel size of PSF
wvl = 600*1e-9 # wavelength [m] wvl = 600*1e-9 # wavelength [m]
......
...@@ -15,7 +15,9 @@ import numpy as np ...@@ -15,7 +15,9 @@ import numpy as np
from maoppy.utils import imcenter, circavgplt from maoppy.utils import imcenter, circavgplt
from maoppy.psfmodel import psffit, Psfao from maoppy.psfmodel import psffit, Psfao
from maoppy.instrument import ZIMPOL from maoppy.instrument import load
ZIMPOL = load('zimpol')
# %% PARAMETERS TO MODIFY # %% PARAMETERS TO MODIFY
psf_path = "path/to/your/zimpol_psf.fits" # set the path to your PSF *.fits file psf_path = "path/to/your/zimpol_psf.fits" # set the path to your PSF *.fits file
......
...@@ -6,13 +6,14 @@ Created on Mon May 27 17:30:51 2019 ...@@ -6,13 +6,14 @@ Created on Mon May 27 17:30:51 2019
@author: rfetick @author: rfetick
""" """
from maoppy.utils import circarr, airy, RAD2ARCSEC from maoppy.utils import circarr, RAD2ARCSEC
import yaml import yaml
import os
#%% INSTRUMENT CLASS AND ITS SUBCLASSES #%% INSTRUMENT CLASS AND ITS SUBCLASSES
class Instrument(object): class Instrument(object):
"""Represents an optical system """Represents an optical system (telescope to detector)
Attributes Attributes
---------- ----------
...@@ -42,7 +43,7 @@ class Instrument(object): ...@@ -42,7 +43,7 @@ class Instrument(object):
if res <= 0: raise ValueError("Keyword `res` must be strictly positive") if res <= 0: raise ValueError("Keyword `res` must be strictly positive")
self.D = D self.D = D
self.occ = occ # occultation ratio self.occ = occ # occultation diameter ratio
self.filters = {} self.filters = {}
self.Nact = Nact self.Nact = Nact
...@@ -54,6 +55,9 @@ class Instrument(object): ...@@ -54,6 +55,9 @@ class Instrument(object):
self.name = "default" # unique identifier name self.name = "default" # unique identifier name
self.fullname = "MAOPPY Instrument" # human readable name self.fullname = "MAOPPY Instrument" # human readable name
# phasemask (not used yet)
self.phasemask_path = None
def __repr__(self): def __repr__(self):
s = "---------------------------------\n" s = "---------------------------------\n"
s += self.fullname+"\n" s += self.fullname+"\n"
...@@ -92,21 +96,9 @@ class Instrument(object): ...@@ -92,21 +96,9 @@ class Instrument(object):
def wvl(self,samp): def wvl(self,samp):
"""Returns wavelength for the given sampling""" """Returns wavelength for the given sampling"""
return samp*(self.resolution_rad*self.D) return samp*(self.resolution_rad*self.D)
def PSFdl(self,Npix,wvl):
"""Returns the diffraction limited PSF
Parameters
----------
Npix : tuple, list of 2 elements
Size of the output 2D array
wvl : float
Observation wavelength
"""
return airy(Npix,self.samp(wvl),self.occ)
def to_yaml(self,filename): def to_yaml(self,filename):
"""Save current instrument as YAML"""
data = {} data = {}
data['name'] = self.name data['name'] = self.name
data['fullname'] = self.fullname data['fullname'] = self.fullname
...@@ -117,19 +109,34 @@ class Instrument(object): ...@@ -117,19 +109,34 @@ class Instrument(object):
data['ron'] = self.ron data['ron'] = self.ron
data['nact'] = self.Nact data['nact'] = self.Nact
data['filters'] = self.filters data['filters'] = self.filters
data['phasemask_path'] = self.phasemask_path
with open(filename,'w') as f: yaml.dump(data,f) with open(filename,'w') as f: yaml.dump(data,f)
# TODO: create instruments from a config file # TODO: manage phasemask
# add phasemask path to config
ZIMPOL = Instrument(D=8.,occ=0.14,res=30*1e-6/1768.,gain=10.5,ron=20.,Nact=40) def load(name):
ZIMPOL.filters["V"] = (554*1e-9, 80.6*1e-9) """Load an instrument saved in the `data` folder of MAOPPY"""
ZIMPOL.filters["N_R"] = (645.9*1e-9, 56.7*1e-9) folder = os.path.abspath(__file__)
ZIMPOL.name = "ZIMPOL" folder = os.sep.join(folder.split(os.sep)[0:-1])+os.sep+'data'+os.sep
ZIMPOL.fullname = "VLT SPHERE/ZIMPOL" with open(folder+name.lower()+".yml",'r') as f:
d = yaml.full_load(f)
instru = Instrument(D=d['d'],occ=d['occ'],res=d['res'],gain=d['gain'],ron=d['ron'],Nact=d['nact'])
instru.name = d['name']
instru.fullname = d['fullname']
instru.filters = d['filters']
instru.phasemask_path = d['phasemask_path']
return instru
#%% OLD WAY to LOAD INSTRUMENTS (now use the `load` function)
MUSE_NFM = Instrument(D=8.,occ=0.14,res=237.15*1e-6/1980.,gain=5.,ron=15.,Nact=39) #ZIMPOL = Instrument(D=8.,occ=0.14,res=30*1e-6/1768.,gain=10.5,ron=20.,Nact=40)
MUSE_NFM.name = "MUSE_NFM" #ZIMPOL.filters["V"] = (554*1e-9, 80.6*1e-9)
MUSE_NFM.fullname = "VLT MUSE (NFM)" #ZIMPOL.filters["N_R"] = (645.9*1e-9, 56.7*1e-9)
#ZIMPOL.name = "ZIMPOL"
#ZIMPOL.fullname = "VLT SPHERE/ZIMPOL"
#
#
#MUSE_NFM = Instrument(D=8.,occ=0.14,res=237.15*1e-6/1980.,gain=5.,ron=15.,Nact=39)
#MUSE_NFM.name = "MUSE_NFM"
#MUSE_NFM.fullname = "VLT MUSE (NFM)"
...@@ -9,7 +9,7 @@ Created on Fri May 8 20:21:20 2020 ...@@ -9,7 +9,7 @@ Created on Fri May 8 20:21:20 2020
import unittest import unittest
import numpy as np import numpy as np
from maoppy.psfmodel import lsq_flux_bck, moffat, gauss, Psfao from maoppy.psfmodel import lsq_flux_bck, moffat, gauss, Psfao
from maoppy.instrument import MUSE_NFM, ZIMPOL from maoppy.instrument import load
class TestLsqFluxBck(unittest.TestCase): class TestLsqFluxBck(unittest.TestCase):
def test_fluxbck(self): def test_fluxbck(self):
...@@ -55,7 +55,7 @@ class TestPsfao(unittest.TestCase): ...@@ -55,7 +55,7 @@ class TestPsfao(unittest.TestCase):
def test_oversampling(self): def test_oversampling(self):
npix = 100 npix = 100
samp = 0.3 samp = 0.3
P = Psfao((npix,npix),system=MUSE_NFM,samp=samp) P = Psfao((npix,npix),system=load('muse_nfm'),samp=samp)
self.assertEqual(samp,P.samp) self.assertEqual(samp,P.samp)
self.assertGreaterEqual(P._samp_over,2.0) self.assertGreaterEqual(P._samp_over,2.0)
self.assertEqual(P._k%1,0) self.assertEqual(P._k%1,0)
...@@ -63,14 +63,14 @@ class TestPsfao(unittest.TestCase): ...@@ -63,14 +63,14 @@ class TestPsfao(unittest.TestCase):
def test_bounds_length(self): def test_bounds_length(self):
npix = 100 npix = 100
samp = 0.3 samp = 0.3
P = Psfao((npix,npix),system=MUSE_NFM,samp=samp) P = Psfao((npix,npix),system=load('muse_nfm'),samp=samp)
self.assertEqual(len(P.bounds[0]),7) self.assertEqual(len(P.bounds[0]),7)
self.assertEqual(len(P.bounds[1]),7) self.assertEqual(len(P.bounds[1]),7)
def test_psd_integral(self): def test_psd_integral(self):
npix = 1024 npix = 1024
samp = 2.0 samp = 2.0
P = Psfao((npix,npix),system=ZIMPOL,samp=samp) P = Psfao((npix,npix),system=load('zimpol'),samp=samp)
fao = P.system.Nact/(2.0*P.system.D) fao = P.system.Nact/(2.0*P.system.D)
df = 1.0/(P.system.D*P._samp_over) df = 1.0/(P.system.D*P._samp_over)
...@@ -104,7 +104,7 @@ class TestPsfao(unittest.TestCase): ...@@ -104,7 +104,7 @@ class TestPsfao(unittest.TestCase):
def test_otf_max(self): def test_otf_max(self):
npix = 1024 npix = 1024
samp = 2.0 samp = 2.0
P = Psfao((npix,npix),system=ZIMPOL,samp=samp) P = Psfao((npix,npix),system=load('zimpol'),samp=samp)
r0 = 0.25 r0 = 0.25
C = 1e-4 C = 1e-4
A = 1.0 A = 1.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment