get_PSF_SLS.py 3.48 KB
Newer Older
Zhang Xin's avatar
Zhang Xin committed
1
2
import numpy as np
import observation_sim.psf.PSFInterpSLS as PSFInterpSLS
Zhang Xin's avatar
Zhang Xin committed
3
import observation_sim.psf.PSFInterp as PSFInterp
Zhang Xin's avatar
Zhang Xin committed
4
5
6
7
from observation_sim.instruments import Chip, Filter, FilterParam
import astropy.io.fits as fitsio

from observation_sim.instruments import Chip, FilterParam, Filter
Zhang Xin's avatar
Zhang Xin committed
8
import galsim
Zhang Xin's avatar
Zhang Xin committed
9

Zhang Xin's avatar
pep8    
Zhang Xin committed
10
11
12
13
14
15
16
17
18
# 计算 0级或1级光谱在某个波长位置的PSF, 返回值是过采样的PSF,像元大小有CSST图像像元大小的1/2
# chipId 必须为[1,2,3,4,5,10,21,26,27,28,29,30]
# order 只有 0 或 1
# pos_img 为直接成像在图像上的位置,[x, y]
# wave: 波长,单位A


def get_SLS_PSF(chipID=1, pos_img=[6000, 4000], order=1, wave=8000, sls_psf_dir='/nfsdata/share/CSSOSDataProductsSims/data/SLS_PSF_PCA_fp_cd/'):
    orders = {0: 'B', 1: 'A'}
Zhang Xin's avatar
Zhang Xin committed
19
20
21
22
23
24
25
26
27
    chip = Chip(chipID)
    filter_id, filter_type = chip.getChipFilter()
    filt = Filter(
        filter_id=filter_id,
        filter_type=filter_type,
        filter_param=FilterParam())

    psf_model = PSFInterpSLS(chip, filt, PSF_data_prefix=sls_psf_dir)
    bandNo = 1
Zhang Xin's avatar
pep8    
Zhang Xin committed
28
29
    for i, brange in enumerate(psf_model.bandranges):
        if wave >= brange[0] and wave < brange[1]:
Zhang Xin's avatar
Zhang Xin committed
30
31
32
33
            bandNo = i + 1
            break

    psf1, _ = psf_model.get_PSF(
Zhang Xin's avatar
pep8    
Zhang Xin committed
34
        chip, pos_img_local=pos_img, bandNo=bandNo, galsimGSObject=False, g_order=orders[order])
Zhang Xin's avatar
Zhang Xin committed
35
    fn = "psf.chip{:}.order{:}.wave{:}.fits".format(chipID, order, wave)
Zhang Xin's avatar
Zhang Xin committed
36
37
38
    hdu = fitsio.PrimaryHDU()
    hdu.data = psf1
    hdu.header.set('pixScale', 5)
Zhang Xin's avatar
pep8    
Zhang Xin committed
39
40
41
42
43
44
    hdu.writeto(fn, overwrite=True)

# 获得成像的PSF,PSF在波长区间分四段采样,返回4段的PSF,每个PSF代表不同band波长范围不同的四段psf,波长从小到大
# chipId 必须为[6,7,8,9,11,12,13,14,15,16,17,18,19,20,22,23,24,25]
# pos_img 为直接成像在图像上的位置,[x, y]

Zhang Xin's avatar
Zhang Xin committed
45

Zhang Xin's avatar
pep8    
Zhang Xin committed
46
def getPSFImage(chipID=6, pos_img=[6000, 4500], psf_pho_dir="/nfsdata/share/CSSOSDataProductsSims/data/psfcube/set1_dynamic/"):
Zhang Xin's avatar
Zhang Xin committed
47
48
    chip = Chip(chipID=chipID)
    print('chip.bound::', chip.bound.xmin, chip.bound.xmax,
Zhang Xin's avatar
pep8    
Zhang Xin committed
49
          chip.bound.ymin, chip.bound.ymax)
Zhang Xin's avatar
Zhang Xin committed
50
51

    # Setup Position on focalplane
Zhang Xin's avatar
pep8    
Zhang Xin committed
52
    # try get the PSF at some location (1234, 1234) on the chip
Zhang Xin's avatar
Zhang Xin committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    pos_img = pos_img
    x, y = pos_img
    x = x+chip.bound.xmin
    y = y+chip.bound.ymin

    pos_img = galsim.PositionD(x, y)

    # Setup sub-bandpass
    # (There are 4 sub-bandpasses for each PSF sample)
    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
    for i in range(len(bandpass_list)):
        print(i, end=" ", flush=True)
        # say you want to access the PSF for the sub-bandpass at the blue end for that chip
        bandpass = bandpass_list[i]

        # Get corresponding PSF model
        psf_model = PSFInterp(chip=chip, npsf=100,
Zhang Xin's avatar
pep8    
Zhang Xin committed
77
                              PSF_data_file=psf_pho_dir)
Zhang Xin's avatar
Zhang Xin committed
78
79
80
81
82
83
        psf = psf_model.get_PSF(
            chip=chip, pos_img=pos_img, bandpass=bandpass, galsimGSObject=False)
        fn = "psf_chip{:}.wave{:}.fits".format(chipID, i)
        hdu = fitsio.PrimaryHDU()
        hdu.data = psf
        hdu.header.set('pixScale', 5)
Zhang Xin's avatar
pep8    
Zhang Xin committed
84
85
86
        hdu.writeto(fn, overwrite=True)


Zhang Xin's avatar
Zhang Xin committed
87
88
89
90
91
if __name__ == "__main__":
    chipid = 2
    pos_img = [6000, 4500]
    order = 1
    w = 5000
Zhang Xin's avatar
pep8    
Zhang Xin committed
92
    get_SLS_PSF(chipID=chipid, pos_img=pos_img, order=order, wave=w)
Zhang Xin's avatar
Zhang Xin committed
93
94
95

    chipid = 7
    pos_img = [6000, 4500]
Zhang Xin's avatar
pep8    
Zhang Xin committed
96
    getPSFImage(chipID=chipid, pos_img=pos_img)