Loading tests/test_camera.py +2 −3 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class TestEMCCD(unittest.TestCase): image = emccd.readout(image_focal, None, expt, iamge_cosmic_ray, emgain=emgain) self.assertEqual(image.shape[0], emccd.bias_shape[0]) self.assertEqual(image.shape[1], emccd.bias_shape[1]) def test_em_fix_fun(self): emccd = CpicVisEmccd() emgain = emccd.em_fix_fuc_fit(-5) Loading @@ -74,5 +75,3 @@ class TestEMCCD(unittest.TestCase): # bias_images = np.array(bias_images) # from astropy.io import fits # fits.writeto("bias.fits", bias_images) tests/test_io.py +10 −10 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import csst_cpic_sim.io as io from astropy.io import fits import numpy as np import yaml import os import logging cstar = { 'magnitude': 5, Loading @@ -34,7 +34,8 @@ params = { 'EXPSTART': '2020-01-01T00:00:00.000', 'EXPEND': '2020-01-02T00:00:00.000', 'frame_info': [ {'expt_start': 0, { 'expt_start': 0, 'expt_end': 20, 'platescale': 1.0, 'iwa': 0, Loading @@ -44,10 +45,8 @@ params = { camera = CpicVisEmccd() import logging class TestIO(unittest.TestCase): class TestIO(unittest.TestCase): def test_obsid_parser(self): self.assertRaises(ValueError, obsid_parser, '20190101') self.assertRaises(ValueError, obsid_parser, '123456789012') Loading Loading @@ -125,5 +124,6 @@ target: self.assertEqual( output_name[:len(tmp_folder_path)], tmp_folder_path) if __name__ == '__main__': unittest.main() tests/test_main.py +7 −11 Original line number Diff line number Diff line import unittest import shutil import os # from CpicImgSim import observation_simulation, quick_run from csst_cpic_sim.main import main, quick_run_v2, observation_simulation_from_config from csst_cpic_sim.config import config import os test_dir = os.path.dirname(__file__) cases = os.path.join(test_dir, 'testcases') output = os.path.join(test_dir, 'test_output') config['output'] = output from unittest.mock import patch # from unittest.mock import patch a = [] import io import shutil def clear_output(): if os.path.exists(output): shutil.rmtree(output) os.mkdir(output) class TestMain(unittest.TestCase): # def test_help(self): # main(argv = None) Loading @@ -37,8 +39,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:9], 'demo_0_20') def test_quick_run_func(self): clear_output() quick_run_v2( Loading @@ -48,8 +48,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'blank') def test_full_run_func(self): clear_output() with open(cases+'/run_config.yaml', 'r') as fid: Loading @@ -76,7 +74,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'SCI') def test_full_run_cmdline(self): clear_output() main(['run', os.path.join(cases, '05_sci.yaml')]) Loading @@ -84,7 +81,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'SCI') # def test_main(self): # target_example = { # 'name': 'test', Loading tests/test_optics.py +12 −31 Original line number Diff line number Diff line import unittest import time from csst_cpic_sim.target import star_photlam from csst_cpic_sim.optics import ideal_focus_image, focal_convolve, focal_mask, filter_throughput, ideal_focus_image from csst_cpic_sim.config import which_focalplane, S from csst_cpic_sim.config import S import numpy as np from astropy.io import fits from csst_cpic_sim.optics import FILTERS def make_test_sub_image(size, shape): shape = np.array([shape, shape]) sub_image = np.zeros(shape) Loading @@ -28,21 +25,21 @@ def make_test_sub_image(size, shape): sub_image2 = (np.sqrt(xx**2*2 + yy**2) < size).astype(int) sub_image = sub_image2 * (1 - sub_image) return sub_image def gaussian_psf(band, spectrum, shape, error=0.1): psf_shape = [shape, shape] xx, yy = np.mgrid[0:psf_shape[0], 0:psf_shape[1]] center = np.array([(psf_shape[0]-1)/2, (psf_shape[1]-1)/2]) sigma = 10 psf = np.exp(-((xx-center[0])**2 + (yy-center[1])**2) / (2*sigma**2)) psf = np.exp(-((xx-center[0])**2 + (yy-center[1])**2) / (2*sigma**2)) psf = psf / psf.sum() filter = filter_throughput(band) return psf * (spectrum * filter).integrate() class TestOptics(unittest.TestCase): def test_filter_throughtput(self): Loading @@ -53,10 +50,6 @@ class TestOptics(unittest.TestCase): bandpass = filter_throughput('deFault') self.assertIsInstance(bandpass, S.spectrum.SpectralElement) # def test_which_focalpalne(self): # self.assertEqual(which_focalplane('f565'), 'vis') def test_ideal_focus_image(self): targets = [ [-20, 0, star_photlam(2, 'G2'), None], Loading @@ -65,7 +58,7 @@ class TestOptics(unittest.TestCase): ] bandpass = S.Box(6000, 500) foc = ideal_focus_image( ideal_focus_image( bandpass, targets, 0.0165, Loading @@ -73,7 +66,7 @@ class TestOptics(unittest.TestCase): ) # fits.writeto('foc.fits', foc, overwrite=True) foc = ideal_focus_image( ideal_focus_image( bandpass, targets, 0.0165, Loading @@ -81,7 +74,7 @@ class TestOptics(unittest.TestCase): rotation=30, ) foc = ideal_focus_image( ideal_focus_image( bandpass, {}, 0.0165, Loading @@ -89,7 +82,6 @@ class TestOptics(unittest.TestCase): rotation=30, ) # fits.writeto('foc_rot30.fits', foc, overwrite=True) def test_focal_mask(self): image = np.zeros((100, 100)) + 1 Loading @@ -103,28 +95,17 @@ class TestOptics(unittest.TestCase): [8, 0, star_photlam(-5, 'G2'), make_test_sub_image(10, 100)], ] img_final = focal_convolve('f661', {}) img_final = focal_convolve('f661', targets) focal_convolve('f661', {}) img_final = focal_convolve('f661', targets, init_shifts=[10, 10]) focal_convolve('f661', targets) # fits.writeto('cov.fits', img_final, overwrite=True) focal_convolve('f661', targets, init_shifts=[10, 10]) # if __name__ == '__main__': # # # unittest.main() # # import time # # from CpicImgSim.target import star_photlam # test_convolve_psf() # # import matplotlib.pyplot as plt Loading tests/test_target.py +8 −14 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ from csst_cpic_sim.config import S tests_folder = os.path.dirname(os.path.abspath(__file__)) class TestTarget(unittest.TestCase): def test_target_object(self): d_cstar = { Loading Loading @@ -43,7 +44,6 @@ class TestTarget(unittest.TestCase): old_planet = TargetOjbect(d_planet, cstar=cstar) self.assertEqual(old_planet.sp_model, 'bcc_planet') def test_bcc_albedo_spectrum(self): spectrum = AlbedoCat(90, 1, 0) self.assertIsInstance(spectrum, S.spectrum.SpectralElement) Loading @@ -56,7 +56,6 @@ class TestTarget(unittest.TestCase): # plt.plot(spectrum.wave, spectrum.throughput) # plt.show() def test_hybrid_albedo_spectrum(self): planet = hybrid_albedo_spectrum(0.5, 1) self.assertIsInstance(planet, S.spectrum.SpectralElement) Loading Loading @@ -138,19 +137,16 @@ class TestTarget(unittest.TestCase): self.assertRaises(FileExistsError, detect_template_path, 'demo_5_35.yaml') def test_target_file_load(self): t0 = target_file_load({0: 0}) self.assertEqual(t0[0], 0) t_error = target_file_load(['1']) self.assertEqual(t_error, {}) t1 = target_file_load('') self.assertEqual(t1, {}) t1 = target_file_load(' ') self.assertEqual(t1, {}) Loading @@ -172,7 +168,6 @@ class TestTarget(unittest.TestCase): self.assertEqual(t3['cstar']['sp_model'], 'reference') self.assertEqual(len(t3['objects']), 0) t4 = target_file_load('demo_0_20') self.assertEqual(t4['cstar']['magnitude'], 0) self.assertEqual(t4['cstar']['sp_model'], 'reference') Loading Loading @@ -222,4 +217,3 @@ class TestTarget(unittest.TestCase): template_star = target_file_load('demo_std_star') spectrums = spectrum_generator(template_star) self.assertEqual(len(spectrums), 1) Loading
tests/test_camera.py +2 −3 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class TestEMCCD(unittest.TestCase): image = emccd.readout(image_focal, None, expt, iamge_cosmic_ray, emgain=emgain) self.assertEqual(image.shape[0], emccd.bias_shape[0]) self.assertEqual(image.shape[1], emccd.bias_shape[1]) def test_em_fix_fun(self): emccd = CpicVisEmccd() emgain = emccd.em_fix_fuc_fit(-5) Loading @@ -74,5 +75,3 @@ class TestEMCCD(unittest.TestCase): # bias_images = np.array(bias_images) # from astropy.io import fits # fits.writeto("bias.fits", bias_images)
tests/test_io.py +10 −10 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import csst_cpic_sim.io as io from astropy.io import fits import numpy as np import yaml import os import logging cstar = { 'magnitude': 5, Loading @@ -34,7 +34,8 @@ params = { 'EXPSTART': '2020-01-01T00:00:00.000', 'EXPEND': '2020-01-02T00:00:00.000', 'frame_info': [ {'expt_start': 0, { 'expt_start': 0, 'expt_end': 20, 'platescale': 1.0, 'iwa': 0, Loading @@ -44,10 +45,8 @@ params = { camera = CpicVisEmccd() import logging class TestIO(unittest.TestCase): class TestIO(unittest.TestCase): def test_obsid_parser(self): self.assertRaises(ValueError, obsid_parser, '20190101') self.assertRaises(ValueError, obsid_parser, '123456789012') Loading Loading @@ -125,5 +124,6 @@ target: self.assertEqual( output_name[:len(tmp_folder_path)], tmp_folder_path) if __name__ == '__main__': unittest.main()
tests/test_main.py +7 −11 Original line number Diff line number Diff line import unittest import shutil import os # from CpicImgSim import observation_simulation, quick_run from csst_cpic_sim.main import main, quick_run_v2, observation_simulation_from_config from csst_cpic_sim.config import config import os test_dir = os.path.dirname(__file__) cases = os.path.join(test_dir, 'testcases') output = os.path.join(test_dir, 'test_output') config['output'] = output from unittest.mock import patch # from unittest.mock import patch a = [] import io import shutil def clear_output(): if os.path.exists(output): shutil.rmtree(output) os.mkdir(output) class TestMain(unittest.TestCase): # def test_help(self): # main(argv = None) Loading @@ -37,8 +39,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:9], 'demo_0_20') def test_quick_run_func(self): clear_output() quick_run_v2( Loading @@ -48,8 +48,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'blank') def test_full_run_func(self): clear_output() with open(cases+'/run_config.yaml', 'r') as fid: Loading @@ -76,7 +74,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'SCI') def test_full_run_cmdline(self): clear_output() main(['run', os.path.join(cases, '05_sci.yaml')]) Loading @@ -84,7 +81,6 @@ class TestMain(unittest.TestCase): self.assertEqual(len(file), 1) self.assertEqual(file[0][:5], 'SCI') # def test_main(self): # target_example = { # 'name': 'test', Loading
tests/test_optics.py +12 −31 Original line number Diff line number Diff line import unittest import time from csst_cpic_sim.target import star_photlam from csst_cpic_sim.optics import ideal_focus_image, focal_convolve, focal_mask, filter_throughput, ideal_focus_image from csst_cpic_sim.config import which_focalplane, S from csst_cpic_sim.config import S import numpy as np from astropy.io import fits from csst_cpic_sim.optics import FILTERS def make_test_sub_image(size, shape): shape = np.array([shape, shape]) sub_image = np.zeros(shape) Loading @@ -28,21 +25,21 @@ def make_test_sub_image(size, shape): sub_image2 = (np.sqrt(xx**2*2 + yy**2) < size).astype(int) sub_image = sub_image2 * (1 - sub_image) return sub_image def gaussian_psf(band, spectrum, shape, error=0.1): psf_shape = [shape, shape] xx, yy = np.mgrid[0:psf_shape[0], 0:psf_shape[1]] center = np.array([(psf_shape[0]-1)/2, (psf_shape[1]-1)/2]) sigma = 10 psf = np.exp(-((xx-center[0])**2 + (yy-center[1])**2) / (2*sigma**2)) psf = np.exp(-((xx-center[0])**2 + (yy-center[1])**2) / (2*sigma**2)) psf = psf / psf.sum() filter = filter_throughput(band) return psf * (spectrum * filter).integrate() class TestOptics(unittest.TestCase): def test_filter_throughtput(self): Loading @@ -53,10 +50,6 @@ class TestOptics(unittest.TestCase): bandpass = filter_throughput('deFault') self.assertIsInstance(bandpass, S.spectrum.SpectralElement) # def test_which_focalpalne(self): # self.assertEqual(which_focalplane('f565'), 'vis') def test_ideal_focus_image(self): targets = [ [-20, 0, star_photlam(2, 'G2'), None], Loading @@ -65,7 +58,7 @@ class TestOptics(unittest.TestCase): ] bandpass = S.Box(6000, 500) foc = ideal_focus_image( ideal_focus_image( bandpass, targets, 0.0165, Loading @@ -73,7 +66,7 @@ class TestOptics(unittest.TestCase): ) # fits.writeto('foc.fits', foc, overwrite=True) foc = ideal_focus_image( ideal_focus_image( bandpass, targets, 0.0165, Loading @@ -81,7 +74,7 @@ class TestOptics(unittest.TestCase): rotation=30, ) foc = ideal_focus_image( ideal_focus_image( bandpass, {}, 0.0165, Loading @@ -89,7 +82,6 @@ class TestOptics(unittest.TestCase): rotation=30, ) # fits.writeto('foc_rot30.fits', foc, overwrite=True) def test_focal_mask(self): image = np.zeros((100, 100)) + 1 Loading @@ -103,28 +95,17 @@ class TestOptics(unittest.TestCase): [8, 0, star_photlam(-5, 'G2'), make_test_sub_image(10, 100)], ] img_final = focal_convolve('f661', {}) img_final = focal_convolve('f661', targets) focal_convolve('f661', {}) img_final = focal_convolve('f661', targets, init_shifts=[10, 10]) focal_convolve('f661', targets) # fits.writeto('cov.fits', img_final, overwrite=True) focal_convolve('f661', targets, init_shifts=[10, 10]) # if __name__ == '__main__': # # # unittest.main() # # import time # # from CpicImgSim.target import star_photlam # test_convolve_psf() # # import matplotlib.pyplot as plt Loading
tests/test_target.py +8 −14 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ from csst_cpic_sim.config import S tests_folder = os.path.dirname(os.path.abspath(__file__)) class TestTarget(unittest.TestCase): def test_target_object(self): d_cstar = { Loading Loading @@ -43,7 +44,6 @@ class TestTarget(unittest.TestCase): old_planet = TargetOjbect(d_planet, cstar=cstar) self.assertEqual(old_planet.sp_model, 'bcc_planet') def test_bcc_albedo_spectrum(self): spectrum = AlbedoCat(90, 1, 0) self.assertIsInstance(spectrum, S.spectrum.SpectralElement) Loading @@ -56,7 +56,6 @@ class TestTarget(unittest.TestCase): # plt.plot(spectrum.wave, spectrum.throughput) # plt.show() def test_hybrid_albedo_spectrum(self): planet = hybrid_albedo_spectrum(0.5, 1) self.assertIsInstance(planet, S.spectrum.SpectralElement) Loading Loading @@ -138,19 +137,16 @@ class TestTarget(unittest.TestCase): self.assertRaises(FileExistsError, detect_template_path, 'demo_5_35.yaml') def test_target_file_load(self): t0 = target_file_load({0: 0}) self.assertEqual(t0[0], 0) t_error = target_file_load(['1']) self.assertEqual(t_error, {}) t1 = target_file_load('') self.assertEqual(t1, {}) t1 = target_file_load(' ') self.assertEqual(t1, {}) Loading @@ -172,7 +168,6 @@ class TestTarget(unittest.TestCase): self.assertEqual(t3['cstar']['sp_model'], 'reference') self.assertEqual(len(t3['objects']), 0) t4 = target_file_load('demo_0_20') self.assertEqual(t4['cstar']['magnitude'], 0) self.assertEqual(t4['cstar']['sp_model'], 'reference') Loading Loading @@ -222,4 +217,3 @@ class TestTarget(unittest.TestCase): template_star = target_file_load('demo_std_star') spectrums = spectrum_generator(template_star) self.assertEqual(len(spectrums), 1)