Changeset 25082 for trunk/magic/remove/src/streaksremove.c
- Timestamp:
- Aug 14, 2009, 3:58:07 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/streaksremove.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/streaksremove.c
r25001 r25082 35 35 // Values to set for masked pixels 36 36 psU32 maskStreak = 0; // for the image and weight (usually NAN, MAXINT for integer images) 37 psU32 maskMask = 0; // value looked up for MASK.STREAK 37 psU32 maskMask = 0; // value looked up for MASK.STREAK 38 38 39 39 psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS"); … … 42 42 Streaks *streaks = readStreaksFile(streaksFileName); 43 43 if (!streaks) { 44 psError(PS_ERR_UNKNOWN, "failed to read streaks file: %s", streaksFileName);44 psError(PS_ERR_UNKNOWN, false, "failed to read streaks file: %s", streaksFileName); 45 45 streaksExit("", PS_EXIT_PROG_ERROR); 46 46 } … … 83 83 psLogMsg("streaksremove", PS_LOG_INFO, "time to compute warped pixels: %f\n", cwp_t); 84 84 } 85 85 86 86 if (sfiles->stage == IPP_STAGE_RAW) { 87 87 // Except for raw stage, all of our (GPC1) files have one image extension. … … 97 97 } 98 98 99 inttotalPixels = 0;100 inttotalStreakPixels = 0;99 long totalPixels = 0; 100 long totalStreakPixels = 0; 101 101 102 102 // Iterate through each component of the input (except for raw images there is only one) … … 132 132 sfiles->inImage->numRows); 133 133 psLogMsg("streaksremove", PS_LOG_INFO, "time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS")); 134 134 135 135 // if this extension contained an image, excise the streaked pixels. 136 136 // otherwise it contained an image cube (video cell) which is handled in the if block … … 172 172 } 173 173 174 } else { 174 } else { 175 175 // this component contains an image cube 176 176 // For now excise it completely … … 215 215 216 216 if (!replicateOutputs(sfiles)) { 217 psError (PS_ERR_UNKNOWN, false, "failed to replicate output files");217 psErrorStackPrint(stderr, "failed to replicate output files"); 218 218 deleteTemps(sfiles); 219 psErrorStackPrint(stderr, "");220 219 exit(PS_EXIT_UNKNOWN_ERROR); 221 220 } … … 247 246 pmConceptsDone(); 248 247 pmModelClassCleanup(); 249 streaksNebulousCleanup(); 248 streaksNebulousCleanup(); 250 249 pmConfigDone(); 251 250 psLogMsg("streaksremove", PS_LOG_INFO, "time to run streaksremove: %f\n", psTimerClear("STREAKSREMOVE")); … … 356 355 true); 357 356 } 358 357 359 358 if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) { 360 359 psArgumentRemove(argnum, &argc, argv); … … 374 373 psArgumentRemove(argnum, &argc, argv); 375 374 } 376 375 377 376 // if skycells are not provided then we have to execise all pixels unless -keepnonwarped 378 377 pmConfigFileSetsMD(config->arguments, &argc, argv, "SKYCELLS", "-skycell", "-skycelllist"); … … 628 627 initValue = NAN; 629 628 } else { 630 // otherwise write it to the output 629 // otherwise write it to the output 631 630 writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum); 632 631 initValue = 0; … … 799 798 sFile *out = sfiles->outSources; 800 799 801 in->header = psFitsReadHeader(NULL, in->fits); 802 if (!in->header) { 803 psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name); 804 streaksExit("", PS_EXIT_DATA_ERROR); 805 } 806 807 bool status; 808 psString extname = psMetadataLookupStr(&status, in->header, "EXTNAME"); 809 if (!extname) { 810 psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name); 811 streaksExit("", PS_EXIT_DATA_ERROR); 812 } 813 814 psArray *inTable = psFitsReadTable(in->fits); 815 if (!inTable->n) { 816 psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name); 817 streaksExit("", PS_EXIT_DATA_ERROR); 818 } 819 820 psArray *outTable = psArrayAllocEmpty(inTable->n); 821 int j = 0; 822 int numCensored = 0; 823 for (int i = 0 ; i < inTable->n; i++) { 824 psMetadata *row = inTable->data[i]; 825 826 psF32 x = psMetadataLookupF32 (&status, row, "X_PSF"); 827 psF32 y = psMetadataLookupF32 (&status, row, "Y_PSF"); 828 829 psU32 mask = psImageGet(maskImage, x, y); 830 831 // Key the source if the center pixel is not masked with maskStreak 832 if (! (mask & maskStreak) ) { 833 psArraySet(outTable, j++, row); 800 801 // Primary header, should be "something.hdr" 802 { 803 psMetadata *header = psFitsReadHeader(NULL, in->fits); 804 if (!header) { 805 psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name); 806 streaksExit("", PS_EXIT_DATA_ERROR); 807 } 808 809 bool status; 810 psString extname = psMetadataLookupStr(&status, header, "EXTNAME"); 811 if (!extname) { 812 psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name); 813 streaksExit("", PS_EXIT_DATA_ERROR); 814 } 815 addDestreakKeyword(header); 816 817 if (!psFitsWriteBlank(in->fits, header, extname)) { 818 psError(PS_ERR_IO, false, "failed to write blank in header of %s", in->resolved_name); 819 streaksExit("", PS_EXIT_DATA_ERROR); 820 } 821 psFree(header); 822 } 823 824 // Extension with PSF fits, should be "something.psf" 825 { 826 psMetadata *header = psFitsReadHeader(NULL, in->fits); 827 if (!header) { 828 psError(PS_ERR_IO, false, "failed to read header from %s", in->resolved_name); 829 streaksExit("", PS_EXIT_DATA_ERROR); 830 } 831 psString extname = psMetadataLookupStr(NULL, header, "EXTNAME"); 832 if (!extname) { 833 psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name); 834 streaksExit("", PS_EXIT_DATA_ERROR); 835 } 836 837 psArray *inTable = psFitsReadTable(in->fits); 838 if (!inTable->n) { 839 psError(PS_ERR_IO, false, "table in %s is empty", in->resolved_name); 840 streaksExit("", PS_EXIT_DATA_ERROR); 841 } 842 843 psArray *outTable = psArrayAllocEmpty(inTable->n); 844 int j = 0; 845 int numCensored = 0; 846 for (int i = 0 ; i < inTable->n; i++) { 847 psMetadata *row = inTable->data[i]; 848 849 psF32 x = psMetadataLookupF32(NULL, row, "X_PSF"); 850 psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF"); 851 852 psU32 mask = psImageGet(maskImage, x, y); 853 854 // Key the source if the center pixel is not masked with maskStreak 855 if (!(mask & maskStreak) ) { 856 psArraySet(outTable, j++, row); 857 } else { 858 numCensored++; 859 } 860 } 861 862 // get rid of unused elements (don't know if this is necessary) 863 psArrayRealloc(outTable, j); 864 865 addDestreakKeyword(header); 866 if (psArrayLength(outTable) > 0) { 867 printf("Censored %d sources\n", numCensored); 868 if (! psFitsWriteTable(out->fits, header, outTable, extname)) { 869 psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name); 870 streaksExit("", PS_EXIT_DATA_ERROR); 871 } 834 872 } else { 835 numCensored++; 836 } 837 } 838 839 // get rid of unused elements (don't know if this is necessary) 840 psArrayRealloc(outTable, j); 841 842 addDestreakKeyword(in->header); 843 if (psArrayLength(outTable) > 0) { 844 printf("Censored %d sources\n", numCensored); 845 if (! psFitsWriteTable(out->fits, in->header, outTable, extname)) { 846 psError(PS_ERR_IO, false, "failed to write table to %s", out->resolved_name); 847 streaksExit("", PS_EXIT_DATA_ERROR); 848 } 849 } else { 850 printf("Censored ALL %d sources\n", numCensored); 851 if (! psFitsWriteTableEmpty(out->fits, in->header, inTable->data[0], extname)) { 852 psError(PS_ERR_IO, false, "failed to write empty table to %s", out->resolved_name); 853 streaksExit("", PS_EXIT_DATA_ERROR); 854 } 855 } 873 printf("Censored ALL %d sources\n", numCensored); 874 if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) { 875 psError(PS_ERR_IO, false, "failed to write empty table to %s", out->resolved_name); 876 streaksExit("", PS_EXIT_DATA_ERROR); 877 } 878 } 879 psFree(header); 880 psFree(outTable); 881 psFree(inTable); 882 } 883 884 // XXX Will need to update to handle extension with extended sources, etc. 856 885 857 886 if (!psFitsClose(out->fits)) {
Note:
See TracChangeset
for help on using the changeset viewer.
