Skip to content
test_loadPSFSet.py 1.92 KiB
Newer Older
import unittest

import sys,os,math
from itertools import islice

import numpy as np

import yaml
from ObservationSim.Instrument import Chip
from ObservationSim.PSF.PSFInterp import PSFInterp


def defineCCD(iccd, config_file):
    with open(config_file, "r") as stream:
        try:
            config = yaml.safe_load(stream)
            #for key, value in config.items():
            #    print (key + " : " + str(value))
        except yaml.YAMLError as exc:
            print(exc)
    chip = Chip(chipID=iccd, config=config)
    #chip = Chip(chipID=iccd, ccdEffCurve_dir=path_dict["ccd_dir"], CRdata_dir=path_dict["CRdata_dir"], normalize_dir=path_dict["normalize_dir"], sls_dir=path_dict['sls_dir'], config=config)
    return chip

def loadPSFSet(iccd, dataPath):
    config_file = os.path.join(dataPath, 'config_test.yaml')
    chip = defineCCD(iccd, config_file)
    print(chip.chipID)
    print(chip.cen_pix_x, chip.cen_pix_y)

    psfMat= PSFInterp(chip, npsf=900, PSF_data_file=dataPath, PSF_data_prefix="S30x30_")
    psfSet= psfMat._loadPSF(iccd, dataPath, PSF_data_prefix="S30x30_")

    twave = 0 #[0...3]
    tpsf  = 0 #[0...899]
    field_x= psfSet[twave][tpsf]['field_x']
    field_y= psfSet[twave][tpsf]['field_y']
    image_x= psfSet[twave][tpsf]['image_x']
    image_y= psfSet[twave][tpsf]['image_y']
    centroid_x= psfSet[twave][tpsf]['centroid_x']
    centroid_y= psfSet[twave][tpsf]['centroid_y']
    print("pos_info:", field_x, field_y, image_x, image_y, centroid_x, centroid_y)
    return psfSet



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_fz_gc1')

        psfSet = loadPSFSet(iccd, dataPath=self.dataPath)


if __name__ == '__main__':
    unittest.main()
    print('#####haha#####')