-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalizing.py
129 lines (87 loc) · 4.34 KB
/
finalizing.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
'''
Routines for moving files around, deleting remaining files
and saving relevant quantities.
'''
import shutil
import yaml
import os
from files import get_truth_catalog_path
from constants import MEDSCONF
def finalize_files(tilename, bands, output_desdata, config):
for b in bands:
move_SrcExtractor_cat(tilename, b, output_desdata)
if config['files']['save_meds'] == True:
move_meds(tilename, b, output_desdata)
move_metacal_cat(tilename, output_desdata)
move_Truth_cat(tilename, output_desdata)
if config['files']['clean_tmpdir'] == True:
cleanup_tmpdir_files(tilename, output_desdata)
#Helper functions to run the above cleanup/re-organization code
def move_SrcExtractor_cat(tile, band, output_desdata):
args = {'dir' : output_desdata,
'name' : os.path.basename(os.path.dirname(output_desdata)),
'mode' : 'plus' if 'plus' in os.path.basename(output_desdata) else 'minus',
'tile' : tile,
'band' : band}
#This is always going to be path in our runs so just sort of hardcode this assumption
config_path = output_desdata + '/simple_des_y3_sims/y3v02/band_info_files/%(tile)s_%(band)s_info.yaml'%args
with open(config_path, 'r') as fp:
band_info = yaml.load(fp, Loader=yaml.Loader)
cat_path = band_info['cat_path'].replace(os.environ['TMPDIR'], output_desdata)
new_path = os.environ['MCAL_DIR'] + "/%(name)s/SrcExtractor_%(tile)s_g%(mode)s_%(band)s-cat.fits" % args
#print(cat_path, new_path)
shutil.move(cat_path, new_path)
return True
#Helper functions to run the above cleanup/re-organization code
def move_Truth_cat(tile, output_desdata):
args = {'dir' : output_desdata,
'name' : os.path.basename(os.path.dirname(output_desdata)),
'mode' : 'plus' if 'plus' in os.path.basename(output_desdata) else 'minus',
'tile' : tile}
cat_path = get_truth_catalog_path(meds_dir = output_desdata, medsconf = MEDSCONF, tilename = tile)
new_path = os.environ['MCAL_DIR'] + "/%(name)s/Input_%(tile)s_g%(mode)s-cat.fits" % args
print(cat_path, new_path)
shutil.move(cat_path, new_path)
return True
def move_metacal_cat(tile, output_desdata):
args = {'dir' : output_desdata,
'name' : os.path.basename(os.path.dirname(output_desdata)),
'mode' : 'plus' if 'plus' in os.path.basename(output_desdata) else 'minus',
'tile' : tile}
cat_path = output_desdata + "/metacal/y3v02/%(tile)s_metacal.fits" % args
new_path = os.environ['MCAL_DIR'] + "/%(name)s/metacal_%(tile)s_g%(mode)s.fits" % args
#print(cat_path, new_path)
shutil.move(cat_path, new_path)
return True
def move_meds(tile, band, output_desdata):
args = {'dir' : output_desdata,
'name' : os.path.basename(os.path.dirname(output_desdata)),
'mode' : 'plus' if 'plus' in os.path.basename(output_desdata) else 'minus',
'tile' : tile,
'band' : band}
meds_path = output_desdata + "/meds/y3v02/%(tile)s/%(tile)s_%(band)s_meds-y3v02.fits.fz" % args
new_path = os.environ['MCAL_DIR'] + "/%(name)s/meds_%(tile)s_g%(mode)s_%(band)s-y3v02.fits.fz" % args
#print(meds_path, new_path)
shutil.move(meds_path, new_path)
return True
def cleanup_tmpdir_files(tile, output_desdata):
#Checks if both plus and minus measurements have been done, and deletes
#input files accordingly
args = {'dir' : output_desdata,
'name' : os.path.basename(os.path.dirname(output_desdata)),
'mode' : 'plus' if 'plus' in os.path.basename(output_desdata) else 'minus',
'tile' : tile}
plus = os.environ['MCAL_DIR'] + "/%(name)s/metacal_%(tile)s_gplus.fits" % args
minus = os.environ['MCAL_DIR'] + "/%(name)s/metacal_%(tile)s_gminus.fits" % args
print(plus)
print(minus)
if os.path.isfile(plus) & os.path.isfile(minus):
file_paths = os.environ['PREP_DIR'] + "/%(name)s/*%(tile)s*" % args
os.system("rm -rv %s" % file_paths)
print(file_paths)
file_paths = os.environ['TMPDIR'] + "/*%(tile)s*" % args
os.system("rm -rv %s" % file_paths)
print(file_paths)
print(args)
print(tile, output_desdata)
return True