PSFProcess.py 2.61 KB
Newer Older
Fang Yuedong's avatar
Fang Yuedong committed
1
2
3
4
5
6
7
8
import os, sys
import numpy as np
import scipy.io
import mpi4py.MPI as MPI



#sys.path.append("/public/home/weichengliang/lnData/CSST_new_framwork/csstPSF_20201222")
Fang Yuedong's avatar
Fang Yuedong committed
9
10
11
12
# import PSFConfig as myConfig
# import PSFUtil as myUtil
import PSFConfig
import PSFUtil
Fang Yuedong's avatar
Fang Yuedong committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

def mkdir(path):
    isExists = os.path.exists(path)
    if not isExists:
        os.mkdir(path)
    

############################################
comm = MPI.COMM_WORLD
ThisTask = comm.Get_rank()
NTasks   = comm.Get_size()

npsf = 900
psfPath = '/data/simudata/CSSOSDataProductsSims/data/csstPSFdata/CSSOS_psf_20210108/CSST_psf_ciomp_2p5um_cycle3_ccr90'

npsfPerTasks = int(npsf/NTasks)
iStart= 0 + npsfPerTasks*ThisTask
iEnd  = npsfPerTasks + npsfPerTasks*ThisTask
if ThisTask == NTasks:
    iEnd = npsf


for iccd in range(1, 31):
    iccdPath = psfPath + '_proc/ccd{:}'.format(iccd)
    if ThisTask == 0:
        mkdir(iccdPath)
    comm.barrier()

    for iwave in range(1, 5):
        iwavePath = iccdPath + '/wave_{:}'.format(iwave)
        if ThisTask == 0:
            mkdir(iwavePath)
        comm.barrier()

        psfMatPath = iwavePath + '/5_psf_array'
        if ThisTask == 0:
            mkdir(psfMatPath)
        comm.barrier()

        for ii in range(iStart, iEnd):
            ipsf = ii+1
            if ThisTask ==0:
                print('iccd-iwave-ipsf: {:4}{:4}{:4}'.format(iccd, iwave, ipsf), end='\r',flush=True)
            #if iccd != 1 or iwave !=1 or ipsf != 1:
            #    continue

            ipsfOutput = psfMatPath + '/psf_{:}_centroidWgt.mat'.format(ipsf)
Fang Yuedong's avatar
Fang Yuedong committed
60
            psfInfo = PSFConfig.LoadPSF(iccd, iwave, ipsf, psfPath, InputMaxPixelPos=True)
Fang Yuedong's avatar
Fang Yuedong committed
61
62
63
64
65
66
67
68
69
70
            ipsfMat  = psfInfo['psfMat']
            npix_y, npix_x = ipsfMat.shape

            #if npsf == 100:
            #    ncut = 160
            #if npsf == 900:
            #    ncut = 200
            ncut = int(npix_y*0.90)
            ncut = ncut + ncut%2  #even pixs

Fang Yuedong's avatar
Fang Yuedong committed
71
            img, cx, cy = PSFUtil.centroidWgt(ipsfMat, nt=ncut)
Fang Yuedong's avatar
Fang Yuedong committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
            dcx = cx - npix_x/2   #pixel coords -> global coords
            dcy = cy - npix_y/2  #pixel coords -> global coords
            dcx*= psfInfo['pixsize']*1e-3 #5e-3  #pixels -> mm
            dcy*= psfInfo['pixsize']*1e-3 #5e-3  #pixels -> mm
            
            nn = npix_y
            dn = int((nn - ncut)/2)
            imgt = np.zeros([nn, nn], dtype=np.float32)
            imgt[dn:-dn, dn:-dn] = img

            scipy.io.savemat(ipsfOutput, {'cx':dcx, 'cy':dcy, 'psf':imgt})
            if iccd != 1 or iwave !=1 or ipsf != 1:
                if ThisTask == 0:
                    print('CHECK::', dcx, dcy, psfInfo['centroid_x'],psfInfo['centroid_y'])