Commit ce48d5053a80a387ebc3d22de21598b8c1d89105

Authored by Jürgen Knödlseder
1 parent 97cf1403

Use GSkyMap::is_empty() method

src/ctbkgcube/ctbkgcube.cpp
@@ -343,17 +343,12 @@ void ctbkgcube::save(void) @@ -343,17 +343,12 @@ void ctbkgcube::save(void)
343 m_outcube = (*this)["outcube"].filename(); 343 m_outcube = (*this)["outcube"].filename();
344 m_outmodel = (*this)["outmodel"].filename(); 344 m_outmodel = (*this)["outmodel"].filename();
345 345
346 - // Determine whether the cube is empty  
347 - bool cube_is_empty = ((m_background.cube().nx() == 0) ||  
348 - (m_background.cube().ny() == 0) ||  
349 - (m_background.cube().nmaps() == 0));  
350 -  
351 // Determine whether a model definition file should be written 346 // Determine whether a model definition file should be written
352 bool write_moddef = ((!m_outmodel.is_empty()) && 347 bool write_moddef = ((!m_outmodel.is_empty()) &&
353 (gammalib::tolower(m_outmodel.url()) != "none")); 348 (gammalib::tolower(m_outmodel.url()) != "none"));
354 349
355 // Save background cube if filename and the background cube are not empty 350 // Save background cube if filename and the background cube are not empty
356 - if (!m_outcube.is_empty() && !cube_is_empty) { 351 + if (!m_outcube.is_empty() && !m_background.cube().is_empty()) {
357 m_background.save(m_outcube, clobber()); 352 m_background.save(m_outcube, clobber());
358 } 353 }
359 354
@@ -365,7 +360,7 @@ void ctbkgcube::save(void) @@ -365,7 +360,7 @@ void ctbkgcube::save(void)
365 // Write into logger what has been done 360 // Write into logger what has been done
366 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); 361 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url();
367 std::string mname = (write_moddef) ? m_outmodel.url() : "NONE"; 362 std::string mname = (write_moddef) ? m_outmodel.url() : "NONE";
368 - if (cube_is_empty) { 363 + if (m_background.cube().is_empty()) {
369 fname.append(" (cube is empty, no file created)"); 364 fname.append(" (cube is empty, no file created)");
370 } 365 }
371 log_value(NORMAL, "Background cube file", fname); 366 log_value(NORMAL, "Background cube file", fname);
@@ -497,7 +492,7 @@ void ctbkgcube::get_parameters(void) @@ -497,7 +492,7 @@ void ctbkgcube::get_parameters(void)
497 std::string incube = (*this)["incube"].filename(); 492 std::string incube = (*this)["incube"].filename();
498 493
499 // Check for filename validity 494 // Check for filename validity
500 - if ((gammalib::toupper(incube) == "NONE") || 495 + if ((gammalib::toupper(incube) == "NONE") ||
501 (gammalib::strip_whitespace(incube) == "")) { 496 (gammalib::strip_whitespace(incube) == "")) {
502 497
503 // Create an event cube based on task parameters 498 // Create an event cube based on task parameters
@@ -520,18 +515,19 @@ void ctbkgcube::get_parameters(void) @@ -520,18 +515,19 @@ void ctbkgcube::get_parameters(void)
520 } // endelse: cube was loaded from file 515 } // endelse: cube was loaded from file
521 516
522 // If there are no models associated with the observations then load now 517 // If there are no models associated with the observations then load now
523 - // the model definition from the XML file 518 + // the model definition from the XML file. Throw an exception if the
  519 + // input model is not set.
524 if (m_obs.models().size() == 0) { 520 if (m_obs.models().size() == 0) {
525 - if ((*this)["inmodel"].is_undefined()) { 521 + std::string inmodel = (*this)["inmodel"].filename();
  522 + if ((gammalib::toupper(inmodel) == "NONE") ||
  523 + (gammalib::strip_whitespace(inmodel) == "")) {
526 std::string msg = "No model definition XML file specified. " 524 std::string msg = "No model definition XML file specified. "
527 "Please set the \"inmodel\" parameter to the " 525 "Please set the \"inmodel\" parameter to the "
528 "XML file that contains the background model " 526 "XML file that contains the background model "
529 "definition."; 527 "definition.";
530 throw GException::invalid_value(G_GET_PARAMETERS, msg); 528 throw GException::invalid_value(G_GET_PARAMETERS, msg);
531 } 529 }
532 - std::string inmodel = (*this)["inmodel"].filename();  
533 - GModels models(inmodel);  
534 - m_obs.models(models); 530 + m_obs.models(GModels(inmodel));
535 } 531 }
536 532
537 // Get remaining parameters 533 // Get remaining parameters
src/ctbkgcube/ctbkgcube.hpp
@@ -70,7 +70,6 @@ protected: @@ -70,7 +70,6 @@ protected:
70 void free_members(void); 70 void free_members(void);
71 void get_parameters(void); 71 void get_parameters(void);
72 void init_cube(void); 72 void init_cube(void);
73 - //void fill_cube(GCTAObservation* obs);  
74 73
75 // User parameters 74 // User parameters
76 GFilename m_outcube; //!< Filename of output cube 75 GFilename m_outcube; //!< Filename of output cube
src/ctedispcube/ctedispcube.cpp
@@ -264,20 +264,15 @@ void ctedispcube::save(void) @@ -264,20 +264,15 @@ void ctedispcube::save(void)
264 // Get output filename 264 // Get output filename
265 m_outcube = (*this)["outcube"].filename(); 265 m_outcube = (*this)["outcube"].filename();
266 266
267 - // Determine whether the cube is empty  
268 - bool cube_is_empty = ((m_edispcube.cube().nx() == 0) ||  
269 - (m_edispcube.cube().ny() == 0) ||  
270 - (m_edispcube.cube().nmaps() == 0));  
271 -  
272 // Save energy dispersion cube if filename and the energy dispersion cube 267 // Save energy dispersion cube if filename and the energy dispersion cube
273 // are not empty 268 // are not empty
274 - if (!m_outcube.is_empty() && !cube_is_empty) { 269 + if (!m_outcube.is_empty() && !m_edispcube.cube().is_empty()) {
275 m_edispcube.save(m_outcube, clobber()); 270 m_edispcube.save(m_outcube, clobber());
276 } 271 }
277 272
278 // Write into logger what has been done 273 // Write into logger what has been done
279 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); 274 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url();
280 - if (cube_is_empty) { 275 + if (m_edispcube.cube().is_empty()) {
281 fname.append(" (cube is empty, no file created)"); 276 fname.append(" (cube is empty, no file created)");
282 } 277 }
283 log_value(NORMAL, "Energy dispersion cube file", fname); 278 log_value(NORMAL, "Energy dispersion cube file", fname);
src/ctexpcube/ctexpcube.cpp
@@ -261,19 +261,14 @@ void ctexpcube::save(void) @@ -261,19 +261,14 @@ void ctexpcube::save(void)
261 // Get exposure cube filename 261 // Get exposure cube filename
262 m_outcube = (*this)["outcube"].filename(); 262 m_outcube = (*this)["outcube"].filename();
263 263
264 - // Determine whether the cube is empty  
265 - bool cube_is_empty = ((m_expcube.cube().nx() == 0) ||  
266 - (m_expcube.cube().ny() == 0) ||  
267 - (m_expcube.cube().nmaps() == 0));  
268 -  
269 // Save exposure cube if filename and the exposure cube are not empty 264 // Save exposure cube if filename and the exposure cube are not empty
270 - if (!m_outcube.is_empty() && !cube_is_empty) { 265 + if (!m_outcube.is_empty() && !m_expcube.cube().is_empty()) {
271 m_expcube.save(m_outcube, clobber()); 266 m_expcube.save(m_outcube, clobber());
272 } 267 }
273 268
274 // Write into logger what has been done 269 // Write into logger what has been done
275 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); 270 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url();
276 - if (cube_is_empty) { 271 + if (m_expcube.cube().is_empty()) {
277 fname.append(" (cube is empty, no file created)"); 272 fname.append(" (cube is empty, no file created)");
278 } 273 }
279 log_value(NORMAL, "Exposure cube file", fname); 274 log_value(NORMAL, "Exposure cube file", fname);
src/ctmapcube/ctmapcube.cpp
@@ -225,19 +225,14 @@ void ctmapcube::save(void) @@ -225,19 +225,14 @@ void ctmapcube::save(void)
225 // Get map cube filename 225 // Get map cube filename
226 m_outcube = (*this)["outcube"].filename(); 226 m_outcube = (*this)["outcube"].filename();
227 227
228 - // Determine whether the cube is empty  
229 - bool cube_is_empty = ((m_cube.cube().nx() == 0) ||  
230 - (m_cube.cube().ny() == 0) ||  
231 - (m_cube.cube().nmaps() == 0));  
232 -  
233 // Save map cube if filename and the map cube are not empty 228 // Save map cube if filename and the map cube are not empty
234 - if (!m_outcube.is_empty() && !cube_is_empty) { 229 + if (!m_outcube.is_empty() && !m_cube.cube().is_empty()) {
235 m_cube.save(m_outcube, clobber()); 230 m_cube.save(m_outcube, clobber());
236 } 231 }
237 232
238 // Write into logger what has been done 233 // Write into logger what has been done
239 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); 234 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url();
240 - if (cube_is_empty) { 235 + if (m_cube.cube().is_empty()) {
241 fname.append(" (cube is empty, no file created)"); 236 fname.append(" (cube is empty, no file created)");
242 } 237 }
243 log_value(NORMAL, "Map cube file", fname); 238 log_value(NORMAL, "Map cube file", fname);
src/ctpsfcube/ctpsfcube.cpp
@@ -250,19 +250,14 @@ void ctpsfcube::save(void) @@ -250,19 +250,14 @@ void ctpsfcube::save(void)
250 // Get output filename 250 // Get output filename
251 m_outcube = (*this)["outcube"].filename(); 251 m_outcube = (*this)["outcube"].filename();
252 252
253 - // Determine whether the cube is empty  
254 - bool cube_is_empty = ((m_psfcube.cube().nx() == 0) ||  
255 - (m_psfcube.cube().ny() == 0) ||  
256 - (m_psfcube.cube().nmaps() == 0));  
257 -  
258 // Save PSF cube if filename and the PSF cube are not empty 253 // Save PSF cube if filename and the PSF cube are not empty
259 - if (!m_outcube.is_empty() && !cube_is_empty) { 254 + if (!m_outcube.is_empty() && !m_psfcube.cube().is_empty()) {
260 m_psfcube.save(m_outcube, clobber()); 255 m_psfcube.save(m_outcube, clobber());
261 } 256 }
262 257
263 // Write into logger what has been done 258 // Write into logger what has been done
264 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); 259 std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url();
265 - if (cube_is_empty) { 260 + if (m_psfcube.cube().is_empty()) {
266 fname.append(" (cube is empty, no file created)"); 261 fname.append(" (cube is empty, no file created)");
267 } 262 }
268 log_value(NORMAL, "PSF cube file", fname); 263 log_value(NORMAL, "PSF cube file", fname);
src/ctskymap/ctskymap.cpp
@@ -284,11 +284,8 @@ void ctskymap::save(void) @@ -284,11 +284,8 @@ void ctskymap::save(void)
284 // Get sky map filename 284 // Get sky map filename
285 m_outmap = (*this)["outmap"].filename(); 285 m_outmap = (*this)["outmap"].filename();
286 286
287 - // Determine whether the map is empty  
288 - bool map_is_empty = ((m_skymap.nx() == 0) || (m_skymap.ny() == 0));  
289 -  
290 // Save sky map if filename and the map are not empty 287 // Save sky map if filename and the map are not empty
291 - if (!m_outmap.is_empty() && !map_is_empty) { 288 + if (!m_outmap.is_empty() && !m_skymap.is_empty()) {
292 289
293 // Create empty FITS file 290 // Create empty FITS file
294 GFits fits; 291 GFits fits;
@@ -303,7 +300,7 @@ void ctskymap::save(void) @@ -303,7 +300,7 @@ void ctskymap::save(void)
303 300
304 // Write into logger what has been done 301 // Write into logger what has been done
305 std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url(); 302 std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url();
306 - if (map_is_empty) { 303 + if (m_skymap.is_empty()) {
307 fname.append(" (map is empty, no file created)"); 304 fname.append(" (map is empty, no file created)");
308 } 305 }
309 log_value(NORMAL, "Sky map file", fname); 306 log_value(NORMAL, "Sky map file", fname);
src/cttsmap/cttsmap.cpp
@@ -355,11 +355,8 @@ void cttsmap::save(void) @@ -355,11 +355,8 @@ void cttsmap::save(void)
355 // Get TS map filename 355 // Get TS map filename
356 m_outmap = (*this)["outmap"].filename(); 356 m_outmap = (*this)["outmap"].filename();
357 357
358 - // Determine whether the TS map is empty  
359 - bool map_is_empty = ((m_tsmap.nx() == 0) || (m_tsmap.ny() == 0));  
360 -  
361 // Save only if filename is non-empty 358 // Save only if filename is non-empty
362 - if (!m_outmap.is_empty() && !map_is_empty) { 359 + if (!m_outmap.is_empty() && !m_tsmap.is_empty()) {
363 360
364 // Create fits file 361 // Create fits file
365 GFits fits; 362 GFits fits;
@@ -388,7 +385,7 @@ void cttsmap::save(void) @@ -388,7 +385,7 @@ void cttsmap::save(void)
388 385
389 // Write into logger what has been done 386 // Write into logger what has been done
390 std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url(); 387 std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url();
391 - if (map_is_empty) { 388 + if (m_tsmap.is_empty()) {
392 fname.append(" (TS map is empty, no file created)"); 389 fname.append(" (TS map is empty, no file created)");
393 } 390 }
394 log_value(NORMAL, "TS map file", fname); 391 log_value(NORMAL, "TS map file", fname);
test/test_ctbkgcube.py
@@ -131,6 +131,24 @@ class Test(test): @@ -131,6 +131,24 @@ class Test(test):
131 # Check model container 131 # Check model container
132 self._check_models(gammalib.GModels('ctbkgcube_py0.xml'), nmodels=0) 132 self._check_models(gammalib.GModels('ctbkgcube_py0.xml'), nmodels=0)
133 133
  134 + # Check saving with empty file names
  135 + bkgcube['outcube'] = ''
  136 + bkgcube['outmodel'] = ''
  137 + bkgcube['logfile'] = 'ctbkgcube_py1.log'
  138 + bkgcube.logFileOpen()
  139 + bkgcube.save()
  140 +
  141 + # Check saving with "none" model definiton name
  142 + bkgcube['outcube'] = ''
  143 + bkgcube['outmodel'] = 'NONE'
  144 + bkgcube['logfile'] = 'ctbkgcube_py2.log'
  145 + bkgcube.logFileOpen()
  146 + bkgcube.save()
  147 +
  148 + # Check that publish method with user name does not lead to an
  149 + # exception or segfault
  150 + bkgcube.publish('My background cube')
  151 +
134 # Check that clearing does not lead to an exception or segfault 152 # Check that clearing does not lead to an exception or segfault
135 bkgcube.clear() 153 bkgcube.clear()
136 154
@@ -151,9 +169,9 @@ class Test(test): @@ -151,9 +169,9 @@ class Test(test):
151 bkgcube['proj'] = 'CAR' 169 bkgcube['proj'] = 'CAR'
152 bkgcube['xref'] = 83.63 170 bkgcube['xref'] = 83.63
153 bkgcube['yref'] = 22.01 171 bkgcube['yref'] = 22.01
154 - bkgcube['outcube'] = 'ctbkgcube_py1.fits'  
155 - bkgcube['outmodel'] = 'ctbkgcube_py1.xml'  
156 - bkgcube['logfile'] = 'ctbkgcube_py1.log' 172 + bkgcube['outcube'] = 'ctbkgcube_py3.fits'
  173 + bkgcube['outmodel'] = 'ctbkgcube_py3.xml'
  174 + bkgcube['logfile'] = 'ctbkgcube_py3.log'
157 bkgcube['chatter'] = 2 175 bkgcube['chatter'] = 2
158 176
159 # Run ctbkgcube tool 177 # Run ctbkgcube tool
@@ -162,7 +180,7 @@ class Test(test): @@ -162,7 +180,7 @@ class Test(test):
162 bkgcube.save() 180 bkgcube.save()
163 181
164 # Check result files 182 # Check result files
165 - self._check_result_files('ctbkgcube_py1') 183 + self._check_result_files('ctbkgcube_py3')
166 184
167 # Copy ctbkgcube tool 185 # Copy ctbkgcube tool
168 cpy_bkgcube = bkgcube.copy() 186 cpy_bkgcube = bkgcube.copy()
@@ -174,14 +192,10 @@ class Test(test): @@ -174,14 +192,10 @@ class Test(test):
174 # Execute copy of ctbkgcube tool again, now with a higher chatter 192 # Execute copy of ctbkgcube tool again, now with a higher chatter
175 # level than before. In addition, use counts cube to define the 193 # level than before. In addition, use counts cube to define the
176 # background cube 194 # background cube
177 - #cpy_bkgcube['inobs'] = self._events  
178 - #cpy_bkgcube['inmodel'] = self._model  
179 cpy_bkgcube['incube'] = self._cntcube 195 cpy_bkgcube['incube'] = self._cntcube
180 - #cpy_bkgcube['caldb'] = self._caldb  
181 - #cpy_bkgcube['irf'] = self._irf  
182 - cpy_bkgcube['outcube'] = 'ctbkgcube_py2.fits'  
183 - cpy_bkgcube['outmodel'] = 'ctbkgcube_py2.xml'  
184 - cpy_bkgcube['logfile'] = 'ctbkgcube_py2.log' 196 + cpy_bkgcube['outcube'] = 'ctbkgcube_py4.fits'
  197 + cpy_bkgcube['outmodel'] = 'ctbkgcube_py4.xml'
  198 + cpy_bkgcube['logfile'] = 'ctbkgcube_py4.log'
185 cpy_bkgcube['chatter'] = 3 199 cpy_bkgcube['chatter'] = 3
186 cpy_bkgcube['publish'] = True 200 cpy_bkgcube['publish'] = True
187 cpy_bkgcube['addbounds'] = True 201 cpy_bkgcube['addbounds'] = True
@@ -189,7 +203,7 @@ class Test(test): @@ -189,7 +203,7 @@ class Test(test):
189 cpy_bkgcube.execute() 203 cpy_bkgcube.execute()
190 204
191 # Check result files 205 # Check result files
192 - self._check_result_files('ctbkgcube_py2') 206 + self._check_result_files('ctbkgcube_py4')
193 207
194 # Now clear copy of ctbkgcube tool 208 # Now clear copy of ctbkgcube tool
195 cpy_bkgcube.clear() 209 cpy_bkgcube.clear()
@@ -215,7 +229,7 @@ class Test(test): @@ -215,7 +229,7 @@ class Test(test):
215 229
216 # Set-up ctbkgcube from observation container 230 # Set-up ctbkgcube from observation container
217 bkgcube = ctools.ctbkgcube(obs) 231 bkgcube = ctools.ctbkgcube(obs)
218 - bkgcube['incube'] = 'NONE' 232 + bkgcube['incube'] = ''
219 bkgcube['caldb'] = self._caldb 233 bkgcube['caldb'] = self._caldb
220 bkgcube['irf'] = self._irf 234 bkgcube['irf'] = self._irf
221 bkgcube['ebinalg'] = 'LOG' 235 bkgcube['ebinalg'] = 'LOG'
@@ -229,9 +243,9 @@ class Test(test): @@ -229,9 +243,9 @@ class Test(test):
229 bkgcube['proj'] = 'CAR' 243 bkgcube['proj'] = 'CAR'
230 bkgcube['xref'] = 83.63 244 bkgcube['xref'] = 83.63
231 bkgcube['yref'] = 22.01 245 bkgcube['yref'] = 22.01
232 - bkgcube['outcube'] = 'ctbkgcube_py3.fits'  
233 - bkgcube['outmodel'] = 'ctbkgcube_py3.xml'  
234 - bkgcube['logfile'] = 'ctbkgcube_py3.log' 246 + bkgcube['outcube'] = 'ctbkgcube_py5.fits'
  247 + bkgcube['outmodel'] = 'ctbkgcube_py5.xml'
  248 + bkgcube['logfile'] = 'ctbkgcube_py5.log'
235 bkgcube['addbounds'] = True 249 bkgcube['addbounds'] = True
236 bkgcube['chatter'] = 4 250 bkgcube['chatter'] = 4
237 251
@@ -240,7 +254,7 @@ class Test(test): @@ -240,7 +254,7 @@ class Test(test):
240 bkgcube.execute() 254 bkgcube.execute()
241 255
242 # Check result files 256 # Check result files
243 - self._check_result_files('ctbkgcube_py3', nenergies=23) 257 + self._check_result_files('ctbkgcube_py5', nenergies=23)
244 258
245 # Return 259 # Return
246 return 260 return