Commit eb060359 authored by FETICK Romain's avatar FETICK Romain
Browse files

Update unittests

parent 43adc332
......@@ -57,6 +57,7 @@ Libraries are now ready to be used in your scripts with commands like `from maop
* **maoppy/**
* **example/** _(some examples to get started)_
* **test/** _(unitary tests of the code)_
* \_\_init\_\_.py
* config.py _(configuration for MAOPPY library)_
* instrument.py _(load defined optical systems)_
......
......@@ -527,7 +527,8 @@ class Psfao(ParametricPSF):
Dphi = fftshift(np.real(2 * (Bg[0, 0] - Bg)))
return np.exp(-Dphi/2.)
def _otf_diffraction(self):
def _otf_diffraction(self):
#TODO: @lru_cache to prevent unecessary calls to this? (2 FFT)
Nx_over = self.Npix[0]*self._k
Ny_over = self.Npix[1]*self._k
......
......@@ -9,7 +9,7 @@ Created on Fri May 8 20:21:20 2020
import unittest
import numpy as np
from maoppy.psfmodel import lsq_flux_bck, moffat, gauss, Psfao
from maoppy.instrument import MUSE_NFM
from maoppy.instrument import MUSE_NFM, ZIMPOL
class TestLsqFluxBck(unittest.TestCase):
def test_fluxbck(self):
......@@ -60,7 +60,7 @@ class TestPsfao(unittest.TestCase):
self.assertGreaterEqual(P._samp_over,2.0)
self.assertEqual(P._k%1,0)
def test_symmetric(self):
def test_bounds_length(self):
npix = 100
samp = 0.3
P = Psfao((npix,npix),system=MUSE_NFM,symmetric=True,samp=samp)
......@@ -70,6 +70,58 @@ class TestPsfao(unittest.TestCase):
self.assertEqual(len(P.bounds[0]),7)
self.assertEqual(len(P.bounds[1]),7)
def test_psd_integral(self):
npix = 1024
samp = 2.0
P = Psfao((npix,npix),system=ZIMPOL,symmetric=True,samp=samp)
fao = P.system.Nact/(2.0*P.system.D)
df = 1.0/(P.system.D*P._samp_over)
r0 = 0.15
C = 0
A = 0
ax = 0.5
ay = 0.5
theta = 0
beta = 1.5
# Integral of the halo
psd = P.psd([r0,C,A,ax,ay,theta,beta])
int_num = np.sum(psd)*df*df
int_ana = 0.023 * 6*np.pi/5 * (fao*r0)**(-5.0/3.0)
self.assertAlmostEqual(int_num,int_ana,delta=1e-2)
# Integral of the constant
r0 = np.inf
C = 1e-2
psd = P.psd([r0,C,A,ax,ay,theta,beta])
int_num = np.sum(psd)*df*df
int_ana = C*np.pi*fao**2.0 - df*df # remove central pixel
self.assertAlmostEqual(int_num,int_ana,delta=1e-2)
# Integral of the Moffat
C = 0.0
A = 1.0
psd = P.psd([r0,C,A,ax,ay,theta,beta])
int_num = np.sum(psd)*df*df
int_ana = A
self.assertAlmostEqual(int_num,int_ana,delta=1e-2)
def test_otf_max(self):
npix = 1024
samp = 2.0
P = Psfao((npix,npix),system=ZIMPOL,symmetric=True,samp=samp)
r0 = 0.15
C = 1e-4
A = 1.0
ax = 0.05
ay = 0.08
theta = np.pi/4
beta = 1.5
otf = P.otf([r0,C,A,ax,ay,theta,beta])
mtf = np.max(np.abs(otf))
self.assertEqual(mtf,1.0)
if __name__=='__main__':
unittest.main()
......
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