Changeset 24691
- Timestamp:
- Jul 6, 2009, 4:24:20 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
ippScripts/scripts/magic_destreak.pl (modified) (4 diffs)
-
magic/remove/src/streaksio.c (modified) (7 diffs)
-
magic/remove/src/streaksremove.c (modified) (6 diffs)
-
magic/remove/src/streaksremove.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/magic_destreak.pl
r24687 r24691 194 194 } 195 195 196 my ($image, $mask, $ch_mask, $weight, $astrom );196 my ($image, $mask, $ch_mask, $weight, $astrom, $sources); 197 197 198 198 if ($stage eq "raw") { … … 211 211 $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base); 212 212 $weight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base); 213 $sources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $path_base); 213 214 } elsif ($stage eq "diff") { 214 215 my $name = $inverse ? "PPSUB.INVERSE" : "PPSUB.OUTPUT"; # Base name for images … … 216 217 $mask = $ipprc->filename("$name.MASK", $path_base); 217 218 $weight = $ipprc->filename("$name.VARIANCE", $path_base); 219 $sources = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base); 218 220 } 219 221 … … 227 229 $command .= " -chip_mask $ch_mask" if defined $ch_mask; 228 230 $command .= " -weight $weight" if defined $weight; 231 $command .= " -sources $sources" if defined $sources; 229 232 $command .= " -skycelllist $skycell_list" if defined $skycell_list; 230 233 $command .= " -replace" if $replace; -
trunk/magic/remove/src/streaksio.c
r24556 r24691 20 20 memset(sf, 0, sizeof(*sf)); 21 21 22 sf->config = config; 23 sf->program_name = basename(program_name); 24 22 25 if (remove) { 23 26 // remember pointer so that streaksExit can delete temps … … 25 28 } 26 29 27 sf->config = config;28 sf->program_name = basename(program_name);29 30 30 31 // error checking is done by sFileOpen. If a file can't be opened we just exit … … 80 81 } else { 81 82 sf->recWeight = sFileOpen(config, stage, "RECOVERY.WEIGHT", NULL, true); 83 } 84 } 85 if (remove) { 86 sf->inSources = sFileOpen(config, stage, "SOURCES", NULL, false); 87 if (sf->inSources) { 88 inputBasename = basename(sf->inSources->name); 89 sf->outSources = sFileOpen(config, stage, "OUTPUT", inputBasename, true); 82 90 } 83 91 } … … 607 615 streaksExit("", PS_EXIT_DATA_ERROR); 608 616 } 609 617 610 618 bool status; 611 619 in->extname = psMetadataLookupStr(&status, in->header, "EXTNAME"); … … 929 937 if (!replicate(sfiles->outWeight, sfiles->inWeight)) { 930 938 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 939 return false; 940 } 941 } 942 943 if (sfiles->outSources) { 944 if (!replicate(sfiles->outSources, sfiles->inSources)) { 945 psError(PM_ERR_SYS, false, "failed to replicate outSources."); 931 946 return false; 932 947 } … … 997 1012 } 998 1013 1014 if (sfiles->outSources) { 1015 if (!swapOutputToInput(sfiles->inSources, sfiles->outSources)) { 1016 psError(PM_ERR_SYS, false, "failed to swap instances for sources."); 1017 return false; 1018 } 1019 } 1020 999 1021 if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) { 1000 1022 psError(PM_ERR_SYS, false, "failed to swap instances for Image."); 1001 1023 return false; 1002 1024 } 1025 1003 1026 1004 1027 return true; … … 1042 1065 if (sfiles->outImage) { 1043 1066 deleteFile(sfiles->outImage); 1067 } 1068 1069 if (sfiles->outSources) { 1070 deleteFile(sfiles->outSources); 1044 1071 } 1045 1072 -
trunk/magic/remove/src/streaksremove.c
r24684 r24691 17 17 static void writeImages(streakFiles *sf, bool exciseImageCube); 18 18 static void updateAstrometry(streakFiles *sfiles); 19 static void censorSources(streakFiles *sfiles, psU32 maskStreak); 19 20 20 21 int … … 188 189 } 189 190 191 censorSources(sfiles, maskStreak); 192 190 193 // write the destreaked "temporary" images and the recovery images 191 194 writeImages(sfiles, exciseImageCube); 195 192 196 193 197 psLogMsg("streaksremove", PS_LOG_INFO, "time to process component %d: %f\n", sfiles->extnum, psTimerClear("PROCESS_COMPONENT")); … … 259 263 fprintf(stderr, "\t-weight WEIGHT.fits: weight file to de-streak\n"); 260 264 fprintf(stderr, "\t-replace: replace the input images with the output\n"); 261 fprintf(stderr, "\t-remove: remove the original image after processing (requires -replace)\n");262 265 fprintf(stderr, "\t-keepnonwarped: do not exise pixels that were not part of difference processing\n"); 263 266 fprintf(stderr, "\t-transparent val: instead of setting excicsed pixel to NAN add val\n"); … … 335 338 bool gotReplace = false; 336 339 if ((argnum = psArgumentGet(argc, argv, "-replace"))) { 340 if (!nebulousImage) { 341 psError(PS_ERR_UNKNOWN, true, "replace is only supported for nebulous files"); 342 usage(); 343 } 337 344 gotReplace = true; 338 345 psArgumentRemove(argnum, &argc, argv); … … 416 423 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "INPUT.WEIGHT", 0, 417 424 "name of input weight image", argv[argnum]); 425 psArgumentRemove(argnum, &argc, argv); 426 } 427 if ((argnum = psArgumentGet(argc, argv, "-sources"))) { 428 psArgumentRemove(argnum, &argc, argv); 429 bool nebulousSources = IN_NEBULOUS(argv[argnum]); 430 if (nebulousSources != nebulousImage) { 431 psError(PS_ERR_UNKNOWN, true, "sources file must have %snebulous path with %s image path\n", 432 nebulousImage ? "" : "non ", nebulousImage ? "nebulous" : "regular"); 433 usage(); 434 } 435 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "SOURCES", 0, 436 "name of input sources file", argv[argnum]); 418 437 psArgumentRemove(argnum, &argc, argv); 419 438 } … … 757 776 } 758 777 778 // read a sources file (.cmf) and remove any rows whose coordinate is convered by a 779 // streak mask 780 static void 781 censorSources(streakFiles *sfiles, psU32 maskStreak) 782 { 783 if ((!sfiles->inSources) || (!sfiles->outMask)) { 784 return; 785 } 786 psImage *maskImage = sfiles->outMask->image; 787 if (!maskImage) { 788 psError(PS_ERR_IO, false, "maskImage is null!"); 789 streaksExit("", PS_EXIT_PROG_ERROR); 790 } 791 792 sFile *in = sfiles->inSources; 793 sFile *out = sfiles->outSources; 794 795 in->header = psFitsReadHeader(NULL, in->fits); 796 if (!in->header) { 797 psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name); 798 streaksExit("", PS_EXIT_DATA_ERROR); 799 } 800 801 bool status; 802 psString extname = psMetadataLookupStr(&status, in->header, "EXTNAME"); 803 if (!extname) { 804 psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name); 805 streaksExit("", PS_EXIT_DATA_ERROR); 806 } 807 808 psArray *inTable = psFitsReadTable(in->fits); 809 if (!inTable->n) { 810 psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name); 811 streaksExit("", PS_EXIT_DATA_ERROR); 812 } 813 814 psArray *outTable = psArrayAllocEmpty(inTable->n); 815 int j = 0; 816 int numCensored = 0; 817 for (int i = 0 ; i < inTable->n; i++) { 818 psMetadata *row = inTable->data[i]; 819 820 psF32 x = psMetadataLookupF32 (&status, row, "X_PSF"); 821 psF32 y = psMetadataLookupF32 (&status, row, "Y_PSF"); 822 823 psU32 mask = psImageGet(maskImage, x, y); 824 825 // Key the source if the center pixel is not masked with maskStreak 826 if (! (mask & maskStreak) ) { 827 psArraySet(outTable, j++, row); 828 } else { 829 numCensored++; 830 } 831 } 832 833 printf("Censored %d sources\n", numCensored); 834 835 // get rid of unused elements (don't know if this is necessary) 836 psArrayRealloc(outTable, j); 837 838 addDestreakKeyword(in->header); 839 if (! psFitsWriteTable(out->fits, in->header, outTable, extname)) { 840 psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name); 841 streaksExit("", PS_EXIT_DATA_ERROR); 842 } 843 844 if (!psFitsClose(out->fits)) { 845 psError(PS_ERR_IO, false, "failed to close table %s", out->resolved_name); 846 streaksExit("", PS_EXIT_DATA_ERROR); 847 } 848 } -
trunk/magic/remove/src/streaksremove.h
r24556 r24691 62 62 sFile *outChMask; 63 63 sFile *recChMask; 64 sFile *inSources; 65 sFile *outSources; 64 66 psString class_id; 65 67 pmFPAfile *inAstrom;
Note:
See TracChangeset
for help on using the changeset viewer.
