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