33 Find observations from an IACT data store
42 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
61 Get parameters from parfile and setup the observation.
65 datapath = self[
'datapath'].string()
66 if gammalib.toupper(datapath) !=
'NONE':
75 self.
_prodname = self[
'prodname'].string()
78 master_indx = self[
'master_indx'].string()
87 if (self[
'ra'].is_valid()
and
88 self[
'dec'].is_valid()
and
89 self[
'rad'].is_valid()):
92 self.
_ra = self[
'ra'].real()
93 self.
_dec = self[
'dec'].real()
94 self.
_radius = self[
'rad'].real()
106 self[
'min_qual'].integer()
107 self[
'expression'].string()
110 if self._read_ahead():
111 self[
'outfile'].filename()
115 master_file = os.path.join(self.
_datapath, master_indx)
116 if not os.path.isfile(master_file):
117 msg = (
'FITS data store not available. No master index file found '
118 'at "%s". Make sure the file is copied from the server and '
119 'your datapath is set correctly.' % master_file)
120 raise RuntimeError(msg)
124 json_data = open(master_file).read()
125 data = json.loads(json_data)
126 if not 'datasets' in data:
127 msg = (
'Key "datasets" not available in master index file.')
128 raise RuntimeError(msg)
131 configs = data[
'datasets']
137 for config
in configs:
145 msg = (
'FITS data store "%s" not available. Run csiactdata to get '
146 'a list of available storage names.' % self.
_prodname)
147 raise RuntimeError(msg)
151 filename = gammalib.GFilename(self.
_obs_index+
'[OBS_INDEX]')
152 if not filename.is_fits():
153 msg = (
'Observation index file "%s[OBS_INDEX]" for FITS data store '
154 '"%s" not available. Check your master index file or run '
155 'csiactdata to get a list of available storage names.' %
157 raise RuntimeError(msg)
160 self._log_parameters(gammalib.TERSE)
175 self._log_header1(gammalib.TERSE,
'Find observations')
186 expr +=
'ANGSEP('+str(self.
_ra)+
','+str(self.
_dec)+ \
187 ',RA_PNT,DEC_PNT)<='+str(self.
_radius)
194 expr +=
'QUALITY<='+str(self[
'min_qual'].integer())
197 expression = self[
'expression'].string()
198 if (expression !=
'NONE' and expression !=
'INDEF' and
199 len(expression) > 0):
200 expr +=
'&&' + expression
203 self._log_value(gammalib.NORMAL,
'Expression', expr)
206 filename = self.
_obs_index+
'[OBS_INDEX]['+expr+
']'
209 fits = gammalib.GFits(filename)
213 obs_index = fits[
'OBS_INDEX']
214 if obs_index.nrows() > 0:
215 for i
in range(obs_index.nrows()):
216 self._runs.append(obs_index[
'OBS_ID'][i])
219 self._log_value(gammalib.TERSE,
'Observations', len(self.
_runs))
222 if len(self.
_runs) > 0:
223 for i, run
in enumerate(self.
_runs):
224 self._log_value(gammalib.NORMAL,
'Observation %d' % (i+1), run)
237 self._log_header1(gammalib.TERSE,
'Save runlist')
240 outfile = self[
'outfile'].filename()
244 if outfile.exists()
and not self._clobber():
245 msg = (
'File "'+outfile+
'" exists already, runlist not saved. '
246 'Set clobber=yes to overwrite the file.\n')
247 self._log_string(gammalib.TERSE, msg)
253 self._log_value(gammalib.NORMAL,
'Runlist file', outfile.url())
256 f = open(outfile.url(),
'w')
257 for run
in self.
_runs:
258 f.write(str(run)+
' \n')
280 if __name__ ==
'__main__':