- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
magic/remove/src/streaksremove.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/magic/remove/src/streaksremove.c
r31716 r33415 278 278 279 279 if (statsFileName) { 280 // Write out281 280 psString resolved = pmConfigConvertFilename(statsFileName, config, true, true); // Resolved filename 282 281 if (!resolved) { … … 292 291 } 293 292 294 // all done. Clean up tolook for memory leaks.293 // all done. Clean up and look for memory leaks. 295 294 296 295 psFree(sfiles); … … 302 301 psLibFinalize(); 303 302 304 fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "streaksremove"); 303 int leaks = psMemCheckLeaks (0, NULL, stdout, false); 304 305 fprintf(stderr, "Found %d leaks at %s\n", leaks, "streaksremove"); 305 306 306 307 return 0; … … 917 918 sFile *out = sfiles->outSources; 918 919 919 920 920 // Primary header, should be "something.hdr" 921 921 { … … 960 960 } 961 961 962 psArray *inTable = psFitsReadTable(in->fits); 963 if (!inTable) { 962 #ifdef CHECK_MEM_USE 963 bool printStats = false; 964 size_t allocated = 0; 965 size_t persistent = 0; 966 size_t allocatedBefore = psMemStats(printStats, &allocated, &persistent); 967 printf("Before: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedBefore); 968 #endif 969 970 psFitsTable *table = psFitsReadTableNew(in->fits); 971 972 #ifdef CHECK_MEM_USE 973 size_t allocatedAfter = psMemStats(printStats, &allocated, &persistent); 974 printf("After: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedAfter); 975 printf("Change: %12lld\n", (long long) allocatedAfter - allocatedBefore); 976 #endif 977 978 if (!table) { 964 979 psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name); 965 980 streaksExit("", PS_EXIT_DATA_ERROR); 966 981 } 967 982 968 psArray *outTable = psArrayAllocEmpty(inTable->n);969 int j = 0;970 983 int numCensored = 0; 971 for (int i = 0 ; i < inTable->n; i++) { 972 psMetadata *row = inTable->data[i]; 973 974 psF32 x = psMetadataLookupF32(NULL, row, "X_PSF"); 975 psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF"); 976 977 psImageMaskType mask; 978 if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x < 0) || (y < 0) || isnan(x) || isnan(y)) { 979 mask = maskStreak; 980 } else { 981 mask = maskImage->data.PS_TYPE_IMAGE_MASK_DATA[(int)y][(int)x]; 982 } 983 984 // Key the source if the center pixel is not masked with maskStreak 985 if (!(mask & maskStreak) ) { 986 psArraySet(outTable, j++, row); 987 } else { 988 numCensored++; 989 } 990 } 991 992 // get rid of unused elements (don't know if this is necessary) 993 psArrayRealloc(outTable, j); 994 995 addDestreakKeyword(header, true); 996 if (psArrayLength(outTable) > 0) { 984 bool *rowCensored = NULL; 985 if (table->numRows > 0) { 986 // For speed we get intimate with the table 987 // avoid 2 * numRows lookups of the column number by looking 988 // it up ahead of time and verifying that the type is what we 989 // expect. 990 int xCol = psFitsTableGetColumnNumber(table, "X_PSF"); 991 assert(xCol >= 0 && xCol < table->numCols); 992 assert(table->columns[xCol].type == PS_DATA_F32); 993 994 int yCol = psFitsTableGetColumnNumber(table, "Y_PSF"); 995 assert(yCol >= 0 && yCol < table->numCols); 996 assert(table->columns[yCol].type == PS_DATA_F32); 997 998 // We mark censored rows in this array. 999 rowCensored = psAlloc(table->numRows * sizeof(bool)); 1000 memset(rowCensored, 0, table->numRows * sizeof(bool)); 1001 1002 for (int i = 0 ; i < table->numRows; i++) { 1003 1004 #ifndef GO_SLOWER 1005 psF32 x = table->columns[xCol].data.F32[i]; 1006 psF32 y = table->columns[yCol].data.F32[i]; 1007 #else 1008 psF32 x = psFitsTableGetF32(NULL, table, i, "X_PSF"); 1009 psF32 y = psFitsTableGetF32(NULL, table, i, "Y_PSF"); 1010 #endif 1011 psImageMaskType mask; 1012 if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x < 0) || (y < 0) || isnan(x) || isnan(y)) { 1013 mask = maskStreak; 1014 } else { 1015 mask = maskImage->data.PS_TYPE_IMAGE_MASK_DATA[(int)y][(int)x]; 1016 } 1017 1018 // Key the source if the center pixel is not masked with maskStreak 1019 if (mask & maskStreak) { 1020 rowCensored[i] = true; 1021 numCensored++; 1022 } 1023 } 1024 1025 // remove the censored rows from the table 1026 if (!psFitsTableCensor(table, rowCensored)) { 1027 streaksExit("", PS_EXIT_PROG_ERROR); 1028 } 1029 1030 addDestreakKeyword(header, true); 1031 } 1032 1033 if (table->numCols > 0) { 997 1034 printf("Censored %d sources\n", numCensored); 998 if (! psFitsWriteTable (out->fits, header, outTable, extname)) {1035 if (! psFitsWriteTableNew(out->fits, header, table, extname)) { 999 1036 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 1000 1037 streaksExit("", PS_EXIT_DATA_ERROR); 1001 1038 } 1002 } else if (psArrayLength(inTable) == 0){1039 } else { 1003 1040 printf("No input sources\n"); 1004 1041 // We'd like to write a blank table, but this is as good as it gets without more work to parse the … … 1008 1045 streaksExit("", PS_EXIT_DATA_ERROR); 1009 1046 } 1010 } else {1011 printf("Censored ALL %d sources\n", numCensored);1012 if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) {1013 psErrorStackPrint(stderr, "failed to write empty table to %s", out->resolved_name);1014 streaksExit("", PS_EXIT_DATA_ERROR);1015 }1016 1047 } 1017 1048 psFree(header); 1018 psFree( outTable);1019 psFree( inTable);1049 psFree(table); 1050 psFree(rowCensored); 1020 1051 } 1021 1052 … … 1038 1069 } 1039 1070 1040 ps Array *inTable = psFitsReadTable(in->fits);1041 if (! inTable) {1071 psFitsTable *table = psFitsReadTableNew(in->fits); 1072 if (!table) { 1042 1073 psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name); 1043 1074 streaksExit("", PS_EXIT_DATA_ERROR); 1044 1075 } 1045 if (! psFitsWriteTable (out->fits, header, inTable, extname)) {1076 if (! psFitsWriteTableNew(out->fits, header, table, extname)) { 1046 1077 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 1047 1078 streaksExit("", PS_EXIT_DATA_ERROR); 1048 1079 } 1049 } 1050 1080 psFree(header); 1081 psFree(table); 1082 } 1051 1083 1052 1084 if (!psFitsClose(out->fits)) { … … 1054 1086 streaksExit("", PS_EXIT_DATA_ERROR); 1055 1087 } 1056 } 1088 out->fits = NULL; // freed by psFitsclose() 1089 }
Note:
See TracChangeset
for help on using the changeset viewer.
