Commit 36189a3e authored by JX's avatar JX 😵
Browse files

Merge remote-tracking branch 'origin/develop'

parents dd26d370 27646bc4
Pipeline #4509 passed with stage
in 0 seconds
from ObservationSim.ObservationSim import Observation from observation_sim.ObservationSim import Observation
from ObservationSim._util import parse_args, make_run_dirs, generate_pointing_list from observation_sim._util import parse_args, make_run_dirs, generate_pointing_list
from importlib.metadata import version from importlib.metadata import version
import os import os
import yaml import yaml
...@@ -18,7 +18,7 @@ def run_sim(): ...@@ -18,7 +18,7 @@ def run_sim():
Parameters Parameters
---------- ----------
Catalog : Class Catalog : Class
a catalog class which is inherited from ObservationSim.MockObject.CatalogBase a catalog class which is inherited from observation_sim.mock_objects.CatalogBase
Returns Returns
---------- ----------
...@@ -94,7 +94,7 @@ def run_sim(): ...@@ -94,7 +94,7 @@ def run_sim():
# Initialize the simulation # Initialize the simulation
if args.catalog is not None: if args.catalog is not None:
catalog_module = importlib.import_module('Catalog.'+args.catalog) catalog_module = importlib.import_module('catalog.'+args.catalog)
obs = Observation(config=config, Catalog=catalog_module.Catalog, obs = Observation(config=config, Catalog=catalog_module.Catalog,
work_dir=config['work_dir'], data_dir=config['data_dir']) work_dir=config['work_dir'], data_dir=config['data_dir'])
else: else:
......
...@@ -39,26 +39,26 @@ class build_ext(build_ext): ...@@ -39,26 +39,26 @@ class build_ext(build_ext):
extensions = [ extensions = [
Extension("ObservationSim.MockObject.SpecDisperser.disperse_c.interp", ["ObservationSim/MockObject/SpecDisperser/disperse_c/interp.pyx"], Extension("observation_sim.mock_objects.SpecDisperser.disperse_c.interp", ["observation_sim/mock_objects/SpecDisperser/disperse_c/interp.pyx"],
include_dirs=[numpy.get_include()], include_dirs=[numpy.get_include()],
libraries=["m"]), libraries=["m"]),
Extension("ObservationSim.MockObject.SpecDisperser.disperse_c.disperse", ["ObservationSim/MockObject/SpecDisperser/disperse_c/disperse.pyx"], Extension("observation_sim.mock_objects.SpecDisperser.disperse_c.disperse", ["observation_sim/mock_objects/SpecDisperser/disperse_c/disperse.pyx"],
include_dirs=[numpy.get_include()], include_dirs=[numpy.get_include()],
libraries=["m"]), libraries=["m"]),
] ]
df_module = [CTypes('ObservationSim.Instrument.Chip.libBF.libmoduleBF', df_module = [CTypes('observation_sim.instruments.chip.libBF.libmoduleBF',
['ObservationSim/Instrument/Chip/libBF/diffusion_X1.c', ['observation_sim/instruments/chip/libBF/diffusion_X1.c',
'ObservationSim/Instrument/Chip/libBF/nrutil.c'], 'observation_sim/instruments/chip/libBF/nrutil.c'],
include_dirs=[ include_dirs=[
'ObservationSim/Instrument/Chip/libBF/', '/usr/include'] 'observation_sim/instruments/chip/libBF/', '/usr/include']
)] )]
cti_module = [CTypes('ObservationSim.Instrument.Chip.libCTI.libmoduleCTI', cti_module = [CTypes('observation_sim.instruments.chip.libCTI.libmoduleCTI',
['ObservationSim/Instrument/Chip/libCTI/src/add_CTI.c', 'ObservationSim/Instrument/Chip/libCTI/src/nrutil.c', 'ObservationSim/Instrument/Chip/libCTI/src/ran1.c', 'ObservationSim/Instrument/Chip/libCTI/src/ran2.c', 'ObservationSim/Instrument/Chip/libCTI/src/poidev.c', ['observation_sim/instruments/chip/libCTI/src/add_CTI.c', 'observation_sim/instruments/chip/libCTI/src/nrutil.c', 'observation_sim/instruments/chip/libCTI/src/ran1.c', 'observation_sim/instruments/chip/libCTI/src/ran2.c', 'observation_sim/instruments/chip/libCTI/src/poidev.c',
'ObservationSim/Instrument/Chip/libCTI/src/gammln.c', 'ObservationSim/Instrument/Chip/libCTI/src/gasdev.c', 'ObservationSim/Instrument/Chip/libCTI/src/sort.c', 'ObservationSim/Instrument/Chip/libCTI/src/creattraps.c'], 'observation_sim/instruments/chip/libCTI/src/gammln.c', 'observation_sim/instruments/chip/libCTI/src/gasdev.c', 'observation_sim/instruments/chip/libCTI/src/sort.c', 'observation_sim/instruments/chip/libCTI/src/creattraps.c'],
include_dirs=[ include_dirs=[
'ObservationSim/Instrument/Chip/libCTI/src/', '/usr/include'] 'observation_sim/instruments/chip/libCTI/src/', '/usr/include']
)] )]
...@@ -93,23 +93,23 @@ setup(name='csst_msc_sim', ...@@ -93,23 +93,23 @@ setup(name='csst_msc_sim',
# ], # ],
package_data={ package_data={
'ObservationSim.Astrometry.lib': ['libshao.so'], 'observation_sim.astrometry.lib': ['libshao.so'],
'ObservationSim.Instrument.Chip.libBF': ['libmoduleBF.so'], 'observation_sim.instruments.chip.libBF': ['libmoduleBF.so'],
'ObservationSim.Instrument.Chip.libCTI': ['libmoduleCTI.so'], 'observation_sim.instruments.chip.libCTI': ['libmoduleCTI.so'],
'ObservationSim.MockObject.data': ['*.dat'], 'observation_sim.mock_objects.data': ['*.dat'],
'ObservationSim.MockObject.data.led': ['*.fits'], 'observation_sim.mock_objects.data.led': ['*.fits'],
'ObservationSim.Instrument.data': ['*.txt', '*.dat', '*.json'], 'observation_sim.instruments.data': ['*.txt', '*.dat', '*.json'],
'ObservationSim.Instrument.data.field_distortion': ['*.pickle'], 'observation_sim.instruments.data.field_distortion': ['*.pickle'],
'ObservationSim.Instrument.data.ccd': ['*.txt', '*.json'], 'observation_sim.instruments.data.ccd': ['*.txt', '*.json'],
'ObservationSim.Instrument.data.filters': ['*.txt', '*.list', '*.dat'], 'observation_sim.instruments.data.filters': ['*.txt', '*.list', '*.dat'],
'ObservationSim.Instrument.data.throughputs': ['*.txt', '*.dat'], 'observation_sim.instruments.data.throughputs': ['*.txt', '*.dat'],
'ObservationSim.Instrument.data.sls_conf': ['*.conf', '*.fits'], 'observation_sim.instruments.data.sls_conf': ['*.conf', '*.fits'],
# 'ObservationSim.Instrument.data.flatCube': ['*.fits'], # 'observation_sim.Instrument.data.flatCube': ['*.fits'],
'Catalog.data': ['*.fits', '*.so'], 'catalog.data': ['*.fits', '*.so'],
'ObservationSim.Config.Header': ['*.fits', '*.lst'], 'observation_sim.config.header': ['*.fits', '*.lst'],
'ObservationSim.Straylight.data': ['*.dat'], 'observation_sim.sky_background.data': ['*.dat'],
'ObservationSim.Straylight.data.sky': ['*.dat'], 'observation_sim.sky_background.data.sky': ['*.dat'],
'ObservationSim.Straylight.lib': ['*'], 'observation_sim.sky_background.lib': ['*'],
}, },
python_requires=">=3.11", # Python版本要求 python_requires=">=3.11", # Python版本要求
install_requires=requirements, install_requires=requirements,
......
import unittest import unittest
import sys,os,math import sys
import os
import math
from itertools import islice from itertools import islice
import numpy as np import numpy as np
import copy import copy
...@@ -9,10 +11,9 @@ import galsim ...@@ -9,10 +11,9 @@ import galsim
import yaml import yaml
from astropy.io import fits from astropy.io import fits
from ObservationSim.Instrument import Chip, Filter, FilterParam, FocalPlane from observation_sim.instruments import Chip, Filter, FilterParam, FocalPlane
from ObservationSim.Instrument.Chip import ChipUtils as chip_utils from observation_sim.instruments.chip import chip_utils
#from ObservationSim.sim_steps import add_brighter_fatter_CTE from observation_sim.instruments.chip.libCTI.CTI_modeling import CTI_sim
from ObservationSim.Instrument.Chip.libCTI.CTI_modeling import CTI_sim
try: try:
import importlib.resources as pkg_resources import importlib.resources as pkg_resources
...@@ -23,14 +24,15 @@ except ImportError: ...@@ -23,14 +24,15 @@ except ImportError:
### test FUNCTION --- START ### ### test FUNCTION --- START ###
def add_brighter_fatter(img): def add_brighter_fatter(img):
#Inital dynamic lib # Inital dynamic lib
try: try:
with pkg_resources.files('ObservationSim.Instrument.Chip.libBF').joinpath("libmoduleBF.so") as lib_path: with pkg_resources.files('observation_sim.instruments.chip.libBF').joinpath("libmoduleBF.so") as lib_path:
lib_bf = ctypes.CDLL(lib_path) lib_bf = ctypes.CDLL(lib_path)
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.Chip.libBF', "libmoduleBF.so") as lib_path: with pkg_resources.path('observation_sim.instruments.chip.libBF', "libmoduleBF.so") as lib_path:
lib_bf = ctypes.CDLL(lib_path) lib_bf = ctypes.CDLL(lib_path)
lib_bf.addEffects.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.c_int] lib_bf.addEffects.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(
ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.c_int]
# Set bit flag # Set bit flag
bit_flag = 1 bit_flag = 1
...@@ -38,11 +40,11 @@ def add_brighter_fatter(img): ...@@ -38,11 +40,11 @@ def add_brighter_fatter(img):
nx, ny = img.array.shape nx, ny = img.array.shape
nn = nx * ny nn = nx * ny
arr_ima= (ctypes.c_float*nn)() arr_ima = (ctypes.c_float*nn)()
arr_imc= (ctypes.c_float*nn)() arr_imc = (ctypes.c_float*nn)()
arr_ima[:]= img.array.reshape(nn) arr_ima[:] = img.array.reshape(nn)
arr_imc[:]= np.zeros(nn) arr_imc[:] = np.zeros(nn)
lib_bf.addEffects(nx, ny, arr_ima, arr_imc, bit_flag) lib_bf.addEffects(nx, ny, arr_ima, arr_imc, bit_flag)
img.array[:, :] = np.reshape(arr_imc, [nx, ny]) img.array[:, :] = np.reshape(arr_imc, [nx, ny])
...@@ -50,20 +52,24 @@ def add_brighter_fatter(img): ...@@ -50,20 +52,24 @@ def add_brighter_fatter(img):
return img return img
### test FUNCTION --- END ### ### test FUNCTION --- END ###
def defineCCD(iccd, config_file): def defineCCD(iccd, config_file):
with open(config_file, "r") as stream: with open(config_file, "r") as stream:
try: try:
config = yaml.safe_load(stream) config = yaml.safe_load(stream)
#for key, value in config.items(): # for key, value in config.items():
# print (key + " : " + str(value)) # print (key + " : " + str(value))
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
chip = Chip(chipID=iccd, config=config) chip = Chip(chipID=iccd, config=config)
chip.img = galsim.ImageF(400, 200) #galsim.ImageF(chip.npix_x, chip.npix_y) # galsim.ImageF(chip.npix_x, chip.npix_y)
chip.img = galsim.ImageF(400, 200)
focal_plane = FocalPlane(chip_list=[iccd]) focal_plane = FocalPlane(chip_list=[iccd])
chip.img.wcs= focal_plane.getTanWCS(192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale) chip.img.wcs = focal_plane.getTanWCS(
192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale)
return chip return chip
def defineFilt(chip): def defineFilt(chip):
filter_param = FilterParam() filter_param = FilterParam()
filter_id, filter_type = chip.getChipFilter() filter_id, filter_type = chip.getChipFilter()
...@@ -79,11 +85,11 @@ def defineFilt(chip): ...@@ -79,11 +85,11 @@ def defineFilt(chip):
class detModule_coverage(unittest.TestCase): class detModule_coverage(unittest.TestCase):
def __init__(self, methodName='runTest'): def __init__(self, methodName='runTest'):
super(detModule_coverage, self).__init__(methodName) super(detModule_coverage, self).__init__(methodName)
##self.dataPath = "/public/home/chengliang/CSSOSDataProductsSims/csst-simulation/tests/UNIT_TEST_DATA" ##os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_fz_gc1') # self.dataPath = "/public/home/chengliang/CSSOSDataProductsSims/csst-simulation/tests/UNIT_TEST_DATA" ##os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_fz_gc1')
self.dataPath = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc') self.dataPath = os.path.join(
os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc')
self.iccd = 1 self.iccd = 1
def test_add_brighter_fatter(self): def test_add_brighter_fatter(self):
config_file = os.path.join(self.dataPath, 'config_test.yaml') config_file = os.path.join(self.dataPath, 'config_test.yaml')
chip = defineCCD(self.iccd, config_file) chip = defineCCD(self.iccd, config_file)
...@@ -91,32 +97,31 @@ class detModule_coverage(unittest.TestCase): ...@@ -91,32 +97,31 @@ class detModule_coverage(unittest.TestCase):
print(chip.chipID) print(chip.chipID)
print(chip.cen_pix_x, chip.cen_pix_y) print(chip.cen_pix_x, chip.cen_pix_y)
#objA-lowSFB # objA-lowSFB
obj = galsim.Gaussian(sigma=0.2, flux=1000) obj = galsim.Gaussian(sigma=0.2, flux=1000)
arr = obj.drawImage(nx=64, ny=64, scale=0.074).array arr = obj.drawImage(nx=64, ny=64, scale=0.074).array
chip.img.array[(100-32):(100+32),(200-32):(200+32)] = arr[:,:] chip.img.array[(100-32):(100+32), (200-32):(200+32)] = arr[:, :]
img_old = copy.deepcopy(chip.img) img_old = copy.deepcopy(chip.img)
img_new = add_brighter_fatter(img=chip.img) img_new = add_brighter_fatter(img=chip.img)
arr1= img_old.array arr1 = img_old.array
arr2= img_new.array arr2 = img_new.array
deltaA_max = np.max(np.abs(arr2-arr1)) deltaA_max = np.max(np.abs(arr2-arr1))
print('deltaA-max:', np.max(np.abs(arr2-arr1))) print('deltaA-max:', np.max(np.abs(arr2-arr1)))
print('deltaA-min:', np.min(np.abs(arr2-arr1))) print('deltaA-min:', np.min(np.abs(arr2-arr1)))
#objB-highSFB # objB-highSFB
obj = galsim.Gaussian(sigma=0.2, flux=10000) obj = galsim.Gaussian(sigma=0.2, flux=10000)
arr = obj.drawImage(nx=64, ny=64, scale=0.074).array arr = obj.drawImage(nx=64, ny=64, scale=0.074).array
chip.img.array[(100-32):(100+32),(200-32):(200+32)] = arr[:,:] chip.img.array[(100-32):(100+32), (200-32):(200+32)] = arr[:, :]
img_old = copy.deepcopy(chip.img) img_old = copy.deepcopy(chip.img)
img_new = add_brighter_fatter(img=chip.img) img_new = add_brighter_fatter(img=chip.img)
arr3= img_old.array arr3 = img_old.array
arr4= img_new.array arr4 = img_new.array
deltaB_max = np.max(np.abs(arr4-arr3)) deltaB_max = np.max(np.abs(arr4-arr3))
print('deltaB-max:', np.max(np.abs(arr4-arr3))) print('deltaB-max:', np.max(np.abs(arr4-arr3)))
print('deltaB-min:', np.min(np.abs(arr4-arr3))) print('deltaB-min:', np.min(np.abs(arr4-arr3)))
self.assertTrue( deltaB_max > deltaA_max )
self.assertTrue(deltaB_max > deltaA_max)
def test_apply_CTE(self): def test_apply_CTE(self):
config_file = os.path.join(self.dataPath, 'config_test.yaml') config_file = os.path.join(self.dataPath, 'config_test.yaml')
...@@ -126,18 +131,21 @@ class detModule_coverage(unittest.TestCase): ...@@ -126,18 +131,21 @@ class detModule_coverage(unittest.TestCase):
print(chip.cen_pix_x, chip.cen_pix_y) print(chip.cen_pix_x, chip.cen_pix_y)
print(" Apply CTE Effect") print(" Apply CTE Effect")
nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10 nx, ny, noverscan, nsp, nmax = 4608, 4616, 84, 3, 10
ntotal = 4700 ntotal = 4700
beta,w,c = 0.478,84700,0 beta, w, c = 0.478, 84700, 0
t = np.array([0.74,7.7,37],dtype=np.float32) t = np.array([0.74, 7.7, 37], dtype=np.float32)
rho_trap = np.array([0.6,1.6,1.4],dtype=np.float32) rho_trap = np.array([0.6, 1.6, 1.4], dtype=np.float32)
trap_seeds = np.array([0,100,1000],dtype=np.int32) trap_seeds = np.array([0, 100, 1000], dtype=np.int32)
release_seed = 500 release_seed = 500
image = fits.getdata(os.path.join(self.dataPath, "testCTE_image_before.fits")).astype(np.int32) image = fits.getdata(os.path.join(
#get_trap_map(trap_seeds,nx,ny,nmax,rho_trap,beta,c,".") self.dataPath, "testCTE_image_before.fits")).astype(np.int32)
#bin2fits("trap.bin",".",nsp,nx,ny,nmax) # get_trap_map(trap_seeds,nx,ny,nmax,rho_trap,beta,c,".")
image_cti = CTI_sim(image,nx,ny,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed) # bin2fits("trap.bin",".",nsp,nx,ny,nmax)
fits.writeto(os.path.join(self.dataPath, "testCTE_image_after.fits"),data=image_cti,overwrite=True) image_cti = CTI_sim(image, nx, ny, noverscan, nsp, nmax,
beta, w, c, t, rho_trap, trap_seeds, release_seed)
fits.writeto(os.path.join(
self.dataPath, "testCTE_image_after.fits"), data=image_cti, overwrite=True)
if __name__ == '__main__': if __name__ == '__main__':
......
import unittest import unittest
import sys,os,math import sys
import os
import math
from itertools import islice from itertools import islice
import numpy as np import numpy as np
import galsim import galsim
import yaml import yaml
from ObservationSim.Instrument import Chip, Filter, FilterParam, FocalPlane from observation_sim.instruments import Chip, Filter, FilterParam, FocalPlane
from ObservationSim.PSF.PSFInterp import PSFInterp from observation_sim.PSF.PSFInterp import PSFInterp
def defineCCD(iccd, config_file): def defineCCD(iccd, config_file):
with open(config_file, "r") as stream: with open(config_file, "r") as stream:
try: try:
config = yaml.safe_load(stream) config = yaml.safe_load(stream)
#for key, value in config.items(): # for key, value in config.items():
# print (key + " : " + str(value)) # print (key + " : " + str(value))
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
chip = Chip(chipID=iccd, config=config) chip = Chip(chipID=iccd, config=config)
chip.img = galsim.ImageF(chip.npix_x, chip.npix_y) chip.img = galsim.ImageF(chip.npix_x, chip.npix_y)
focal_plane = FocalPlane(chip_list=[iccd]) focal_plane = FocalPlane(chip_list=[iccd])
chip.img.wcs= focal_plane.getTanWCS(192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale) chip.img.wcs = focal_plane.getTanWCS(
192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale)
return chip return chip
def defineFilt(chip): def defineFilt(chip):
filter_param = FilterParam() filter_param = FilterParam()
filter_id, filter_type = chip.getChipFilter() filter_id, filter_type = chip.getChipFilter()
...@@ -39,7 +43,8 @@ def defineFilt(chip): ...@@ -39,7 +43,8 @@ def defineFilt(chip):
class PSFInterpModule_coverage(unittest.TestCase): class PSFInterpModule_coverage(unittest.TestCase):
def __init__(self, methodName='runTest'): def __init__(self, methodName='runTest'):
super(PSFInterpModule_coverage, self).__init__(methodName) super(PSFInterpModule_coverage, self).__init__(methodName)
self.dataPath = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc') self.dataPath = os.path.join(
os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc')
self.iccd = 8 self.iccd = 8
def test_loadPSFSet(self): def test_loadPSFSet(self):
...@@ -48,23 +53,28 @@ class PSFInterpModule_coverage(unittest.TestCase): ...@@ -48,23 +53,28 @@ class PSFInterpModule_coverage(unittest.TestCase):
bandpass = defineFilt(chip) bandpass = defineFilt(chip)
print(chip.chipID) print(chip.chipID)
print(chip.cen_pix_x, chip.cen_pix_y) print(chip.cen_pix_x, chip.cen_pix_y)
pathTemp = self.dataPath #"/public/share/yangxuliu/CSSOSDataProductsSims/psfCube/set1_dynamic/" # "/public/share/yangxuliu/CSSOSDataProductsSims/psfCube/set1_dynamic/"
psfModel= PSFInterp(chip, npsf=900, PSF_data_file=pathTemp, PSF_data_prefix="", HocBuild=True, LOG_DEBUG=True) pathTemp = self.dataPath
psfModel = PSFInterp(chip, npsf=900, PSF_data_file=pathTemp,
x, y = 4096, 4096 #imgPos[iobj, :] # try get the PSF at some location (1234, 1234) on the chip PSF_data_prefix="", HocBuild=True, LOG_DEBUG=True)
# imgPos[iobj, :] # try get the PSF at some location (1234, 1234) on the chip
x, y = 4096, 4096
x = x+chip.bound.xmin x = x+chip.bound.xmin
y = y+chip.bound.ymin y = y+chip.bound.ymin
pos_img = galsim.PositionD(x, y) pos_img = galsim.PositionD(x, y)
psf,_ = psfModel.get_PSF(chip=chip, pos_img=pos_img, bandpass=0, galsimGSObject=True) psf, _ = psfModel.get_PSF(
psfA = psfModel.get_PSF(chip=chip, pos_img=pos_img, bandpass=bandpass[0], galsimGSObject=False) chip=chip, pos_img=pos_img, bandpass=0, galsimGSObject=True)
psfB = psfModel.get_PSF(chip=chip, pos_img=pos_img, findNeighMode='hoclistFind', bandpass=bandpass[0], galsimGSObject=False) psfA = psfModel.get_PSF(
chip=chip, pos_img=pos_img, bandpass=bandpass[0], galsimGSObject=False)
self.assertTrue( psf != None ) psfB = psfModel.get_PSF(
self.assertTrue( np.max(np.abs(psfA-psfB))<1e-6 ) chip=chip, pos_img=pos_img, findNeighMode='hoclistFind', bandpass=bandpass[0], galsimGSObject=False)
self.assertTrue(psf != None)
self.assertTrue(np.max(np.abs(psfA-psfB)) < 1e-6)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
#need add environment parameter UNIT_TEST_DATA_ROOT, link to "testData/" # need add environment parameter UNIT_TEST_DATA_ROOT, link to "testData/"
#linx and mac can run as follow, need modify the name of file directory # linx and mac can run as follow, need modify the name of file directory
#export UNIT_TEST_DATA_ROOT=/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData # export UNIT_TEST_DATA_ROOT=/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData
# #
import unittest import unittest
from ObservationSim.MockObject.SpecDisperser import rotate90, SpecDisperser from observation_sim.mock_objects.SpecDisperser import rotate90, SpecDisperser
from ObservationSim.Config import ChipOutput from observation_sim.config import ChipOutput
from ObservationSim.Instrument import Telescope, Chip, FilterParam, Filter, FocalPlane from observation_sim.instruments import Telescope, Chip, FilterParam, Filter, FocalPlane
from ObservationSim.MockObject import MockObject, Star from observation_sim.mock_objects import MockObject, Star
from ObservationSim.PSF import PSFGauss from observation_sim.PSF import PSFGauss
import numpy as np import numpy as np
import galsim import galsim
...@@ -20,36 +20,37 @@ import matplotlib.pyplot as plt ...@@ -20,36 +20,37 @@ import matplotlib.pyplot as plt
from lmfit.models import LinearModel, GaussianModel from lmfit.models import LinearModel, GaussianModel
from ObservationSim.Config.Header import generateExtensionHeader from observation_sim.config.header import generateExtensionHeader
import math import math
import yaml import yaml
import os import os
def getAngle132(x1=0, y1=0, z1=0, x2=0, y2=0, z2=0, x3=0, y3=0, z3=0): def getAngle132(x1=0, y1=0, z1=0, x2=0, y2=0, z2=0, x3=0, y3=0, z3=0):
cosValue = 0; cosValue = 0
angle = 0; angle = 0
x11 = x1 - x3; x11 = x1 - x3
y11 = y1 - y3; y11 = y1 - y3
z11 = z1 - z3; z11 = z1 - z3
x22 = x2 - x3; x22 = x2 - x3
y22 = y2 - y3; y22 = y2 - y3
z22 = z2 - z3; z22 = z2 - z3
tt = np.sqrt((x11 * x11 + y11 * y11 + z11 * z11) * (x22 * x22 + y22 * y22 + z22 * z22)); tt = np.sqrt((x11 * x11 + y11 * y11 + z11 * z11)
* (x22 * x22 + y22 * y22 + z22 * z22))
if (tt == 0): if (tt == 0):
return 0; return 0
cosValue = (x11 * x22 + y11 * y22 + z11 * z22) / tt; cosValue = (x11 * x22 + y11 * y22 + z11 * z22) / tt
if (cosValue > 1): if (cosValue > 1):
cosValue = 1; cosValue = 1
if (cosValue < -1): if (cosValue < -1):
cosValue = -1; cosValue = -1
angle = math.acos(cosValue); angle = math.acos(cosValue)
return angle * 360 / (2 * math.pi); return angle * 360 / (2 * math.pi)
def fit_SingleGauss(xX, yX, contmX, iHa0): def fit_SingleGauss(xX, yX, contmX, iHa0):
...@@ -71,26 +72,35 @@ def fit_SingleGauss(xX, yX, contmX, iHa0): ...@@ -71,26 +72,35 @@ def fit_SingleGauss(xX, yX, contmX, iHa0):
# print outX.params['g_center'] # print outX.params['g_center']
outX.fit_report(min_correl=0.25) outX.fit_report(min_correl=0.25)
# print(outX.fit_report(min_correl=0.25)) # print(outX.fit_report(min_correl=0.25))
line_slopeX = float(outX.fit_report(min_correl=0.25).split('line_slope:')[1].split('+/-')[0]) * contmX line_slopeX = float(outX.fit_report(min_correl=0.25).split(
'line_slope:')[1].split('+/-')[0]) * contmX
err_line_slopeX = float( err_line_slopeX = float(
outX.fit_report(min_correl=0.25).split('line_slope:')[1].split('+/-')[1].split('(')[0]) * contmX outX.fit_report(min_correl=0.25).split('line_slope:')[1].split('+/-')[1].split('(')[0]) * contmX
line_interceptX = float(outX.fit_report(min_correl=0.25).split('line_intercept:')[1].split('+/-')[0]) * contmX line_interceptX = float(outX.fit_report(min_correl=0.25).split(
'line_intercept:')[1].split('+/-')[0]) * contmX
err_line_interceptX = float( err_line_interceptX = float(
outX.fit_report(min_correl=0.25).split('line_intercept:')[1].split('+/-')[1].split('(')[0]) * contmX outX.fit_report(min_correl=0.25).split('line_intercept:')[1].split('+/-')[1].split('(')[0]) * contmX
sigmaX = float(outX.fit_report(min_correl=0.25).split('g_sigma:')[1].split('+/-')[0]) sigmaX = float(outX.fit_report(min_correl=0.25).split(
err_sigmaX = float(outX.fit_report(min_correl=0.25).split('g_sigma:')[1].split('+/-')[1].split('(')[0]) 'g_sigma:')[1].split('+/-')[0])
err_sigmaX = float(outX.fit_report(min_correl=0.25).split(
'g_sigma:')[1].split('+/-')[1].split('(')[0])
fwhmX = float(outX.fit_report(min_correl=0.25).split('g_fwhm:')[1].split('+/-')[0]) fwhmX = float(outX.fit_report(min_correl=0.25).split(
err_fwhmX = float(outX.fit_report(min_correl=0.25).split('g_fwhm:')[1].split('+/-')[1].split('(')[0]) 'g_fwhm:')[1].split('+/-')[0])
err_fwhmX = float(outX.fit_report(min_correl=0.25).split(
'g_fwhm:')[1].split('+/-')[1].split('(')[0])
centerX = float(outX.fit_report(min_correl=0.25).split('g_center:')[1].split('+/-')[0]) centerX = float(outX.fit_report(min_correl=0.25).split(
err_centerX = float(outX.fit_report(min_correl=0.25).split('g_center:')[1].split('+/-')[1].split('(')[0]) 'g_center:')[1].split('+/-')[0])
err_centerX = float(outX.fit_report(min_correl=0.25).split(
'g_center:')[1].split('+/-')[1].split('(')[0])
return sigmaX, err_sigmaX, fwhmX, err_fwhmX, centerX, err_centerX return sigmaX, err_sigmaX, fwhmX, err_fwhmX, centerX, err_centerX
def produceObj(x,y,chip, ra, dec, pa):
def produceObj(x, y, chip, ra, dec, pa):
pos_img = galsim.PositionD(x, y) pos_img = galsim.PositionD(x, y)
param = {} param = {}
...@@ -104,22 +114,22 @@ def produceObj(x,y,chip, ra, dec, pa): ...@@ -104,22 +114,22 @@ def produceObj(x,y,chip, ra, dec, pa):
obj = Star(param) obj = Star(param)
header_wcs = generateExtensionHeader(chip, header_wcs = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
pixel_size=chip.pix_size, pixel_size=chip.pix_size,
xcen=chip.x_cen, xcen=chip.x_cen,
ycen=chip.y_cen, ycen=chip.y_cen,
extName='SCI') extName='SCI')
chip_wcs = galsim.FitsWCS(header=header_wcs) chip_wcs = galsim.FitsWCS(header=header_wcs)
param["ra"] = chip_wcs.posToWorld(pos_img).ra.deg param["ra"] = chip_wcs.posToWorld(pos_img).ra.deg
...@@ -143,50 +153,56 @@ def produceObj(x,y,chip, ra, dec, pa): ...@@ -143,50 +153,56 @@ def produceObj(x,y,chip, ra, dec, pa):
class TestSpecDisperse(unittest.TestCase): class TestSpecDisperse(unittest.TestCase):
def __init__(self, methodName='runTest'): def __init__(self, methodName='runTest'):
super(TestSpecDisperse,self).__init__(methodName) super(TestSpecDisperse, self).__init__(methodName)
self.filePath('csst_msc_sim/test_sls_and_straylight') self.filePath('csst_msc_sim/test_sls_and_straylight')
# self.conff = conff # self.conff = conff
# self.throughputf = throughputf # self.throughputf = throughputf
def filePath(self, file_name): def filePath(self, file_name):
fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name) fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name)
self.conff= os.path.join(fn, 'CSST_GI2.conf') self.conff = os.path.join(fn, 'CSST_GI2.conf')
self.throughputf= os.path.join(fn, 'GI.Throughput.1st.fits') self.throughputf = os.path.join(fn, 'GI.Throughput.1st.fits')
self.testDir = fn self.testDir = fn
self.outDataFn = os.path.join(fn,'output') self.outDataFn = os.path.join(fn, 'output')
if os.path.isdir(self.outDataFn): if os.path.isdir(self.outDataFn):
pass pass
else: else:
os.mkdir(self.outDataFn) os.mkdir(self.outDataFn)
def test_rotate901(self): def test_rotate901(self):
m = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]) m = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [
m1 = np.array([[21,16,11,6,1],[22,17,12,7,2],[23,18,13,8,3],[24,19,14,9,4],[25,20,15,10,5]]) 16, 17, 18, 19, 20], [21, 22, 23, 24, 25]])
m2 = np.array([[5,10,15,20,25],[4,9,14,19,24],[3,8,13,18,23],[2,7,12,17,22],[1,6,11,16,21]]) m1 = np.array([[21, 16, 11, 6, 1], [22, 17, 12, 7, 2], [
23, 18, 13, 8, 3], [24, 19, 14, 9, 4], [25, 20, 15, 10, 5]])
m2 = np.array([[5, 10, 15, 20, 25], [4, 9, 14, 19, 24], [
3, 8, 13, 18, 23], [2, 7, 12, 17, 22], [1, 6, 11, 16, 21]])
xc = 2 xc = 2
yc = 2 yc = 2
isClockwise = 0 isClockwise = 0
m1, xc1, yc1 = rotate90(array_orig=m, xc=xc, yc=yc, isClockwise=isClockwise) m1, xc1, yc1 = rotate90(array_orig=m, xc=xc,
yc=yc, isClockwise=isClockwise)
self.assertTrue(xc1-xc == 0) self.assertTrue(xc1-xc == 0)
self.assertTrue(yc1-yc == 0) self.assertTrue(yc1-yc == 0)
self.assertTrue(np.sum(m-m1) == 0) self.assertTrue(np.sum(m-m1) == 0)
def test_rotate902(self): def test_rotate902(self):
m = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]) m = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [
m1 = np.array([[21,16,11,6,1],[22,17,12,7,2],[23,18,13,8,3],[24,19,14,9,4],[25,20,15,10,5]]) 16, 17, 18, 19, 20], [21, 22, 23, 24, 25]])
m2 = np.array([[5,10,15,20,25],[4,9,14,19,24],[3,8,13,18,23],[2,7,12,17,22],[1,6,11,16,21]]) m1 = np.array([[21, 16, 11, 6, 1], [22, 17, 12, 7, 2], [
23, 18, 13, 8, 3], [24, 19, 14, 9, 4], [25, 20, 15, 10, 5]])
m2 = np.array([[5, 10, 15, 20, 25], [4, 9, 14, 19, 24], [
3, 8, 13, 18, 23], [2, 7, 12, 17, 22], [1, 6, 11, 16, 21]])
xc = 2 xc = 2
yc = 2 yc = 2
isClockwise =1 isClockwise = 1
m1, xc1, yc1 = rotate90(array_orig=m, xc=xc, yc=yc, isClockwise=isClockwise) m1, xc1, yc1 = rotate90(array_orig=m, xc=xc,
yc=yc, isClockwise=isClockwise)
self.assertTrue(xc1-xc == 0) self.assertTrue(xc1-xc == 0)
self.assertTrue(yc1-yc == 0) self.assertTrue(yc1-yc == 0)
self.assertTrue(np.sum(m-m2) == 0) self.assertTrue(np.sum(m-m2) == 0)
def test_Specdistperse1(self): def test_Specdistperse1(self):
star = galsim.Gaussian(fwhm=0.39) star = galsim.Gaussian(fwhm=0.39)
...@@ -236,7 +252,8 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -236,7 +252,8 @@ class TestSpecDisperse(unittest.TestCase):
ids = wave_pix < 9700 ids = wave_pix < 9700
ids1 = wave_pix[ids] > 6500 ids1 = wave_pix[ids] > 6500
print('Spec disperse flux test') print('Spec disperse flux test')
self.assertTrue(np.mean((wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1]))<0.004) self.assertTrue(np.mean(
(wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1])) < 0.004)
# plt.figure() # plt.figure()
# plt.plot(wave_pix, wave_flux) # plt.plot(wave_pix, wave_flux)
# plt.plot(sed['WAVELENGTH'], sed['FLUX']) # plt.plot(sed['WAVELENGTH'], sed['FLUX'])
...@@ -299,14 +316,17 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -299,14 +316,17 @@ class TestSpecDisperse(unittest.TestCase):
input_em_lam = 6600 input_em_lam = 6600
ids = wave_pix < input_em_lam+200 ids = wave_pix < input_em_lam+200
ids1 = wave_pix[ids] > input_em_lam-200 ids1 = wave_pix[ids] > input_em_lam-200
deltLamda_pix = (max(wave_pix[ids][ids1]) - min(wave_pix[ids][ids1])) / (wave_pix[ids][ids1].shape[0] - 1) deltLamda_pix = (max(
_, _, fwhmx, fwhmx_err, center, center_err = fit_SingleGauss(wave_pix[ids][ids1], wave_flux[ids][ids1], 1.0, 6600) wave_pix[ids][ids1]) - min(wave_pix[ids][ids1])) / (wave_pix[ids][ids1].shape[0] - 1)
_, _, fwhmx, fwhmx_err, center, center_err = fit_SingleGauss(
wave_pix[ids][ids1], wave_flux[ids][ids1], 1.0, 6600)
print('Emission line position and shape test') print('Emission line position and shape test')
self.assertTrue(input_em_lam-center < deltLamda_pix) self.assertTrue(input_em_lam-center < deltLamda_pix)
# print(fwhmx/deltLamda_pix*pix_scale - psf_fwhm) # print(fwhmx/deltLamda_pix*pix_scale - psf_fwhm)
self.assertTrue(fwhmx/deltLamda_pix*pix_scale - psf_fwhm < np.abs(0.02)) self.assertTrue(fwhmx/deltLamda_pix*pix_scale -
psf_fwhm < np.abs(0.02))
# print('error is ',np.mean((wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1]))) # print('error is ',np.mean((wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1])))
# self.assertTrue(np.mean((wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1]))<0.004) # self.assertTrue(np.mean((wave_flux[ids][ids1] - sed_i(wave_pix[ids][ids1]))/sed_i(wave_pix[ids][ids1]))<0.004)
# plt.figure() # plt.figure()
...@@ -356,7 +376,6 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -356,7 +376,6 @@ class TestSpecDisperse(unittest.TestCase):
for i in range(sh[1]): for i in range(sh[1]):
spec_pix[i] = sum(Aimg[:, i]) spec_pix[i] = sum(Aimg[:, i])
wave_flux = np.zeros(wave_pix.shape[0]) wave_flux = np.zeros(wave_pix.shape[0])
for i in np.arange(1, wave_pix.shape[0] - 1): for i in np.arange(1, wave_pix.shape[0] - 1):
w = wave_pix[i] w = wave_pix[i]
...@@ -414,14 +433,12 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -414,14 +433,12 @@ class TestSpecDisperse(unittest.TestCase):
plt.legend(['one spec', 'split in 8000 A']) plt.legend(['one spec', 'split in 8000 A'])
plt.show() plt.show()
def test_double_disperse(self): def test_double_disperse(self):
# work_dir = "/public/home/fangyuedong/CSST_unittest/CSST/test/" # work_dir = "/public/home/fangyuedong/CSST_unittest/CSST/test/"
# data_dir = "/Volumes/Extreme SSD/SimData/" # data_dir = "/Volumes/Extreme SSD/SimData/"
# data_dir = "/data/simudata/CSSOSDataProductsSims/data/" # data_dir = "/data/simudata/CSSOSDataProductsSims/data/"
configFn = os.path.join(self.testDir, 'config_C6.yaml') configFn = os.path.join(self.testDir, 'config_C6.yaml')
normFilterFn = os.path.join(self.testDir, 'SLOAN_SDSS.g.fits') normFilterFn = os.path.join(self.testDir, 'SLOAN_SDSS.g.fits')
norm_star = Table.read(normFilterFn) norm_star = Table.read(normFilterFn)
with open(configFn, "r") as stream: with open(configFn, "r") as stream:
try: try:
...@@ -431,9 +448,9 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -431,9 +448,9 @@ class TestSpecDisperse(unittest.TestCase):
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
filter_param = FilterParam() filter_param = FilterParam()
focal_plane = FocalPlane(survey_type=config["obs_setting"]["survey_type"]) focal_plane = FocalPlane(
survey_type=config["obs_setting"]["survey_type"])
chip = Chip(1, config=config) chip = Chip(1, config=config)
filter_id, filter_type = chip.getChipFilter() filter_id, filter_type = chip.getChipFilter()
filt = Filter(filter_id=filter_id, filter_type=filter_type, filter_param=filter_param, filt = Filter(filter_id=filter_id, filter_type=filter_type, filter_param=filter_param,
...@@ -442,13 +459,14 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -442,13 +459,14 @@ class TestSpecDisperse(unittest.TestCase):
psf_model = PSFGauss(chip=chip) psf_model = PSFGauss(chip=chip)
wcs_fp = focal_plane.getTanWCS(float(config["obs_setting"]["ra_center"]), float(
wcs_fp = focal_plane.getTanWCS(float(config["obs_setting"]["ra_center"]), float(config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"]) * galsim.degrees, chip.pix_scale) config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"]) * galsim.degrees, chip.pix_scale)
chip.img = galsim.ImageF(chip.npix_x, chip.npix_y) chip.img = galsim.ImageF(chip.npix_x, chip.npix_y)
chip.img.setOrigin(chip.bound.xmin, chip.bound.ymin) chip.img.setOrigin(chip.bound.xmin, chip.bound.ymin)
chip.img.wcs = wcs_fp chip.img.wcs = wcs_fp
obj, pos_img = produceObj(2000,4500, chip,float(config["obs_setting"]["ra_center"]), float(config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"])) obj, pos_img = produceObj(2000, 4500, chip, float(config["obs_setting"]["ra_center"]), float(
config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"]))
# print(pos_img,chip.pix_scale) # print(pos_img,chip.pix_scale)
obj.drawObj_slitless( obj.drawObj_slitless(
tel=tel, tel=tel,
...@@ -462,7 +480,8 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -462,7 +480,8 @@ class TestSpecDisperse(unittest.TestCase):
exptime=150, exptime=150,
normFilter=norm_star) normFilter=norm_star)
obj, pos_img = produceObj(3685, 6500, chip,float(config["obs_setting"]["ra_center"]), float(config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"])) obj, pos_img = produceObj(3685, 6500, chip, float(config["obs_setting"]["ra_center"]), float(
config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"]))
obj.drawObj_slitless( obj.drawObj_slitless(
tel=tel, tel=tel,
pos_img=pos_img, pos_img=pos_img,
...@@ -475,7 +494,8 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -475,7 +494,8 @@ class TestSpecDisperse(unittest.TestCase):
exptime=150, exptime=150,
normFilter=norm_star) normFilter=norm_star)
obj, pos_img = produceObj(5000, 2500, chip, float(config["obs_setting"]["ra_center"]), float(config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"])) obj, pos_img = produceObj(5000, 2500, chip, float(config["obs_setting"]["ra_center"]), float(
config["obs_setting"]["dec_center"]), float(config["obs_setting"]["image_rot"]))
obj.drawObj_slitless( obj.drawObj_slitless(
tel=tel, tel=tel,
pos_img=pos_img, pos_img=pos_img,
...@@ -490,7 +510,8 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -490,7 +510,8 @@ class TestSpecDisperse(unittest.TestCase):
print('Spec double disperse test') print('Spec double disperse test')
from astropy.io import fits from astropy.io import fits
fits.writeto(os.path.join(self.outDataFn,'test_sls_doubleDisp.fits'),chip.img.array, overwrite = True) fits.writeto(os.path.join(
self.outDataFn, 'test_sls_doubleDisp.fits'), chip.img.array, overwrite=True)
# plt.figure() # plt.figure()
# plt.imshow(chip.img.array) # plt.imshow(chip.img.array)
...@@ -498,7 +519,7 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -498,7 +519,7 @@ class TestSpecDisperse(unittest.TestCase):
def test_SLSImage_rotation(self): def test_SLSImage_rotation(self):
from astropy.wcs import WCS from astropy.wcs import WCS
configFn = os.path.join(self.testDir,'config_C6.yaml') configFn = os.path.join(self.testDir, 'config_C6.yaml')
with open(configFn, "r") as stream: with open(configFn, "r") as stream:
try: try:
...@@ -509,71 +530,71 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -509,71 +530,71 @@ class TestSpecDisperse(unittest.TestCase):
print(exc) print(exc)
chip = Chip(1, config=config) chip = Chip(1, config=config)
ra=float(config["obs_setting"]["ra_center"]) ra = float(config["obs_setting"]["ra_center"])
dec=float(config["obs_setting"]["dec_center"]) dec = float(config["obs_setting"]["dec_center"])
pa=float(config["obs_setting"]["image_rot"]) pa = float(config["obs_setting"]["image_rot"])
chip.rotate_angle = 0 chip.rotate_angle = 0
header_wcs1 = generateExtensionHeader(chip, header_wcs1 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
center = np.array([chip.npix_x / 2, chip.npix_y / 2]) center = np.array([chip.npix_x / 2, chip.npix_y / 2])
h_wcs1 = WCS(header_wcs1) h_wcs1 = WCS(header_wcs1)
x1, y1 = center + [100,0] x1, y1 = center + [100, 0]
sky_1 = h_wcs1.pixel_to_world(x1,y1) sky_1 = h_wcs1.pixel_to_world(x1, y1)
chip = Chip(1, config=config) chip = Chip(1, config=config)
rot_angle = 1 rot_angle = 1
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
angle = getAngle132(x1,y1,0,x2,y2,0,center[0],center[1],0) angle = getAngle132(x1, y1, 0, x2, y2, 0, center[0], center[1], 0)
# print("rotation angle:" ,rot_angle ,chip.rotate_angle, angle) # print("rotation angle:" ,rot_angle ,chip.rotate_angle, angle)
# self.assertTrue(rot_angle - angle < np.abs(0.001)) # self.assertTrue(rot_angle - angle < np.abs(0.001))
rot_angle = 10 rot_angle = 10
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
...@@ -584,19 +605,19 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -584,19 +605,19 @@ class TestSpecDisperse(unittest.TestCase):
rot_angle = 50 rot_angle = 50
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
...@@ -604,7 +625,6 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -604,7 +625,6 @@ class TestSpecDisperse(unittest.TestCase):
# print(rot_angle - angle) # print(rot_angle - angle)
self.assertTrue(rot_angle - angle < np.abs(0.001)) self.assertTrue(rot_angle - angle < np.abs(0.001))
chip = Chip(27, config=config) chip = Chip(27, config=config)
ra = float(config["obs_setting"]["ra_center"]) ra = float(config["obs_setting"]["ra_center"])
...@@ -612,19 +632,19 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -612,19 +632,19 @@ class TestSpecDisperse(unittest.TestCase):
pa = float(config["obs_setting"]["image_rot"]) pa = float(config["obs_setting"]["image_rot"])
chip.rotate_angle = 0 chip.rotate_angle = 0
header_wcs1 = generateExtensionHeader(chip, header_wcs1 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
center = np.array([chip.npix_x / 2, chip.npix_y / 2]) center = np.array([chip.npix_x / 2, chip.npix_y / 2])
h_wcs1 = WCS(header_wcs1) h_wcs1 = WCS(header_wcs1)
...@@ -634,19 +654,19 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -634,19 +654,19 @@ class TestSpecDisperse(unittest.TestCase):
rot_angle = 1 rot_angle = 1
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
...@@ -657,19 +677,19 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -657,19 +677,19 @@ class TestSpecDisperse(unittest.TestCase):
rot_angle = 10 rot_angle = 10
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
...@@ -680,19 +700,19 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -680,19 +700,19 @@ class TestSpecDisperse(unittest.TestCase):
rot_angle = 50 rot_angle = 50
chip.rotate_angle = rot_angle chip.rotate_angle = rot_angle
header_wcs2 = generateExtensionHeader(chip, header_wcs2 = generateExtensionHeader(chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=ra, ra=ra,
dec=dec, dec=dec,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
readout=chip.read_noise, readout=chip.read_noise,
dark=chip.dark_noise, dark=chip.dark_noise,
saturation=90000, saturation=90000,
pixel_scale=chip.pix_scale, pixel_scale=chip.pix_scale,
row_num=chip.rowID, row_num=chip.rowID,
col_num=chip.colID, col_num=chip.colID,
extName='raw') extName='raw')
h_wcs2 = WCS(header_wcs2) h_wcs2 = WCS(header_wcs2)
x2, y2 = h_wcs2.world_to_pixel(sky_1) x2, y2 = h_wcs2.world_to_pixel(sky_1)
...@@ -701,11 +721,9 @@ class TestSpecDisperse(unittest.TestCase): ...@@ -701,11 +721,9 @@ class TestSpecDisperse(unittest.TestCase):
self.assertTrue(rot_angle - angle < np.abs(0.001)) self.assertTrue(rot_angle - angle < np.abs(0.001))
if __name__ == '__main__': if __name__ == '__main__':
os.environ['UNIT_TEST_DATA_ROOT']="/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData" os.environ['UNIT_TEST_DATA_ROOT'] = "/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData"
testDir = os.getenv('UNIT_TEST_DATA_ROOT') testDir = os.getenv('UNIT_TEST_DATA_ROOT')
# conff= os.path.join(testDir, 'CSST_GI2.conf') # conff= os.path.join(testDir, 'CSST_GI2.conf')
# throughputf= os.path.join(testDir, 'GI.Throughput.1st.fits') # throughputf= os.path.join(testDir, 'GI.Throughput.1st.fits')
...@@ -723,4 +741,4 @@ if __name__ == '__main__': ...@@ -723,4 +741,4 @@ if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suit) unittest.TextTestRunner(verbosity=2).run(suit)
# runner = unittest.TextTestRunner() # runner = unittest.TextTestRunner()
# runner.run(suit) # runner.run(suit)
\ No newline at end of file
# #
#need add environment parameter UNIT_TEST_DATA_ROOT, link to "testData/" # need add environment parameter UNIT_TEST_DATA_ROOT, link to "testData/"
#linx and mac can run as follow, need modify the name of file directory # linx and mac can run as follow, need modify the name of file directory
#export UNIT_TEST_DATA_ROOT=/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData # export UNIT_TEST_DATA_ROOT=/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData
# #
import unittest import unittest
from ObservationSim.Straylight import Straylight from observation_sim.sky_background import Straylight
import numpy as np import numpy as np
import math import math
...@@ -17,8 +17,10 @@ import matplotlib.pyplot as plt ...@@ -17,8 +17,10 @@ import matplotlib.pyplot as plt
import os import os
hubbleAverZodiacal = {'nuv':0.0035,'u':0.0163,'g':0.1109,'r':0.1471,'i':0.1568,'z':0.0953,'y':0.0283} hubbleAverZodiacal = {'nuv': 0.0035, 'u': 0.0163, 'g': 0.1109,
hubbleAverEarthShine = {'nuv':0.00024,'u':0.0051,'g':0.0506,'r':0.0591,'i':0.0568,'z':0.0315,'y':0.0090} 'r': 0.1471, 'i': 0.1568, 'z': 0.0953, 'y': 0.0283}
hubbleAverEarthShine = {'nuv': 0.00024, 'u': 0.0051, 'g': 0.0506,
'r': 0.0591, 'i': 0.0568, 'z': 0.0315, 'y': 0.0090}
# def transRaDec2D(ra, dec): # def transRaDec2D(ra, dec):
# x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795); # x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795);
...@@ -28,63 +30,69 @@ hubbleAverEarthShine = {'nuv':0.00024,'u':0.0051,'g':0.0506,'r':0.0591,'i':0.056 ...@@ -28,63 +30,69 @@ hubbleAverEarthShine = {'nuv':0.00024,'u':0.0051,'g':0.0506,'r':0.0591,'i':0.056
def getAngle132(x1=0, y1=0, z1=0, x2=0, y2=0, z2=0, x3=0, y3=0, z3=0): def getAngle132(x1=0, y1=0, z1=0, x2=0, y2=0, z2=0, x3=0, y3=0, z3=0):
cosValue = 0; cosValue = 0
angle = 0; angle = 0
x11 = x1 - x3; x11 = x1 - x3
y11 = y1 - y3; y11 = y1 - y3
z11 = z1 - z3; z11 = z1 - z3
x22 = x2 - x3; x22 = x2 - x3
y22 = y2 - y3; y22 = y2 - y3
z22 = z2 - z3; z22 = z2 - z3
tt = np.sqrt((x11 * x11 + y11 * y11 + z11 * z11) * (x22 * x22 + y22 * y22 + z22 * z22)); tt = np.sqrt((x11 * x11 + y11 * y11 + z11 * z11)
* (x22 * x22 + y22 * y22 + z22 * z22))
if (tt == 0): if (tt == 0):
return 0; return 0
cosValue = (x11 * x22 + y11 * y22 + z11 * z22) / tt; cosValue = (x11 * x22 + y11 * y22 + z11 * z22) / tt
if (cosValue > 1): if (cosValue > 1):
cosValue = 1; cosValue = 1
if (cosValue < -1): if (cosValue < -1):
cosValue = -1; cosValue = -1
angle = math.acos(cosValue); angle = math.acos(cosValue)
return angle * 360 / (2 * math.pi); return angle * 360 / (2 * math.pi)
def calculateAnglePwithEarth(sat = np.array([0,0,0]), pointing = np.array([0,0,0]), sun = np.array([0,0,0])):
def calculateAnglePwithEarth(sat=np.array([0, 0, 0]), pointing=np.array([0, 0, 0]), sun=np.array([0, 0, 0])):
modSat = np.sqrt(sat[0]*sat[0] + sat[1]*sat[1]+sat[2]*sat[2]) modSat = np.sqrt(sat[0]*sat[0] + sat[1]*sat[1]+sat[2]*sat[2])
modPoint = np.sqrt(pointing[0]*pointing[0] + pointing[1]*pointing[1] + pointing[2]*pointing[2]) modPoint = np.sqrt(pointing[0]*pointing[0] +
withLocalZenithAngle = (pointing[0] * sat[0] + pointing[1] * sat[1] + pointing[2] * sat[2]) / (modPoint*modSat) pointing[1]*pointing[1] + pointing[2]*pointing[2])
withLocalZenithAngle = (
pointing[0] * sat[0] + pointing[1] * sat[1] + pointing[2] * sat[2]) / (modPoint*modSat)
innerM_sat_sun = sat[0] * sun[0] + sat[1] * sun[1] + sat[2] * sun[2] innerM_sat_sun = sat[0] * sun[0] + sat[1] * sun[1] + sat[2] * sun[2]
cosAngle = innerM_sat_sun / (modSat * cons.au.value/1000) cosAngle = innerM_sat_sun / (modSat * cons.au.value/1000)
isInSunSide = 1 isInSunSide = 1
if (cosAngle < -0.3385737): #cos109.79 if (cosAngle < -0.3385737): # cos109.79
isInSunSide = -1; isInSunSide = -1
elif cosAngle >= -0.3385737 and cosAngle <= 0.3385737: elif cosAngle >= -0.3385737 and cosAngle <= 0.3385737:
isInSunSide = 0; isInSunSide = 0
return math.acos(withLocalZenithAngle)*180/math.pi, isInSunSide
return math.acos(withLocalZenithAngle)*180/math.pi,isInSunSide
class TestStraylight(unittest.TestCase): class TestStraylight(unittest.TestCase):
def __init__(self,methodName='runTest', filter = 'i', grating = "GI"): def __init__(self, methodName='runTest', filter='i', grating="GI"):
super(TestStraylight,self).__init__(methodName) super(TestStraylight, self).__init__(methodName)
# print(file_name) # print(file_name)
# fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name) # fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name)
# self.pointingData = np.loadtxt(os.path.join(fn, 'Straylight_test.dat'), dtype=np.double) # self.pointingData = np.loadtxt(os.path.join(fn, 'Straylight_test.dat'), dtype=np.double)
self.filePath('csst_msc_sim/test_sls_and_straylight') self.filePath('csst_msc_sim/test_sls_and_straylight')
self.filter = filter self.filter = filter
self.grating = grating self.grating = grating
def filePath(self, file_name): def filePath(self, file_name):
fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name) fn = os.path.join(os.getenv('UNIT_TEST_DATA_ROOT'), file_name)
self.pointingData = np.loadtxt(os.path.join(fn, 'Straylight_test.dat'), dtype=np.double) self.pointingData = np.loadtxt(os.path.join(
fn, 'Straylight_test.dat'), dtype=np.double)
def test_EarthShineFilter(self): def test_EarthShineFilter(self):
d_sh = self.pointingData.shape d_sh = self.pointingData.shape
sl_e_pix = np.zeros([d_sh[0],3],dtype=np.double) sl_e_pix = np.zeros([d_sh[0], 3], dtype=np.double)
for i in np.arange(d_sh[0]): for i in np.arange(d_sh[0]):
# if i > 50: # if i > 50:
...@@ -92,17 +100,19 @@ class TestStraylight(unittest.TestCase): ...@@ -92,17 +100,19 @@ class TestStraylight(unittest.TestCase):
ju = self.pointingData[i, 5] ju = self.pointingData[i, 5]
# pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1]) # pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1])
# print(ju, pointing, surveylist[i,3:9]) # print(ju, pointing, surveylist[i,3:9])
sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array([self.pointingData[i, 0], self.pointingData[i, 1]]),sun_pos=self.pointingData[i,9:12]) sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array(
[self.pointingData[i, 0], self.pointingData[i, 1]]), sun_pos=self.pointingData[i, 9:12])
e1, py = sl.calculateEarthShineFilter(filter=self.filter) e1, py = sl.calculateEarthShineFilter(filter=self.filter)
earthZenithAngle, isInSunSide = calculateAnglePwithEarth(sat=self.pointingData[i, 6:9], pointing= sl.pointing, sun=self.pointingData[i,9:12]) earthZenithAngle, isInSunSide = calculateAnglePwithEarth(
sat=self.pointingData[i, 6:9], pointing=sl.pointing, sun=self.pointingData[i, 9:12])
# e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos) # e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos)
# e3 = sl.calculateStarLightFilter(filter='i', pointYaxis=py) # e3 = sl.calculateStarLightFilter(filter='i', pointYaxis=py)
# e_all = sl.calculateStrayLightFilter(filter='i') # e_all = sl.calculateStrayLightFilter(filter='i')
# s_pix, spec = sl.calculateStrayLightGrating(grating='GI') # s_pix, spec = sl.calculateStrayLightGrating(grating='GI')
sl_e_pix[i,0] = e1 sl_e_pix[i, 0] = e1
sl_e_pix[i, 1] = earthZenithAngle sl_e_pix[i, 1] = earthZenithAngle
sl_e_pix[i, 2] = isInSunSide sl_e_pix[i, 2] = isInSunSide
median = np.median(sl_e_pix[:,0]) median = np.median(sl_e_pix[:, 0])
print(' average Earthshine %s: %e' % (self.filter, median)) print(' average Earthshine %s: %e' % (self.filter, median))
self.assertTrue(median-hubbleAverEarthShine[self.filter] < 0.1) self.assertTrue(median-hubbleAverEarthShine[self.filter] < 0.1)
plt.figure() plt.figure()
...@@ -117,27 +127,29 @@ class TestStraylight(unittest.TestCase): ...@@ -117,27 +127,29 @@ class TestStraylight(unittest.TestCase):
def test_ZodiacalFilter(self): def test_ZodiacalFilter(self):
d_sh = self.pointingData.shape d_sh = self.pointingData.shape
sl_e_pix = np.zeros([d_sh[0],2],dtype=np.double) sl_e_pix = np.zeros([d_sh[0], 2], dtype=np.double)
for i in np.arange(d_sh[0]): for i in np.arange(d_sh[0]):
ju = self.pointingData[i, 5] ju = self.pointingData[i, 5]
sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array([self.pointingData[i, 0], self.pointingData[i, 1]]),sun_pos=self.pointingData[i,9:12]) sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array(
e1, _ = sl.calculateZodiacalFilter2(filter=self.filter, sun_pos=sl.sun_pos) [self.pointingData[i, 0], self.pointingData[i, 1]]), sun_pos=self.pointingData[i, 9:12])
sl_e_pix[i,0] = e1 e1, _ = sl.calculateZodiacalFilter2(
sl_e_pix[i,1] = getAngle132(x1=self.pointingData[i,9], y1=self.pointingData[i,10], z1=self.pointingData[i,11], x2=sl.pointing[0], filter=self.filter, sun_pos=sl.sun_pos)
y2=sl.pointing[1], z2=sl.pointing[2], x3=0, y3=0, z3=0) sl_e_pix[i, 0] = e1
sl_e_pix[i, 1] = getAngle132(x1=self.pointingData[i, 9], y1=self.pointingData[i, 10], z1=self.pointingData[i, 11], x2=sl.pointing[0],
y2=sl.pointing[1], z2=sl.pointing[2], x3=0, y3=0, z3=0)
plt.figure() plt.figure()
plt.plot(sl_e_pix[:, 0], sl_e_pix[:, 1], 'r.') plt.plot(sl_e_pix[:, 0], sl_e_pix[:, 1], 'r.')
plt.xlabel('straylight-zodiacal(e-/pixel/s)') plt.xlabel('straylight-zodiacal(e-/pixel/s)')
plt.ylabel('Angle between pointing and sun(degree)') plt.ylabel('Angle between pointing and sun(degree)')
plt.show() plt.show()
median = np.median(sl_e_pix[:,0]) median = np.median(sl_e_pix[:, 0])
print(' average Zodiacal %s: %f' % (self.filter, median)) print(' average Zodiacal %s: %f' % (self.filter, median))
self.assertTrue(median-hubbleAverZodiacal[self.filter] < 0.1) self.assertTrue(median-hubbleAverZodiacal[self.filter] < 0.1)
def test_StarFilter(self): def test_StarFilter(self):
d_sh = self.pointingData.shape d_sh = self.pointingData.shape
sl_e_pix = np.zeros(d_sh[0],dtype=np.double) sl_e_pix = np.zeros(d_sh[0], dtype=np.double)
tnum = 10 tnum = 10
for i in np.arange(tnum): for i in np.arange(tnum):
...@@ -146,20 +158,21 @@ class TestStraylight(unittest.TestCase): ...@@ -146,20 +158,21 @@ class TestStraylight(unittest.TestCase):
ju = self.pointingData[i, 5] ju = self.pointingData[i, 5]
# pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1]) # pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1])
# print(ju, pointing, surveylist[i,3:9]) # print(ju, pointing, surveylist[i,3:9])
sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array([self.pointingData[i, 0], self.pointingData[i, 1]]),sun_pos=self.pointingData[i,9:12]) sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array(
[self.pointingData[i, 0], self.pointingData[i, 1]]), sun_pos=self.pointingData[i, 9:12])
e1, py = sl.calculateEarthShineFilter(filter=self.filter) e1, py = sl.calculateEarthShineFilter(filter=self.filter)
# e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos) # e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos)
e3 = sl.calculateStarLightFilter(filter=self.filter, pointYaxis=py) e3 = sl.calculateStarLightFilter(filter=self.filter, pointYaxis=py)
# e_all = sl.calculateStrayLightFilter(filter='i') # e_all = sl.calculateStrayLightFilter(filter='i')
# s_pix, spec = sl.calculateStrayLightGrating(grating='GI') # s_pix, spec = sl.calculateStrayLightGrating(grating='GI')
sl_e_pix[i] = e3 sl_e_pix[i] = e3
median = np.median(sl_e_pix[0:tnum]) median = np.median(sl_e_pix[0:tnum])
print(' average Earthshine %s: %e' % (self.filter, median)) print(' average Earthshine %s: %e' % (self.filter, median))
self.assertTrue(median-hubbleAverEarthShine[self.filter] < 0.2) self.assertTrue(median-hubbleAverEarthShine[self.filter] < 0.2)
def test_GratingStraylight(self): def test_GratingStraylight(self):
d_sh = self.pointingData.shape d_sh = self.pointingData.shape
sl_e_pix = np.zeros(d_sh[0],dtype=np.double) sl_e_pix = np.zeros(d_sh[0], dtype=np.double)
tnum = 10 tnum = 10
for i in np.arange(tnum): for i in np.arange(tnum):
...@@ -168,7 +181,8 @@ class TestStraylight(unittest.TestCase): ...@@ -168,7 +181,8 @@ class TestStraylight(unittest.TestCase):
ju = self.pointingData[i, 5] ju = self.pointingData[i, 5]
# pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1]) # pointing = transRaDec2D(self.pointingData[i, 0], self.pointingData[i, 1])
# print(ju, pointing, surveylist[i,3:9]) # print(ju, pointing, surveylist[i,3:9])
sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array([self.pointingData[i, 0], self.pointingData[i, 1]]),sun_pos=self.pointingData[i,9:12]) sl = Straylight(jtime=ju, sat_pos=self.pointingData[i, 6:9], pointing_radec=np.array(
[self.pointingData[i, 0], self.pointingData[i, 1]]), sun_pos=self.pointingData[i, 9:12])
# e1, py = sl.calculateEarthShineFilter(filter=self.filter) # e1, py = sl.calculateEarthShineFilter(filter=self.filter)
# e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos) # e2, _ = sl.calculateZodiacalFilter2(filter='i', sun_pos=sl.sun_pos)
# e3 = sl.calculateStarLightFilter(filter=self.filter, pointYaxis=py) # e3 = sl.calculateStarLightFilter(filter=self.filter, pointYaxis=py)
...@@ -179,18 +193,15 @@ class TestStraylight(unittest.TestCase): ...@@ -179,18 +193,15 @@ class TestStraylight(unittest.TestCase):
plt.plot(spec['WAVELENGTH'], spec['FLUX'], 'r') plt.plot(spec['WAVELENGTH'], spec['FLUX'], 'r')
plt.xlabel('WAVELENGTH') plt.xlabel('WAVELENGTH')
plt.ylabel('F$\lambda$(erg/s/cm2/A/arcsec2)') plt.ylabel('F$\lambda$(erg/s/cm2/A/arcsec2)')
plt.xlim(2000,10000) plt.xlim(2000, 10000)
plt.show() plt.show()
median = np.median(sl_e_pix[0:tnum]) median = np.median(sl_e_pix[0:tnum])
print(' average Earthshine %s: %e' % (self.grating, median)) print(' average Earthshine %s: %e' % (self.grating, median))
self.assertTrue(median < 0.8) self.assertTrue(median < 0.8)
if __name__ == '__main__': if __name__ == '__main__':
os.environ['UNIT_TEST_DATA_ROOT']="/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData" os.environ['UNIT_TEST_DATA_ROOT'] = "/Users/zhangxin/Work/SlitlessSim/CSST_SIM/CSST_develop/csst-simulation/tests/testData"
# suit = unittest.TestSuite() # suit = unittest.TestSuite()
# case1 = TestStraylight('test_EarthShineFilter', filter = 'i') # case1 = TestStraylight('test_EarthShineFilter', filter = 'i')
...@@ -201,4 +212,4 @@ if __name__ == '__main__': ...@@ -201,4 +212,4 @@ if __name__ == '__main__':
# suit.addTest(case3) # suit.addTest(case3)
# case4 = TestStraylight('test_GratingStraylight', grating = 'GI') # case4 = TestStraylight('test_GratingStraylight', grating = 'GI')
# suit.addTest(case4) # suit.addTest(case4)
# unittest.TextTestRunner(verbosity=2).run(suit) # unittest.TextTestRunner(verbosity=2).run(suit)
\ No newline at end of file
...@@ -4,7 +4,7 @@ import sys ...@@ -4,7 +4,7 @@ import sys
from astropy.time import Time from astropy.time import Time
from datetime import datetime from datetime import datetime
from ObservationSim.Astrometry.Astrometry_util import on_orbit_obs_position from observation_sim.astrometry.Astrometry_util import on_orbit_obs_position
class TestAstrometry(unittest.TestCase): class TestAstrometry(unittest.TestCase):
......
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