- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 5 edited
-
. (modified) (1 prop)
-
magic (modified) (1 prop)
-
magic/remove (modified) (1 prop)
-
magic/remove/src (modified) (1 prop)
-
magic/remove/src/streaksio.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/magic
- Property svn:ignore
-
old new 1 1 magic 2 2 ssa-core-cpp 3 Makefile4 3 Makefile.bak
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/magic/remove
-
Property svn:ignore
set to
configure
Makefile.in
Doxyfile
config.log
depcomp
config.status
config.guess
ltmain.sh
config.sub
autom4te.cache
libtool
missing
Makefile
aclocal.m4
install-sh
-
Property svn:ignore
set to
-
branches/simtest_nebulous_branches/magic/remove/src
- Property svn:ignore
-
old new 4 4 streakscompare 5 5 streaksrelease 6 makefile 6 Makefile 7 Makefile.in 8 config.h 9 .deps 10 streaksVersionDefinitions.h 11 config.h.in 12 stamp-h1
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/magic/remove/src/streaksio.c
r24853 r27840 12 12 // Assumptions about the file structure of non-raw files 13 13 // The 'image' for each file (image, mask weight) is contained in the first 14 // extension. 14 // extension. 15 15 16 16 … … 121 121 sf->transparentStreaks = psMetadataLookupF64(&status, config->arguments, "TRANSPARENT_STREAKS"); 122 122 123 sf->stats = psMetadataAlloc(); 124 psString statsFileName= psMetadataLookupStr(&status, config->arguments, "STATS"); 125 if (statsFileName) { 126 sf->statsFile = fopen(statsFileName, "w"); 127 if (!sf->statsFile) { 128 psError(PS_ERR_IO, true, "failed to open stats file %s", statsFileName); 129 streaksExit("", PS_EXIT_CONFIG_ERROR); 130 } 131 } 132 123 133 return sf; 124 134 } … … 128 138 { 129 139 freeImages(sf); 130 psFree(sf-> warpedPixels);140 psFree(sf->diffedPixels); 131 141 psFree(sf->tiles); 132 142 psFree(sf->view); … … 288 298 sfile->resolved_name = psStringCopy(sfile->pmfile->filename); 289 299 300 sfile->nHDU = psFitsGetSize(sfile->pmfile->fits); 301 290 302 // copy header from fpu 291 303 sfile->header = (psMetadata*) psMemIncrRefCounter(sfile->pmfile->fpa->hdu->header); 292 293 sfile->nHDU = psFitsGetSize(sfile->pmfile->fits);294 304 295 305 return sfile; … … 625 635 streaksExit("", PS_EXIT_DATA_ERROR); 626 636 } 627 637 628 638 bool status; 629 639 in->extname = psMetadataLookupStr(&status, in->header, "EXTNAME"); … … 654 664 streaksExit("", PS_EXIT_DATA_ERROR); 655 665 } 656 psImage *image = (psImage *) (in->imagecube->data[0]); 666 667 // Ensure input is of the expected type 668 psDataType expected = isMask ? PS_TYPE_IMAGE_MASK : PS_TYPE_F32; // Expected type for image 669 for (int i = 0; i < in->imagecube->n; i++) { 670 psImage *image = in->imagecube->data[i]; // Image of interest 671 if (image->type.type != expected) { 672 psImage *temp = psImageCopy(NULL, image, expected); 673 psFree(image); 674 in->imagecube->data[i] = temp; 675 } 676 } 657 677 } 658 678 setDataExtent(stage, in, (stage == IPP_STAGE_RAW) && !isMask); … … 671 691 sfile->fits->options = psFitsOptionsAlloc(); 672 692 sfile->fits->options->scaling = PS_FITS_SCALE_MANUAL; 693 sfile->fits->options->fuzz = false; 673 694 sfile->fits->options->bitpix = bitpix; 674 695 sfile->fits->options->bscale = bscale; … … 789 810 return; 790 811 } 812 streaksVersionHeaderFull(sfile->header); 813 791 814 if (!psFitsWriteImage(sfile->fits, sfile->header, sfile->image, 0, extname)) { 792 815 psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d", … … 806 829 return; 807 830 } 831 streaksVersionHeaderFull(sfile->header); 808 832 if (!psFitsWriteImageCube(sfile->fits, sfile->header, imagecube, extname)) { 809 833 psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d", … … 840 864 sfile->header = NULL; 841 865 psFree(sfile->image); 842 sfile-> header= NULL;866 sfile->image = NULL; 843 867 psFree(sfile->imagecube); 844 sfile-> header= NULL;868 sfile->imagecube = NULL; 845 869 } 846 870 … … 848 872 closeImages(streakFiles *sf) 849 873 { 874 if (sf->stage == IPP_STAGE_RAW) { 875 if (sf->view) { 876 sf->view->readout = -1; 877 pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER); 878 sf->view->cell = -1; 879 pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER); 880 sf->view->chip = -1; 881 pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER); 882 } 883 } 850 884 closeImage(sf->inImage); 851 885 closeImage(sf->outImage); … … 902 936 bool free_user_copies = true; 903 937 if (user_copies == NULL) { 904 user_copies = "2";905 free_user_copies = false;938 // input does not have replication requested 939 return true; 906 940 } 907 941 if (!nebSetXattr(server, outFile->name, "user.copies", user_copies, NEB_REPLACE)) { … … 909 943 return false; 910 944 } 911 if (!nebReplicate(server, outFile->name, "any", NULL)) {945 if (!nebReplicate(server, outFile->name, NULL, NULL)) { 912 946 psError(PM_ERR_UNKNOWN, true, "nebReplicate failed for %s\n%s", outFile->name, nebErr(server)); 913 947 return false; … … 925 959 replicateOutputs(streakFiles *sfiles) 926 960 { 927 bool status = false;928 929 961 if (!replicate(sfiles->outImage, sfiles->inImage)) { 930 962 psError(PM_ERR_SYS, false, "failed to replicate outImage."); … … 973 1005 974 1006 if (!nebSwap(server, in->name, out->name)) { 975 psError(PM_ERR_SYS, true, "failed to swap files for : %s.",1007 psError(PM_ERR_SYS, true, "failed to swap files for %s: %s.", 976 1008 in->name, nebErr(server)); 977 1009 return false; … … 1097 1129 setMaskedToNAN(streakFiles *sfiles, psU32 maskMask, bool printCounts) 1098 1130 { 1099 intmaskedPixels = 0;1100 intnandPixels = 0;1101 intnandWeights = 0;1131 long maskedPixels = 0; 1132 long nandPixels = 0; 1133 long nandWeights = 0; 1102 1134 1103 1135 psImage *image = sfiles->outImage->image; 1136 int imageType = image->type.type; 1137 double exciseValue = sfiles->inImage->exciseValue; 1138 1104 1139 psImage *mask = sfiles->inMask->image; 1105 1140 psImage *weight = NULL; 1141 int weightType = 0; 1142 double weightExciseValue = NAN; 1106 1143 if (sfiles->outWeight) { 1107 1144 weight = sfiles->outWeight->image; 1108 } 1109 double exciseValue = sfiles->inImage->exciseValue; 1145 weightType = weight->type.type; 1146 weightExciseValue = sfiles->inWeight->exciseValue; 1147 } 1110 1148 1111 1149 if (printCounts) { … … 1117 1155 // these gets are not necessary, we could just set the pixels to nan 1118 1156 // but I want to get the counts 1119 double imageVal = psImageGet(image, x, y); 1120 psU32 maskVal; 1157 double imageVal = 0; // avoid compiler warning 1158 if (imageType == PS_TYPE_F32) { 1159 imageVal = image->data.F32[y][x]; 1160 } else if (imageType == PS_TYPE_S16) { 1161 imageVal = image->data.S16[y][x]; 1162 } else if (imageType == PS_TYPE_U16) { 1163 imageVal = image->data.U16[y][x]; 1164 } else { 1165 psError(PS_ERR_PROGRAMMING, true, "unexpected image type found: %d\n", 1166 imageType); 1167 streaksExit("", PS_EXIT_PROG_ERROR); 1168 } 1169 psU32 maskVal = 0; 1121 1170 if (sfiles->stage == IPP_STAGE_RAW) { 1122 int xChip, yChip;1171 unsigned int xChip, yChip; 1123 1172 cellToChipInt(&xChip, &yChip, sfiles->astrom, x, y); 1124 maskVal = psImageGet(mask, xChip, yChip);1173 maskVal = mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip]; 1125 1174 } else { 1126 maskVal = psImageGet(mask, x, y);1175 maskVal = mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x]; 1127 1176 } 1128 1177 if (maskVal & maskMask) { 1129 1178 ++maskedPixels; 1130 if (!isExciseValue(imageVal, sfiles->inImage->exciseValue)) {1179 if (!isExciseValue(imageVal, exciseValue)) { 1131 1180 ++nandPixels; 1132 psImageSet(image, x, y, exciseValue); 1181 if (imageType == PS_TYPE_F32) { 1182 image->data.F32[y][x] = exciseValue; 1183 } else if (imageType == PS_TYPE_S16) { 1184 image->data.S16[y][x] = exciseValue; 1185 } else if (imageType == PS_TYPE_U16) { 1186 image->data.U16[y][x] = exciseValue; 1187 } else { 1188 psError(PS_ERR_PROGRAMMING, true, "unexpected image type found: %d\n", 1189 imageType); 1190 streaksExit("", PS_EXIT_PROG_ERROR); 1191 } 1133 1192 } 1134 1193 if (weight) { 1135 double weightVal = weight ? psImageGet(weight, x, y) : 0; 1136 if (!isnan(weightVal)) { 1137 ++nandWeights; 1138 psImageSet(weight, x, y, NAN); 1194 if (weightType == PS_TYPE_F32) { 1195 double weightVal = weight->data.F32[y][x]; 1196 if (!isnan(weightVal)) { 1197 ++nandWeights; 1198 weight->data.F32[y][x] = NAN; 1199 } 1200 } else if(weightType == PS_TYPE_S16) { 1201 double weightVal = weight->data.S16[y][x]; 1202 if (!isExciseValue(weightVal, weightExciseValue)) { 1203 ++nandWeights; 1204 image->data.S16[y][x] = weightExciseValue; 1205 } 1206 } else if (weightType == PS_TYPE_U16) { 1207 double weightVal = weight->data.U16[y][x]; 1208 if (!isExciseValue(weightVal, weightExciseValue)) { 1209 ++nandWeights; 1210 image->data.U16[y][x] = weightExciseValue; 1211 } 1212 } else { 1213 psError(PS_ERR_PROGRAMMING, true, "unexpected image type found: %d\n", 1214 weightType); 1215 streaksExit("", PS_EXIT_PROG_ERROR); 1139 1216 } 1140 1217 } … … 1144 1221 if (printCounts) { 1145 1222 psLogMsg(sfiles->program_name, PS_LOG_INFO, "time to NAN mask pixels: %f\n", psTimerClear("NAN_MASKED")); 1146 inttotalPixels = image->numRows * image->numCols;1223 long totalPixels = image->numRows * image->numCols; 1147 1224 psLogMsg(sfiles->program_name, PS_LOG_INFO, "pixels: %10ld\n", totalPixels); 1148 1225 psLogMsg(sfiles->program_name, PS_LOG_INFO, "masked pixels: %10ld %4.2f%%\n", maskedPixels, 100. * maskedPixels / totalPixels); … … 1167 1244 psMetadataAddU16(in->header, PS_LIST_TAIL, "BLANK", 0, "", 65535); 1168 1245 psMetadataAddU16(in->header, PS_LIST_TAIL, "ZBLANK", 0, "", 65535); 1169 } else { 1246 } else if (in->image->type.type == PS_TYPE_S16) { 1247 in->exciseValue = 32767; 1248 psMetadataAddU16(in->header, PS_LIST_TAIL, "BLANK", 0, "", 32767); 1249 psMetadataAddU16(in->header, PS_LIST_TAIL, "ZBLANK", 0, "", 32767); 1250 } else if (in->image->type.type == PS_TYPE_F32) { 1170 1251 in->exciseValue = NAN; 1171 } 1172 } 1173 1174 void 1175 strkGetMaskValues(streakFiles *sfiles, psU32 *maskStreak, psU32 *maskMask) 1176 { 1252 } else { 1253 psError(PS_ERR_PROGRAMMING, true, "unexpected image type found: %d\n", in->image->type.type); 1254 streaksExit("", PS_EXIT_PROG_ERROR); 1255 } 1256 } 1257 1258 // Get the mask values that we need. 1259 // If an input mask file is provided get them from there. 1260 // Otherwise get them from the recipe MASKS 1261 void 1262 strkGetMaskValues(streakFiles *sfiles) 1263 { 1264 if (sfiles->maskStreak) { 1265 // already done 1266 return; 1267 } 1177 1268 if (sfiles->inMask && sfiles->inMask->header) { 1178 1269 if (!pmConfigMaskReadHeader(sfiles->config, sfiles->inMask->header)) { … … 1187 1278 streaksExit("", PS_EXIT_CONFIG_ERROR); 1188 1279 } 1189 *maskStreak = psMetadataLookupU32(&status, masks, "STREAK");1280 sfiles->maskStreak = psMetadataLookupU32(&status, masks, "STREAK"); 1190 1281 if (!status) { 1191 1282 psError(PM_ERR_CONFIG, false, "failed to lookup mask value for STREAK in recipes\n"); … … 1203 1294 } 1204 1295 } 1205 *maskMask = ~convPoor;1296 sfiles->maskMask = ~convPoor; 1206 1297 } 1207 1298 … … 1215 1306 if (SFILE_IS_IMAGE(in)) { 1216 1307 // Turn off compression (code adapted from pmFPAWrite) 1217 #ifdef SAVE_AND_RESTORE_COMPRESSION1218 1308 int bitpix = out->fits->options ? out->fits->options->bitpix : 0; // Desired bits per pixel 1219 1309 psFitsCompression *compress = psFitsCompressionGet(out->fits); // Current compression options 1220 #endif1221 1310 if (!psFitsSetCompression(out->fits, PS_FITS_COMPRESS_NONE, NULL, 0, 0, 0)) { 1222 1311 psError(PM_ERR_UNKNOWN, false, "failed to turn off compression for extension %d\n", extnum); 1223 1312 streaksExit("", PS_EXIT_UNKNOWN_ERROR); 1224 1313 } 1225 #ifdef SAVE_AND_RESTORE_COMPRESSION1226 1314 if (out->fits->options) { 1227 1315 out->fits->options->bitpix = 0; … … 1238 1326 streaksExit("", PS_EXIT_UNKNOWN_ERROR); 1239 1327 } 1240 #endif1241 1328 } else { 1242 1329 copyTable(out, in, extnum);
Note:
See TracChangeset
for help on using the changeset viewer.
