Repository navigation
Expand file tree
/
Copy pathpodi_multicollect.py
More file actions
executable file
·174 lines (136 loc) · 5.62 KB
/
Copy pathpodi_multicollect.py
File metadata and controls
executable file
·174 lines (136 loc) · 5.62 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
#
# Copyright 2012-2013 Ralf Kotulla
# kotulla@uwm.edu
#
# This file is part of the ODI QuickReduce pipeline package.
#
# If you find this program or parts thereof please make sure to
# cite it appropriately (please contact the author for the most
# up-to-date reference to use). Also if you find any problems
# or have suggestiosn on how to improve the code or its
# functionality please let me know. Comments and questions are
# always welcome.
#
# The code is made publicly available. Feel free to share the link
# with whoever might be interested. However, I do ask you to not
# publish additional copies on your own website or other sources.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
"""podi_multicollect is a wrapper around podi_collectcells that allows to
batch-reduce a number of files consecutively.
Usage:
-----------
``podi_multicollect.py -fromfile=file.list -formatout=(format) (options)``
file.list is list of either directories named after the OBSID of the frames it
contains (e.g. ``/some/dir/o20131212T012345.1/``) or a list of files, with one file
per exposure (e.g. ``/some/dir/o20131212T012345.1/o20131212T012345.1.33.fits``). In
both cases, multicollect or collectcells automatically determines the name of
all other FITS files for this exposure.
Warning
-------
If the input file-list contains two FITS files of the same exposure
(e.g. xxx.33.fits and xxx.00.fits), this results in this frame being
reduced twice. No harm done, just a waste of time.
**-formatout=format**
This allows to put information from the FITS header into the filename to
form informative, human-readable filenames.
Valid format string include
* %OBJECT
* %OBSID
* %FILTER
* %EXPTIME
These can be assembled in any order. for example into
``-formatout=%OBSID___%OBJECT___%FILTER___%EXPTIME.fits``. This would be
translated during execution into:
``o20131112T012345.0___M51_pointing1___odi_r___1200.fits``
**Note** If the formatout-string contains directories, these will be created
during execution.
**(options)**
All other options are handled by collectcells, thus all collectcells
options can also be given to podi_multicollect.
"""
import sys
import os
import astropy.io.fits as pyfits
import numpy
import scipy
import traceback
import time
gain_correct_frames = False
from podi_collectcells import *
from podi_definitions import *
from podi_commandline import *
if __name__ == "__main__":
# Loop over all files and collect all cells. Name output files after the basename of the input file.
start = 1
output_directory = None
keeppath = False
# Read all options from command line. This is 100% compatible
# with an individual call to podi_collectcells.
options = read_options_from_commandline(None)
# Setup everything we need for logging
podi_logging.setup_logging(options)
output_directory = cmdline_arg_set_or_default("-output", None)
if (output_directory != None):
if (not os.path.isdir(output_directory)):
os.makedirs(output_directory)
if (cmdline_arg_isset("-fromfile")):
filename = get_cmdline_arg("-fromfile")
file = open(filename, "r")
lines = file.readlines()
filelist = []
for line in lines:
if (len(line) <=1):
continue
if (line[0] == "#"):
continue
fitsfilename = line.strip().split()[0]
filelist.append(fitsfilename)
#print filelist
#sys.exit(0)
else:
filelist = get_clean_cmdline()[1:]
logger = logging.getLogger("MultiCollect")
# Now loop over all files and run collectcells
for folder in filelist:
if (folder[-1] == "/"):
folder = folder[:-1]
directory,basename = os.path.split(folder)
if (directory == ""):
directory = "."
# Figure out into what directory we should put the output file
if (output_directory != None):
outputfile_dir = output_directory
elif (cmdline_arg_isset("-keeppath")):
outputfile_dir = directory
else:
outputfile_dir = "."
# And also figure out what the filename is supposed to be
if (cmdline_arg_isset("-formatout")):
outputfile = get_cmdline_arg("-formatout")
else:
# Then assemble the actual filename
outputfile_name = "%s.fits" % (basename)
outputfile = "%s/%s" % (outputfile_dir, outputfile_name)
logger.info("Collecting cells from %s ==> %s\n" % (folder,outputfile))
start_time = time.time()
# Collect all cells, perform reduction and write result file
try:
collectcells(folder, outputfile, options=options, batchmode=False)
except:
stdout_write("\n\n##############################\n#\n# Something terrible happened!\n")
etype, error, stackpos = sys.exc_info()
stdout_write("# Exception report:")
stdout_write("# ==> %s\n" % (error))
print(traceback.format_exc())
stdout_write("##############################\n")
end_time = time.time()
logger.debug("done with this file!")
logger.debug("QR run-time (%s): %.3f" % (folder, end_time-start_time))
logger.info("Yippie, completely done with all files!\n")
# Shutdown logging to shutdown cleanly
podi_logging.shutdown_logging(options)