Commit ce48d5053a80a387ebc3d22de21598b8c1d89105
1 parent
97cf1403
Use GSkyMap::is_empty() method
Showing
9 changed files
with
52 additions
and
69 deletions
src/ctbkgcube/ctbkgcube.cpp
| ... | ... | @@ -343,17 +343,12 @@ void ctbkgcube::save(void) |
| 343 | 343 | m_outcube = (*this)["outcube"].filename(); |
| 344 | 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 | 346 | // Determine whether a model definition file should be written |
| 352 | 347 | bool write_moddef = ((!m_outmodel.is_empty()) && |
| 353 | 348 | (gammalib::tolower(m_outmodel.url()) != "none")); |
| 354 | 349 | |
| 355 | 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 | 352 | m_background.save(m_outcube, clobber()); |
| 358 | 353 | } |
| 359 | 354 | |
| ... | ... | @@ -365,7 +360,7 @@ void ctbkgcube::save(void) |
| 365 | 360 | // Write into logger what has been done |
| 366 | 361 | std::string fname = (m_outcube.is_empty()) ? "NONE" : m_outcube.url(); |
| 367 | 362 | std::string mname = (write_moddef) ? m_outmodel.url() : "NONE"; |
| 368 | - if (cube_is_empty) { | |
| 363 | + if (m_background.cube().is_empty()) { | |
| 369 | 364 | fname.append(" (cube is empty, no file created)"); |
| 370 | 365 | } |
| 371 | 366 | log_value(NORMAL, "Background cube file", fname); |
| ... | ... | @@ -497,7 +492,7 @@ void ctbkgcube::get_parameters(void) |
| 497 | 492 | std::string incube = (*this)["incube"].filename(); |
| 498 | 493 | |
| 499 | 494 | // Check for filename validity |
| 500 | - if ((gammalib::toupper(incube) == "NONE") || | |
| 495 | + if ((gammalib::toupper(incube) == "NONE") || | |
| 501 | 496 | (gammalib::strip_whitespace(incube) == "")) { |
| 502 | 497 | |
| 503 | 498 | // Create an event cube based on task parameters |
| ... | ... | @@ -520,18 +515,19 @@ void ctbkgcube::get_parameters(void) |
| 520 | 515 | } // endelse: cube was loaded from file |
| 521 | 516 | |
| 522 | 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 | 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 | 524 | std::string msg = "No model definition XML file specified. " |
| 527 | 525 | "Please set the \"inmodel\" parameter to the " |
| 528 | 526 | "XML file that contains the background model " |
| 529 | 527 | "definition."; |
| 530 | 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 | 533 | // Get remaining parameters | ... | ... |
src/ctbkgcube/ctbkgcube.hpp
src/ctedispcube/ctedispcube.cpp
| ... | ... | @@ -264,20 +264,15 @@ void ctedispcube::save(void) |
| 264 | 264 | // Get output filename |
| 265 | 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 | 267 | // Save energy dispersion cube if filename and the energy dispersion cube |
| 273 | 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 | 270 | m_edispcube.save(m_outcube, clobber()); |
| 276 | 271 | } |
| 277 | 272 | |
| 278 | 273 | // Write into logger what has been done |
| 279 | 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 | 276 | fname.append(" (cube is empty, no file created)"); |
| 282 | 277 | } |
| 283 | 278 | log_value(NORMAL, "Energy dispersion cube file", fname); | ... | ... |
src/ctexpcube/ctexpcube.cpp
| ... | ... | @@ -261,19 +261,14 @@ void ctexpcube::save(void) |
| 261 | 261 | // Get exposure cube filename |
| 262 | 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 | 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 | 266 | m_expcube.save(m_outcube, clobber()); |
| 272 | 267 | } |
| 273 | 268 | |
| 274 | 269 | // Write into logger what has been done |
| 275 | 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 | 272 | fname.append(" (cube is empty, no file created)"); |
| 278 | 273 | } |
| 279 | 274 | log_value(NORMAL, "Exposure cube file", fname); | ... | ... |
src/ctmapcube/ctmapcube.cpp
| ... | ... | @@ -225,19 +225,14 @@ void ctmapcube::save(void) |
| 225 | 225 | // Get map cube filename |
| 226 | 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 | 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 | 230 | m_cube.save(m_outcube, clobber()); |
| 236 | 231 | } |
| 237 | 232 | |
| 238 | 233 | // Write into logger what has been done |
| 239 | 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 | 236 | fname.append(" (cube is empty, no file created)"); |
| 242 | 237 | } |
| 243 | 238 | log_value(NORMAL, "Map cube file", fname); | ... | ... |
src/ctpsfcube/ctpsfcube.cpp
| ... | ... | @@ -250,19 +250,14 @@ void ctpsfcube::save(void) |
| 250 | 250 | // Get output filename |
| 251 | 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 | 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 | 255 | m_psfcube.save(m_outcube, clobber()); |
| 261 | 256 | } |
| 262 | 257 | |
| 263 | 258 | // Write into logger what has been done |
| 264 | 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 | 261 | fname.append(" (cube is empty, no file created)"); |
| 267 | 262 | } |
| 268 | 263 | log_value(NORMAL, "PSF cube file", fname); | ... | ... |
src/ctskymap/ctskymap.cpp
| ... | ... | @@ -284,11 +284,8 @@ void ctskymap::save(void) |
| 284 | 284 | // Get sky map filename |
| 285 | 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 | 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 | 290 | // Create empty FITS file |
| 294 | 291 | GFits fits; |
| ... | ... | @@ -303,7 +300,7 @@ void ctskymap::save(void) |
| 303 | 300 | |
| 304 | 301 | // Write into logger what has been done |
| 305 | 302 | std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url(); |
| 306 | - if (map_is_empty) { | |
| 303 | + if (m_skymap.is_empty()) { | |
| 307 | 304 | fname.append(" (map is empty, no file created)"); |
| 308 | 305 | } |
| 309 | 306 | log_value(NORMAL, "Sky map file", fname); | ... | ... |
src/cttsmap/cttsmap.cpp
| ... | ... | @@ -355,11 +355,8 @@ void cttsmap::save(void) |
| 355 | 355 | // Get TS map filename |
| 356 | 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 | 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 | 361 | // Create fits file |
| 365 | 362 | GFits fits; |
| ... | ... | @@ -388,7 +385,7 @@ void cttsmap::save(void) |
| 388 | 385 | |
| 389 | 386 | // Write into logger what has been done |
| 390 | 387 | std::string fname = (m_outmap.is_empty()) ? "NONE" : m_outmap.url(); |
| 391 | - if (map_is_empty) { | |
| 388 | + if (m_tsmap.is_empty()) { | |
| 392 | 389 | fname.append(" (TS map is empty, no file created)"); |
| 393 | 390 | } |
| 394 | 391 | log_value(NORMAL, "TS map file", fname); | ... | ... |
test/test_ctbkgcube.py
| ... | ... | @@ -131,6 +131,24 @@ class Test(test): |
| 131 | 131 | # Check model container |
| 132 | 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 | 152 | # Check that clearing does not lead to an exception or segfault |
| 135 | 153 | bkgcube.clear() |
| 136 | 154 | |
| ... | ... | @@ -151,9 +169,9 @@ class Test(test): |
| 151 | 169 | bkgcube['proj'] = 'CAR' |
| 152 | 170 | bkgcube['xref'] = 83.63 |
| 153 | 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 | 175 | bkgcube['chatter'] = 2 |
| 158 | 176 | |
| 159 | 177 | # Run ctbkgcube tool |
| ... | ... | @@ -162,7 +180,7 @@ class Test(test): |
| 162 | 180 | bkgcube.save() |
| 163 | 181 | |
| 164 | 182 | # Check result files |
| 165 | - self._check_result_files('ctbkgcube_py1') | |
| 183 | + self._check_result_files('ctbkgcube_py3') | |
| 166 | 184 | |
| 167 | 185 | # Copy ctbkgcube tool |
| 168 | 186 | cpy_bkgcube = bkgcube.copy() |
| ... | ... | @@ -174,14 +192,10 @@ class Test(test): |
| 174 | 192 | # Execute copy of ctbkgcube tool again, now with a higher chatter |
| 175 | 193 | # level than before. In addition, use counts cube to define the |
| 176 | 194 | # background cube |
| 177 | - #cpy_bkgcube['inobs'] = self._events | |
| 178 | - #cpy_bkgcube['inmodel'] = self._model | |
| 179 | 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 | 199 | cpy_bkgcube['chatter'] = 3 |
| 186 | 200 | cpy_bkgcube['publish'] = True |
| 187 | 201 | cpy_bkgcube['addbounds'] = True |
| ... | ... | @@ -189,7 +203,7 @@ class Test(test): |
| 189 | 203 | cpy_bkgcube.execute() |
| 190 | 204 | |
| 191 | 205 | # Check result files |
| 192 | - self._check_result_files('ctbkgcube_py2') | |
| 206 | + self._check_result_files('ctbkgcube_py4') | |
| 193 | 207 | |
| 194 | 208 | # Now clear copy of ctbkgcube tool |
| 195 | 209 | cpy_bkgcube.clear() |
| ... | ... | @@ -215,7 +229,7 @@ class Test(test): |
| 215 | 229 | |
| 216 | 230 | # Set-up ctbkgcube from observation container |
| 217 | 231 | bkgcube = ctools.ctbkgcube(obs) |
| 218 | - bkgcube['incube'] = 'NONE' | |
| 232 | + bkgcube['incube'] = '' | |
| 219 | 233 | bkgcube['caldb'] = self._caldb |
| 220 | 234 | bkgcube['irf'] = self._irf |
| 221 | 235 | bkgcube['ebinalg'] = 'LOG' |
| ... | ... | @@ -229,9 +243,9 @@ class Test(test): |
| 229 | 243 | bkgcube['proj'] = 'CAR' |
| 230 | 244 | bkgcube['xref'] = 83.63 |
| 231 | 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 | 249 | bkgcube['addbounds'] = True |
| 236 | 250 | bkgcube['chatter'] = 4 |
| 237 | 251 | |
| ... | ... | @@ -240,7 +254,7 @@ class Test(test): |
| 240 | 254 | bkgcube.execute() |
| 241 | 255 | |
| 242 | 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 | 259 | # Return |
| 246 | 260 | return | ... | ... |