Commit eecf0c9d29d43b24ecfd3dba3e5251710c42a7ce

Authored by Jürgen Knödlseder
1 parent 9051002e

ctfindvar does not save anything if it has nothing to save

Showing 1 changed file with 52 additions and 36 deletions
src/ctfindvar/ctfindvar.cpp
@@ -262,45 +262,70 @@ void ctfindvar::save(void) @@ -262,45 +262,70 @@ void ctfindvar::save(void)
262 // Write header 262 // Write header
263 log_header1(TERSE, "Saving results"); 263 log_header1(TERSE, "Saving results");
264 264
265 - // Write counts cube 265 + // Save counts cube if a valid filename is given and the counts cube is
  266 + // not empty
266 if ((*this)["outcube"].is_valid()) { 267 if ((*this)["outcube"].is_valid()) {
267 268
268 // Get counts cube output filename 269 // Get counts cube output filename
269 GFilename outcube = (*this)["outcube"].filename(); 270 GFilename outcube = (*this)["outcube"].filename();
270 271
271 - // Save counts cube  
272 - m_counts.save(outcube, (*this)["clobber"].boolean()); 272 + // Save counts cube if it is not empty. Otherwise signal that no
  273 + // counts cube was saved.
  274 + if (!m_counts.is_empty()) {
  275 + m_counts.save(outcube, (*this)["clobber"].boolean());
  276 + log_value(TERSE, "Counts cube file", outcube.url());
  277 + }
  278 + else {
  279 + log_value(TERSE, "Counts cube file",
  280 + outcube.url()+" (cube is empty, no file created)");
  281 + }
273 282
274 - // Log saving  
275 - log_value(TERSE, "Saving counts cube", outcube);  
276 } 283 }
277 284
278 - // Create a FITS file for storing the output  
279 - GFits fits; 285 + // Get output map and model filenames
  286 + GFilename outmap = (*this)["outmap"].filename();
  287 + GFilename outmodel = (*this)["outmodel"].filename();
280 288
281 - // Write the most significant values for each pixel  
282 - m_peaksigmap.write(fits, "PEAKSIGMAP"); 289 + // Save output map if the significance map is not empty
  290 + if (!m_peaksigmap.is_empty()) {
283 291
284 - // Write source histograms  
285 - write_source_histograms(fits); 292 + // Create a FITS file for storing the output
  293 + GFits fits;
286 294
287 - // Get output map filename  
288 - GFilename outmap = (*this)["outmap"].filename(); 295 + // Write the most significant values for each pixel
  296 + m_peaksigmap.write(fits, "PEAKSIGMAP");
289 297
290 - // Save output map  
291 - fits.saveto(outmap, (*this)["clobber"].boolean()); 298 + // Write source histograms
  299 + write_source_histograms(fits);
292 300
293 - // Log saving  
294 - log_value(TERSE, "Saving output map", outmap); 301 + // Save significance map
  302 + fits.saveto(outmap, (*this)["clobber"].boolean());
295 303
296 - // Get output model definition file filename  
297 - GFilename outmodel = (*this)["outmodel"].filename(); 304 + // Log saving
  305 + log_value(TERSE, "Output map file", outmap.url());
298 306
299 - // Save model  
300 - m_model_above_thr.save(outmodel); 307 + }
  308 + else {
  309 + log_value(TERSE, "Output map file",
  310 + outmap.url()+" (map is empty, no file created)");
  311 + }
301 312
302 - // Log saving  
303 - log_value(TERSE, "Saving output model", outmodel); 313 + // Save model definiton XML file if the significance map is not empty.
  314 + // This may store an empty model in case that none of the pixels is
  315 + // above threshold.
  316 + if (!m_peaksigmap.is_empty()) {
  317 +
  318 + // Save model
  319 + m_model_above_thr.save(outmodel);
  320 +
  321 + // Log saving
  322 + log_value(TERSE, "Model definition file", outmodel.url());
  323 +
  324 + }
  325 + else {
  326 + log_value(TERSE, "Model definition file",
  327 + outmodel.url()+" (map is empty, no file created)");
  328 + }
304 329
305 // Return 330 // Return
306 return; 331 return;
@@ -415,11 +440,9 @@ void ctfindvar::get_parameters(void) @@ -415,11 +440,9 @@ void ctfindvar::get_parameters(void)
415 // Get minimum significance to set a source as variable 440 // Get minimum significance to set a source as variable
416 m_sig_threshold = (*this)["threshold"].real(); 441 m_sig_threshold = (*this)["threshold"].real();
417 442
418 - // Query smoothing parameters  
419 - if ((*this)["smooth_kernel"].is_valid()) {  
420 - (*this)["smooth_kernel"].string();  
421 - (*this)["smooth_rad"].real();  
422 - } 443 + // Query (hidden) smoothing parameters
  444 + (*this)["smooth_kernel"].string();
  445 + (*this)["smooth_rad"].real();
423 446
424 // If needed later, query output filenames now 447 // If needed later, query output filenames now
425 if (read_ahead()) { 448 if (read_ahead()) {
@@ -561,8 +584,7 @@ void ctfindvar::create_cube(void) @@ -561,8 +584,7 @@ void ctfindvar::create_cube(void)
561 } // endfor: looped over observations 584 } // endfor: looped over observations
562 585
563 // Smooth the maps if requested 586 // Smooth the maps if requested
564 - if ((*this)["smooth_kernel"].is_valid() &&  
565 - (*this)["smooth_kernel"].string() != "NONE") { 587 + if ((*this)["smooth_kernel"].string() != "NONE") {
566 m_counts.smooth((*this)["smooth_kernel"].string(), 588 m_counts.smooth((*this)["smooth_kernel"].string(),
567 (*this)["smooth_rad"].real()); 589 (*this)["smooth_rad"].real());
568 } 590 }
@@ -717,12 +739,6 @@ void ctfindvar::analyse_cube(void) @@ -717,12 +739,6 @@ void ctfindvar::analyse_cube(void)
717 #pragma omp parallel for 739 #pragma omp parallel for
718 for (int ipix = 0; ipix < m_counts.npix(); ++ipix) { 740 for (int ipix = 0; ipix < m_counts.npix(); ++ipix) {
719 741
720 - // Compute total counts for pixel  
721 - //double total_counts = 0.0;  
722 - //for (int k = 0; k < nbins; ++k) {  
723 - // total_counts += m_counts(ipix, k);  
724 - //}  
725 -  
726 // Getting the variability significance for the current pixel 742 // Getting the variability significance for the current pixel
727 GNdarray pixSig = get_variability_sig(ipix); 743 GNdarray pixSig = get_variability_sig(ipix);
728 744