-
Notifications
You must be signed in to change notification settings - Fork 1
/
pied_piper.py
125 lines (92 loc) · 3.72 KB
/
pied_piper.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
import argparse
import numpy as np
import os
from configparser import ConfigParser, ExtendedInterpolation
import sys
from astropy.coordinates import SkyCoord
def print_stage(line2print, ch='-'):
'''
Function that prints lines for organizational purposes in the code outputs.
Parameters:
-----------
line2print: str, the message to be printed
ch : str, the boundary dividing character of the message
'''
nl = len(line2print)
print(ch*nl)
print(line2print)
print(ch*nl)
print(' ')
def argument_parser():
'''
Function that parses the arguments passed while running a script
fits : str, the multi extension fits file outputted by galfit
for_cutout: str, True of False
'''
result = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# path to the config file with parameters and information about the run
result.add_argument('-t', dest='t', type=str,default="sci_info.txt")
return result
def read_config_file(config_file=None):
'''
Function that reads the ini file
Parameters:
-------------
config_file: str, path to the config file
Returns:
------------
iniconf: dict, dictionary of parameters in the config file
'''
if config_file is None:
raise ValueError('input configuration file is not provided. Use -ini config_file_path to specify the config file')
if not os.path.isfile(config_file):
raise ValueError('input configuration file %s does not exist!'%config_file)
iniconf = ConfigParser(interpolation=ExtendedInterpolation())
iniconf.read(config_file)
return iniconf
if __name__ == '__main__':
# read in command line arguments
args = argument_parser().parse_args()
PATH_ini = os.getcwd() + '/pipeline/fourstar_pipeline.ini'
# read parameters and information from the sci_info file
txt_info = np.loadtxt(args.t,dtype=str)
pipeline_dir = txt_info[0]
data_dir = txt_info[1]
output_dir = txt_info[2]
temp_dir = txt_info[3]
mode_pro = txt_info[4]
use_astrometry = txt_info[5]
which_band = txt_info[6].strip()
flat_range = txt_info[7]
for i in range(len(txt_info[8:])):
sci_info = txt_info[8+i].split(',')
sci_range = sci_info[0].replace(" ","")+','+sci_info[1].replace(" ","")
#############
sci_ra_hr = sci_info[2].replace(" ","")
sci_ra_min = sci_info[3].replace(" ","")
sci_dec_deg = sci_info[4].replace(" ","")
sci_dec_arcmin = sci_info[5].replace(" ","")
RA = '%sh%sm'%(sci_ra_hr,sci_ra_min)
DEC = '%sd%sm'%(sci_dec_deg,sci_dec_arcmin)
c = SkyCoord(RA,DEC)
ra_val = c.ra.degree
dec_val = c.dec.degree
#############
obj_id = sci_info[6].replace(" ","")
iniconf = read_config_file(PATH_ini)
iniconf.set('all info','science',str(sci_range))
iniconf.set('all info','ra',str(ra_val))
iniconf.set('all info','dec',str(dec_val))
iniconf.set('all info', 'flats', str(flat_range))
iniconf.set('all info','data_dir', str(data_dir) )
iniconf.set('all info','which_band',str(which_band))
iniconf.set('all info','use_astrometry',str(use_astrometry))
iniconf.set('all info','obj_id',str(obj_id))
iniconf.set('all info','parallel_or_serial',str(mode_pro))
iniconf.set('all info','output_dir',str(output_dir))
iniconf.set('all info','pipeline_dir',str(pipeline_dir))
iniconf.set('all info','temp_dir',str(temp_dir))
with open(PATH_ini,'w') as f:
iniconf.write(f)
print_stage("File Range %s for %s is being processed."%(sci_range, obj_id))
os.system('python3 pipeline/run_pipeline.py')