Changeset 24691 for trunk/magic/remove/src/streaksremove.c
- Timestamp:
- Jul 6, 2009, 4:24:20 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/streaksremove.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
