31 Creates an observation definition file from a pointing list
33 The pointing list is a comma-separated value ASCII file with header
34 keywords in the first row followed by a list of pointings (one
35 pointing per row). The following header keywords are supported (case
36 sensitive, column order irrelevant):
38 name - Observation name string
39 id - Unique observation identifier string
40 ra - Right Ascension of pointing (deg)
41 dec - Declination of pointing (deg)
42 lon - Galactic longitude of pointing (deg)
43 lat - Galactic latitude of pointing (deg)
44 tmin - Start of pointing (seconds)
45 duration - Duration of pointing (seconds)
46 emin - Lower energy limit (TeV)
47 emax - Upper energy limit (TeV)
48 rad - Radius of region of interest (deg)
49 deadc - Deadtime correction factor [0-1]
50 instrument - Name of Cherenkov telescope
51 caldb - Calibration database
52 irf - Response function name
54 Only the pairs (ra,dec) or (lon,lat) are mandatory header keywords.
55 All other keywords are optional and can be specified when calling
56 csobsdef as user parameters. The only exception is the "duration"
57 keyword that will automatically be queried.
62 Creates minimal observation definition file.
64 ./csobsdef emin=0.1 emax=100.0
65 Creates observation definition file with an energy range
69 Creates observation definition file with a ROI radius of
72 ./csobsdef caldb=prod2 irf=South_50h
73 Creates observation definition file using the "South_50h"
74 IRF in the "prod2" calibration database of CTA.
85 List of IRAF command line parameter strings of the form
89 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
92 self.
_obs = gammalib.GObservations()
103 Get parameters from parfile
106 if self._pntdef.size() == 0:
107 self[
'inpnt'].filename()
110 if self._read_ahead():
111 self[
'outobs'].query()
114 self._log_parameters(gammalib.TERSE)
121 Set response for an observation
123 The method creates an XML element so that that the response XML
124 writer will write the database and response name into the
125 observation definition file.
129 obs : `~gammalib.GCTAObservation`
134 Instrument response function
138 obs : `~gammalib.GCTAObservation`
139 CTA observation with response attached
142 xml = gammalib.GXmlElement()
145 parameter =
'parameter name="Calibration" database="'+caldb+\
146 '" response="'+irf+
'"'
147 xml.append(gammalib.GXmlElement(parameter))
150 response = gammalib.GCTAResponseIrf()
154 obs.response(response)
168 Invalid pointing definition file format
174 self._log_header1(gammalib.TERSE,
175 'Creating observation definition XML file')
179 if self._pntdef.size() == 0:
180 self.
_pntdef = gammalib.GCsv(self[
'inpnt'].filename(),
',')
181 ncols = self._pntdef.ncols()
182 npnt = self._pntdef.nrows()-1
185 if self._pntdef.nrows() < 1:
186 raise RuntimeError(
'No header found in pointing definition file.')
197 for col
in range(ncols):
198 header.append(self.
_pntdef[0,col])
201 for pnt
in range(npnt):
207 obs = gammalib.GCTAObservation()
210 if 'instrument' in header:
211 instrument = self.
_pntdef[row, header.index(
'instrument')]
213 instrument = self[
'instrument'].string()
214 instrument = gammalib.toupper(instrument)
215 obs.instrument(instrument)
220 name = self.
_pntdef[row, header.index(
'name')]
222 name = self[
'name'].string()
228 obsid = self.
_pntdef[row, header.index(
'id')]
230 obsid =
'%6.6d' % identifier
236 if 'ra' in header
and 'dec' in header:
237 ra = float(self.
_pntdef[row, header.index(
'ra')])
238 dec = float(self.
_pntdef[row, header.index(
'dec')])
239 pntdir = gammalib.GSkyDir()
240 pntdir.radec_deg(ra,dec)
241 elif 'lon' in header
and 'lat' in header:
242 lon = float(self.
_pntdef[row, header.index(
'lon')])
243 lat = float(self.
_pntdef[row, header.index(
'lat')])
244 pntdir = gammalib.GSkyDir()
245 pntdir.lb_deg(lon,lat)
247 raise RuntimeError(
'No (ra,dec) or (lon,lat) columns '
248 'found in pointing definition file.')
249 obs.pointing(gammalib.GCTAPointing(pntdir))
253 if 'caldb' in header:
254 caldb = self.
_pntdef[row, header.index(
'caldb')]
256 caldb = self[
'caldb'].string()
258 irf = self.
_pntdef[row, header.index(
'irf')]
260 irf = self[
'irf'].string()
261 if caldb !=
'' and irf !=
'':
262 obs = self.
_set_irf(obs, caldb, irf)
266 if 'deadc' in header:
267 deadc = float(self.
_pntdef[row, header.index(
'deadc')])
269 deadc = self[
'deadc'].real()
275 self.
_tmin = float(self.
_pntdef[row, header.index(
'tmin')])
276 if 'duration' in header:
277 duration = float(self.
_pntdef[row, header.index(
'duration')])
279 duration = self[
'duration'].real()
280 tref = gammalib.GTimeReference(self[
'mjdref'].real(),
's')
282 tmax = self.
_tmin + duration
283 gti = gammalib.GGti(tref)
284 tstart = gammalib.GTime(tmin, tref)
285 tstop = gammalib.GTime(tmax, tref)
287 gti.append(tstart, tstop)
288 obs.ontime(gti.ontime())
289 obs.livetime(gti.ontime()*deadc)
297 emin = float(self.
_pntdef[row, header.index(
'emin')])
300 if self[
'emin'].is_valid():
301 emin = self[
'emin'].real()
304 emax = float(self.
_pntdef[row, header.index(
'emax')])
307 if self[
'emax'].is_valid():
308 emax = self[
'emax'].real()
310 has_ebounds = has_emin
and has_emax
312 ebounds = gammalib.GEbounds(gammalib.GEnergy(emin,
'TeV'),
313 gammalib.GEnergy(emax,
'TeV'))
319 rad = float(self.
_pntdef[row, header.index(
'rad')])
322 if self[
'rad'].is_valid():
323 rad = self[
'rad'].real()
326 roi = gammalib.GCTARoi(gammalib.GCTAInstDir(pntdir), rad)
329 event_list = gammalib.GCTAEventList()
334 event_list.ebounds(ebounds)
339 obs.events(event_list)
342 name = obs.instrument()+
' observation'
343 value =
'Name="%s" ID="%s"' % (obs.name(), obs.id())
344 self._log_value(gammalib.NORMAL, name, value)
345 self._log_string(gammalib.EXPLICIT, str(obs)+
'\n')
348 self._obs.append(obs)
355 Save observation definition XML file.
358 self._log_header1(gammalib.TERSE,
'Save observation definition XML file')
361 if self[
'outobs'].is_valid():
364 outobs = self[
'outobs'].filename()
367 self._log_value(gammalib.NORMAL,
'Observation XML file', outobs.url())
370 self._obs.save(outobs)
377 Returns observation container
380 obs : `~gammalib.GObservations`
381 Observation container
388 Set pointing definition from a CSV table
392 csv : `~gammalib.GCsv`
393 Comma-separated values table
405 if __name__ ==
'__main__':