43 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
52 Get parameters from parfile
55 self[
'indir'].filename()
56 self[
'outdir'].filename()
59 self._log_parameters(gammalib.TERSE)
75 tarfiles : list of str
82 files = glob.glob(
'%s/*.FITS.tar*' % indir.url())
83 tarfiles.extend(files)
86 files = glob.glob(
'%s/fits/*.FITS.tar*' % indir.url())
87 tarfiles.extend(files)
94 Collect IRFs from tarfile
106 List of IRF dictionaries
112 tar = tarfile.open(file)
115 for member
in tar.getmembers():
118 if member.name[0] ==
'.':
124 if 'LST' in member.name:
127 if 'MST' in member.name:
130 if 'SST' in member.name:
137 if 'South-' in member.name:
141 if '180000s' in member.name:
143 elif '18000s' in member.name:
145 elif '1800s' in member.name:
147 if 'SouthAz' in member.name:
150 elif 'NorthAz' in member.name:
156 if 'D25' in member.name:
158 elif 'D27' in member.name:
163 elements = member.name.split(
'-')
164 zenith = [e
for e
in elements
if 'deg' in e][0].strip(
'deg')
165 instrument =
'%s%s_z%s%s_%s%s' % (site, suffix, zenith, orientation, duration, subarrays)
168 path =
'%s/%s' % (outdir, instrument)
171 self._log_header3(gammalib.TERSE,
'Extract IRFs from "%s"' % member.name)
172 self._log_value(gammalib.NORMAL,
'Instrument', instrument)
175 tar.extract(member, path=
'%s/%s' % (self[
'outdir'].filename().url(), path))
178 record = {
'path': path,
'instrument': instrument,
'file': member.name,
179 'site': site,
'duration': duration,
'zenith': zenith,
'azimuth': azimuth,
180 'orientation': orientation}
193 Add IRF to calibration index file HDU
199 hdu : ~gammalib.GFitsBinTable
206 components = [{
'name':
'EA',
'CNAM':
'EFF_AREA',
'DESC':
'CTA effective area'},
207 {
'name':
'PSF',
'CNAM':
'RPSF',
'DESC':
'CTA point spread function'},
208 {
'name':
'EDISP',
'CNAM':
'EDISP',
'DESC':
'CTA energy dispersion'},
209 {
'name':
'BKG',
'CNAM':
'BKG',
'DESC':
'CTA background'}]
215 hdu.append_rows(len(components))
218 for component
in components:
221 cal_name =
'NAME(%s)' % irf[
'instrument']
222 cal_version =
'VERSION(%s)' % prod
223 cal_cut =
'CLASS(BEST)'
224 cal_analysis =
'ANALYSIS(CTA)'
225 cal_zenith =
'ZENITH(%.3f)deg' % float(irf[
'zenith'])
226 cal_azimuth =
'AZIMUTH(%.3f)deg' % float(irf[
'azimuth'])
227 cal_bounds = [cal_name, cal_version, cal_cut, cal_analysis, \
228 cal_zenith, cal_azimuth]
231 hdu[
'TELESCOP'][row] =
'CTA'
232 hdu[
'INSTRUME'][row] = gammalib.toupper(prod)
233 hdu[
'DETNAM'][row] =
'NONE'
234 hdu[
'FILTER'][row] =
'NONE'
235 hdu[
'CAL_DEV'][row] =
'ONLINE'
236 hdu[
'CAL_CLAS'][row] =
'BCF'
237 hdu[
'CAL_DTYP'][row] =
'DATA'
238 hdu[
'CAL_VSD'][row] =
'2014-01-30'
239 hdu[
'CAL_VST'][row] =
'00:00:00'
240 hdu[
'REF_TIME'][row] = 51544.0
241 hdu[
'CAL_QUAL'][row] = 0
242 hdu[
'CAL_DATE'][row] =
'14/01/30'
245 hdu[
'CAL_DIR'][row] = irf[
'path']
246 hdu[
'CAL_FILE'][row] = irf[
'file']
247 hdu[
'CAL_CNAM'][row] = component[
'CNAM']
248 hdu[
'CAL_DESC'][row] = component[
'DESC']
249 hdu[
'CAL_XNO'][row] = 1
251 if i >= len(cal_bounds):
252 hdu[
'CAL_CBD'][row,i] =
'NONE'
254 hdu[
'CAL_CBD'][row,i] = cal_bounds[i]
264 Create Calibration Database Index File binary table
268 table : ~gammalib.GFitsBinTable
269 Calibration Database Index File binary table
272 table = gammalib.GFitsBinTable()
275 table.append(gammalib.GFitsTableStringCol(
'TELESCOP', 0, 10))
276 table.append(gammalib.GFitsTableStringCol(
'INSTRUME', 0, 10))
277 table.append(gammalib.GFitsTableStringCol(
'DETNAM', 0, 20))
278 table.append(gammalib.GFitsTableStringCol(
'FILTER', 0, 10))
279 table.append(gammalib.GFitsTableStringCol(
'CAL_DEV', 0, 20))
280 table.append(gammalib.GFitsTableStringCol(
'CAL_DIR', 0, 70))
281 table.append(gammalib.GFitsTableStringCol(
'CAL_FILE', 0, 128))
282 table.append(gammalib.GFitsTableStringCol(
'CAL_CLAS', 0, 3))
283 table.append(gammalib.GFitsTableStringCol(
'CAL_DTYP', 0, 4))
284 table.append(gammalib.GFitsTableStringCol(
'CAL_CNAM', 0, 20))
285 table.append(gammalib.GFitsTableStringCol(
'CAL_CBD', 0, 70, 9))
286 table.append(gammalib.GFitsTableShortCol(
'CAL_XNO', 0))
287 table.append(gammalib.GFitsTableStringCol(
'CAL_VSD', 0, 10))
288 table.append(gammalib.GFitsTableStringCol(
'CAL_VST', 0, 8))
289 table.append(gammalib.GFitsTableDoubleCol(
'REF_TIME', 0))
290 table.append(gammalib.GFitsTableShortCol(
'CAL_QUAL', 0))
291 table.append(gammalib.GFitsTableStringCol(
'CAL_DATE', 0, 8))
292 table.append(gammalib.GFitsTableStringCol(
'CAL_DESC', 0, 70))
296 table.card(
'CIFVERSN',
'1992a',
'Version of CIF format')
303 Add IRFs to calibration index file
313 fname =
'%s/data/cta/%s/caldb.indx' % (self[
'outdir'].filename().url(), prod)
316 cif = gammalib.GFits(fname,
True)
319 if not cif.contains(
'CIF'):
323 cif_hdu = cif.table(
'CIF')
338 Add IRFs to calibration database
344 if len(tarfiles) == 0:
345 msg = (
'No tarfiles found in folder "'+self[
'indir'].filename().url()+
'. '
346 'Please specify a folder that contains IRF tarfiles.')
347 raise RuntimeError(msg)
350 for file
in tarfiles:
353 fname = os.path.basename(file)
354 elements = fname.split(
'-')
355 prod = [e
for e
in elements
if 'prod' in e][0]
356 version = [e
for e
in elements
if 'v' in e][0]
357 prod =
'%s-%s' % (prod, version)
360 outdir =
'data/cta/%s/bcf' % (prod)
363 self._log_header2(gammalib.TERSE,
'Extract IRFs')
364 self._log_value(gammalib.NORMAL,
'Tarfile', file)
365 self._log_value(gammalib.NORMAL,
'Production', prod)
366 self._log_value(gammalib.NORMAL,
'Target directory', outdir)
387 self._log_header1(gammalib.TERSE,
'Add IRFs to CALDB')
399 if __name__ ==
'__main__':