31 Selects observations from an observation definition XML file
40 self._init_csobservation(self.__class__.__name__, ctools.__version__, argv)
49 Get parameters from parfile and setup observations
53 if self.obs().is_empty():
54 self[
'inobs'].filename()
57 pntselect = self[
'pntselect'].string()
58 coordsys = self[
'coordsys'].string()
65 if pntselect ==
'CIRCLE':
74 self._get_gti(gammalib.GTimeReference())
77 if self._read_ahead():
78 self[
'outobs'].filename()
82 if self.obs().is_empty():
83 self.obs(self._get_observations(
False))
86 self._log_parameters(gammalib.TERSE)
93 Log observation selection
97 obs : `~gammalib.GObservation`
103 if len(obs.name()) > 0:
109 if len(obs.id()) > 0:
110 msg = obs.id()+
' '+msg
113 self._log_value(gammalib.NORMAL, name, msg)
124 obs : `~gammalib.GObservation`
130 Observation selection flag
136 if obs.classname() ==
'GCTAObservation':
140 obs_tstart = obs_gti.tstart()
141 obs_tstop = obs_gti.tstop()
145 gti = self._get_gti(obs_gti.reference())
146 tstart = gti.tstart()
152 if gti.size() > 0
and (obs_tstop < tstart
or obs_tstart > tstop):
159 pntselect = self[
'pntselect'].string()
162 if pntselect ==
'CIRCLE':
172 Select observation in a pointing circle
176 obs : `~gammalib.GCTAObservation`
182 Observation selection flag
185 coordsys = self[
'coordsys'].string()
188 pnt = obs.pointing().dir()
191 centre = gammalib.GSkyDir()
192 if coordsys ==
'CEL':
193 centre.radec_deg(self[
'ra'].real(), self[
'dec'].real())
195 centre.lb_deg(self[
'glon'].real(), self[
'glat'].real())
198 if centre.dist_deg(pnt) <= self[
'rad'].real():
200 msg =
'inside selection circle'
203 msg =
'outside selection circle'
213 Select observation in a pointing box
217 obs : `~gammalib.GCTAObservation`
223 Observation selection flag
227 msg =
'outside selection box'
230 coordsys = self[
'coordsys'].string()
233 pnt = obs.pointing().dir()
236 width = self[
'width'].real()
237 height = self[
'height'].real()
240 if coordsys ==
'CEL':
243 ra = self[
'ra'].real()
244 dec = self[
'dec'].real()
245 ra_min = ra - 0.5 * width
246 ra_max = ra + 0.5 * width
247 dec_min = dec - 0.5 * height
248 dec_max = dec + 0.5 * height
253 ra_minus = ra - 360.0
255 if dec >= dec_min
and dec <= dec_max:
256 if ra >= ra_min
and ra <= ra_max
or \
257 ra_plus >= ra_min
and ra_plus <= ra_max
or \
258 ra_minus >= ra_min
and ra_minus <= ra_max:
260 msg =
'inside selection box'
266 glon = self[
'glon'].real()
267 glat = self[
'glat'].real()
268 glon_min = glon - 0.5 * width
269 glon_max = glon + 0.5 * width
270 glat_min = glat - 0.5 * height
271 glat_max = glat + 0.5 * height
275 glon_plus = glon + 360.0
276 glon_minus = glon - 360.0
278 if glat >= glat_min
and glat <= glat_max:
279 if glon >= glon_min
and glon <= glon_max
or \
280 glon_plus >= glon_min
and glon_plus <= glon_max
or \
281 glon_minus >= glon_min
and glon_minus <= glon_max:
283 msg =
'inside selection box'
301 selected_obs = gammalib.GObservations()
304 selected_obs.models(self.obs().models())
307 self._log_observations(gammalib.NORMAL, self.obs(),
'Input observation')
310 self._log_header1(gammalib.TERSE,
'Observation selection')
313 for obs
in self.obs():
317 selected_obs.append(obs)
320 self.obs(selected_obs)
323 self._log_observations(gammalib.NORMAL, self.obs(),
'Selected observation')
330 Save observation definition XML file
333 self._log_header1(gammalib.TERSE,
'Save observations')
336 outobs = self[
'outobs'].filename()
339 if outobs.exists()
and not self._clobber:
340 msg = (
'Cannot save "'+outobs.url()+
'": File already exists. '
341 'Use parameter clobber=yes to allow overwriting of files.')
342 raise RuntimeError(msg)
347 self._log_value(gammalib.NORMAL,
'Obs. definition XML file',
351 self.obs().
save(outobs)
360 if __name__ ==
'__main__':