Changeset 36767 for branches/eam_branches/ipp-20140423/Ohana
- Timestamp:
- May 23, 2014, 9:36:11 AM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140423/Ohana/src/delstar
- Files:
-
- 3 edited
-
include/delstar.h (modified) (2 diffs)
-
src/args.c (modified) (2 diffs)
-
src/delete_duplicate_images.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140423/Ohana/src/delstar/include/delstar.h
r35837 r36767 2 2 # include <dvo.h> 3 3 # include <signal.h> 4 5 # define MARKTIME(MSG,...) { \ 6 gettimeofday (&stopTimer, (void *) NULL); \ 7 float dtime = DTIME (stopTimer, startTimer); \ 8 fprintf (stderr, MSG, __VA_ARGS__); } 9 10 # define INITTIME \ 11 struct timeval startTimer, stopTimer; \ 12 gettimeofday (&startTimer, (void *) NULL); 4 13 5 14 // options for generating the IndexArray used to select images for deletion (delete_duplicate_images.c) … … 67 76 int UPDATE; 68 77 int IMAGE_DETAILS; 78 int IMAGE_DUPLICATES_BY_OBSTIME; 69 79 int IMAGE_ONLY; 70 80 int ORPHAN; -
branches/eam_branches/ipp-20140423/Ohana/src/delstar/src/args.c
r35758 r36767 18 18 fprintf (stderr, " -image-details : list info about the deleted images (-dup-images only)\n"); 19 19 fprintf (stderr, " -image-only : only examine the image table (changes are NOT saved; -dup-images only)\n"); 20 fprintf (stderr, " -image-only-force : modify only the image table (-dup-images only)\n"); 21 fprintf (stderr, " -image-by-obstime : use date/time and photcode (not externID) to find duplicates\n"); 20 22 fprintf (stderr, " -region Rmin Rmax Dmin Dmax : apply changes to this part of the sky\n"); 21 23 … … 68 70 if ((N = get_argument (argc, argv, "-image-details"))) { 69 71 IMAGE_DETAILS = TRUE; 72 remove_argument (N, &argc, argv); 73 } 74 75 IMAGE_DUPLICATES_BY_OBSTIME = FALSE; 76 if ((N = get_argument (argc, argv, "-image-by-obstime"))) { 77 IMAGE_DUPLICATES_BY_OBSTIME = TRUE; 70 78 remove_argument (N, &argc, argv); 71 79 } -
branches/eam_branches/ipp-20140423/Ohana/src/delstar/src/delete_duplicate_images.c
r35758 r36767 1 1 # include "delstar.h" 2 3 IndexArray *find_duplicates_obstime (Image *image, off_t Nimage, off_t *Nduplicates); 4 off_t find_obstime_range (Image *image, off_t Nimage, off_t firstEntry); 5 void sort_by_obstime (e_time *T, short *P, off_t *I, off_t N); 6 void sort_by_photcode (short *P, off_t *I, off_t N); 2 7 3 8 // this function identifies the images to be deleted based on duplication of the … … 18 23 19 24 off_t Nduplicates = 0; 20 IndexArray *imageID = find_duplicates (image, Nimage, &Nduplicates); 25 IndexArray *imageID = NULL; 26 27 if (IMAGE_DUPLICATES_BY_OBSTIME) { 28 imageID = find_duplicates_obstime (image, Nimage, &Nduplicates); 29 } else { 30 imageID = find_duplicates (image, Nimage, &Nduplicates); 31 } 21 32 22 33 if (Nduplicates == 0) { … … 494 505 } 495 506 507 // sort by increasing obstime 508 void sort_by_obstime (e_time *T, short *P, off_t *I, off_t N) { 509 510 # define SWAPFUNC(A,B){ e_time tmpT; short tmpP; off_t tmpI; \ 511 tmpT = T[A]; T[A] = T[B]; T[B] = tmpT; \ 512 tmpP = P[A]; P[A] = P[B]; P[B] = tmpP; \ 513 tmpI = I[A]; I[A] = I[B]; I[B] = tmpI; \ 514 } 515 # define COMPARE(A,B)(T[A] < T[B]) 516 517 OHANA_SORT (N, COMPARE, SWAPFUNC); 518 519 # undef SWAPFUNC 520 # undef COMPARE 521 522 } 523 524 // sort by increasing photcode 525 void sort_by_photcode (short *P, off_t *I, off_t N) { 526 527 # define SWAPFUNC(A,B){ short tmpP; off_t tmpI; \ 528 tmpP = P[A]; P[A] = P[B]; P[B] = tmpP; \ 529 tmpI = I[A]; I[A] = I[B]; I[B] = tmpI; \ 530 } 531 # define COMPARE(A,B)(P[A] < P[B]) 532 533 OHANA_SORT (N, COMPARE, SWAPFUNC); 534 535 # undef SWAPFUNC 536 # undef COMPARE 537 538 } 539 540 static e_time *obstime = NULL; 541 static short *photcode = NULL; 542 static off_t *primary = NULL; 543 static off_t *idx = NULL; 544 static char *keep = NULL; 545 546 static short *photcode_subset = NULL; 547 static off_t *idx_subset = NULL; 548 549 static off_t Nsubset = 0; 550 static off_t NSUBSET = 300; 551 552 off_t find_obstime_range (Image *image, off_t Nimage, off_t firstEntry) { 553 554 Nsubset = 0; 555 556 // find all entries with the same obstime: 557 e_time firstTime = obstime[firstEntry]; 558 559 idx_subset[Nsubset] = idx[firstEntry]; 560 photcode_subset[Nsubset] = photcode[firstEntry]; 561 Nsubset++; 562 563 off_t i = firstEntry + Nsubset; 564 while ((i < Nimage) && (obstime[i] == firstTime)) { 565 idx_subset[Nsubset] = idx[i]; 566 photcode_subset[Nsubset] = photcode[i]; 567 Nsubset++; 568 i++; 569 if (Nsubset >= NSUBSET) { 570 NSUBSET += 1000; 571 REALLOCATE (photcode_subset, short, NSUBSET); 572 REALLOCATE (idx_subset, off_t, NSUBSET); 573 } 574 } 575 576 sort_by_photcode (photcode_subset, idx_subset, Nsubset); 577 578 return i; 579 } 580 581 // alternative version to find duplicates based on obstime and photcode 582 IndexArray *find_duplicates_obstime (Image *image, off_t Nimage, off_t *Nduplicates) { 583 584 if (Nimage < 1) return NULL; 585 586 // how to find duplicates: 587 // generate a set of arrays (idx, obstime, photcode, keep) 588 // sort the arrays by obstime 589 // loop over obstime. 590 // for a given new obstime, scan through the entries with the same value 591 // create a sub-array of photcodes, idx 592 // sort by photcode 593 // loop over entries 594 // find matching photcodes 595 // mark duplicate enties 596 597 ALLOCATE (obstime, e_time, Nimage); 598 ALLOCATE (photcode, short, Nimage); 599 ALLOCATE (primary, off_t, Nimage); 600 ALLOCATE (idx, off_t, Nimage); 601 ALLOCATE (keep, char, Nimage); 602 603 off_t i; 604 605 INITTIME; 606 607 // skip entries with photcode == 0? 608 for (i = 0; i < Nimage; i++) { 609 idx[i] = i; 610 primary[i] = -1; // only duplicates get a value for primary 611 keep[i] = TRUE; 612 obstime[i] = image[i].tzero; 613 photcode[i] = image[i].photcode; 614 } 615 MARKTIME(" generate index arrays: %f sec\n", dtime); 616 617 // sort the 4 arrays 618 sort_by_obstime (obstime, photcode, idx, Nimage); 619 MARKTIME(" sort index arrays: %f sec\n", dtime); 620 621 // image[idx[i]].tzero = obstime[i] 622 // keep[i] -> keep image[i] ('keep' is NOT resorted) 623 624 // allocate arrays to store the subsets (these are global static) 625 // These get reallocated if necessary in find_obstime_range() 626 ALLOCATE (photcode_subset, short, NSUBSET); 627 ALLOCATE (idx_subset, off_t, NSUBSET); 628 629 // entries of idx_subset correspond to the original image sequence: 630 // image[idx_subset[i]].tzero = obstime[i] 631 632 off_t firstEntry = 0; 633 off_t nextEntry = 0; 634 635 while (nextEntry < Nimage) { 636 if (firstEntry >= Nimage) { 637 fprintf (stderr, "error, too far?\n"); 638 } 639 640 // generate photcode_subset, idx_subset in order of photcode for this unique obstime[firstEntry] 641 // returned value is the first value of the next entry 642 nextEntry = find_obstime_range (image, Nimage, firstEntry); 643 644 // step through the photcodes and find duplicates 645 int j; 646 int firstCodeEntry = 0; 647 short firstCode = photcode_subset[firstCodeEntry]; 648 for (j = 1; j < Nsubset; j++) { 649 if (photcode_subset[j] == firstCode) { 650 // mark as duplicate 651 off_t dupIndex = idx_subset[j]; 652 keep[dupIndex] = FALSE; 653 primary[dupIndex] = idx_subset[firstCodeEntry]; 654 } else { 655 // new value of photcode, call if the first one 656 firstCodeEntry = j; 657 firstCode = photcode_subset[firstCodeEntry]; 658 } 659 } 660 firstEntry = nextEntry; 661 } 662 MARKTIME(" find duplicates: %f sec\n", dtime); 663 664 IndexArray *imageID = make_index_array (image, Nimage, IMAGE_ID); 665 MARKTIME(" make index array: %f sec\n", dtime); 666 667 // set imageID->value to TRUE for images we want to delete 668 off_t Ndup = 0; 669 for (i = 0; i < Nimage; i++) { 670 if (keep[i]) continue; 671 off_t Ni = image[i].imageID - imageID->minID; 672 myAssert (Ni >= 0, "oops"); 673 myAssert (Ni < imageID->range, "oops"); 674 imageID->value[Ni] = TRUE; 675 Ndup ++; 676 } 677 MARKTIME(" mark duplicates: %f sec\n", dtime); 678 679 for (i = 0; IMAGE_DETAILS && (i < Nimage); i++) { 680 off_t Ni = image[i].imageID - imageID->minID; 681 if (!imageID->value[Ni]) continue; 682 683 char *date = NULL; 684 date = ohana_sec_to_date (image[i].tzero); 685 fprintf (stderr, "delete image : (" OFF_T_FMT "), extID = %d : %30s : %20s %5d == ", i, image[i].externID, image[i].name, date, image[i].photcode); 686 free (date); 687 688 off_t myPrimary = primary[i]; 689 if (myPrimary < 0) { 690 fprintf (stderr, "ERROR: this should never happen\n"); 691 abort(); 692 } 693 date = ohana_sec_to_date (image[myPrimary].tzero); 694 fprintf (stderr, "parent image : (" OFF_T_FMT "), extID = %d : %30s : %20s %5d\n", myPrimary, image[myPrimary].externID, image[myPrimary].name, date, image[myPrimary].photcode); 695 free (date); 696 } 697 698 *Nduplicates = Ndup; 699 700 free (photcode_subset); 701 free (idx_subset); 702 703 free (obstime); 704 free (photcode); 705 free (primary); 706 free (idx); 707 free (keep); 708 709 return imageID;; 710 } 711 496 712 // find the min & max values of the given ID (externID or imageID) 497 713 // construct an empty array with length needed to fit IDs
Note:
See TracChangeset
for help on using the changeset viewer.
