-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_SEproc.py
executable file
·132 lines (108 loc) · 5.12 KB
/
run_SEproc.py
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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from desdmLiby1e2 import *
import numpy as np
import os
import glob
#from joblib import Parallel, delayed
#for ccd in CCD:
# ccdstring= "%02d"%int(ccd)
# pixcorrect('detrend',ccdstring,**args)
# nullweight('detrend', 'nullweight', ccdstring,**args)
# sextractor('nullweight', 'sextractor', ccdstring, **args)
# psfex( 'sextractor', ccdstring, **args)
def run_stage_1(ccd):
ccdstring= "%02d"%int(ccd)
pixcorrect('detrend',ccdstring,**args)
nullweight('detrend', 'nullweight', ccdstring,**args)
sextractor('nullweight', 'sextractor', ccdstring, **args)
#run "stage 2" loop over all ccds
#for ccd in CCD:
# ccdstring= "%02d"%int(ccd)
# bleedmask(ccdstring,'wcs','bleedmasked',**args)
# skycompress(ccdstring,'bleedmasked','bleedmask-mini',**args)
def run_stage_2(ccd):
ccdstring= "%02d"%int(ccd)
#use the entire image to get astrometry solution
scamp('D{:08d}'.format(int(EXPNUM))+'_'+FILTER+'_'+ccdstring+'_r'+rRun+'p'+pRun+'_sextractor.fits')
change_head('D{:08d}'.format(int(EXPNUM))+'_'+FILTER+'_'+ccdstring+'_r'+rRun+'p'+pRun+'_sextractor.head', 'sextractor', 'detrend', 'wcs', CCD, **args)
bleedmask(ccdstring,'wcs','bleedmasked',**args)
skycompress(ccdstring,'bleedmasked','bleedmask-mini',**args)
#run "stage 3" loop over all ccds
#for ccd in CCD:
# ccdstring= "%02d"%int(ccd)
# skysubtract(ccd,'bleedmasked','skysub','skyfit-binned-fp',**args )
# pixcorr_starflat('skysub', 'starflat', ccdstring,**args)
# nullweightbkg('starflat','nullwtbkg',ccdstring,**args)
# sextractorsky('nullwtbkg','bkg',ccdstring,**args)
# immask(ccdstring,'starflat','immask',**args)
# rowinterp_nullweight('immask', 'nullweightimmask', ccdstring,**args)
# sextractorPSF('nullweightimmask', 'nullweightimmask', 'sextractor_psf', 'sextractor.psf', ccdstring, **args)
# read_geometry('sextractor_psf', 'regions', ccdstring, **args)
def run_stage_3(ccd):
ccdstring= "%02d"%int(ccd)
skysubtract(ccd,'bleedmasked','skysub','skyfit-binned-fp',**args )
pixcorr_starflat('skysub', 'starflat', ccdstring,**args)
#pixcorr_starflat('bleedmasked', 'starflat', ccdstring,**args)
nullweightbkg('starflat','nullwtbkg',ccdstring,**args)
sextractorsky('nullwtbkg','bkg',ccdstring,**args)
immask(ccdstring,'starflat','immask',**args)
rowinterp_nullweight('immask', 'nullweightimmask', ccdstring,**args)
sextractorPSFEX('nullweightimmask', 'sextractorPSFEX', ccdstring, **args)
psfex( 'sextractorPSFEX', ccdstring, **args)
sextractorPSF('nullweightimmask', 'nullweightimmask', 'fullcat', 'sextractorPSFEX.psf', ccdstring, **args)
read_geometry('fullcat', 'regions', ccdstring, **args)
#def run_stage_4(ccd):
# ccdstring= "%02d"%int(ccd)
# sextractorPSFEX('nullweightimmask', 'sextractorPSFEX', ccdstring, **args)
# psfex( 'sextractorPSFEX', ccdstring, **args)
#def run_stage_5(ccd):
# ccdstring= "%02d"%int(ccd)
# sextractorPSF('nullweightimmask', 'nullweightimmask', 'fullcat', 'sextractorPSFEX.psf', ccdstring, **args)
# read_geometry('fullcat', 'regions', ccdstring, **args)
if __name__ == '__main__':
# read config info
EXPNUM = ConfigSectionMap("General")['expnum']
FILTER = ConfigSectionMap("General")['filter']
NITE = ConfigSectionMap("General")['nite']
CCD = (ConfigSectionMap("General")['chiplist']).split( ',')
rRun = str(ConfigSectionMap("General")['r'])
pRun = str(ConfigSectionMap("General")['p'])
YEAR = ConfigSectionMap("General")['year']
EPOCH = ConfigSectionMap("General")['epoch']
# setup args
EXPFILE = 'DECam_{:08d}'.format(int(EXPNUM))+'.fits.fz'
args = {'expnum': EXPNUM, 'filter': FILTER, 'ccd':'0', 'r':rRun, 'p':pRun, 'year': YEAR, 'epoch': EPOCH}
NPARALLEL = 4
cfg_file_copy(**args)
#run crosstalk
crosstalk(EXPFILE,NITE,**args)
#run "stage 1" loop over all ccds
if not os.path.exists('default.psf'):
copy_from_Dcache(data_conf+'default.psf')
for ccd in CCD:
run_stage_1(ccd)
for ccd in CCD:
run_stage_2(ccd)
##Parallel(n_jobs=NPARALLEL)(delayed(run_stage_1)(ccd) for ccd in CCD)
##Parallel(n_jobs=NPARALLEL)(delayed(run_stage_2)(ccd) for ccd in CCD)
#use the entire image to get skyfit
skyCombineFit('bleedmask-mini','bleedmask-mini-fp','skyfit-binned-fp',**args)
##Parallel(n_jobs=NPARALLEL)(delayed(run_stage_3)(ccd) for ccd in CCD)
for ccd in CCD:
run_stage_3(ccd)
# Parallel(n_jobs=NPARALLEL)(delayed(run_stage_4)(ccd) for ccd in CCD)
# Parallel(n_jobs=NPARALLEL)(delayed(run_stage_5)(ccd) for ccd in CCD)
#create list of ccd corners (.out file)
for ccd in CCD:
os.system('bash getcorners.sh '+str(EXPNUM)+' . . '+str(ccd))
# compress immask.fits files before copyback
for immaskfile in glob.glob('*_immask.fits'):
os.system('fpack -Y ' + str(immaskfile) )
# copy outputs to Dcache
data_exp = ConfigSectionMap("General")['exp_dir']
dir_nite = data_exp+NITE
dir_final = dir_nite+'/'+EXPNUM
os.system('ifdh mkdir '+str(dir_nite) )
os.system('ifdh mkdir '+str(dir_final) )
cmd = 'ifdh cp --force=xrootd -D *.out *fullcat* *_immask.fits.fz ' +str(dir_final)
print cmd
os.system(cmd)