- Timestamp:
- Jun 21, 2016, 1:14:24 PM (10 years ago)
- Location:
- trunk/Ohana/src/delstar
- Files:
-
- 2 edited
-
include/delstar.h (modified) (2 diffs)
-
src/delete_duplicate_measures.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/delstar/include/delstar.h
r39579 r39605 43 43 int imageID; 44 44 } MeasureEdge; 45 46 typedef struct { 47 off_t NdelWarp; 48 off_t NdelChip; 49 off_t NdelStack; 50 off_t NdelOther; 51 off_t NdelAves; 52 off_t NdelMeas; 53 } DeleteMeasureResult; 45 54 46 55 /* global variables set in parameter file */ … … 163 172 int delete_duplicate_measures (); 164 173 int delete_duplicate_measures_parallel (SkyList *sky); 165 int delete_duplicate_measures_catalog (Catalog *catalog);174 DeleteMeasureResult delete_duplicate_measures_catalog (Catalog *catalog); 166 175 167 176 int delete_fix_LAP (ImageSubset *image, off_t Nimage); -
trunk/Ohana/src/delstar/src/delete_duplicate_measures.c
r39579 r39605 1 1 # include "delstar.h" 2 int isGPC1chip (int photcode); 3 int isGPC1warp (int photcode); 4 int isGPC1stack (int photcode); 5 int dvo_catalog_subset_backup (Catalog *catalog, char *suffix); 2 6 3 7 // this function identifies detections to be deleted as being duplicates based on imageID + detID … … 52 56 catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i]; 53 57 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 54 catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_ MISSING | DVO_LOAD_SECFILT;58 catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT; 55 59 56 60 if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename); … … 68 72 } 69 73 70 if (delete_duplicate_measures_catalog (&catalog)) { 71 // skip if nothing was deleted 72 if (UPDATE) { 73 if (!dvo_catalog_backup (&catalog, "~", TRUE)) { 74 fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", catalog.filename); 75 exit (1); 76 } 77 SetProtect (TRUE); 78 dvo_catalog_save_complete (&catalog, VERBOSE2); 79 } 80 } 74 DeleteMeasureResult result = delete_duplicate_measures_catalog (&catalog); 75 76 // track number of deletions and only update if modifications are made 77 int Nmods = 0; 78 Nmods += result.NdelWarp; 79 Nmods += result.NdelChip; 80 Nmods += result.NdelStack; 81 Nmods += result.NdelOther; 82 Nmods += result.NdelAves; 83 Nmods += result.NdelMeas; 84 if (!Nmods) { 85 fprintf (stderr, "no changes to %s, no output\n", catalog.filename); 86 dvo_catalog_unlock (&catalog); 87 dvo_catalog_free (&catalog); 88 continue; 89 } 90 91 if (!UPDATE) { 92 dvo_catalog_unlock (&catalog); 93 dvo_catalog_free (&catalog); 94 continue; 95 } 96 97 char history[128]; 98 struct timeval now; 99 gettimeofday (&now, (void *) NULL); 100 char *moddate = ohana_sec_to_date (now.tv_sec); 101 snprintf (history, 128, "delete duplicate measurements: %s", moddate); 102 gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry 103 free (moddate); 104 105 // add metadata to define number of corrections 106 char line[128]; 107 snprintf (line, 60, "Chip "OFF_T_FMT", Warp "OFF_T_FMT", Stack "OFF_T_FMT, result.NdelChip, result.NdelWarp, result.NdelStack); 108 gfits_modify (&catalog.header, "DELETE_1", "%s", 1, line); 109 snprintf (line, 60, "Other "OFF_T_FMT", Measure "OFF_T_FMT", Average "OFF_T_FMT, result.NdelOther, result.NdelMeas, result.NdelAves); 110 gfits_modify (&catalog.header, "DELETE_2", "%s", 1, line); 111 112 // save backup of original cpm file 113 if (!dvo_catalog_subset_backup (&catalog, ".dl1")) { 114 fprintf (stderr, "ERROR: failed to make backup cpt table for catalog %s\n", catalog.filename); 115 exit (1); 116 } 117 if (!dvo_catalog_subset_backup (catalog.measure_catalog, ".d1l")) { 118 fprintf (stderr, "ERROR: failed to make backup cpm table for catalog %s\n", catalog.filename); 119 exit (1); 120 } 121 if (!dvo_catalog_subset_backup (catalog.secfilt_catalog, ".dl1")) { 122 fprintf (stderr, "ERROR: failed to make backup cps table for catalog %s\n", catalog.filename); 123 exit (1); 124 } 125 126 // XXX something of a hack : I only want to save average, measure, secfilt. 127 catalog.Nmissing = catalog.Nmissing_off; 128 catalog.Nlensing = catalog.Nlensing_off; 129 catalog.Nlensobj = catalog.Nlensobj_off; 130 catalog.Nstarpar = catalog.Nstarpar_off; 131 catalog.Ngalphot = catalog.Ngalphot_off; 132 133 catalog.Nmissing_off = 0; 134 catalog.Nlensing_off = 0; 135 catalog.Nlensobj_off = 0; 136 catalog.Nstarpar_off = 0; 137 catalog.Ngalphot_off = 0; 138 139 SetProtect (TRUE); 140 dvo_catalog_save_complete (&catalog, VERBOSE2); 81 141 dvo_catalog_unlock (&catalog); 82 142 SetProtect (FALSE); … … 89 149 FreePhotcodeTable (); 90 150 151 return TRUE; 152 } 153 154 int dvo_catalog_subset_backup (Catalog *catalog, char *suffix) { 155 156 int dbstate; 157 158 char tmpfilename[DVO_MAX_PATH]; 159 int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s%s", catalog->filename, suffix); 160 if (status >= DVO_MAX_PATH) { 161 fprintf (stderr, "path name too long: %s\n", catalog->filename); 162 return FALSE; 163 } 164 165 // play it safe: do not overwrite an existing backup file 166 struct stat fileStats; 167 status = stat (tmpfilename, &fileStats); 168 if (!status) { 169 fprintf (stderr, "ERROR: backup file %s already exists, exiting\n", tmpfilename); 170 return FALSE; 171 } 172 173 // some error accessing the file. there is only one acceptable error: file not found 174 if (status && (errno != ENOENT)) { 175 perror ("problem with output target"); 176 return FALSE; 177 } 178 179 if (fflush (catalog[0].f)) { 180 perror ("fflush: "); 181 fprintf (stderr, "failed to flush file %s\n", catalog[0].filename); 182 return FALSE; 183 } 184 185 // closes f but does not set back to NULL 186 if (!fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate)) { 187 fprintf (stderr, "failed to unlock or close file\n"); 188 return FALSE; 189 } 190 191 status = rename (catalog->filename, tmpfilename); 192 if (status) { 193 fprintf (stderr, "failed to rename catalog %s\n", catalog->filename); 194 return FALSE; 195 } 196 197 // re-lock file, create stream f 198 catalog[0].f = fsetlockfile (catalog[0].filename, 3600.0, catalog[0].lockmode, &dbstate); 199 if (catalog[0].f == NULL) return FALSE; 200 if (dbstate != LCK_EMPTY) return FALSE; 201 202 if (fseeko (catalog[0].f, 0, SEEK_SET)) { 203 perror ("fseeko: "); 204 return FALSE; 205 } 206 91 207 return TRUE; 92 208 } … … 177 293 } 178 294 179 int delete_duplicate_measures_catalog (Catalog *catalog) {295 DeleteMeasureResult delete_duplicate_measures_catalog (Catalog *catalog) { 180 296 181 297 off_t i, j, n, m, N, D, currentAve; … … 257 373 } 258 374 375 # if (0) 259 376 FILE *fsave = NULL; 260 377 if (SAVE_DUPLICATES) { … … 274 391 } 275 392 } 276 393 # endif 394 395 DeleteMeasureResult result; 396 result.NdelWarp = 0; 397 result.NdelChip = 0; 398 result.NdelStack = 0; 399 result.NdelOther = 0; 400 result.NdelAves = 0; 401 result.NdelMeas = 0; 402 277 403 // mark the measures to be dropped 278 404 for (i = 0; i < Nmeasure; i++) { … … 282 408 off_t N = measure[j].averef; 283 409 if (VERBOSE) fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode); 284 if (fsave) { 285 fprintf (fsave, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode); 286 } 410 // if (fsave) { 411 // fprintf (fsave, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode); 412 // } 413 if (isGPC1chip(measure[j].photcode)) { 414 result.NdelChip ++; 415 continue; 416 } 417 if (isGPC1warp(measure[j].photcode)) { 418 result.NdelWarp ++; 419 continue; 420 } 421 if (isGPC1stack(measure[j].photcode)) { 422 result.NdelStack ++; 423 continue; 424 } 425 result.NdelOther ++; 287 426 } 288 427 289 if (fsave) fclose (fsave);428 // if (fsave) fclose (fsave); 290 429 291 430 // set up the measure sequence lists … … 311 450 // n = measureRefOut[i] : measureOut[n] = measure[i] 312 451 ALLOCATE (measureAveOut, off_t, NmeasOut); 313 314 315 452 316 453 // count the number of measures for each averef … … 438 575 if (VERBOSE) fprintf (stderr, "ending with Nave, Nmeas: "OFF_T_FMT" "OFF_T_FMT"\n", catalog[0].Naverage, catalog[0].Nmeasure); 439 576 440 off_t NdelAves = Naverage - catalog[0].Naverage; 441 off_t NdelMeas = Nmeasure - catalog[0].Nmeasure; 442 443 if (NdelAves || NdelMeas) { 444 fprintf (stderr, "deleting "OFF_T_FMT" measures and "OFF_T_FMT" averages : %s\n", NdelMeas, NdelAves, catalog[0].filename); 445 } 577 result.NdelAves = Naverage - catalog[0].Naverage; 578 result.NdelMeas = Nmeasure - catalog[0].Nmeasure; 579 580 fprintf (stderr, "deleting from %s : "OFF_T_FMT" meas, "OFF_T_FMT" aves : "OFF_T_FMT" chip, "OFF_T_FMT" stack, "OFF_T_FMT" warp, "OFF_T_FMT" other\n", catalog[0].filename, result.NdelMeas, result.NdelAves, result.NdelChip, result.NdelStack, result.NdelWarp, result.NdelOther); 446 581 447 582 FREE (fullID); … … 460 595 FREE (measureAveOut); 461 596 462 if (NdelAves || NdelMeas) return TRUE; 463 return FALSE; 597 return result; 464 598 } 465 599 … … 480 614 } 481 615 616 // for now (20140710) I need to identify gpc1 chips explicitly. generalize in the future 617 int isGPC1chip (int photcode) { 618 619 if ((photcode > 10000) && (photcode < 10077)) return TRUE; // g-band 620 if ((photcode > 10100) && (photcode < 10177)) return TRUE; // r-band 621 if ((photcode > 10200) && (photcode < 10277)) return TRUE; // i-band 622 if ((photcode > 10300) && (photcode < 10377)) return TRUE; // z-band 623 if ((photcode > 10400) && (photcode < 10477)) return TRUE; // y-band 624 if ((photcode > 10500) && (photcode < 10577)) return TRUE; // w-band 625 626 return FALSE; 627 } 628 629 // for now (20140710) I need to identify gpc1 stacks explicitly. generalize in the future 630 int isGPC1stack (int photcode) { 631 632 if (photcode == 11000) return TRUE; // g-band 633 if (photcode == 11100) return TRUE; // r-band 634 if (photcode == 11200) return TRUE; // i-band 635 if (photcode == 11300) return TRUE; // z-band 636 if (photcode == 11400) return TRUE; // y-band 637 if (photcode == 11500) return TRUE; // w-band 638 639 return FALSE; 640 } 641 642 // for now (20140710) I need to identify gpc1 stacks explicitly. generalize in the future 643 int isGPC1warp (int photcode) { 644 645 if (photcode == 12000) return TRUE; // g-band 646 if (photcode == 12100) return TRUE; // r-band 647 if (photcode == 12200) return TRUE; // i-band 648 if (photcode == 12300) return TRUE; // z-band 649 if (photcode == 12400) return TRUE; // y-band 650 if (photcode == 12500) return TRUE; // w-band 651 652 return FALSE; 653 }
Note:
See TracChangeset
for help on using the changeset viewer.
