Newer
Older
from itertools import islice
import numpy as np
import galsim
import yaml
from observation_sim.instruments import Chip, Filter, FilterParam, FocalPlane
from observation_sim.PSF.PSFInterp import PSFInterp
def defineCCD(iccd, config_file):
with open(config_file, "r") as stream:
try:
config = yaml.safe_load(stream)
# print (key + " : " + str(value))
except yaml.YAMLError as exc:
print(exc)
chip = Chip(chipID=iccd, config=config)
chip.img = galsim.ImageF(chip.npix_x, chip.npix_y)
focal_plane = FocalPlane(chip_list=[iccd])
chip.img.wcs = focal_plane.getTanWCS(
192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale)
def defineFilt(chip):
filter_param = FilterParam()
filter_id, filter_type = chip.getChipFilter()
filt = Filter(
filter_id=filter_id,
filter_type=filter_type,
filter_param=filter_param,
ccd_bandpass=chip.effCurve)
bandpass_list = filt.bandpass_sub_list
return bandpass_list
class PSFInterpModule_coverage(unittest.TestCase):
def __init__(self, methodName='runTest'):
super(PSFInterpModule_coverage, self).__init__(methodName)
self.dataPath = os.path.join(
os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc')
def test_loadPSFSet(self):
config_file = os.path.join(self.dataPath, 'config_test.yaml')
chip = defineCCD(self.iccd, config_file)
bandpass = defineFilt(chip)
print(chip.chipID)
print(chip.cen_pix_x, chip.cen_pix_y)
# "/public/share/yangxuliu/CSSOSDataProductsSims/psfCube/set1_dynamic/"
pathTemp = self.dataPath
psfModel = PSFInterp(chip, npsf=900, PSF_data_file=pathTemp,
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
y = y+chip.bound.ymin
pos_img = galsim.PositionD(x, y)
psf, _ = psfModel.get_PSF(
chip=chip, pos_img=pos_img, bandpass=0, galsimGSObject=True)
psfA = psfModel.get_PSF(
chip=chip, pos_img=pos_img, bandpass=bandpass[0], galsimGSObject=False)
psfB = psfModel.get_PSF(
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)