- Timestamp:
- Aug 20, 2009, 12:42:13 PM (17 years ago)
- Location:
- branches/czw_branch/cleanup
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
magic/remove/src/streaksremove.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/cleanup
- Property svn:mergeinfo changed
/trunk merged: 25052-25060,25063-25068,25070-25084,25087,25156
- Property svn:mergeinfo changed
-
branches/czw_branch/cleanup/magic/remove/src/streaksremove.c
r25051 r25158 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); 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(out->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 if (!psFitsMoveExtNum(in->fits, 1, true)) { 827 psErrorStackPrint(stderr, "failed to read header from %s", in->resolved_name); 828 streaksExit("", PS_EXIT_DATA_ERROR); 829 } 830 831 psMetadata *header = psFitsReadHeader(NULL, in->fits); 832 if (!header) { 833 psErrorStackPrint(stderr, "failed to read header from %s", in->resolved_name); 834 streaksExit("", PS_EXIT_DATA_ERROR); 835 } 836 psString extname = psMetadataLookupStr(NULL, header, "EXTNAME"); 837 if (!extname) { 838 psError(PS_ERR_IO, false, "failed to find extname in header of %s", in->resolved_name); 839 streaksExit("", PS_EXIT_DATA_ERROR); 840 } 841 842 psArray *inTable = psFitsReadTable(in->fits); 843 if (!inTable->n) { 844 psErrorStackPrint(stderr, "table in %s is empty", in->resolved_name); 845 streaksExit("", PS_EXIT_DATA_ERROR); 846 } 847 848 psArray *outTable = psArrayAllocEmpty(inTable->n); 849 int j = 0; 850 int numCensored = 0; 851 for (int i = 0 ; i < inTable->n; i++) { 852 psMetadata *row = inTable->data[i]; 853 854 psF32 x = psMetadataLookupF32(NULL, row, "X_PSF"); 855 psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF"); 856 857 psU32 mask = psImageGet(maskImage, x, y); 858 859 // Key the source if the center pixel is not masked with maskStreak 860 if (!(mask & maskStreak) ) { 861 psArraySet(outTable, j++, row); 862 } else { 863 numCensored++; 864 } 865 } 866 867 // get rid of unused elements (don't know if this is necessary) 868 psArrayRealloc(outTable, j); 869 870 addDestreakKeyword(header); 871 if (psArrayLength(outTable) > 0) { 872 printf("Censored %d sources\n", numCensored); 873 if (! psFitsWriteTable(out->fits, header, outTable, extname)) { 874 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 875 streaksExit("", PS_EXIT_DATA_ERROR); 876 } 877 } else { 878 printf("Censored ALL %d sources\n", numCensored); 879 if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) { 880 psErrorStackPrint(stderr, "failed to write empty table to %s", out->resolved_name); 881 streaksExit("", PS_EXIT_DATA_ERROR); 882 } 883 } 884 psFree(header); 885 psFree(outTable); 886 psFree(inTable); 887 } 888 889 // XXX Will need to update to handle extension with extended sources, etc. 890 891 if (!psFitsClose(out->fits)) { 892 psErrorStackPrint(stderr, "failed to close table %s", out->resolved_name); 804 893 streaksExit("", PS_EXIT_DATA_ERROR); 805 894 } 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); 834 } 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 } 856 857 if (!psFitsClose(out->fits)) { 858 psError(PS_ERR_IO, false, "failed to close table %s", out->resolved_name); 859 streaksExit("", PS_EXIT_DATA_ERROR); 860 } 861 } 895 }
Note:
See TracChangeset
for help on using the changeset viewer.
