From 986548bff6d34618e5324d38ba8f10601d227f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Neveu?= Date: Fri, 13 Sep 2019 18:59:32 +0200 Subject: [PATCH] add integration tests for atmosphere --- tests/test_simulator.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index ee74ebbd1..90353ae6f 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -1,4 +1,5 @@ from numpy.testing import run_module_suite +import numpy as np from spectractor import parameters from spectractor.simulation.simulator import (SpectrumSimulator, SpectrumSimulatorSimGrid, @@ -8,6 +9,38 @@ import os +def test_atmosphere(): + a = Atmosphere(airmass=1.2, pressure=800, temperature=5) + transmission = a.simulate(ozone=400, pwv=5, aerosols=0.05) + assert transmission is not None + assert a.transmission(500) > 0 + assert a.ozone == 400 + assert a.pwv == 5 + assert a.aerosols == 0.05 + a.plot_transmission() + + a = AtmosphereGrid(image_filename='tests/data/reduc_20170605_028.fits', pwv_grid = [5, 5, 1], ozone_grid = [400, 400, 1], aerosol_grid = [0.0, 0.1, 2]) + atmospheric_grid = a.compute() + assert np.sum(atmospheric_grid) > 0 + assert np.all(np.isclose(a.atmgrid[0, a.index_atm_data:], parameters.LAMBDAS)) + assert not np.any(np.isclose(a.atmgrid[1, a.index_atm_data:], np.zeros_like(parameters.LAMBDAS), rtol=1e-6)) + assert a.atmgrid.shape == (3, a.index_atm_data + len(parameters.LAMBDAS)) + a.save_file(a.image_filename.replace('.fits', '_atmsim.fits')) + assert os.path.isfile('tests/data/reduc_20170605_028_atmsim.fits') + a.load_file(a.image_filename.replace('.fits', '_atmsim.fits')) + assert np.all(a.AER_Points == np.array([0., 0.1])) + assert np.all(a.PWV_Points == np.array([5.])) + assert np.all(a.OZ_Points == np.array([400.])) + + a.plot_transmission() + a.plot_transmission_image() + + a = AtmosphereGrid(filename='tests/data/reduc_20170530_134_atmsim.fits') + lambdas = np.arange(200, 1200) + transmission = a.simulate(ozone=400, pwv=5, aerosols=0.05) + assert np.max(transmission(lambdas)) < 1 and np.min(transmission(lambdas)) >= 0 + + def test_simulator(): file_names = ['tests/data/reduc_20170530_134_spectrum.fits']