Changeset 28280
- Timestamp:
- Jun 9, 2010, 6:16:39 PM (16 years ago)
- Location:
- trunk/ppBackground
- Files:
-
- 10 edited
- 1 moved
-
. (modified) (1 prop)
-
configure.ac (modified) (1 diff)
-
src (modified) (1 prop)
-
src/Makefile.am (modified) (3 diffs)
-
src/ppBackground.c (modified) (3 diffs)
-
src/ppBackground.h (modified) (2 diffs)
-
src/ppBackgroundArguments.c (modified) (2 diffs)
-
src/ppBackgroundCamera.c (modified) (5 diffs)
-
src/ppBackgroundLoop.c (modified) (7 diffs)
-
src/ppBackgroundRestore.c (moved) (moved from trunk/ppBackground/src/ppBackgroundModel.c ) (1 diff)
-
src/ppBackgroundVersionDefinitions.h.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground
-
Property svn:ignore
set to
configure
Makefile.in
ignore
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
-
trunk/ppBackground/configure.ac
r28276 r28280 20 20 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.0.0]) 21 21 PKG_CHECK_MODULES([PSMODULE], [psmodules >= 1.0.0]) 22 PKG_CHECK_MODULES([PSPHOT], [psphot >= 1.0.0]) 22 PKG_CHECK_MODULES([PSPHOT], [psphot]) 23 24 AC_PATH_PROG([ERRORCODES], [psParseErrorCodes], [missing]) 25 if test "$ERRORCODES" = "missing" ; then 26 AC_MSG_ERROR([psParseErrorCodes is required]) 27 fi 23 28 24 29 dnl Set CFLAGS for build -
trunk/ppBackground/src
-
Property svn:ignore
set to
ppBackground
Makefile.in
config.h
ppBackgroundVersionDefinitions.h
.deps
Makefile
ppBackgroundErrorCodes.c
ppBackgroundErrorCodes.h
stamp-h1
config.h.in
-
Property svn:ignore
set to
-
trunk/ppBackground/src/Makefile.am
r28276 r28280 2 2 3 3 if HAVE_SVNVERSION 4 PP VIZPATTERN_VERSION=`$(SVNVERSION) ..`4 PPBACKGROUND_VERSION=`$(SVNVERSION) ..` 5 5 else 6 PP VIZPATTERN_VERSION="UNKNOWN"6 PPBACKGROUND_VERSION="UNKNOWN" 7 7 endif 8 8 9 9 if HAVE_SVN 10 PP VIZPATTERN_BRANCH=`$(SVN) info .. | $(SED) -n -e '/URL:/ h' -e '/Repository Root:/ { x; H; x; s|Repository Root: \(.*\)\nURL: \1\(.*\)|\2| ; s|^/|| ; s|/[a-zA-Z]*/src.*|| ; p }'`11 PP VIZPATTERN_SOURCE=`$(SVN) info | $(SED) -n -e 's/Repository UUID: // p'`10 PPBACKGROUND_BRANCH=`$(SVN) info .. | $(SED) -n -e '/URL:/ h' -e '/Repository Root:/ { x; H; x; s|Repository Root: \(.*\)\nURL: \1\(.*\)|\2| ; s|^/|| ; s|/[a-zA-Z]*/src.*|| ; p }'` 11 PPBACKGROUND_SOURCE=`$(SVN) info | $(SED) -n -e 's/Repository UUID: // p'` 12 12 else 13 PP VIZPATTERN_BRANCH="UNKNOWN"14 PP VIZPATTERN_SOURCE="UNKNOWN"13 PPBACKGROUND_BRANCH="UNKNOWN" 14 PPBACKGROUND_SOURCE="UNKNOWN" 15 15 endif 16 16 … … 19 19 ppBackgroundVersionDefinitions.h: ppBackgroundVersionDefinitions.h.in FORCE 20 20 -$(RM) ppBackgroundVersionDefinitions.h 21 $(SED) -e "s|@PP VIZPATTERN_VERSION@|\"$(PPVIZPATTERN_VERSION)\"|" -e "s|@PPVIZPATTERN_BRANCH@|\"$(PPVIZPATTERN_BRANCH)\"|" -e "s|@PPVIZPATTERN_SOURCE@|\"$(PPVIZPATTERN_SOURCE)\"|" ppBackgroundVersionDefinitions.h.in > ppBackgroundVersionDefinitions.h21 $(SED) -e "s|@PPBACKGROUND_VERSION@|\"$(PPBACKGROUND_VERSION)\"|" -e "s|@PPBACKGROUND_BRANCH@|\"$(PPBACKGROUND_BRANCH)\"|" -e "s|@PPBACKGROUND_SOURCE@|\"$(PPBACKGROUND_SOURCE)\"|" ppBackgroundVersionDefinitions.h.in > ppBackgroundVersionDefinitions.h 22 22 FORCE: ; 23 23 … … 35 35 ppBackgroundLoop.c \ 36 36 ppBackgroundVersion.c \ 37 ppBackgroundModel.c \ 38 ppBackgroundErrorCodes.c 37 ppBackgroundRestore.c \ 38 ppBackgroundErrorCodes.c \ 39 ppBackgroundExit.c 39 40 40 41 noinst_HEADERS = \ -
trunk/ppBackground/src/ppBackground.c
r28276 r28280 6 6 #include <pslib.h> 7 7 #include <psmodules.h> 8 #include <psphot.h> 8 9 9 10 #include "ppBackground.h" … … 12 13 { 13 14 ppBackgroundVersionPrint(); 15 16 pmErrorRegister(); 17 psphotErrorRegister(); 18 ppBackgroundErrorRegister(); 14 19 15 20 ppBackgroundData *data = ppBackgroundDataInit(&argc, argv); … … 46 51 } 47 52 data->statsFile = NULL; 48 pmConfigRunFilenameAddWrite(data->config, "STATS", data->statsName);49 53 exitValue = ppBackgroundExitCode(exitValue); 50 54 } -
trunk/ppBackground/src/ppBackground.h
r28276 r28280 5 5 #include <psmodules.h> 6 6 7 #include <ppBackgroundErrorCodes.h>7 #include "ppBackgroundErrorCodes.h" 8 8 9 9 #define PPBACKGROUND_RECIPE "PPBACKGROUND" // Recipe name … … 37 37 ); 38 38 39 /// Restore the background to an image 40 bool ppBackgroundRestore( 41 pmChip *chip, // Input chip 42 const pmChip *background, // Chip with background model 43 const pmChip *pattern, // Chip with pattern 44 const pmFPAview *view, // View to data 45 pmConfig *config // Configuration 46 ); 47 39 48 /// Determine exit code 40 49 psExit ppBackgroundExitCode( -
trunk/ppBackground/src/ppBackgroundArguments.c
r28276 r28280 48 48 psMetadataAddStr(arguments, PS_LIST_TAIL, "-pattern", 0, "Filename of pattern correction", NULL); 49 49 psMetadataAddStr(arguments, PS_LIST_TAIL, "-background", 0, "Filename of background model", NULL); 50 psMetadataAddStr(arguments, PS_LIST_TAIL, "-image", 0, "Filename of image ", NULL);50 psMetadataAddStr(arguments, PS_LIST_TAIL, "-image", 0, "Filename of image (required)", NULL); 51 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", 0, "Filename of mask", NULL); 52 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stats", 0, "Output statistics file", NULL); 52 53 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 2) { 53 54 usage(argv[0], arguments, data); … … 68 69 return false; 69 70 } 71 if (!data->imageName) { 72 psError(PPBACKGROUND_ERR_CONFIG, true, "Must specify -image"); 73 return false; 74 } 70 75 71 76 PS_ASSERT_STRING_NON_EMPTY(data->outRoot, false); 77 78 const char *statsName = psMetadataLookupStr(NULL, arguments, "-stats"); 79 if (statsName) { 80 data->statsFile = fopen(statsName, "w"); 81 if (!data->statsFile) { 82 psError(PPBACKGROUND_ERR_IO, true, "Unable to open statistics file %s", statsName); 83 return false; 84 } 85 data->stats = psMetadataAlloc(); 86 pmConfigRunFilenameAddWrite(data->config, "STATS", statsName); 87 } 72 88 73 89 return true; -
trunk/ppBackground/src/ppBackgroundCamera.c
r28276 r28280 33 33 34 34 fileArguments("PATTERN", data->patternName, "Input pattern", data->config); 35 pmFPAfile *pattern = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.PATTERN", 36 "PATTERN"); // File 35 pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.PATTERN", "PATTERN"); // File 37 36 if (!status) { 38 37 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.PATTERN"); … … 41 40 42 41 fileArguments("BACKGROUND", data->backgroundName, "Input background model", data->config); 43 pmFPAfile *background = pmFPAfileBindFromArgs(&status, data->config, "PPBACKGROUND.BACKGROUND", 44 "BACKGROUND"); // File 42 pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.BACKGROUND", "BACKGROUND"); // File 45 43 if (!status) { 46 44 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.BACKGROUND"); … … 49 47 50 48 fileArguments("IMAGE", data->backgroundName, "Input uncorrected image", data->config); 51 pmFPAfile *image = pmFPAfile BindFromArgs(&status, background, data->config, "PPBACKGROUND.IMAGE",52 "IMAGE"); // File53 if (!status ) {49 pmFPAfile *image = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.IMAGE", 50 "IMAGE"); // File 51 if (!status || !image) { 54 52 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.IMAGE"); 55 53 return false; … … 57 55 58 56 fileArguments("MASK", data->backgroundName, "Input uncorrected mask", data->config); 59 pmFPAfile *mask = pmFPAfileBindFromArgs(&status, image, data->config, "PPBACKGROUND.MASK", 60 "MASK"); // File 57 pmFPAfileBindFromArgs(&status, image, data->config, "PPBACKGROUND.MASK", "MASK"); // File 61 58 if (!status) { 62 59 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.MASK"); … … 64 61 } 65 62 66 pmFPAfile *output = pmFPAfileDefineOutput(data->config, file->fpa, "PPBACKGROUND.OUTPUT");63 pmFPAfile *output = pmFPAfileDefineOutput(data->config, image->fpa, "PPBACKGROUND.OUTPUT"); 67 64 if (!output) { 68 65 psError(psErrorCodeLast(), false, "Unable to define output."); -
trunk/ppBackground/src/ppBackgroundLoop.c
r28276 r28280 13 13 { 14 14 pmConfig *config = data->config; // Configuration data 15 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPBACKGROUND. BACKGROUND", 0);15 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPBACKGROUND.IMAGE", 0); 16 16 pmFPAfile *patternFile = pmFPAfileSelectSingle(config->files, "PPBACKGROUND.PATTERN", 0); // File with data 17 pmFPAfile *bgFile = pmFPAfileSelectSingle(config->files, "PPBACKGROUND.BACKGROUND", 0); // File with bg 17 18 pmFPA *patternMosaic = pmFPAConstruct(file->camera, file->cameraName); // Mosaicked FPA for pattern 18 19 … … 34 35 } 35 36 36 if (chip->cell ->n > 1) {37 if (chip->cells->n > 1) { 37 38 psError(PPBACKGROUND_ERR_CONFIG, true, 38 39 "Input image and background model should be chip-mosaicked"); … … 44 45 pmFPAfileActivate(config->files, true, "PPBACKGROUND.PATTERN"); 45 46 46 pmCell * cell; // Cell with pattern data47 pmCell *patternCell; // Cell with pattern data 47 48 while ((patternCell = pmFPAviewNextCell(view, patternFile->fpa, 1))) { 48 if (! cell->process || !cell->file_exists) {49 if (!patternCell->process || !patternCell->file_exists) { 49 50 continue; 50 51 } … … 68 69 // Get size of image from concepts 69 70 if (numCols == 0 || numRows == 0) { 70 numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE");71 numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE");71 numCols = psMetadataLookupS32(NULL, patternCell->concepts, "CELL.XSIZE"); 72 numRows = psMetadataLookupS32(NULL, patternCell->concepts, "CELL.YSIZE"); 72 73 } 73 74 // Get size of image from TRIMSEC 74 75 if (numCols == 0 || numRows == 0) { 75 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");76 psRegion *trimsec = psMetadataLookupPtr(NULL, patternCell->concepts, "CELL.TRIMSEC"); 76 77 numCols = trimsec->x1 - trimsec->x0; 77 78 numRows = trimsec->y1 - trimsec->y0; … … 91 92 92 93 // Remove bias sections to avoid warnings 93 psMetadataItem *biassec = psMetadataLookup(pattern RO->parent->concepts, "CELL.BIASSEC");94 psMetadataItem *biassec = psMetadataLookup(patternCell->concepts, "CELL.BIASSEC"); 94 95 if (psListLength(biassec->data.V)) { 95 96 psFree(biassec->data.V); … … 123 124 } 124 125 126 pmChip *patternChip = patternFile ? pmFPAviewThisChip(view, patternMosaic) : NULL; // Chip with pattern 127 pmChip *bgChip = bgFile ? pmFPAviewThisChip(view, bgFile->fpa) : NULL; // Chip with background model 128 if (!ppBackgroundRestore(chip, bgChip, patternChip, view, config)) { 129 psError(psErrorCodeLast(), false, "Unable to replace background"); 130 return false; 131 } 132 pmChipFreeData(patternChip); 125 133 126 127 128 129 130 131 pmHDU *hdu = pmHDUGetLowest(file->fpa, chip, cell); // HDU for readout 132 if (!hdu) { 133 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU for data."); 134 return false; 135 } 136 if (!hdu->header) { 137 hdu->header = psMetadataAlloc(); 138 } 139 ppBackgroundVersionHeader(hdu->header); 140 141 142 143 144 145 146 134 pmHDU *hdu = pmHDUGetLowest(file->fpa, chip, NULL); // HDU for chip 135 if (!hdu) { 136 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU for data."); 137 return false; 138 } 139 if (!hdu->header) { 140 hdu->header = psMetadataAlloc(); 141 } 142 ppBackgroundVersionHeader(hdu->header); 147 143 148 144 // Chip … … 158 154 } 159 155 156 psFree(view); 157 psFree(patternMosaic); 158 160 159 return true; 161 160 } -
trunk/ppBackground/src/ppBackgroundRestore.c
r28279 r28280 4 4 #include <psphot.h> 5 5 6 #include "ppBackground.h" 6 7 7 bool ppBackgroundModel( 8 pmReadout *ro = cell->readouts->data[0]; // Readout of interest 9 if (!ro || !ro->data_exists) { 10 psError(PS_ERR_UNKNOWN, true, "readout has no data"); 8 bool ppBackgroundRestore(pmChip *chip, const pmChip *background, const pmChip *pattern, 9 const pmFPAview *oldView, pmConfig *config) 10 { 11 PS_ASSERT_PTR_NON_NULL(chip, false); 12 PS_ASSERT_PTR_NON_NULL(oldView, false); 13 14 pmFPAview *view = pmFPAviewAlloc(0); // View to readout 15 *view = *oldView; 16 view->cell = 0; 17 view->readout = 0; 18 19 pmReadout *ro = pmFPAviewThisReadout(view, chip->parent); 20 if (!ro || !ro->data_exists) { 21 psError(PPBACKGROUND_ERR_CONFIG, true, "Readout has no data"); 22 return false; 23 } 24 psImage *image = ro->image; // Image to correct 25 int numCols = image->numCols, numRows = image->numRows; // Size of image 26 27 if (background) { 28 pmReadout *bgRO = pmFPAviewThisReadout(view, background->parent); // Readout with background 29 psImageBinning *binning = psphotBackgroundBinning(bgRO->image, config); 30 if (!binning) { 31 psError(psErrorCodeLast(), false, "Unable to find background binning"); 11 32 return false; 12 33 } 13 psImage *image = ro->image; 14 // psImage *mask = NULL; 15 // psImageMaskType maskVal = 0; 16 17 pmFPAview roView = *view; 18 roView.cell = 0; 19 roView.readout = 0; 20 pmReadout *modelRO = pmFPAviewThisReadout(&roView, backmdl->fpa); 21 if (!modelRO || !modelRO->data_exists) { 22 psError(PS_ERR_UNKNOWN, true, "model readout has no data"); 34 if (binning->nXfine != numCols || binning->nYfine != numRows) { 35 psError(PPBACKGROUND_ERR_CONFIG, true, 36 "Unbinned background model and input don't match (%dx%d vs %dx%d)", 37 binning->nXfine, binning->nYfine, numCols, numRows); 23 38 return false; 24 39 } 25 output->save = true;26 background->save = save_background;27 40 28 psImageBinning *binning = psphotBackgroundBinning(image, config); 29 if (!binning) { 30 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find background binning"); 31 return false; 32 } 33 pmReadout *backgroundRO; 34 #define USE_CELL 35 #ifdef USE_CELL 36 pmCell *backgroundCell = pmFPAviewThisCell(&roView, background->fpa); 37 backgroundRO = pmReadoutAlloc(backgroundCell); 38 #else 39 backgroundRO = pmFPAviewThisReadout(&roView, background->fpa); 40 // backgroundRO = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32); 41 #endif 42 backgroundRO->image = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 43 backgroundRO->data_exists = true; 44 backgroundRO->parent->data_exists = true; 45 backgroundRO->parent->parent->data_exists = true; 46 47 // linear interpolation to full-scale 48 if (!psImageUnbin (backgroundRO->image, modelRO->image, binning)) { 49 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for unbinning"); 41 psImage *bgImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Background 42 if (!psImageUnbin(bgImage, bgRO->image, binning)) { 43 psError(psErrorCodeLast(), false, "Unable to unbin background model"); 50 44 psFree(binning); 51 45 return false; 52 46 } 53 47 psFree(binning); 54 psF32 **backData = backgroundRO->image->data.F32;55 48 56 // Undo the background subtraction57 int numCols = image->numCols, numRows = image->numRows; // Size of image58 long nancount = 0;59 long naninputs = 0;60 long finitecount = 0;61 49 for (int y = 0; y < numRows; y++) { 62 50 for (int x = 0; x < numCols; x++) { 63 float imageval = image->data.F32[y][x] ; 64 float bgvalue = backData[y][x]; 65 if (!isfinite(bgvalue)) { 66 // if background is NAN leave the image unchanged 67 // According to ppImageSubtractBackground pixels where the background is not finite should be NAN 68 // experimentally 69 // for breakpoint 70 nancount++; 71 if (isfinite(imageval)) { 72 finitecount++; 73 // psWarning("unexpected finite image value %f found at %d %d background is infinite", imageval, x, y); 74 } 75 // Doing this is causes a lot of new NAN pixels to appear. 76 // NANS are appearing in the model for some reason. 77 // image->data.F32[y][x] = NAN; 78 } else if (isfinite(imageval)) { 79 // XXX: TODO:following ppImage we should not modify pixels that are masked. 80 image->data.F32[y][x] = imageval + bgvalue; 81 } else { 82 naninputs++; 83 } 51 image->data.F32[y][x] += bgImage->data.F32[y][x]; 84 52 } 85 53 } 86 if (naninputs) { 87 printf("%ld infinite pixels found in input image\n", naninputs); 54 psFree(bgImage); 55 } 56 57 if (pattern) { 58 pmReadout *patternRO = pmFPAviewThisReadout(view, pattern->parent); // Readout with pattern 59 psImage *patternImage = patternRO->image; // Image with pattern 60 for (int y = 0; y < numRows; y++) { 61 for (int x = 0; x < numCols; x++) { 62 image->data.F32[y][x] += patternImage->data.F32[y][x]; 63 } 88 64 } 89 if (nancount) { 90 psWarning("%ld infinite pixels found in background %ld pixels were finite\n", nancount, finitecount); 91 } 92 // pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND"); 65 } 66 67 return true; 68 } 69 70 71 -
trunk/ppBackground/src/ppBackgroundVersionDefinitions.h.in
r28276 r28280 1 #ifndef PP VIZPATTERN_VERSION_DEFINITIONS_H2 #define PP VIZPATTERN_VERSION_DEFINITIONS_H1 #ifndef PPBACKGROUND_VERSION_DEFINITIONS_H 2 #define PPBACKGROUND_VERSION_DEFINITIONS_H 3 3 4 #define PP VIZPATTERN_VERSION @PPVIZPATTERN_VERSION@ // SVN version5 #define PP VIZPATTERN_BRANCH @PPVIZPATTERN_BRANCH@ // SVN branch6 #define PP VIZPATTERN_SOURCE @PPVIZPATTERN_SOURCE@ // SVN source4 #define PPBACKGROUND_VERSION @PPBACKGROUND_VERSION@ // SVN version 5 #define PPBACKGROUND_BRANCH @PPBACKGROUND_BRANCH@ // SVN branch 6 #define PPBACKGROUND_SOURCE @PPBACKGROUND_SOURCE@ // SVN source 7 7 8 8 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
