Commit 4d52937f79a69f172f99f94e31d717469d38a589

Authored by Jürgen Knödlseder
1 parent 71926bca

Correct segmentation fault in csmodelselect script (SWIG problem)

Showing 1 changed file with 15 additions and 13 deletions
cscripts/csmodelselect.py
@@ -61,7 +61,7 @@ class csmodelselect(ctools.cscript): @@ -61,7 +61,7 @@ class csmodelselect(ctools.cscript):
61 # Query input parameters 61 # Query input parameters
62 self['inobs'].filename() 62 self['inobs'].filename()
63 self['inmodel'].filename() 63 self['inmodel'].filename()
64 - 64 +
65 # Query hidden parameters 65 # Query hidden parameters
66 self['roilimit'].real() 66 self['roilimit'].real()
67 self['roimargin'].real() 67 self['roimargin'].real()
@@ -85,7 +85,7 @@ class csmodelselect(ctools.cscript): @@ -85,7 +85,7 @@ class csmodelselect(ctools.cscript):
85 85
86 # Write input parameters into logger 86 # Write input parameters into logger
87 self._log_parameters(gammalib.TERSE) 87 self._log_parameters(gammalib.TERSE)
88 - 88 +
89 # Return 89 # Return
90 return 90 return
91 91
@@ -111,7 +111,7 @@ class csmodelselect(ctools.cscript): @@ -111,7 +111,7 @@ class csmodelselect(ctools.cscript):
111 ethres = self['ethres'].real() 111 ethres = self['ethres'].real()
112 fluxlimit = self['fluxlimit'].real() 112 fluxlimit = self['fluxlimit'].real()
113 tslimit = self['tslimit'].real() 113 tslimit = self['tslimit'].real()
114 - 114 +
115 # Initialise selection flag to True 115 # Initialise selection flag to True
116 select = True 116 select = True
117 msg = 'Select by default' 117 msg = 'Select by default'
@@ -133,8 +133,11 @@ class csmodelselect(ctools.cscript): @@ -133,8 +133,11 @@ class csmodelselect(ctools.cscript):
133 # Get RoI centre and radius. The RoI radius is limited by 133 # Get RoI centre and radius. The RoI radius is limited by
134 # roilimit. A margin given by roimargin is added to the RoI 134 # roilimit. A margin given by roimargin is added to the RoI
135 # radius. 135 # radius.
136 - obs_centre = o.roi().centre().dir()  
137 - obs_radius = o.roi().radius() 136 + #obs_centre = o.roi().centre().dir() # Segmentation fault
  137 + #obs_radius = o.roi().radius() # Segmentation fault
  138 + obs_roi = o.roi()
  139 + obs_centre = obs_roi.centre().dir()
  140 + obs_radius = obs_roi.radius()
138 if obs_radius > roilimit: 141 if obs_radius > roilimit:
139 obs_radius = roilimit 142 obs_radius = roilimit
140 obs_radius += roimargin 143 obs_radius += roimargin
@@ -154,7 +157,6 @@ class csmodelselect(ctools.cscript): @@ -154,7 +157,6 @@ class csmodelselect(ctools.cscript):
154 if model.ts() < tslimit: 157 if model.ts() < tslimit:
155 select = False 158 select = False
156 msg = 'Exclude since below TS limit (TS=%.3f)' % model.ts() 159 msg = 'Exclude since below TS limit (TS=%.3f)' % model.ts()
157 -  
158 160
159 # If model is selected and if model is a sky model then apply flux 161 # If model is selected and if model is a sky model then apply flux
160 # limit selection 162 # limit selection
@@ -245,7 +247,7 @@ class csmodelselect(ctools.cscript): @@ -245,7 +247,7 @@ class csmodelselect(ctools.cscript):
245 247
246 # Loop over model components 248 # Loop over model components
247 for model in self._models: 249 for model in self._models:
248 - 250 +
249 # If model should be selected then set model parameters and append 251 # If model should be selected then set model parameters and append
250 # model to the output container 252 # model to the output container
251 if self._select_model(model, self._obs): 253 if self._select_model(model, self._obs):
@@ -261,7 +263,7 @@ class csmodelselect(ctools.cscript): @@ -261,7 +263,7 @@ class csmodelselect(ctools.cscript):
261 263
262 # Write selected models into logger 264 # Write selected models into logger
263 self._log_models(gammalib.VERBOSE, self._models, 'Selected model') 265 self._log_models(gammalib.VERBOSE, self._models, 'Selected model')
264 - 266 +
265 # Return 267 # Return
266 return 268 return
267 269
@@ -274,22 +276,22 @@ class csmodelselect(ctools.cscript): @@ -274,22 +276,22 @@ class csmodelselect(ctools.cscript):
274 276
275 # Get output filename in case it was not read ahead 277 # Get output filename in case it was not read ahead
276 outmodel = self['outmodel'].filename() 278 outmodel = self['outmodel'].filename()
277 - 279 +
278 # If file exists and clobber flag is false then raise an exception 280 # If file exists and clobber flag is false then raise an exception
279 if outmodel.exists() and not self._clobber: 281 if outmodel.exists() and not self._clobber:
280 msg = ('Cannot save "'+outmodel.url()+'": File already exists. ' 282 msg = ('Cannot save "'+outmodel.url()+'": File already exists. '
281 'Use parameter clobber=yes to allow overwriting of files.') 283 'Use parameter clobber=yes to allow overwriting of files.')
282 raise RuntimeError(msg) 284 raise RuntimeError(msg)
283 - 285 +
284 # Otherwise log filename and save file 286 # Otherwise log filename and save file
285 else: 287 else:
286 # Log filename 288 # Log filename
287 self._log_value(gammalib.NORMAL, 'Model definition XML file', 289 self._log_value(gammalib.NORMAL, 'Model definition XML file',
288 outmodel.url()) 290 outmodel.url())
289 - 291 +
290 # Save models 292 # Save models
291 self._models.save(outmodel) 293 self._models.save(outmodel)
292 - 294 +
293 # Return 295 # Return
294 return 296 return
295 297
@@ -320,6 +322,6 @@ if __name__ == &#39;__main__&#39;: @@ -320,6 +322,6 @@ if __name__ == &#39;__main__&#39;:
320 322
321 # Create instance of application 323 # Create instance of application
322 app = csmodelselect(sys.argv) 324 app = csmodelselect(sys.argv)
323 - 325 +
324 # Execute application 326 # Execute application
325 app.execute() 327 app.execute()