Changeset 6872
- Timestamp:
- Apr 17, 2006, 8:01:05 AM (20 years ago)
- Location:
- trunk/psModules
- Files:
-
- 100 added
- 33 edited
-
configure.ac (modified) (8 diffs)
-
src/Makefile.am (modified) (1 diff)
-
src/astrom/Makefile.am (modified) (1 diff)
-
src/astrom/pmAstrometry.c (modified) (22 diffs)
-
src/astrom/pmAstrometry.h (modified) (14 diffs)
-
src/astrom/pmAstrometryObjects.c (modified) (3 diffs)
-
src/astrom/pmAstrometryObjects.h (modified) (27 diffs)
-
src/astrom/pmChipMosaic.c (added)
-
src/astrom/pmChipMosaic.h (added)
-
src/astrom/pmConcepts.c (added)
-
src/astrom/pmConcepts.h (added)
-
src/astrom/pmConceptsRead.c (added)
-
src/astrom/pmConceptsRead.h (added)
-
src/astrom/pmConceptsStandard.c (added)
-
src/astrom/pmConceptsStandard.h (added)
-
src/astrom/pmConceptsWrite.c (added)
-
src/astrom/pmConceptsWrite.h (added)
-
src/astrom/pmFPA.c (added)
-
src/astrom/pmFPA.h (added)
-
src/astrom/pmFPAAstrometry.c (added)
-
src/astrom/pmFPAAstrometry.h (added)
-
src/astrom/pmFPAConceptsGet.c (added)
-
src/astrom/pmFPAConceptsGet.h (added)
-
src/astrom/pmFPAConceptsSet.c (added)
-
src/astrom/pmFPAConceptsSet.h (added)
-
src/astrom/pmFPAConstruct.c (added)
-
src/astrom/pmFPAConstruct.h (added)
-
src/astrom/pmFPACopy.c (added)
-
src/astrom/pmFPACopy.h (added)
-
src/astrom/pmFPAMaskWeight.c (added)
-
src/astrom/pmFPAMaskWeight.h (added)
-
src/astrom/pmFPARead.c (added)
-
src/astrom/pmFPARead.h (added)
-
src/astrom/pmFPAUtils.c (added)
-
src/astrom/pmFPAUtils.h (added)
-
src/astrom/pmFPAWrite.c (added)
-
src/astrom/pmFPAWrite.h (added)
-
src/astrom/pmFPA_JPEG.c (added)
-
src/astrom/pmFPA_JPEG.h (added)
-
src/astrom/pmFPAfile.c (added)
-
src/astrom/pmFPAfile.h (added)
-
src/astrom/pmFPAview.c (added)
-
src/astrom/pmFPAview.h (added)
-
src/astrom/pmHDU.c (added)
-
src/astrom/pmHDU.h (added)
-
src/astrom/pmHDUUtils.c (added)
-
src/astrom/pmHDUUtils.h (added)
-
src/astrom/pmReadout.c (added)
-
src/astrom/pmReadout.h (added)
-
src/camera/Makefile.am (modified) (1 diff)
-
src/config/pmConfig.h (modified) (4 diffs)
-
src/detrend/Makefile.am (modified) (1 diff)
-
src/detrend/pmFlatField.c (modified) (10 diffs)
-
src/detrend/pmFlatField.h (modified) (3 diffs)
-
src/detrend/pmFringeStats.c (added)
-
src/detrend/pmFringeStats.h (added)
-
src/detrend/pmMaskBadPixels.c (modified) (5 diffs)
-
src/detrend/pmMaskBadPixels.h (modified) (5 diffs)
-
src/detrend/pmMaskBadPixelsErrors.h (modified) (3 diffs)
-
src/detrend/pmNonLinear.c (modified) (5 diffs)
-
src/detrend/pmNonLinear.h (modified) (3 diffs)
-
src/imcombine/Makefile.am (modified) (1 diff)
-
src/imcombine/pmReadoutCombine.h (modified) (4 diffs)
-
src/imsubtract/Makefile.am (modified) (1 diff)
-
src/imsubtract/pmSubtractBias.h (modified) (4 diffs)
-
src/imsubtract/pmSubtractSky.h (modified) (2 diffs)
-
src/objects/Makefile.am (modified) (2 diffs)
-
src/objects/models/pmModel_PGAUSS.c (modified) (4 diffs)
-
src/objects/models/pmModel_QGAUSS.c (modified) (7 diffs)
-
src/objects/models/pmModel_RGAUSS.c (modified) (2 diffs)
-
src/objects/models/pmModel_SGAUSS.c (modified) (10 diffs)
-
src/objects/models/pmModel_ZGAUSS.c (modified) (4 diffs)
-
src/objects/pmGrowthCurve.c (added)
-
src/objects/pmGrowthCurve.h (added)
-
src/objects/pmModel.c (added)
-
src/objects/pmModel.h (added)
-
src/objects/pmModelGroup.c (modified) (4 diffs)
-
src/objects/pmModelGroup.h (modified) (5 diffs)
-
src/objects/pmMoments.c (added)
-
src/objects/pmMoments.h (added)
-
src/objects/pmObjects.h (modified) (4 diffs)
-
src/objects/pmPSF.h (modified) (5 diffs)
-
src/objects/pmPSF_IO.c (added)
-
src/objects/pmPSF_IO.h (added)
-
src/objects/pmPSFtry.h (modified) (6 diffs)
-
src/objects/pmPeaks.c (added)
-
src/objects/pmPeaks.h (added)
-
src/objects/pmSource.c (added)
-
src/objects/pmSource.h (added)
-
src/objects/pmSourceContour.c (added)
-
src/objects/pmSourceContour.h (added)
-
src/objects/pmSourceFitModel.c (added)
-
src/objects/pmSourceFitModel.h (added)
-
src/objects/pmSourceFitSet.c (added)
-
src/objects/pmSourceFitSet.h (added)
-
src/objects/pmSourceIO.c (added)
-
src/objects/pmSourceIO.h (added)
-
src/objects/pmSourceIO_CMF.c (added)
-
src/objects/pmSourceIO_CMP.c (added)
-
src/objects/pmSourceIO_OBJ.c (added)
-
src/objects/pmSourceIO_RAW.c (added)
-
src/objects/pmSourceIO_SX.c (added)
-
src/objects/pmSourcePhotometry.c (added)
-
src/objects/pmSourcePhotometry.h (added)
-
src/objects/pmSourceSky.c (added)
-
src/objects/pmSourceSky.h (added)
-
src/pslib (added)
-
src/pslib/.cvsignore (added)
-
src/pslib/Makefile.am (added)
-
src/pslib/psAdditionals.c (added)
-
src/pslib/psAdditionals.h (added)
-
src/pslib/psEllipse.c (added)
-
src/pslib/psEllipse.h (added)
-
src/pslib/psImageFlip.c (added)
-
src/pslib/psImageFlip.h (added)
-
src/pslib/psImageJpeg.c (added)
-
src/pslib/psImageJpeg.h (added)
-
src/pslib/psImageUnbin.c (added)
-
src/pslib/psImageUnbin.h (added)
-
src/pslib/psLine.c (added)
-
src/pslib/psLine.h (added)
-
src/pslib/psMetadataItemParse.c (added)
-
src/pslib/psMetadataItemParse.h (added)
-
src/pslib/psPolynomialUtils.c (added)
-
src/pslib/psPolynomialUtils.h (added)
-
src/pslib/psRegionIsBad.c (added)
-
src/pslib/psRegionIsBad.h (added)
-
src/pslib/psSparse.c (added)
-
src/pslib/psSparse.h (added)
-
src/psmodules.h (added)
-
test/pslib (added)
-
test/pslib/.cvsignore (added)
-
test/pslib/Makefile.am (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/configure.ac
r6298 r6872 8 8 AM_MAINTAINER_MODE 9 9 10 dnl handle debug building 11 AC_ARG_ENABLE(optimize, 12 [AS_HELP_STRING(--enable-optimize,enable compiler optimization)], 13 [AC_MSG_RESULT(compile optimization enabled) 14 CFLAGS="${CFLAGS=} -O2"], 15 [AC_MSG_RESULT([compile optimization disabled]) 16 CFLAGS="${CFLAGS=} -O0 -g"] 17 ) 18 19 dnl handle profiler building 20 AC_ARG_ENABLE(profile, 21 [AS_HELP_STRING(--enable-profile,enable compiler profiler information inclusion)], 22 [AC_MSG_RESULT(compile optimization enabled) 23 CFLAGS="${CFLAGS=} -fprofile-arcs -ftest-coverage -pg"] 24 ) 25 10 dnl otherise AC_PROG_CC will default CFLAGS to "-g -02" 11 if test -z ${CFLAGS} ; then 12 CFLAGS="" 13 fi 26 14 AC_SUBST([CFLAGS]) 27 15 … … 29 17 AC_PROG_CC 30 18 dnl FIXME document why GNU_SOURCE is being set 31 dnlAC_GNU_SOURCE19 AC_GNU_SOURCE 32 20 AC_PROG_INSTALL 33 21 AM_PROG_LIBTOOL 34 AC_SYS_LARGEFILE35 22 36 23 AC_PREFIX_DEFAULT([`pwd`]) … … 62 49 63 50 SRCPATH='${top_srcdir}/src' 64 SRCDIRS="astrom c amera config detrend imcombine imsubtract objects photom"51 SRCDIRS="astrom config detrend imcombine imsubtract objects pslib" 65 52 # escape two escapes at this level so \\ gets passed to the shell and \ to perl 66 53 SRCINC=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|-I\\\\${SRCPATH=}/\1|g"` 67 54 SRCINC="-I${SRCPATH=} ${SRCINC=}" 68 55 SRCSUBLIBS=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|\1/libpsmodule\1.la|g"` 69 AC_SUBST( [SRCSUBLIBS],${SRCSUBLIBS=})70 AC_SUBST( [SRCINC],${SRCINC=})56 AC_SUBST(SRCSUBLIBS,${SRCSUBLIBS=}) 57 AC_SUBST(SRCINC,${SRCINC=}) 71 58 AC_SUBST([SRCDIRS],${SRCDIRS=}) 59 60 dnl handle debug building 61 AC_ARG_ENABLE(optimize, 62 [AS_HELP_STRING(--enable-optimize,enable compiler optimization)], 63 [AC_MSG_RESULT(compile optimization enabled) 64 CFLAGS="${CFLAGS=} -O2"], 65 [AC_MSG_RESULT([compile optimization disabled]) 66 CFLAGS="${CFLAGS=} -O0 -g"] 67 ) 68 69 dnl handle profiler building 70 AC_ARG_ENABLE(profile, 71 [AS_HELP_STRING(--enable-profile,enable compiler profiler information inclusion)], 72 [AC_MSG_RESULT(compile optimization enabled) 73 CFLAGS="${CFLAGS=} -pg"] 74 ) 75 76 dnl CFLAGS="${CFLAGS=} -fprofile-arcs -ftest-coverage -pg"] 72 77 73 78 dnl doxygen ------------------------------------------------------------------- … … 75 80 AC_CHECK_PROG([doxygen], [doxygen], [true], [false]) 76 81 AM_CONDITIONAL(DOXYGEN, test x$doxygen = xtrue) 82 83 dnl libjpeg ------------------------------------------------------------------- 84 85 AC_CHECK_LIB(jpeg,jpeg_CreateCompress,[],[AC_MSG_ERROR([jpeg library not found.])]) 77 86 78 87 dnl pslib --------------------------------------------------------------------- … … 82 91 83 92 if test -z ${PSLIB_CONFIG} ; then 84 PKG_CHECK_MODULES([PSLIB], [pslib >= 0. 10.0])93 PKG_CHECK_MODULES([PSLIB], [pslib >= 0.9.0]) 85 94 else 86 95 AC_CHECK_FILE($PSLIB_CONFIG,[], … … 105 114 src/Makefile 106 115 src/astrom/Makefile 107 src/camera/Makefile108 116 src/config/Makefile 109 117 src/detrend/Makefile … … 111 119 src/imsubtract/Makefile 112 120 src/objects/Makefile 113 src/p hotom/Makefile121 src/pslib/Makefile 114 122 test/Makefile 115 123 test/astrom/Makefile 116 test/camera/Makefile117 124 test/config/Makefile 118 125 test/detrend/Makefile … … 120 127 test/imsubtract/Makefile 121 128 test/objects/Makefile 122 test/p hotom/Makefile129 test/pslib/Makefile 123 130 Doxyfile 124 131 psmodule-config -
trunk/psModules/src/Makefile.am
r5685 r6872 7 7 libpsmodule_la_DEPENDENCIES = $(SRCSUBLIBS) 8 8 9 include_HEADERS = \ 10 psmodules.h 11 9 12 EXTRA_DIST = psErrorCodes.dat -
trunk/psModules/src/astrom/Makefile.am
r6301 r6872 1 1 noinst_LTLIBRARIES = libpsmoduleastrom.la 2 2 3 libpsmoduleastrom_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 3 libpsmoduleastrom_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) -I../pslib/ 4 4 libpsmoduleastrom_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 5 libpsmoduleastrom_la_SOURCES = \ 6 pmAstrometry.c \ 7 pmAstrometryObjects.c 6 pmFPA.c \ 7 pmFPAConstruct.c \ 8 pmFPACopy.c \ 9 pmFPAMaskWeight.c \ 10 pmFPARead.c \ 11 pmFPAUtils.c \ 12 pmFPAWrite.c \ 13 pmHDU.c \ 14 pmHDUUtils.c \ 15 pmReadout.c \ 16 pmConcepts.c \ 17 pmConceptsRead.c \ 18 pmConceptsWrite.c \ 19 pmConceptsStandard.c \ 20 pmFPA_JPEG.c \ 21 pmFPAview.c \ 22 pmFPAfile.c 23 24 # pmFPAAstrometry.c 25 # pmAstrometryObjects.c 26 # pmChipMosaic.c 8 27 9 28 psmoduleincludedir = $(includedir) 10 29 psmoduleinclude_HEADERS = \ 11 pmAstrometry.h \ 12 pmAstrometryObjects.h 30 pmFPA.h \ 31 pmFPAConstruct.h \ 32 pmFPACopy.h \ 33 pmFPAMaskWeight.h \ 34 pmFPARead.h \ 35 pmFPAUtils.h \ 36 pmFPAWrite.h \ 37 pmHDU.h \ 38 pmHDUUtils.h \ 39 pmReadout.h \ 40 pmConcepts.h \ 41 pmConceptsRead.h \ 42 pmConceptsWrite.h \ 43 pmConceptsStandard.h \ 44 pmFPA_JPEG.h \ 45 pmFPAview.h \ 46 pmFPAfile.h 47 48 # pmFPAAstrometry.h 49 # pmAstrometryObjects.h 50 # pmChipMosaic.h -
trunk/psModules/src/astrom/pmAstrometry.c
r6205 r6872 10 10 * XXX: We should review the extent of the warning messages on these functions 11 11 * when the transformations are not successful. 12 * 12 * 13 13 * XXX: Should we implement non-linear cell->chip transforms? 14 * 15 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 1-26 21:10:50$14 * 15 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-04-17 18:01:04 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include <math.h> 26 26 #include "pslib.h" 27 27 28 #include "pmAstrometry.h" 29 #include "pmConcepts.h" 28 30 29 31 /***************************************************************************** … … 60 62 psFree(readout->mask); 61 63 psFree(readout->weight); 62 //63 // XXX: Not sure if this is the right way to do things. Currently the psListAdd()64 // increase the memory reference counter to the list data. So, we65 // iterate through the list, and decrement the reference counters.66 //67 if (1) {68 if ((readout->bias != NULL) && (readout->bias->head != NULL)) {69 psListElem *tmpElem = (psListElem *) readout->bias->head;70 while (NULL != tmpElem) {71 psMemDecrRefCounter((psImage *) tmpElem->data);72 tmpElem = tmpElem->next;73 }74 }75 }76 psFree(readout->bias);77 64 psFree(readout->analysis); 65 #if 0 66 78 67 psFree(readout->parent); 68 #endif 69 70 readout->parent = NULL; 79 71 } 80 72 } … … 88 80 psFree(cell->concepts); 89 81 psFree(cell->analysis); 82 psFree(cell->camera); 90 83 // 91 84 // Set the parent to NULL in all cell->readouts before psFree(cell->readouts) 92 85 // in order to avoid memory reference counter problems. 93 86 // 87 #if 0 88 94 89 for (psS32 i = 0 ; i < cell->readouts->n ; i++) { 95 90 pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i]; … … 99 94 } 100 95 } 96 psFree(cell->parent); 97 #endif 98 99 cell->parent = NULL; 100 101 101 psFree(cell->readouts); 102 psFree(cell->parent);103 102 psFree(cell->hdu); 103 104 104 } 105 105 } … … 116 116 // in order to avoid memory reference counter problems. 117 117 // 118 #if 0 119 118 120 for (psS32 i = 0 ; i < chip->cells->n ; i++) { 119 121 pmCell *tmpCell = (pmCell *) chip->cells->data[i]; … … 123 125 } 124 126 } 127 psFree(chip->parent); 128 #endif 129 130 chip->parent = NULL; 125 131 psFree(chip->cells); 126 psFree(chip->parent);127 132 psFree(chip->hdu); 128 133 } … … 143 148 // in order to avoid memory reference counter problems. 144 149 // 150 #if 0 151 145 152 for (psS32 i = 0 ; i < fpa->chips->n ; i++) { 146 153 pmChip *tmpChip = (pmChip *) fpa->chips->data[i]; … … 150 157 } 151 158 } 159 #endif 152 160 psFree(fpa->chips); 153 161 psFree(fpa->hdu); … … 156 164 } 157 165 166 void p_pmHDUFree(p_pmHDU *hdu) 167 { 168 if (hdu) { 169 psFree(hdu->extname); 170 psFree(hdu->header); 171 psFree(hdu->images); 172 psFree(hdu->masks); 173 psFree(hdu->weights); 174 } 175 } 176 158 177 // XXX: Verify these default values for row0, col0, rowBins, colBins 178 // PAP: These values may disappear in the future in favour of values in parent->concepts? 159 179 pmReadout *pmReadoutAlloc(pmCell *cell) 160 180 { 161 181 pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout)); 162 182 163 tmpReadout->col0 = -1;164 tmpReadout->row0 = -1;165 tmpReadout->colBins = -1;166 tmpReadout->rowBins = -1;183 tmpReadout->col0 = 0; 184 tmpReadout->row0 = 0; 185 tmpReadout->colBins = 0; 186 tmpReadout->rowBins = 0; 167 187 tmpReadout->image = NULL; 168 188 tmpReadout->mask = NULL; 169 189 tmpReadout->weight = NULL; 170 tmpReadout->bias = NULL;171 190 tmpReadout->analysis = psMetadataAlloc(); 172 191 tmpReadout->parent = cell; … … 179 198 180 199 // XXX: Verify these default values for row0, col0. 200 // PAP: These values may disappear in the future in favour of values in the "concepts"? 181 201 pmCell *pmCellAlloc( 182 202 pmChip *chip, 183 psMetadata *camera data,184 psStringname)203 psMetadata *cameraData, 204 const char *name) 185 205 { 186 206 pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell)); 187 207 188 tmpCell->col0 = -1;189 tmpCell->row0 = -1;208 tmpCell->col0 = 0; 209 tmpCell->row0 = 0; 190 210 tmpCell->toChip = NULL; 191 211 tmpCell->toFPA = NULL; … … 196 216 psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n"); 197 217 } 198 tmpCell->camera = cameradata;199 tmpCell->analysis = NULL;218 tmpCell->camera = psMemIncrRefCounter(cameraData); 219 tmpCell->analysis = psMetadataAlloc(); 200 220 tmpCell->readouts = psArrayAlloc(0); 201 221 tmpCell->parent = chip; … … 203 223 chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell); 204 224 } 205 tmpCell->valid = false; 225 tmpCell->process = true; // All cells are processed by default 226 tmpCell->exists = false; // Not yet read in 206 227 tmpCell->hdu = NULL; 228 229 pmConceptsBlankCell(tmpCell); 207 230 208 231 psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree); … … 211 234 212 235 // XXX: Verify these default values for row0, col0. 236 // PAP: row0, col0 may disappear in the future in favour of storing values in the "concepts". 213 237 pmChip *pmChipAlloc( 214 238 pmFPA *fpa, 215 psStringname)239 const char *name) 216 240 { 217 241 pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip)); 218 242 219 tmpChip->col0 = -1;220 tmpChip->row0 = -1;243 tmpChip->col0 = 0; 244 tmpChip->row0 = 0; 221 245 tmpChip->toFPA = NULL; 222 246 tmpChip->fromFPA = NULL; … … 226 250 psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME to metadata.\n"); 227 251 } 228 tmpChip->analysis = NULL;252 tmpChip->analysis = psMetadataAlloc(); 229 253 tmpChip->cells = psArrayAlloc(0); 230 254 tmpChip->parent = fpa; … … 232 256 fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip); 233 257 } 234 tmpChip->valid = false; 258 tmpChip->process = true; // Work on all chips, by default 259 tmpChip->exists = false; // Not read in yet 235 260 tmpChip->hdu = NULL; 261 262 pmConceptsBlankChip(tmpChip); 236 263 237 264 psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree); … … 248 275 tmpFPA->concepts = psMetadataAlloc(); 249 276 tmpFPA->analysis = NULL; 250 tmpFPA->camera = camera;277 tmpFPA->camera = psMemIncrRefCounter((psPtr)camera); 251 278 tmpFPA->chips = psArrayAlloc(0); 252 279 tmpFPA->hdu = NULL; 253 280 tmpFPA->phu = NULL; 254 281 282 pmConceptsBlankFPA(tmpFPA); 283 255 284 psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree); 256 285 return(tmpFPA); 286 } 287 288 p_pmHDU *p_pmHDUAlloc(const char *extname) 289 { 290 p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU)); 291 psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree); 292 293 hdu->extname = psStringCopy(extname); 294 hdu->header = NULL; 295 hdu->images = NULL; 296 hdu->masks = NULL; 297 hdu->weights = NULL; 298 299 return hdu; 257 300 } 258 301 … … 317 360 318 361 319 /*****************************************************************************/320 /* FUNCTION IMPLEMENTATION - PUBLIC */321 /*****************************************************************************/322 323 pmCell* pmCellInFPA(324 const psPlane* fpaCoord,325 const pmFPA* FPA)326 {327 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);328 PS_ASSERT_PTR_NON_NULL(FPA, NULL);329 330 pmChip* tmpChip = NULL;331 psPlane chipCoord;332 pmCell* outCell = NULL;333 334 // Determine which chip contains the fpaCoords.335 tmpChip = pmChipInFPA(fpaCoord, FPA);336 if (tmpChip == NULL) {337 return(NULL);338 }339 340 // Convert to those chip coordinates.341 psPlane *rc = pmCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);342 if (rc == NULL) {343 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine Chip coords.\n");344 return(NULL);345 }346 347 // Determine which cell contains those chip coordinates.348 outCell = pmCellInChip(&chipCoord, tmpChip);349 if (outCell == NULL) {350 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the cell.\n");351 return(NULL);352 }353 354 return (outCell);355 }356 357 pmChip* pmChipInFPA(358 const psPlane* fpaCoord,359 const pmFPA* FPA)360 {361 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);362 PS_ASSERT_PTR_NON_NULL(FPA, NULL);363 PS_ASSERT_PTR_NON_NULL(FPA->chips, NULL);364 365 psArray* chips = FPA->chips;366 psS32 nChips = chips->n;367 psPlane chipCoord;368 pmCell *tmpCell = NULL;369 370 //371 // Loop through every chip in this FPA. Convert the original FPA372 // coordinates to chip coordinates for that chip. Then, determine if any373 // cells in that chip contain those chip coordinates.374 // XXX: Depending on the number of chips, and their topology, there may be375 // a much more efficient way of doing this.376 //377 for (psS32 i = 0; i < nChips; i++) {378 pmChip* tmpChip = chips->data[i];379 PS_ASSERT_PTR_NON_NULL(tmpChip, NULL);380 PS_ASSERT_PTR_NON_NULL(tmpChip->fromFPA, NULL);381 382 psPlaneTransformApply(&chipCoord, tmpChip->fromFPA, fpaCoord);383 384 tmpCell = pmCellInChip(&chipCoord, tmpChip);385 if (tmpCell != NULL) {386 return(tmpChip);387 }388 }389 390 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the chip.\n");391 return (NULL);392 }393 394 395 pmCell* pmCellInChip(396 const psPlane* chipCoord,397 const pmChip* chip)398 {399 PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);400 PS_ASSERT_PTR_NON_NULL(chip, NULL);401 402 psPlane cellCoord;403 psArray* cells;404 405 cells = chip->cells;406 if (cells == NULL) {407 return NULL;408 }409 410 //411 // We loop over each cell in the chip. We transform the chipCoord into412 // a cellCoord for that cell and determine if that cellCoord is valid.413 // If so, then we return that cell.414 // XXX: Depending on the number of cells, and their topology, there may be415 // a much more efficient way of doing this.416 //417 for (psS32 i = 0; i < cells->n; i++) {418 pmCell* tmpCell = (pmCell* ) cells->data[i];419 PS_ASSERT_PTR_NON_NULL(tmpCell, NULL);420 421 psPlaneTransform *chipToCell = NULL;422 if (true == p_psIsProjectionLinear(tmpCell->toChip)) {423 chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);424 } else {425 psLogMsg(__func__, PS_LOG_WARN, "WARNING: non-linear cell->chip transforms are not yet implemented.\n");426 //chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);427 chipToCell = NULL;428 }429 if (chipToCell == NULL) {430 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not invert the Cell->toChip transform.\n");431 return(NULL);432 }433 psArray* readouts = tmpCell->readouts;434 435 if (readouts != NULL) {436 for (psS32 j = 0; j < readouts->n; j++) {437 pmReadout* tmpReadout = readouts->data[j];438 PS_ASSERT_READOUT_NON_NULL(tmpReadout, NULL);439 440 psPlaneTransformApply(&cellCoord,441 chipToCell,442 chipCoord);443 444 if (checkValidImageCoords(cellCoord.x,445 cellCoord.y,446 tmpReadout->image)) {447 psFree(chipToCell);448 return (tmpCell);449 }450 }451 }452 psFree(chipToCell);453 }454 455 //psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the cell.\n");456 return (NULL);457 }458 459 460 psPlane* pmCoordCellToFPA(461 psPlane* fpaCoord,462 const psPlane* cellCoord,463 const pmCell* cell)464 {465 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);466 PS_ASSERT_PTR_NON_NULL(cell, NULL);467 468 psPlane *rc = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord);469 if (rc == NULL) {470 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform cell coords to FPA coords.\n");471 }472 return(rc);473 }474 475 476 psPlane* pmCoordChipToFPA(477 psPlane* outCoord,478 const psPlane* inCoord,479 const pmChip* chip)480 {481 PS_ASSERT_PTR_NON_NULL(inCoord, NULL);482 PS_ASSERT_PTR_NON_NULL(chip, NULL);483 484 psPlane *rc = psPlaneTransformApply(outCoord, chip->toFPA, inCoord);485 if (rc == NULL) {486 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform chip coords to FPA coords.\n");487 }488 return(rc);489 }490 491 492 psPlane* pmCoordFPAToChip(493 psPlane* chipCoord,494 const psPlane* fpaCoord,495 const pmChip* chip)496 {497 PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);498 PS_ASSERT_PTR_NON_NULL(chip, NULL);499 PS_ASSERT_PTR_NON_NULL(chip->fromFPA, NULL);500 501 psPlane *rc = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord);502 if (rc == NULL) {503 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform FPA coords to Chip coords.\n");504 }505 return(rc);506 }507 508 psPlane* pmCoordCellToChip(509 psPlane* outCoord,510 const psPlane* inCoord,511 const pmCell* cell)512 {513 PS_ASSERT_PTR_NON_NULL(inCoord, NULL);514 PS_ASSERT_PTR_NON_NULL(cell, NULL);515 516 psPlane *rc = psPlaneTransformApply(outCoord, cell->toChip, inCoord);517 if (rc == NULL) {518 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform Cell coords to Chip coords.\n");519 }520 return(rc);521 }522 523 psPlane* pmCoordChipToCell(524 psPlane* cellCoord,525 const psPlane* chipCoord,526 const pmCell* cell)527 {528 PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);529 PS_ASSERT_PTR_NON_NULL(cell, NULL);530 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);531 532 pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent);533 if (tmpCell == NULL) {534 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine the proper cell.\n");535 return(NULL);536 }537 538 psPlaneTransform *tmpChipToCell = NULL;539 PS_ASSERT_PTR_NON_NULL(tmpCell->toChip, NULL);540 if (true == p_psIsProjectionLinear(tmpCell->toChip)) {541 tmpChipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);542 } else {543 psLogMsg(__func__, PS_LOG_WARN, "WARNING: non-linear cell->chip transforms are not yet implemented.\n");544 // XXX: tmpChipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);545 tmpChipToCell = NULL;546 }547 if (tmpChipToCell == NULL) {548 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not invert the Cell->toChip transform.\n");549 return(NULL);550 }551 552 psPlane *rc = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord);553 if (rc == NULL) {554 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform Chip coords to Cell coords.\n");555 }556 psFree(tmpChipToCell);557 return(rc);558 }559 560 psPlane* pmCoordFPAToTP(561 psPlane* outCoord,562 const psPlane* inCoord,563 double color,564 double magnitude,565 const pmFPA* fpa)566 {567 PS_ASSERT_PTR_NON_NULL(inCoord, NULL);568 PS_ASSERT_PTR_NON_NULL(fpa, NULL);569 570 psPlane *rc = psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, color, magnitude);571 if (rc == NULL) {572 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform FPA coords to tangent plane coords.\n");573 }574 return(rc);575 }576 577 psPlane* pmCoordTPToFPA(578 psPlane* fpaCoord,579 const psPlane* tpCoord,580 double color,581 double magnitude,582 const pmFPA* fpa)583 {584 PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);585 PS_ASSERT_PTR_NON_NULL(fpa, NULL);586 PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL);587 588 psPlane *rc = psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, tpCoord, color, magnitude);589 if (rc == NULL) {590 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform tangent plane coords to FPA coords.\n");591 }592 return(rc);593 }594 595 596 /*****************************************************************************597 XXXDeproject(outSphere, coord, projection): This private routine is a wrapper598 for p_psDeproject(). The reason: p_psDeproject() and p_psProject() combined599 do not seem to produce the original coordinates when they even though they600 should. XXXDeproject() simply negates the ->r and ->d members of the output601 psSphere if the input ->y is larger than 0.0. I don't know why it works.602 603 I'm guessing the p_psProject() and p_psDeproject() functions have bugs.604 605 XXX: It appears that p_psProject() and p_psDeproject() have been fixed.606 Remove this.607 *****************************************************************************/608 psSphere* XXXDeproject(609 psSphere *outSphere,610 const psPlane* coord,611 const psProjection* projection)612 {613 psSphere *rc = p_psDeproject(outSphere, coord, projection);614 615 if (coord->y >= 0.0) {616 rc->d = -rc->d;617 rc->r = -rc->r;618 }619 620 return(rc);621 }622 623 /*****************************************************************************624 *****************************************************************************/625 psSphere* pmCoordTPToSky(626 psSphere* outSphere,627 const psPlane* tpCoord,628 const psProjection *projection)629 {630 PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);631 PS_ASSERT_PTR_NON_NULL(projection, NULL);632 633 // psSphere *rc = XXXDeproject(outSphere, tpCoord, projection);634 psSphere *rc = p_psDeproject(outSphere, tpCoord, projection);635 if (rc == NULL) {636 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform tangent plane coords to sky coords.\n");637 }638 return(rc);639 }640 641 362 /***************************************************************************** 642 363 *****************************************************************************/ 643 psPlane* pmCoordSkyToTP( 644 psPlane* tpCoord, 645 const psSphere* in, 646 const psProjection *projection) 647 { 648 PS_ASSERT_PTR_NON_NULL(in, NULL); 649 PS_ASSERT_PTR_NON_NULL(projection, NULL); 650 651 psPlane *rc = p_psProject(tpCoord, in, projection); 652 if (rc == NULL) { 653 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform sky to tangent plane coords.\n"); 654 } 655 return(rc); 656 } 657 658 /***************************************************************************** 659 *****************************************************************************/ 660 psSphere* pmCoordCellToSky( 661 psSphere* skyCoord, 662 const psPlane* cellCoord, 663 double color, 664 double magnitude, 665 const pmCell* cell) 666 { 667 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL); 668 PS_ASSERT_PTR_NON_NULL(cell, NULL); 669 PS_ASSERT_PTR_NON_NULL(cell->toFPA, NULL); 670 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL); 671 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 672 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->toTangentPlane, NULL); 673 PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL); 674 psPlane fpaCoord; 675 psPlane tpCoord; 676 psPlane *rc; 677 pmFPA* parFPA = (cell->parent)->parent; 678 679 // Convert the input cell coordinates to FPA coordinates. 680 rc = psPlaneTransformApply(&fpaCoord, cell->toFPA, cellCoord); 681 if (rc == NULL) { 682 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform cell coords to FPA coords.\n"); 683 return(NULL); 684 } 685 686 // Convert the FPA coordinates to tangent plane Coordinates. 687 rc = psPlaneDistortApply(&tpCoord, parFPA->toTangentPlane, &fpaCoord, color, magnitude); 688 if (rc == NULL) { 689 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform FPA coords to tangent plane coords.\n"); 690 return(NULL); 691 } 692 693 // Convert the tangent plane Coordinates to sky coordinates. 694 psSphere *rc2 = pmCoordTPToSky(skyCoord, &tpCoord, parFPA->projection); 695 if (rc2 == NULL) { 696 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform cell coords to sky coords.\n"); 697 } 698 699 return(rc2); 700 } 701 702 /***************************************************************************** 703 *****************************************************************************/ 704 psPlane* pmCoordSkyToCell( 705 psPlane* cellCoord, 706 const psSphere* skyCoord, 707 float color, 708 float magnitude, 709 const pmCell* cell) 710 { 711 PS_ASSERT_PTR_NON_NULL(skyCoord, NULL); 712 PS_ASSERT_PTR_NON_NULL(cell, NULL); 713 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL); 714 PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL); 715 pmChip *parChip = cell->parent; 716 pmFPA *parFPA = parChip->parent; 717 psPlane tpCoord; 718 psPlane fpaCoord; 719 psPlane chipCoord; 720 psPlane *rc; 721 722 // Convert the skyCoords to tangent plane coords. 723 rc = pmCoordSkyToTP(&tpCoord, skyCoord, parFPA->projection); 724 if (rc == NULL) { 725 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine tangent plane coords.\n"); 726 return(NULL); 727 } 728 729 // Convert the tangent plane coords to FPA coords. 730 rc = pmCoordTPToFPA(&fpaCoord, &tpCoord, color, magnitude, parFPA); 731 if (rc == NULL) { 732 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine FPA coords.\n"); 733 return(NULL); 734 } 735 736 // Convert the FPA coords to chip coords. 737 rc = pmCoordFPAToChip(&chipCoord, &fpaCoord, parChip); 738 if (rc == NULL) { 739 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine chip coords.\n"); 740 return(NULL); 741 } 742 743 // Convert the chip coords to cell coords. 744 rc = pmCoordChipToCell(cellCoord, &chipCoord, cell); 745 if (rc == NULL) { 746 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not determine cell coords.\n"); 747 return(NULL); 748 } 749 750 return (cellCoord); 751 } 752 753 /***************************************************************************** 754 *****************************************************************************/ 755 psSphere* pmCoordCellToSkyQuick( 756 psSphere* outSphere, 757 const psPlane* cellCoord, 758 const pmCell* cell) 759 { 760 PS_ASSERT_PTR_NON_NULL(cellCoord, NULL); 761 PS_ASSERT_PTR_NON_NULL(cell, NULL); 762 PS_ASSERT_PTR_NON_NULL(cell->toSky, NULL); 763 psPlane outPlane; 764 psPlane *rc; 765 rc = psPlaneTransformApply(&outPlane, cell->toSky, cellCoord); 766 if (rc == NULL) { 767 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could transform cell coords to sky coords.\n"); 768 return(NULL); 769 } 770 771 psSphere *out = outSphere; 772 if (out == NULL) { 773 out = psSphereAlloc(); 774 } 775 out->r = outPlane.y; 776 out->d = outPlane.x; 777 778 return(out); 779 } 780 781 /***************************************************************************** 782 *****************************************************************************/ 783 psPlane* pmCoordSkyToCellQuick( 784 psPlane* cellCoord, 785 const psSphere* skyCoord, 786 const pmCell* cell) 787 { 788 PS_ASSERT_PTR_NON_NULL(skyCoord, NULL); 789 PS_ASSERT_PTR_NON_NULL(cell, NULL); 790 PS_ASSERT_PTR_NON_NULL(cell->toSky, NULL); 791 psPlane skyPlane; 792 skyPlane.y = skyCoord->r; 793 skyPlane.x = skyCoord->d; 794 795 psPlane *rc = psPlaneTransformApply(cellCoord, cell->toSky, &skyPlane); 796 if (rc == NULL) { 797 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not transform sky to cell coords.\n"); 798 } 799 return(cellCoord); 364 365 // Set cells within a chip to be processed or not 366 static bool setCellsProcess(const pmChip *chip, // Chip of interest 367 bool process // Process this chip? 368 ) 369 { 370 PS_ASSERT_PTR_NON_NULL(chip, false); 371 372 psArray *cells = chip->cells; // Component cells 373 if (! cells) { 374 return false; 375 } 376 for (int i = 0; i < cells->n; i++) { 377 pmCell *tmpCell = cells->data[i]; // Cell of interest 378 if (tmpCell) { 379 tmpCell->process = process; 380 } 381 } 382 383 return true; 800 384 } 801 385 … … 807 391 { 808 392 PS_ASSERT_PTR_NON_NULL(fpa, false); 809 if ((fpa->chips == NULL) || (chipNum >= fpa->chips->n)) { 393 394 psArray *chips = fpa->chips; // Component chips 395 if ((chips == NULL) || (chipNum >= chips->n)) { 810 396 return(false); 811 397 } 812 psBool rc = true; 813 814 for (psS32 i = 0 ; i < fpa->chips->n ; i++) { 815 pmChip *tmpChip = (pmChip *) fpa->chips->data[i]; 398 399 for (int i = 0 ; i < chips->n ; i++) { 400 pmChip *tmpChip = (pmChip *) chips->data[i]; 816 401 if (tmpChip == NULL) { 817 rc = false; 402 continue; 403 } 404 if (i == chipNum) { 405 tmpChip->process = true; 406 setCellsProcess(tmpChip, true); 818 407 } else { 819 if (i == chipNum) { 820 tmpChip->valid = true; 821 } else { 822 tmpChip->valid = false; 823 } 824 } 825 } 826 827 return(rc); 408 tmpChip->process = false; 409 setCellsProcess(tmpChip, false); 410 } 411 412 } 413 414 return true; 828 415 } 829 416 … … 831 418 /***************************************************************************** 832 419 XXX: The SDRS is ambiguous on a few things: 833 Whether or not the other chips should be set valid=true.834 Should we return the number of chip valid=true before or after they're set,420 Whether or not the other chips should be set process=true. [PAP: No] 421 Should we return the number of chip process=true before or after they're set, [PAP: After] 835 422 *****************************************************************************/ 836 423 /** 837 * 838 * pmFPAExcludeChip shall set validto false only for the specified chip424 * 425 * pmFPAExcludeChip shall set process to false only for the specified chip 839 426 * number (chipNum). In the event that the specified chip number does not exist 840 427 * within the fpa, the function shall generate a warning, and perform no action. 841 * The function shall return the number of chips within the fpa that have valid428 * The function shall return the number of chips within the fpa that have process 842 429 * set to true. 843 * 430 * 844 431 */ 845 432 int pmFPAExcludeChip( … … 849 436 PS_ASSERT_PTR_NON_NULL(fpa, false); 850 437 851 if (fpa->chips == NULL) { 438 psArray *chips = fpa->chips; // Component chips 439 if (chips == NULL) { 852 440 psLogMsg(__func__, PS_LOG_WARN, "WARNING: fpa->chips == NULL\n"); 853 441 return(0); 854 442 } 855 if ((chipNum >= fpa->chips->n) || (NULL == (pmChip *) fpa->chips->data[chipNum])) {443 if ((chipNum >= chips->n) || (NULL == (pmChip *) chips->data[chipNum])) { 856 444 psLogMsg(__func__, PS_LOG_WARN, "WARNING: the specified chip (%d) does not exist.\n", chipNum); 857 445 return(0); 858 446 } 859 447 860 psS32 numChips = 0;861 for ( psS32 i = 0 ; i < fpa->chips->n ; i++) {862 pmChip *tmpChip = (pmChip *) fpa->chips->data[i];448 int numChips = 0; // Number of chips to be processed 449 for (int i = 0 ; i < chips->n ; i++) { 450 pmChip *tmpChip = (pmChip *) chips->data[i]; // Chip of interest 863 451 if (tmpChip != NULL) { 864 452 if (i == chipNum) { 865 tmpChip-> valid= false;866 } else {867 tmpChip->valid = true;453 tmpChip->process = false; 454 setCellsProcess(tmpChip, false); // Wipe out the cell as well 455 } else if (tmpChip->process) { 868 456 numChips++; 869 457 } … … 874 462 } 875 463 464 465 bool pmCellSetWeights(pmCell *cell // Cell for which to set weights 466 ) 467 { 468 float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // Cell gain 469 float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); // Cell read noise 470 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); // Trim section 471 472 p_pmHDU *hdu = cell->hdu; // The data unit, containing the weight and mask originals 473 if (!hdu) { 474 pmChip *chip = cell->parent; // The parent chip 475 if (chip->hdu) { 476 hdu = chip->hdu; 477 } else { 478 pmFPA *fpa = chip->parent; // The parent FPA 479 hdu = fpa->hdu; 480 if (!hdu) { 481 psError(PS_ERR_UNKNOWN, true, "Unable to find the HDU in the hierarchy!\n"); 482 return false; 483 } 484 } 485 } 486 487 psArray *pixels = hdu->images; // Array of images 488 psArray *weights = hdu->weights; // Array of weight images 489 psArray *masks = hdu->masks; // Array of mask images 490 // Generate the weights and masks if required 491 if (! weights) { 492 weights = psArrayAlloc(pixels->n); 493 for (int i = 0; i < pixels->n; i++) { 494 psImage *image = pixels->data[i]; 495 weights->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 496 psImageInit(weights->data[i], 0.0); 497 } 498 hdu->weights = weights; 499 } 500 if (! masks) { 501 masks = psArrayAlloc(pixels->n); 502 for (int i = 0; i < pixels->n; i++) { 503 psImage *image = pixels->data[i]; 504 masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8); 505 psImageInit(masks->data[i], 0); 506 } 507 hdu->masks = masks; 508 } 509 510 // Set the pixels 511 psArray *readouts = cell->readouts; // Array of readouts 512 for (int i = 0; i < readouts->n; i++) { 513 pmReadout *readout = readouts->data[i]; // The readout of interest 514 515 if (! readout->weight) { 516 readout->weight = weights->data[i]; 517 } 518 if (! readout->mask) { 519 readout->mask = masks->data[i]; 520 } 521 522 // Mask is already set to 0 523 524 // Set weight image to the variance = g*f + rn^2 525 psImage *image = psImageSubset(readout->image, *trimsec); // The pixels 526 psImage *weight = psImageSubset(readout->weight, *trimsec); // The weight map 527 psBinaryOp(weight, image, "*", psScalarAlloc(gain, PS_TYPE_F32)); 528 psBinaryOp(weight, weight, "+", psScalarAlloc(readnoise*readnoise, PS_TYPE_F32)); 529 } 530 531 return true; 532 } 533 534 -
trunk/psModules/src/astrom/pmAstrometry.h
r6205 r6872 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 1-26 21:10:50$10 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-04-17 18:01:04 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 { 31 31 const char *extname; // Extension name, if it corresponds to this level 32 psArray *pixels; // The pixel data, if it corresponds to this level33 32 psMetadata *header; // The FITS header, if it corresponds to this level 33 psArray *images; // The pixel data, if it corresponds to this level 34 psArray *masks; // The mask data, if it corresponds to this level 35 psArray *weights; // The weight data, if it corresponds to this level 34 36 } 35 37 p_pmHDU; 36 38 37 p_pmHDU *pmHDUAlloc();38 void *pmHDUFree(p_pmHDU *hdu);39 40 39 /** Focal plane data structure 41 * 40 * 42 41 * A focal plane consists of one or more chips (according to the number of 43 42 * pieces of contiguous silicon). It contains metadata containers for the … … 52 51 * transformation which will be derived from numerically inverting the forward 53 52 * transformation. 54 * 53 * 55 54 */ 56 55 typedef struct … … 71 70 72 71 /** Chip data structure 73 * 72 * 74 73 * A chip consists of one or more cells (according to the number of amplifiers 75 74 * on the device). The chip contains metadata containers for the concepts and … … 82 81 * inverting the forward transformation. A boolean indicates whether the chip is 83 82 * of interest, allowing it to be excluded from analysis. 84 * 83 * 85 84 */ 86 85 typedef struct … … 97 96 psArray *cells; ///< The cells (referred to by name) 98 97 pmFPA *parent; ///< Parent FPA 99 bool valid; ///< Do we bother about reading and working with this chip? 98 bool process; ///< Do we bother about reading and working with this chip? 99 bool exists; ///< Does the chip exist --- has it been read in? 100 100 p_pmHDU *hdu; ///< FITS data 101 101 } … … 126 126 psArray *readouts; ///< The readouts (referred to by number) 127 127 pmChip *parent; ///< Parent chip 128 bool valid; ///< Do we bother about reading and working with this cell? 128 bool process; ///< Do we bother about reading and working with this cell? 129 bool exists; ///< Does the cell exist --- has it been read in? 129 130 p_pmHDU *hdu; ///< FITS data 130 131 } … … 144 145 { 145 146 // Position on the cell 147 // XXX: These may be removed in the future; use parent->concepts instead? 146 148 int col0; ///< Offset from the left of chip. 147 149 int row0; ///< Offset from the bottom of chip. … … 152 154 psImage *mask; ///< Mask of input image 153 155 psImage *weight; ///< Weight of input image 154 psList *bias; ///< List of bias section (sub-)images155 156 psMetadata *analysis; ///< Readout-level analysis metadata 156 157 pmCell *parent; ///< Parent cell … … 183 184 */ 184 185 pmCell *pmCellAlloc( 185 pmChip *chip, ///< Parent chip186 psMetadata *camera data,187 psString name186 pmChip *chip, ///< Parent chip 187 psMetadata *cameraData, ///< Camera data 188 const char *name ///< Name of cell 188 189 ); 189 190 190 191 /** Allocates a pmChip 191 * 192 * 192 193 * The constructor shall make an empty pmChip. If the parent fpa is not NULL, 193 194 * the parent link is made and the chip shall be placed in the parent's array … … 199 200 */ 200 201 pmChip *pmChipAlloc( 201 pmFPA *fpa, 202 psString name 203 202 pmFPA *fpa, ///< FPA to which the chip belongs 203 const char *name ///< Name of chip 204 204 ); 205 205 206 206 /** Allocates a pmFPA 207 * 207 * 208 208 * The constructor shall make an empty pmFPA. The chips array shall be 209 209 * allocated with a zero size, the camera and db pointers set to the values 210 210 * provided, and the concepts metadata constructed. All other pointers in the 211 211 * structure shall be initialized to NULL. 212 * 212 * 213 213 */ 214 214 pmFPA *pmFPAAlloc( … … 216 216 ); 217 217 218 /** Allocates a p_pmHDU 219 * 220 * XXX: More detailed description 221 * 222 * @return p_pmHDU* newly allocated p_pmHDU 223 */ 224 p_pmHDU *p_pmHDUAlloc(const char *extname // Extension name 225 ); 226 218 227 219 228 /** Verify parent links. 220 * 229 * 221 230 * This function checks the validity of the parent links in the FPA hierarchy. 222 231 * If a parent link is not set (or not set correctly), it is corrected, and the 223 232 * function shall return false. If all the parent pointers were correct, the 224 233 * function shall return true. 225 * 234 * 226 235 */ 227 236 bool pmFPACheckParents( … … 232 241 233 242 /** FUNC DESC 234 * 235 * 236 * 237 * 238 */ 239 243 * 244 * 245 * 246 * 247 */ 248 249 250 251 /** 252 * 253 * pmFPASelectChip shall set valid to true for the specified chip number 254 * (chipNum), and all other chips shall have valid set to false. In the event 255 * that the specified chip number does not exist within the fpa, the function 256 * shall return false. 257 * 258 */ 259 bool pmFPASelectChip( 260 pmFPA *fpa, 261 int chipNum 262 ); 263 264 /** 265 * 266 * pmFPAExcludeChip shall set valid to false only for the specified chip 267 * number (chipNum). In the event that the specified chip number does not exist 268 * within the fpa, the function shall generate a warning, and perform no action. 269 * The function shall return the number of chips within the fpa that have valid 270 * set to true. 271 * 272 */ 273 int pmFPAExcludeChip( 274 pmFPA *fpa, 275 int chipNum 276 ); 240 277 241 278 … … 426 463 ); 427 464 428 /**429 *430 * pmFPASelectChip shall set valid to true for the specified chip number431 * (chipNum), and all other chips shall have valid set to false. In the event432 * that the specified chip number does not exist within the fpa, the function433 * shall return false.434 *435 */436 bool pmFPASelectChip(437 pmFPA *fpa,438 int chipNum439 );440 441 442 /**443 *444 * pmFPAExcludeChip shall set valid to false only for the specified chip445 * number (chipNum). In the event that the specified chip number does not exist446 * within the fpa, the function shall generate a warning, and perform no action.447 * The function shall return the number of chips within the fpa that have valid448 * set to true.449 *450 */451 int pmFPAExcludeChip(452 pmFPA *fpa,453 int chipNum454 );455 456 457 /**458 *459 * pmFPAConstruct shall construct a focal plane hierarchy from a camera460 * configuration. A db handle is also provided so that may be set in the pmFPA.461 * The resultant pmFPA and its lower-down components shall be ready for to read a462 * FITS file into it by setting the extname pointers at the appropriate levels to463 * the appropriate FITS extension name.464 *465 */466 pmFPA *pmFPAConstruct(467 const psMetadata *camera,468 psDB *db469 );470 471 465 472 466 #endif // #ifndef PS_ASTROMETRY_H -
trunk/psModules/src/astrom/pmAstrometryObjects.c
r6511 r6872 8 8 * @author EAM, IfA 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 3-04 01:01:33$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-04-17 18:01:04 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 20 20 #include <math.h> 21 21 #include "pslib.h" 22 #include "pm Astrometry.h"22 #include "pmFPA.h" 23 23 #include "pmAstrometryObjects.h" 24 24 … … 540 540 psArray *rot; 541 541 542 pmAstromStats minStat, newStat; 542 pmAstromStats minStat; 543 pmAstromStats newStat = {{0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0}; 543 544 psPlane center; 544 545 -
trunk/psModules/src/astrom/pmAstrometryObjects.h
r6205 r6872 8 8 * @author EAM, IfA 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 1-26 21:10:50$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-04-17 18:01:04 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 21 21 # include <unistd.h> // for unlink 22 22 # include <pslib.h> 23 # include <pm Astrometry.h>24 25 /* 26 * 23 # include <pmFPA.h> 24 25 /* 26 * 27 27 * This structure specifies the coordinate of the detection in each of the 28 28 * four necessary coordinate frames: pix defines the position in the psReadout … … 35 35 * coordinates, while the reference detections will be projected to the other 36 36 * frames from the sky coordinates. 37 * 37 * 38 38 * XXX: There are more members here than in the SDRS. 39 * 39 * 40 40 */ 41 41 typedef struct … … 55 55 56 56 /* 57 * 57 * 58 58 * The pmAstromMatch structure defines the cross-correlation between two 59 59 * arrays. A single such data item specifies that item number pmAstromMatch.idx1 60 60 * in the first list corresponds to pmAstromMatch.idx2 in the second list. 61 * 61 * 62 62 */ 63 63 typedef struct … … 70 70 71 71 /* 72 * 72 * 73 73 * XXX: Not in SDRS. 74 * 74 * 75 75 */ 76 76 typedef struct … … 88 88 89 89 /* 90 * 90 * 91 91 * If the two sets of coordinates are expected to agree very well (ie, the 92 92 * current best-guess astrometric solution is quite close to the radius. The … … 97 97 * ASTROM.MATCH.RADIUS). The output consists an array of pmAstromMatch values, 98 98 * defined below. 99 * 99 * 100 100 */ 101 101 psArray *pmAstromRadiusMatch( … … 108 108 109 109 /* 110 * 110 * 111 111 * This function accepts an array of pmAstromObj objects and rotates them by 112 112 * the given angle about the given center coordinate pCenter,qCenter in the Focal 113 113 * Plane Array coordinates. 114 * 114 * 115 115 * XXX: This differs from the SDRS 116 * 116 * 117 117 */ 118 118 /* SDRS … … 132 132 133 133 /* 134 * 134 * 135 135 * If the two sets of coordinates are not known to agree well, but the 136 136 * relative scale and approximate relative rotation is known, then a much faster … … 147 147 * allowing the procedure to scan over a range of rotations. We define the 148 148 * following function to apply this matching algorithm: 149 * 149 * 150 150 * XXX: In the SDRS, this function is a pointer. 151 * 151 * 152 152 */ 153 153 pmAstromStats pmAstromGridMatch( … … 159 159 160 160 /* 161 * 161 * 162 162 * The result of a pmAstromGridMatch may be used to modify the astrometry 163 163 * transformation information for a pmFPA image hierarchy structure. The result … … 167 167 * the linear terms of the pmFPA.toTangentPlane transformation. These two 168 168 * adjustments are made using the function: 169 * 169 * 170 170 * XXX: This function name is different in the SDRS. 171 * 171 * 172 172 */ 173 173 psPlaneTransform *pmAstromGridApply( … … 178 178 179 179 /* 180 * 180 * 181 181 * This function is identical to pmAstromGridMatch, but is valid for only a 182 182 * single relative rotation. The input config information need not contain any of 183 183 * the GRID.*.ANGLE entries (they will be ignored). 184 * 184 * 185 * XXX: This function name is different in the SDRS. 186 * 185 187 */ 186 188 /* in pmAstromGrid.c */ … … 193 195 194 196 /* 195 * 197 * 196 198 * This function accepts the raw and reference source lists and the list of 197 199 * matched entries. It uses the matched list to determine a polynomial … … 207 209 * modifications to pmFPA.toTangentPlane incorporate the rotation component of 208 210 * the linear terms and the higher-order terms of the polynomial fits. 209 * 211 * 210 212 * XXX: No prototype code. 211 * 213 * 212 214 */ 213 215 bool pmAstromFitFPA( … … 233 235 *ASTROM.ORDER). The result of this fit is a set of modifications of the 234 236 *components of the pmChip.toFPA transformation. 235 * 237 * 236 238 * XXX: No prototype code. 237 * 239 * 238 240 */ 239 241 bool pmAstromFitChip( … … 247 249 248 250 /* 249 * 251 * 250 252 * The following function determines the position residual, in the tangent 251 253 * plane, as a function of position in the focal plane, for a collection of raw … … 253 255 * the bin size over which the gradient is measured (keyword: ASTROM.GRAD.BOX). 254 256 * The function returns an array of pmAstromGradient structures, defined below. 255 * 257 * 256 258 * XXX: No prototype code. 257 * 259 * 258 260 */ 259 261 psArray pmAstromMeasureGradients( … … 267 269 268 270 /* 269 * 271 * 270 272 * The following data structure carries the information about the residual 271 273 * gradient of source positions in the tangent plane (pmAstromObj.TP) as a 272 274 * function of position in the focal plane (pmAstromObj.FP). 273 * 275 * 274 276 */ 275 277 typedef struct … … 283 285 284 286 /* 285 * 287 * 286 288 * The gradient set measured above can be fitted with a pair of 2D 287 289 * polynomials. The resulting fits can then be related back to the implied … … 290 292 * supplied pmFPA structure. The configuration variable supplies the polynomial 291 293 * order (keyword: ASTROM.DISTORT.ORDER). 292 * 294 * 293 295 * XXX: No prototype code. 294 * 296 * 295 297 */ 296 298 psArray pmAstromFitDistortion( … … 308 310 ******************************************************************************/ 309 311 /* 310 * 311 * 312 * 313 * 314 */ 315 316 317 /* 318 * 312 * 313 * 314 * 315 * 316 */ 317 318 319 /* 320 * 319 321 * Allocates a pmAstromObj struct. 320 * 322 * 321 323 */ 322 324 pmAstromObj *pmAstromObjAlloc (void); … … 325 327 326 328 /* 327 * 329 * 328 330 * Copies a pmAstromObj struct. 329 * 331 * 330 332 */ 331 333 pmAstromObj *pmAstromObjCopy( … … 336 338 337 339 /* 338 * 339 * 340 * 340 * 341 * 342 * 341 343 */ 342 344 pmAstromMatch *pmAstromMatchAlloc( … … 349 351 350 352 /* 351 * 352 * 353 * 353 * 354 * 355 * 354 356 */ 355 357 psPlaneTransform *pmAstromMatchFit( … … 364 366 365 367 /* 366 * 367 * 368 * 368 * 369 * 370 * 369 371 */ 370 372 int pmAstromObjSortByFPX( … … 376 378 377 379 /* 378 * 379 * 380 * 380 * 381 * 382 * 381 383 */ 382 384 int pmAstromObjSortByMag( -
trunk/psModules/src/camera/Makefile.am
r5170 r6872 3 3 libpsmodulecamera_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 4 4 libpsmodulecamera_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 libpsmodulecamera_la_SOURCES = 5 libpsmodulecamera_la_SOURCES = \ 6 pmChipMosaic.c \ 7 pmFPAConceptsGet.c \ 8 pmFPAConceptsSet.c \ 9 pmFPAConstruct.c \ 10 pmFPAMorph.c \ 11 pmFPARead.c \ 12 pmFPAWrite.c 6 13 7 14 psmoduleincludedir = $(includedir) 8 psmoduleinclude_HEADERS = 9 15 psmoduleinclude_HEADERS = \ 16 pmChipMosaic.h \ 17 pmFPAConceptsGet.h \ 18 pmFPAConceptsSet.h \ 19 pmFPAConstruct.h \ 20 pmFPAMorph.h \ 21 pmFPARead.h \ 22 pmFPAWrite.h -
trunk/psModules/src/config/pmConfig.h
r6297 r6872 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 2-02 04:51:14$5 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-04-17 18:01:05 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 16 16 17 // Configuration information 18 typedef struct 19 { 20 psMetadata *site; // Site configuration 21 psMetadata *camera; // Camera specification 22 psMetadata *recipes; // Recipes for processing 23 psMetadata *arguments; // Command-line arguments 24 psMetadata *files; // pmFPAfiles used for analysis 25 // psMetadata *format; // camera format for primary image 26 psDB *database; // Database handle 27 } 28 pmConfig; 29 30 pmConfig *pmConfigAlloc(void); 31 32 // Free static variables 33 void pmConfigDone(void); 17 34 18 35 /** pmConfigRead 19 * 36 * 20 37 * pmConfigRead shall load the site configuration (according to the above rule 21 38 * for determining the source). The camera configuration shall also be loaded if … … 32 49 * 33 50 */ 34 bool pmConfigRead( 35 psMetadata **site, 36 psMetadata **camera, 37 psMetadata **recipe, 51 pmConfig *pmConfigRead( 38 52 int *argc, 39 char **argv, 40 const char *recipeName 53 char **argv); 54 55 /** we need this elsewhere; make it public **/ 56 bool readConfig( 57 psMetadata **config, // Config to output 58 const char *name, // Name of file 59 const char *description // Description of file 41 60 ); 42 61 43 44 45 62 /** pmConfigValidateCamera 46 * 63 * 47 64 * This function, used by pmConfigCameraFromHeader, shall return true if the 48 65 * FITS header matches the rule contained in the camera configuration (see 49 66 * x2.2.2.3); otherwise it shall return false. 50 * 67 * 51 68 */ 52 bool pmConfigValidateCamera( 53 const psMetadata *camera, 54 const psMetadata *header 55 ); 56 69 bool pmConfigValidateCameraFormat( 70 const psMetadata *cameraFormat, 71 const psMetadata *header); 57 72 58 73 59 74 /** pmConfigCameraFromHeader 60 * 75 * 61 76 * pmConfigCameraFromHeader shall load the camera configuration based on the 62 77 * contents of the FITS header, using the list of known cameras contained in the 63 78 * site configuration. If more than one camera matches the FITS header, a warning 64 79 * shall be generated and the first matching camera returned. 65 * 80 * 66 81 */ 67 psMetadata *pmConfigCameraF romHeader(68 const psMetadata *site,69 const psMetadata *header 82 psMetadata *pmConfigCameraFormatFromHeader( 83 pmConfig *config, // The configuration 84 const psMetadata *header // The FITS header 70 85 ); 71 86 72 87 73 74 88 /** pmConfigRecipeFromCamera 75 * 76 * pmConfigRecipeFromCamera shall load the recipe configuration based on the 77 * recipeName and the list of known recipes contained in the camera 89 * 90 * pmConfigRecipeFromCamera shall load the recipes from the list of known recipes contained in the camera 78 91 * configuration. 79 * 92 * 80 93 */ 81 psMetadata *pmConfigRecipeFromCamera( 82 const psMetadata *camera, 83 const char *recipeName 94 bool pmConfigReadRecipes( 95 pmConfig *config 84 96 ); 85 97 86 98 /** pmConfigDB 87 * 99 * 88 100 * pmConfigDB shall use the site configuration data to open a database handle. 89 101 * This is fairly straightforward at the moment, but will change when we beef up 90 102 * security. (TBD) 91 * 103 * 92 104 */ 93 105 #ifdef DOMIT_PSDB … … 99 111 ); 100 112 113 /** pmConfigConformHeader 114 * 115 * Make the supplied header conform to the nominated camera format. 116 */ 117 bool pmConfigConformHeader(psMetadata *header, // Header to conform 118 const psMetadata *format // Camera format 119 ); 120 121 122 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list); 123 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list); 124 101 125 102 126 #endif -
trunk/psModules/src/detrend/Makefile.am
r5170 r6872 3 3 libpsmoduledetrend_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 4 4 libpsmoduledetrend_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 libpsmoduledetrend_la_SOURCES = pmFlatField.c \ 6 pmMaskBadPixels.c \ 7 pmNonLinear.c 5 libpsmoduledetrend_la_SOURCES = \ 6 pmFlatField.c \ 7 pmFringeStats.c \ 8 pmMaskBadPixels.c \ 9 pmNonLinear.c 8 10 9 11 psmoduleincludedir = $(includedir) 10 12 psmoduleinclude_HEADERS = \ 11 pmFlatField.h \ 12 pmFlatFieldErrors.h \ 13 pmMaskBadPixelsErrors.h \ 14 pmMaskBadPixels.h \ 15 pmNonLinear.h 13 pmFlatField.h \ 14 pmFlatFieldErrors.h \ 15 pmFringeStats.h \ 16 pmMaskBadPixelsErrors.h \ 17 pmMaskBadPixels.h \ 18 pmNonLinear.h 16 19 17 20 EXTRA_DIST = pmFlatFieldErrors.dat pmMaskBadPixelsErrors.dat -
trunk/psModules/src/detrend/pmFlatField.c
r5543 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 6 1 7 /** @file pmFlatField.c 2 8 * … … 18 24 * @author Ross Harman, MHPCC 19 25 * 20 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $21 * @date $Date: 200 5-11-18 19:43:14$26 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 22 28 * 23 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 36 #include<stdio.h> 31 37 #include<math.h> 32 #include <string .h>38 #include <strings.h> 33 39 34 40 #include "pslib.h" … … 36 42 #include "pmMaskBadPixels.h" 37 43 #include "pmFlatFieldErrors.h" 38 #include "pmSubtractBias.h"39 44 40 // XXX: This should be removed when the autoconf stuff handles psConstants.h correctly.41 #define PS_WARN_PTR_NON_NULL(NAME) \42 if ((NAME) == NULL) { \43 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \44 } \45 45 46 bool pmFlatField( 47 pmReadout *in, 48 const pmReadout *flat) 46 bool pmFlatField(pmReadout *in, const pmReadout *flat) 49 47 { 50 // XXX: Use the proper image and readout asserts.51 PS_ASSERT_PTR_NON_NULL(in, true);52 PS_ASSERT_PTR_NON_NULL(in->image, false);53 PS_ASSERT_PTR_NON_NULL(in->mask, false);54 PS_ASSERT_PTR_NON_NULL(flat, false);55 PS_ASSERT_PTR_NON_NULL(flat->image, false);56 if (in == NULL)57 printf("XXX: NULL\n");58 59 // XXX: Not sure if this is correct. Must consult with IfA.60 PS_ASSERT_PTR_NON_NULL(in->mask, false);61 62 PS_WARN_PTR_NON_NULL(in->parent);63 if (in->parent != NULL) {64 PS_WARN_PTR_NON_NULL(in->parent->concepts);65 }66 48 int i = 0; 67 49 int j = 0; … … 71 53 psElemType flatType; 72 54 psElemType maskType; 73 psImage *inMask = NULL;74 psImage *flatImage = NULL;75 55 76 // 77 // Determine trimmed image from metadata. 78 // 79 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 80 flatImage = flat->image; 81 inMask = in->mask; 56 // Check for nulls 57 if (in == NULL) { 58 return true; // Readout may not have data in it 59 } else if(flat==NULL) { 60 psError( PS_ERR_BAD_PARAMETER_NULL, true, 61 PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT); 62 return false; 63 } 64 65 psImage *inImage = in->image; // Input image 66 psImage *inMask = in->mask; // Mask for input image 67 psImage *flatImage = flat->image; // Flat-field image 68 69 // Offsets on the chip 70 int x0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.X0"); 71 int y0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.Y0"); 72 int x0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.X0"); 73 int y0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.Y0"); 74 75 if (inImage == NULL) { 76 psError( PS_ERR_BAD_PARAMETER_NULL, true, 77 PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE); 78 return false; 79 } else if(flatImage == NULL) { 80 psError( PS_ERR_BAD_PARAMETER_NULL, true, 81 PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE); 82 return false; 83 } 82 84 83 85 // Check input image and its mask are not larger than flat image 84 86 85 if (trimmedImg == NULL) 86 printf("XXX: 00\n"); 87 if (flatImage == NULL) 88 printf("XXX 01\n"); 89 90 if (trimmedImg->numRows>flatImage->numRows || trimmedImg->numCols>flatImage->numCols) { 87 if (inImage->numRows>flatImage->numRows || inImage->numCols>flatImage->numCols) { 91 88 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 92 89 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE, 93 trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols);90 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols); 94 91 return false; 95 92 } 96 if (inMask ->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols) {93 if (inMask && (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols)) { 97 94 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 98 95 PS_ERRORTEXT_pmFlatField_SIZE_MASK_IMAGE, … … 102 99 103 100 // Determine total offset based on image offset with chip offset 104 totOffCol = trimmedImg->col0 + in->col0;105 totOffRow = trimmedImg->row0 + in->row0;101 totOffCol = inImage->col0 + y0in - flatImage->col0 - y0flat; 102 totOffRow = inImage->row0 + x0in - flatImage->row0 - x0flat; 106 103 107 104 // Check that offsets are within image limits … … 111 108 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols); 112 109 return false; 113 } else if(totOffRow>= trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {110 } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) { 114 111 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 115 112 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE, 116 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);113 totOffRow, totOffCol, inImage->numRows, inImage->numCols); 117 114 return false; 118 } else if( totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {115 } else if(inMask && (totOffRow>=inMask->numRows || totOffCol>=inMask->numCols)) { 119 116 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 120 117 PS_ERRORTEXT_pmFlatField_OFFSET_MASK_IMAGE, … … 124 121 125 122 // Check for incorrect types 126 inType = trimmedImg->type.type;123 inType = inImage->type.type; 127 124 flatType = flatImage->type.type; 128 125 maskType = inMask->type.type; … … 137 134 flatType); 138 135 return false; 139 } else if( maskType != PS_TYPE_MASK) {136 } else if(inMask && inMask->type.type != PS_TYPE_MASK) { 140 137 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 141 138 PS_ERRORTEXT_pmFlatField_TYPE_MASK_IMAGE, … … 153 150 case PS_TYPE_##TYPE: \ 154 151 /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */ \ 155 for(j = totOffRow; j < trimmedImg->numRows; j++) { \156 for(i = totOffCol; i < trimmedImg->numCols; i++) { \152 for(j = totOffRow; j < inImage->numRows; j++) { \ 153 for(i = totOffCol; i < inImage->numCols; i++) { \ 157 154 if(flatImage->data.TYPE[j][i] <= 0.0) { \ 158 155 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ 159 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT; \ 156 if (inMask) { \ 157 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT; \ 158 } \ 160 159 flatImage->data.TYPE[j][i] = 0.0; \ 161 160 } \ 162 161 } \ 163 162 } \ 164 for(j = totOffRow; j < trimmedImg->numRows; j++) { \165 for(i = totOffCol; i < trimmedImg->numCols; i++) { \166 if( !inMask->data.PS_TYPE_MASK_DATA[j][i]) {\163 for(j = totOffRow; j < inImage->numRows; j++) { \ 164 for(i = totOffCol; i < inImage->numCols; i++) { \ 165 if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) { \ 167 166 /* Module shall divide the input image by the flat-fielded image */ \ 168 trimmedImg->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \167 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ 169 168 } \ 170 169 } \ -
trunk/psModules/src/detrend/pmFlatField.h
r5435 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 6 1 7 /** @file pmFlatField.h 2 8 * … … 18 24 * @author Ross Harman, MHPCC 19 25 * 20 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $21 * @date $Date: 200 5-10-20 23:06:24$26 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 22 28 * 23 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 31 26 32 #include "pslib.h" 27 #include "pm Astrometry.h"33 #include "pmFPA.h" 28 34 29 35 -
trunk/psModules/src/detrend/pmMaskBadPixels.c
r5543 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmMaskBadPixels.c 2 7 * … … 19 24 * @author Ross Harman, MHPCC 20 25 * 21 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $22 * @date $Date: 200 5-11-18 19:43:14$26 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 23 28 * 24 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 36 #include<stdio.h> 32 37 #include<math.h> 33 #include<string .h>38 #include<strings.h> 34 39 35 40 #include "pmMaskBadPixels.h" 36 41 #include "pmMaskBadPixelsErrors.h" 37 #include "pmSubtractBias.h"38 42 39 //XXX: REmove, autoconf is broken. 40 #define PS_WARN_PTR_NON_NULL(NAME) \ 41 if ((NAME) == NULL) { \ 42 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \ 43 } \ 43 bool pmMaskBadPixels(pmReadout *in, const psImage *mask, unsigned int maskVal, float sat, 44 unsigned int growVal, int grow) 45 { 46 int i = 0; 47 int j = 0; 48 int jj = 0; 49 int ii = 0; 50 int rRound = 0; 51 int rowMin = 0; 52 int rowMax = 0; 53 int colMin = 0; 54 int colMax = 0; 55 int totOffCol = 0; 56 int totOffRow = 0; 57 float r = 0.0f; 58 psElemType inType; 59 psElemType maskType; 60 psImage *inImage = NULL; 61 psImage *inMask = NULL; 44 62 45 63 46 /****************************************************************************** 47 GrowPixel(inMask, row, col, radius, maskVal): This private routine takes an 48 input image mask and a pixel location, then sets (logical or) all pixels with 49 parameter radius if that pixel to maskVal parameter. 50 *****************************************************************************/ 51 psBool GrowPixel( 52 psImage *inMask, 53 psS32 col, 54 psS32 row, 55 psS32 radius, 56 psU32 maskVal) 57 { 58 psS32 rowMin = PS_MAX(row-radius, 0); 59 psS32 rowMax = PS_MIN(row+radius+1, inMask->numRows); 60 psS32 colMin = PS_MAX(col-radius, 0); 61 psS32 colMax = PS_MIN(col+radius+1, inMask->numCols); 62 psF32 squareRadius = PS_SQR(radius); 64 // Check for nulls 65 if (in == NULL) { 66 return true; // Readout may not have data in it 67 } else if(mask==NULL) { 68 psError( PS_ERR_BAD_PARAMETER_NULL, true, 69 PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE); 70 return false; 71 } 63 72 64 65 for(psS32 i=rowMin; i<rowMax; i++) { 66 for(psS32 j=colMin; j<colMax; j++) { 67 // Old code: 68 // psF32 rRound = 0.5 + sqrtf((psF32) (((col-j)*(col-j)) + ((row-i)*(row-i)))); 69 // if(rRound <= radius) { 70 psF32 squareDis = (psF32) (((col-j)*(col-j)) + ((row-i)*(row-i))); 71 if (squareDis <= squareRadius) { 72 inMask->data.U8[i][j] |= maskVal; 73 } 74 } 75 } 76 return(true); 77 } 78 79 /****************************************************************************** 80 GetRadius(inImg, col, row, sat, growVal, grow): This private routine takes an 81 input image and pixel location and determines what radius that pixel must grow 82 by. 83 84 //XXX: Inline this or macro it for speed. 85 *****************************************************************************/ 86 static psS32 GetRadius( 87 psImage *inImg, 88 psS32 col, 89 psS32 row, 90 psF32 sat, 91 psU32 growVal, 92 psS32 grow) 93 { 94 psS32 growRadius = 0; 95 if (inImg->type.type == PS_TYPE_F32) { 96 if(inImg->data.F32[row][col] == growVal) { 97 growRadius = grow; 98 } 99 if (inImg->data.F32[row][col] > sat) { 100 growRadius = PS_MAX(growRadius+1, 2); 101 } 102 } else if (inImg->type.type == PS_TYPE_S32) { 103 if(inImg->data.S32[row][col] == growVal) { 104 growRadius = grow; 105 } 106 if (inImg->data.S32[row][col] > sat) { 107 growRadius = PS_MAX(growRadius+1, 2); 108 } 109 } else if (inImg->type.type == PS_TYPE_U16) { 110 if(inImg->data.U16[row][col] == growVal) { 111 growRadius = grow; 112 } 113 if (inImg->data.U16[row][col] > sat) { 114 growRadius = PS_MAX(growRadius+1, 2); 115 } 116 } else { 117 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 118 PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE, 119 inImg->type.type); 120 } 121 return(growRadius); 122 } 123 124 125 bool pmMaskBadPixels( 126 pmReadout *in, 127 const pmReadout *mask, 128 unsigned int maskVal, 129 float sat, 130 unsigned int growVal, 131 int grow) 132 { 133 // XXX: Review this code then put all asserts at the top. 134 PS_ASSERT_PTR_NON_NULL(in, true); 135 PS_ASSERT_PTR_NON_NULL(in->image, false); 136 PS_WARN_PTR_NON_NULL(in->parent); 137 if (in->parent != NULL) { 138 PS_WARN_PTR_NON_NULL(in->parent->concepts); 139 } 140 PS_ASSERT_PTR_NON_NULL(mask, false); 141 int i = 0; 142 int j = 0; 143 int totOffCol = 0; 144 int totOffRow = 0; 145 psElemType inType; 146 psElemType maskType; 147 psImage *inMask = NULL; 148 149 // 150 // Determine trimmed image from metadata. 151 // 152 psImage *trimmedImg = p_psDetermineTrimmedImage(in); 153 if(in->mask == NULL) { 154 in->mask = psImageAlloc(trimmedImg->numCols, trimmedImg->numRows, PS_TYPE_MASK); 155 PS_IMAGE_SET_U8(in->mask, 0); 73 inImage = in->image; 74 if (inImage == NULL) { 75 psError( PS_ERR_BAD_PARAMETER_NULL, true, 76 PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE); 77 return false; 78 } else if(in->mask == NULL) { 79 in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK); 80 memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK)); 156 81 } 157 82 inMask = in->mask; 158 83 159 84 // Check input image and its mask are not larger than mask 160 if( trimmedImg->numRows > mask->image->numRows || trimmedImg->numCols > mask->image->numCols) {85 if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) { 161 86 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 162 87 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE, 163 trimmedImg->numRows, trimmedImg->numCols, mask->image->numRows, mask->image->numCols);88 inImage->numRows, inImage->numCols, mask->numRows, mask->numCols); 164 89 return false; 165 } else if(inMask->numRows > mask->image->numRows || inMask->numCols > mask->image->numCols) {90 } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) { 166 91 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 167 92 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE, 168 inMask->numRows, inMask->numCols, mask-> image->numRows, mask->image->numCols);93 inMask->numRows, inMask->numCols, mask->numRows, mask->numCols); 169 94 return false; 170 95 } 171 96 172 97 // Determine total offset based on image offset with chip offset 173 totOffCol = trimmedImg->col0+ in->col0;174 totOffRow = trimmedImg->row0+ in->row0;98 totOffCol = inImage->col0; // + in->col0; 99 totOffRow = inImage->row0; // + in->row0; 175 100 176 101 // Check that offsets are within image limits 177 if(totOffRow>=mask-> image->numRows || totOffCol>=mask->image->numCols) {102 if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) { 178 103 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 179 104 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE, 180 totOffRow, totOffCol, mask-> image->numRows, mask->image->numCols);105 totOffRow, totOffCol, mask->numRows, mask->numCols); 181 106 return false; 182 } else if(totOffRow>= trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {107 } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) { 183 108 psError( PS_ERR_BAD_PARAMETER_SIZE, true, 184 109 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE, 185 totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);110 totOffRow, totOffCol, inImage->numRows, inImage->numCols); 186 111 return false; 187 112 } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) { … … 193 118 194 119 // Check for incorrect types 195 inType = trimmedImg->type.type;196 maskType = mask-> image->type.type;120 inType = inImage->type.type; 121 maskType = mask->type.type; 197 122 if(PS_IS_PSELEMTYPE_COMPLEX(inType)) { 198 123 psError( PS_ERR_BAD_PARAMETER_TYPE, true, … … 207 132 } 208 133 209 // 210 // This is the main loop which examines each pixel and masks pixels if 211 // A: The mask matches the maskValue 212 // B: The pixel is larger than the saturation value 213 // C: The pixel equals the grow value (in which case a circle is masked) 214 // 215 for(i=totOffRow; i<trimmedImg->numRows; i++) { 216 for(j=totOffCol; j<trimmedImg->numCols; j++) { 217 // 218 // A: Pixels which satisfy maskVal shall be masked 219 // 220 if (mask->image->data.U8[i][j] == maskVal) { 221 in->mask->data.U8[i][j] |= maskVal; 222 } 134 // Macro for all PS types 135 #define PM_BAD_PIXELS(TYPE) \ 136 case PS_TYPE_##TYPE: \ 137 for(j=totOffRow; j<inImage->numRows; j++) { \ 138 for(i=totOffCol; i<inImage->numCols; i++) { \ 139 \ 140 /* Pixels with flux greater than sat shall be masked */ \ 141 if(inImage->data.TYPE[j][i] > sat) { \ 142 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT; \ 143 } \ 144 \ 145 /* Pixels which satisfy maskVal shall be masked */ \ 146 inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal); \ 147 \ 148 /* Pixels which satisfy growVal and within the grow radius shall be masked */ \ 149 if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) { \ 150 rowMin = MAX(j-grow, 0); \ 151 rowMax = MIN(j+grow+1, inImage->numRows); \ 152 colMin = MAX(i-grow, 0); \ 153 colMax = MIN(i+grow+1, inImage->numCols); \ 154 for(jj=rowMin; jj<rowMax; jj++) { \ 155 for(ii=colMin; ii<colMax; ii++) { \ 156 r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j)); \ 157 rRound = r + 0.5; \ 158 if(rRound <= grow) { \ 159 inMask->data.PS_TYPE_MASK_DATA[jj][ii] |= \ 160 (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal); \ 161 } \ 162 } \ 163 } \ 164 } \ 165 } \ 166 } \ 167 break; 223 168 224 // 225 // We first determine how much we need to grow by and store this in 226 // growRadius. 227 // 228 psS32 growRadius = GetRadius(trimmedImg, j, i, sat, growVal, grow); 229 230 // 231 // Grow the pixel mask if necessary. 232 // 233 if (growRadius != 0) { 234 GrowPixel(in->mask, j, i, growRadius, maskVal); 235 } 236 } 169 // Switch to call bad pixel masking macro defined above 170 switch(inType) { 171 PM_BAD_PIXELS(U8); 172 PM_BAD_PIXELS(U16); 173 PM_BAD_PIXELS(U32); 174 PM_BAD_PIXELS(U64); 175 PM_BAD_PIXELS(S8); 176 PM_BAD_PIXELS(S16); 177 PM_BAD_PIXELS(S32); 178 PM_BAD_PIXELS(S64); 179 PM_BAD_PIXELS(F32); 180 PM_BAD_PIXELS(F64); 181 default: 182 psError( PS_ERR_BAD_PARAMETER_TYPE, true, 183 PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED, 184 inType); 237 185 } 238 186 239 return true;187 return false; 240 188 } -
trunk/psModules/src/detrend/pmMaskBadPixels.h
r5516 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmMaskBadPixels.h 2 7 * … … 19 24 * @author Ross Harman, MHPCC 20 25 * 21 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $22 * @date $Date: 200 5-11-15 20:09:03$26 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 27 * @date $Date: 2006-04-17 18:01:05 $ 23 28 * 24 29 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 31 27 32 #include "pslib.h" 28 #include "pm Astrometry.h"33 #include "pmFPA.h" 29 34 30 35 /** Mask values */ … … 33 38 PM_MASK_BADCOL = 0x0002, ///< The pixel is a bad column. 34 39 PM_MASK_SAT = 0x0004, ///< The pixel is saturated. 35 PM_MASK_FLAT = 0x0008 ///< The pixel is non-positive in the flat-field. 40 PM_MASK_BAD = 0x0008, ///< The pixel is low 41 PM_MASK_FLAT = 0x0010 ///< The pixel is non-positive in the flat-field. 36 42 } pmMaskValue; 37 43 38 // XXX: Use PS_MIN, PS_MAX39 44 /** Macro to find maximum of two numbers */ 40 45 #define MAX(A,B)((A)>=(B)?(A):(B)) … … 54 59 bool pmMaskBadPixels( 55 60 pmReadout *in, ///< Readout containing input image data. 56 const p mReadout *mask,///< Mask data to be added to readout mask data.61 const psImage *mask, ///< Mask data to be added to readout mask data. 57 62 unsigned int maskVal, ///< Mask value to determine what to add to input mask. 58 63 float sat, ///< Saturation limit to mask bad pixels. -
trunk/psModules/src/detrend/pmMaskBadPixelsErrors.h
r5170 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmMaskBadPixelsErrors.h 2 7 * … … 7 12 * @author Ross Harman, MHPCC 8 13 * 9 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $10 * @date $Date: 200 5-09-28 20:43:52$14 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-04-17 18:01:05 $ 11 16 * 12 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 28 * $2 The error text (rest of the line in pmMaskBadPixelsErrors.h) 24 29 * $n The order of the source line in pmMaskBadPixelsErrors.h (comments excluded) 25 * 30 * 26 31 * DO NOT EDIT THE LINES BETWEEN //~Start and //~End! ANY CHANGES WILL BE OVERWRITTEN. 27 32 */ -
trunk/psModules/src/detrend/pmNonLinear.c
r5675 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmNonLinear.c 2 7 * … … 5 10 * @author GLG, MHPCC 6 11 * 7 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-12-05 20:49:40$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 9 14 * 10 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 27 23 28 #include "pmNonLinear.h" 24 #include "pmSubtractBias.h"25 29 26 // XXX: Remove, autoconf must be27 #define PS_WARN_PTR_NON_NULL(NAME) \28 if ((NAME) == NULL) { \29 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \30 } \31 30 /****************************************************************************** 32 31 pmNonLinearityLookup(): This routine will take an pmReadout image as input 33 32 and a 1-D polynomial. For each pixel in the input image, the polynomial will 34 be evaluated at that pixels value, and the image pixel will then be set 35 to 33 be evaluated at that pixels value, and the image pixel will then be set to 36 34 that value. 37 *****************************************************************************/35 *****************************************************************************/ 38 36 39 pmReadout *pmNonLinearityPolynomial( 40 pmReadout *inputReadout, 41 const psPolynomial1D *input1DPoly) 37 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, 38 const psPolynomial1D *input1DPoly) 42 39 { 43 40 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL); … … 45 42 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 46 43 PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL); 47 PS_WARN_PTR_NON_NULL(inputReadout->parent);48 if (inputReadout->parent != NULL) {49 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts);50 }51 44 52 // 53 // Determine trimmed image from metadata. 54 // 55 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 45 psS32 i; 46 psS32 j; 56 47 57 for (psS32 i=0;i<trimmedImg->numRows;i++) { 58 for (psS32 j=0;j<trimmedImg->numCols;j++) { 59 trimmedImg->data.F32[i][j] = psPolynomial1DEval(input1DPoly, 60 trimmedImg->data.F32[i][j]); 48 for (i=0;i<inputReadout->image->numRows;i++) { 49 for (j=0;j<inputReadout->image->numCols;j++) { 50 inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]); 61 51 } 62 52 } … … 71 61 inFluxe, and the corresponding value in outFlux. The image pixel will then 72 62 be set to the value from outFlux. 73 74 XXX: Must assert that filename exists. This should probably happen in75 the lookup files.76 63 *****************************************************************************/ 77 pmReadout *pmNonLinearityLookup( 78 pmReadout *inputReadout, 79 const char *filename 80 ) 64 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, 65 const psVector *inFlux, 66 const psVector *outFlux) 81 67 { 82 68 PS_ASSERT_PTR_NON_NULL(inputReadout,NULL); 83 69 PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL); 84 70 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 85 PS_WARN_PTR_NON_NULL(inputReadout->parent); 86 if (inputReadout->parent != NULL) { 87 PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts); 71 PS_ASSERT_PTR_NON_NULL(inFlux,NULL); 72 if (inFlux->n < 2) { 73 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements. Returning inputReadout image."); 74 return(inputReadout); 88 75 } 89 // 90 // Determine trimmed image from metadata. 91 // 92 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 76 PS_ASSERT_PTR_NON_NULL(outFlux,NULL); 77 psS32 tableSize = inFlux->n; 78 if (inFlux->n != outFlux->n) { 79 tableSize = PS_MIN(inFlux->n, outFlux->n); 80 psLogMsg(__func__, PS_LOG_WARN, 81 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n); 82 } 83 PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL); 84 PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL); 93 85 94 psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0); 95 psS32 numLines = psLookupTableRead(tmpLT); 86 psS32 i; 87 psS32 j; 88 psS32 binNum; 89 psScalar x; 96 90 psS32 numPixels = 0; 97 if (numLines < 2) { 98 psLogMsg(__func__, PS_LOG_WARN, 99 "WARNING: Lookup Table is too small. Returning original pmReadout.\n"); 100 } else { 101 for (psS32 i=0;i<trimmedImg->numRows;i++) { 102 for (psS32 j=0;j<trimmedImg->numCols;j++) { 103 psF64 tmpD = psLookupTableInterpolate(tmpLT, trimmedImg->data.F32[i][j], 1); 104 if (!isnan(tmpD)) { 105 trimmedImg->data.F32[i][j] = tmpD; 106 } else { 107 numPixels++; 108 } 91 psF32 slope; 92 93 x.type.type = PS_TYPE_F32; 94 for (i=0;i<inputReadout->image->numRows;i++) { 95 for (j=0;j<inputReadout->image->numCols;j++) { 96 x.data.F32 = inputReadout->image->data.F32[i][j]; 97 binNum = p_psVectorBinDisect((psVector *)inFlux, &x); 98 99 if (binNum == -2) { 100 // We get here if x is below the table lookup range. 101 inputReadout->image->data.F32[i][j] = outFlux->data.F32[0]; 102 numPixels++; 103 104 } else if (binNum == -1) { 105 // We get here if x is above the table lookup range. 106 inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1]; 107 numPixels++; 108 109 } else if (binNum < -2) { 110 // We get here if there was some other problem. 111 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). Returning inputReadout image."); 112 return(inputReadout); 113 numPixels++; 114 } else { 115 // Perform linear interpolation. 116 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) / 117 (inFlux->data.F32[binNum+1] - inFlux->data.F32[binNum]); 118 inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] + 119 ((x.data.F32 - inFlux->data.F32[binNum]) * slope); 109 120 } 110 121 } 111 if (numPixels > 0) {112 psLogMsg(__func__, PS_LOG_WARN,113 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);114 }115 122 } 116 123 if (numPixels > 0) { 124 psLogMsg(__func__, PS_LOG_WARN, 125 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 126 } 117 127 return(inputReadout); 118 128 } -
trunk/psModules/src/detrend/pmNonLinear.h
r5435 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmNonLinear.h 2 7 * … … 5 10 * @author GLG, MHPCC 6 11 * 7 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-10-20 23:06:24$12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 9 14 * 10 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 21 17 22 #include "pslib.h" 18 #include "pm Astrometry.h"23 #include "pmFPA.h" 19 24 20 pmReadout *pmNonLinearityPolynomial( 21 pmReadout *in, 22 const psPolynomial1D *coeff 23 ); 25 pmReadout *pmNonLinearityPolynomial(pmReadout *in, 26 const psPolynomial1D *coeff); 24 27 25 pmReadout *pmNonLinearityLookup( 26 pmReadout *in, 27 const char *filename 28 ); 28 pmReadout *pmNonLinearityLookup(pmReadout *in, 29 const psVector *inFlux, 30 const psVector *outFlux); 29 31 30 32 #endif -
trunk/psModules/src/imcombine/Makefile.am
r5170 r6872 3 3 libpsmoduleimcombine_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 4 4 libpsmoduleimcombine_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 libpsmoduleimcombine_la_SOURCES = pmImageCombine.c \6 pmReadoutCombine.c5 libpsmoduleimcombine_la_SOURCES = pmImageCombine.c 6 # pmReadoutCombine.c 7 7 8 8 psmoduleincludedir = $(includedir) 9 9 psmoduleinclude_HEADERS = \ 10 pmImageCombine.h \11 pmReadoutCombine.h10 pmImageCombine.h 11 # pmReadoutCombine.h -
trunk/psModules/src/imcombine/pmReadoutCombine.h
r6205 r6872 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-0 1-26 21:10:50$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-04-17 18:01:05 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include "pslib.h" 24 24 #include "psConstants.h" 25 #include "pm Astrometry.h"25 #include "pmFPA.h" 26 26 27 27 typedef struct … … 33 33 int nKeep; 34 34 } 35 psCombineParams; 35 pmCombineParams; 36 37 pmCombineParams *pmCombineParamsAlloc (psStatsOptions statsOptions); 36 38 37 39 psImage *pmReadoutCombine(psImage *output, 38 const psList *inputs, 39 psCombineParams *params, 40 const psArray *inputs, 40 41 const psVector *zero, 41 42 const psVector *scale, 43 pmCombineParams *params, 42 44 bool applyZeroScale, 43 45 float gain, … … 72 74 pmFringePoint; 73 75 74 75 /**76 *77 * The input array fluxLevels consists of Ni vectors, one per mosaic image.78 * Each vector consists of Nj elements, each a measurement of the input79 * flat-field image flux levels. All of these vectors must be constructed with80 * the same number of elements, or the function will return an error. If a chip81 * is missing from a particular image, that element should be set to NaN. The82 * vector chipGains supplies initial guesses for the chip gains. If the vector83 * contains the values 0.0 or NaN for any of the elements, the gain is set to the84 * mean of the valid values. If the vector length does not match the number of85 * chips, an warning is raised, all chip gain guesses will be set to 1.0, and the86 * vector length modified to match the number of chips defined by the supplied87 * fluxLevels. The sourceFlux input vector must be allocated (not NULL), but the88 * routine will set the vector length to the number of source images regardless89 * of the initial state of the vector. All vectors used by this function must be90 * of type PS_DATA_F64.91 *92 */93 bool pmFlatNormalization(94 psVector *sourceFlux,95 psVector *chipGains,96 psArray *fluxLevels97 );98 99 100 76 #endif -
trunk/psModules/src/imsubtract/Makefile.am
r5170 r6872 4 4 libpsmoduleimsubtract_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 5 libpsmoduleimsubtract_la_SOURCES = pmImageSubtract.c \ 6 pmSubtractBias.c \7 pmSubtractSky.c6 pmSubtractBias.c 7 # pmSubtractSky.c 8 8 9 9 psmoduleincludedir = $(includedir) 10 10 psmoduleinclude_HEADERS = \ 11 11 pmImageSubtract.h \ 12 pmSubtractBias.h \13 pmSubtractSky.h12 pmSubtractBias.h 13 # pmSubtractSky.h -
trunk/psModules/src/imsubtract/pmSubtractBias.h
r5587 r6872 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the 3 // one that was being worked on. 4 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 1 6 /** @file pmSubtractBias.h 2 7 * … … 6 11 * @author GLG, MHPCC 7 12 * 8 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * @date $Date: 200 5-11-23 23:54:30$13 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-04-17 18:01:05 $ 10 15 * 11 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 28 #include<math.h> 24 29 #include "pslib.h" 25 #include "pmAstrometry.h" 30 31 #include "pmFPA.h" 26 32 27 33 typedef enum { 28 34 PM_OVERSCAN_NONE, ///< No overscan subtraction 35 PM_OVERSCAN_EDGE, ///< Subtract the statistic of pixels along the to-be-determined readout direction 29 36 PM_OVERSCAN_ROWS, ///< Subtract rows 30 37 PM_OVERSCAN_COLUMNS, ///< Subtract columns … … 33 40 34 41 typedef enum { 35 PM_FIT_NONE, ///< No fit 36 PM_FIT_POLYNOMIAL, ///< Fit polynomial 37 PM_FIT_SPLINE ///< Fit cubic splines 42 PM_FIT_NONE, ///< No fit 43 PM_FIT_POLY_ORD, ///< Fit ordinary polynomial 44 PM_FIT_POLY_CHEBY, ///< Fit Chebyshev polynomial 45 PM_FIT_SPLINE ///< Fit cubic splines 38 46 } pmFit; 39 47 40 pmReadout *pmSubtractBias( 41 pmReadout *in, ///< The input pmReadout image 42 void *fitSpec, ///< A polynomial or spline, defining the fit type. 43 pmFit fit, ///< PM_FIT_SPLINE, PM_FIT_POLYNOMIAL, or PM_FIT_NONE 44 bool overscan, 45 psStats *stat, ///< The statistic to be used in combining overscan data 46 int nBin, ///< The amount of binning to be done image pixels. 47 const pmReadout *bias, ///< A possibly NULL bias pmReadout which is to be subtracted 48 const pmReadout *dark ///< A possibly NULL bias pmReadout which is to be subtracted 49 ); 48 typedef struct 49 { 50 // Inputs 51 bool single; // Reduce all overscan regions to a single value? 52 pmFit fitType; // Type of fit to overscan 53 unsigned int order; // Order of polynomial, or number of spline pieces 54 psStats *stat; // Statistic to use when reducing the minor direction 55 // Outputs 56 psPolynomial1D *poly; // Result of polynomial fit 57 psSpline1D *spline; // Result of spline fit 58 } 59 pmOverscanOptions; 50 60 51 /****************************************************************************** 52 DetermineTrimmedImageg() This private routine determines the region of the 53 input pmReadout which will be operated on by the various detrend modules. It 54 does a metadata fetch on "CELL.TRIMSEC" for the parent cell of the pmReadout. 55 56 XXX: Consider making a pmUtils.c file and put this routine there. 57 *****************************************************************************/ 58 psImage *p_psDetermineTrimmedImage( 59 pmReadout *in 60 ); 61 pmOverscanOptions *pmOverscanOptionsAlloc(bool single, pmFit fitType, unsigned int order, psStats *stat); 62 63 pmReadout *pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts, 64 const pmReadout *bias, const pmReadout *dark); 65 66 #if 0 67 pmReadout *pmSubtractBias(pmReadout *in, ///< The input pmReadout image 68 void *fitSpec, ///< A polynomial or spline, defining the fit type. 69 const psList *overscans, ///< A psList of overscan images 70 pmOverscanAxis overScanAxis, ///< Defines how overscans are applied 71 psStats *stat, ///< The statistic to be used in combining overscan data 72 int nBin, ///< The amount of binning to be done image pixels. 73 pmFit fit, ///< PM_FIT_SPLINE, PM_FIT_POLYNOMIAL, or PM_FIT_NONE 74 const pmReadout *bias); ///< A possibly NULL bias pmReadout which is to be subtracted 75 #endif 61 76 62 77 #endif -
trunk/psModules/src/imsubtract/pmSubtractSky.h
r5170 r6872 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 200 5-09-28 20:43:52$8 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-04-17 18:01:05 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include<math.h> 24 24 #include "pslib.h" 25 #include "pm Astrometry.h"25 #include "pmFPA.h" 26 26 27 27 // XXX: this is pmFit in pmSubtractBias.c, named psFit here. -
trunk/psModules/src/objects/Makefile.am
r5844 r6872 1 1 noinst_LTLIBRARIES = libpsmoduleobjects.la 2 2 3 libpsmoduleobjects_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) 3 libpsmoduleobjects_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) -I../pslib/ 4 4 libpsmoduleobjects_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 5 libpsmoduleobjects_la_SOURCES = \ 6 pmObjects.c \ 7 pmPSF.c \ 8 pmPSFtry.c \ 9 pmModelGroup.c \ 10 psEllipse.c 6 pmPeaks.c \ 7 pmMoments.c \ 8 pmModel.c \ 9 pmModelGroup.c \ 10 pmSource.c \ 11 pmSourceSky.c \ 12 pmSourceContour.c \ 13 pmSourceFitModel.c \ 14 pmSourcePhotometry.c \ 15 pmSourceIO.c \ 16 pmSourceIO_CMF.c \ 17 pmSourceIO_CMP.c \ 18 pmSourceIO_OBJ.c \ 19 pmSourceIO_SX.c \ 20 pmSourceIO_RAW.c \ 21 pmPSF.c \ 22 pmPSF_IO.c \ 23 pmPSFtry.c \ 24 pmGrowthCurve.c 11 25 12 26 EXTRA_DIST = \ … … 18 32 psmoduleincludedir = $(includedir) 19 33 psmoduleinclude_HEADERS = \ 20 pmObjects.h \ 21 pmPSF.h \ 22 pmPSFtry.h \ 23 pmModelGroup.h \ 24 psEllipse.h 34 pmPeaks.h \ 35 pmMoments.h \ 36 pmModel.h \ 37 pmModelGroup.h \ 38 pmSource.h \ 39 pmSourceSky.h \ 40 pmSourceContour.h \ 41 pmSourceFitModel.h \ 42 pmSourcePhotometry.h \ 43 pmSourceIO.h \ 44 pmPSF.h \ 45 pmPSF_IO.h \ 46 pmPSFtry.h \ 47 pmGrowthCurve.h -
trunk/psModules/src/objects/models/pmModel_PGAUSS.c
r6511 r6872 26 26 27 27 if (deriv != NULL) { 28 // note difference from a pure gaussian: q = PAR[1]*r28 psF32 *dPAR = deriv->data.F32; 29 29 psF32 q = PAR[1]*r*r*t; 30 d eriv->data.F32[0] = +1.0;31 d eriv->data.F32[1] = +r;32 d eriv->data.F32[2] = q*(2.0*px*PAR[4] + PAR[6]*Y);33 d eriv->data.F32[3] = q*(2.0*py*PAR[5] + PAR[6]*X);34 d eriv->data.F32[4] = -2.0*q*px*X;35 d eriv->data.F32[5] = -2.0*q*py*Y;36 d eriv->data.F32[6] = -q*X*Y;30 dPAR[0] = +1.0; 31 dPAR[1] = +r; 32 dPAR[2] = q*(2.0*px*PAR[4] + PAR[6]*Y); 33 dPAR[3] = q*(2.0*py*PAR[5] + PAR[6]*X); 34 dPAR[4] = -2.0*q*px*X; 35 dPAR[5] = -2.0*q*py*Y; 36 dPAR[6] = -q*X*Y; 37 37 } 38 38 return(f); … … 50 50 51 51 beta_lim[0][0].data.F32[0] = 1000; 52 beta_lim[0][0].data.F32[1] = 10000;52 beta_lim[0][0].data.F32[1] = 3e6; 53 53 beta_lim[0][0].data.F32[2] = 5; 54 54 beta_lim[0][0].data.F32[3] = 5; … … 66 66 67 67 params_max[0][0].data.F32[0] = 1e5; 68 params_max[0][0].data.F32[1] = 1e 6;68 params_max[0][0].data.F32[1] = 1e8; 69 69 params_max[0][0].data.F32[2] = 1e4; // this should be set by image dimensions! 70 70 params_max[0][0].data.F32[3] = 1e4; // this should be set by image dimensions! … … 133 133 params[5] = 1.2 / moments->Sy; 134 134 params[6] = 0.0; 135 135 136 return(true); 136 137 } -
trunk/psModules/src/objects/models/pmModel_QGAUSS.c
r6511 r6872 26 26 psF32 py = PAR[5]*Y; 27 27 psF32 z = 0.5*PS_SQR(px) + 0.5*PS_SQR(py) + PAR[6]*X*Y; 28 29 psF32 r = 1.0 / (1 + PAR[7]*z + pow(z, 2.25)); 30 psF32 f = PAR[1]*r + PAR[0]; 28 psF32 zp = pow(z,1.25); 29 30 psF32 r = 1.0 / (1 + PAR[7]*z + z*zp); 31 // test: psF32 r = 1.0 / (1 + PAR[7]*z + PS_SQR(z)); 32 psF32 r1 = PAR[1]*r; 33 psF32 f = r1 + PAR[0]; 31 34 32 35 if (deriv != NULL) { 36 psF32 *dPAR = deriv->data.F32; 37 33 38 // note difference from a pure gaussian: q = params->data.F32[1]*r 34 psF32 t = PAR[1]*r*r; 35 psF32 q = t*(PAR[7] + 2.25*pow(z, 1.25)); 36 37 deriv->data.F32[0] = +1.0; 38 deriv->data.F32[1] = +r; 39 deriv->data.F32[2] = q*(2.0*px*PAR[4] + PAR[6]*Y); 40 deriv->data.F32[3] = q*(2.0*py*PAR[5] + PAR[6]*X); 41 deriv->data.F32[4] = -2.0*q*px*X; 42 deriv->data.F32[5] = -2.0*q*py*Y; 43 deriv->data.F32[6] = -q*X*Y; 44 deriv->data.F32[7] = -t*z; 39 psF32 t = r1*r; 40 psF32 q = t*(PAR[7] + 2.25*zp); 41 // test: psF32 q = t*(PAR[7] + 2*z); 42 43 dPAR[0] = +1.0; 44 dPAR[1] = +r; 45 dPAR[2] = q*(2.0*px*PAR[4] + PAR[6]*Y); 46 dPAR[3] = q*(2.0*py*PAR[5] + PAR[6]*X); 47 dPAR[4] = -2.0*q*px*X; 48 dPAR[5] = -2.0*q*py*Y; 49 dPAR[6] = -q*X*Y; 50 dPAR[7] = -t*z; 45 51 } 46 52 return(f); … … 58 64 59 65 beta_lim[0][0].data.F32[0] = 1000; 60 beta_lim[0][0].data.F32[1] = 10000;66 beta_lim[0][0].data.F32[1] = 3e6; 61 67 beta_lim[0][0].data.F32[2] = 5; 62 68 beta_lim[0][0].data.F32[3] = 5; … … 76 82 77 83 params_max[0][0].data.F32[0] = 1e5; 78 params_max[0][0].data.F32[1] = 1e 6;84 params_max[0][0].data.F32[1] = 1e8; 79 85 params_max[0][0].data.F32[2] = 1e4; // this should be set by image dimensions! 80 86 params_max[0][0].data.F32[3] = 1e4; // this should be set by image dimensions! … … 102 108 params[6] = 0.0; 103 109 params[7] = 1.0; 110 104 111 return(true); 105 112 } … … 119 126 // the area needs to be multiplied by the integral of f(z) 120 127 norm = 0.0; 121 for (z = 0.0 05; z < 50; z += 0.01) {128 for (z = 0.05; z < 50; z += 0.1) { 122 129 f = 1.0 / (1 + PAR[7]*z + pow(z, 2.25)); 130 // test: f = 1.0 / (1 + PAR[7]*z + PS_SQR(z)); 123 131 norm += f; 124 132 } 125 norm *= 0. 01;133 norm *= 0.1; 126 134 127 135 psF64 Flux = PAR[1] * Area * norm; … … 150 158 151 159 // we can do this much better with intelligent choices here 152 for (z = 0.0; z < 20.0; z += dz) {160 for (z = 0.0; z < 30.0; z += dz) { 153 161 f = 1.0 / (1 + PAR[7]*z + pow(z, 2.25)); 162 // test: f = 1.0 / (1 + PAR[7]*z + PS_SQR(z)); 154 163 if (f < limit) 155 164 break; … … 201 210 status &= ((dPAR[1]/PAR[1]) < 0.5); 202 211 203 if ( status)204 return true;205 return false;206 } 212 if (!status) 213 return false; 214 return true; 215 } -
trunk/psModules/src/objects/models/pmModel_RGAUSS.c
r5257 r6872 117 117 psVector *params = model->params; 118 118 119 EllipseAxes axes;120 EllipseShape shape;121 EllipseMoments moments;119 psEllipseAxes axes; 120 psEllipseShape shape; 121 psEllipseMoments moments; 122 122 123 123 moments.x2 = PS_SQR(source->moments->Sx); … … 125 125 moments.xy = source->moments->Sxy; 126 126 127 axes = EllipseMomentsToAxes(moments);128 shape = EllipseAxesToShape(axes);127 axes = psEllipseMomentsToAxes(moments); 128 shape = psEllipseAxesToShape(axes); 129 129 130 130 params->data.F32[0] = source->moments->Sky; -
trunk/psModules/src/objects/models/pmModel_SGAUSS.c
r6511 r6872 17 17 18 18 # define SQ(A)((A)*(A)) 19 psF64 psImageEllipseContour ( EllipseAxes axes, double xc, double yc, psImage *image);19 psF64 psImageEllipseContour (psEllipseAxes axes, double xc, double yc, psImage *image); 20 20 psF64 p_psImageGetElementF64(psImage *a, int i, int j); 21 21 … … 102 102 103 103 // measure the flux for the elliptical contour 104 psF64 psImageEllipseContour ( EllipseAxes axes, double xc, double yc, psImage *image)104 psF64 psImageEllipseContour (psEllipseAxes axes, double xc, double yc, psImage *image) 105 105 { 106 106 … … 149 149 psF32 *params = model->params->data.F32; 150 150 151 EllipseAxes axes;152 EllipseShape shape;153 EllipseMoments moments;151 psEllipseAxes axes; 152 psEllipseShape shape; 153 psEllipseMoments moments; 154 154 155 155 moments.x2 = PS_SQR(sMoments->Sx); … … 158 158 159 159 // solve the math to go from Moments To Shape 160 axes = EllipseMomentsToAxes(moments);161 shape = EllipseAxesToShape(axes);160 axes = psEllipseMomentsToAxes(moments); 161 shape = psEllipseAxesToShape(axes); 162 162 163 163 params[0] = sMoments->Sky; … … 199 199 float f1, f2; 200 200 201 EllipseAxes axes;202 EllipseShape shape;203 EllipseMoments moments;201 psEllipseAxes axes; 202 psEllipseShape shape; 203 psEllipseMoments moments; 204 204 205 205 moments.x2 = PS_SQR(sMoments->Sx); … … 208 208 209 209 // solve the math to go from Moments To Shape 210 axes = EllipseMomentsToAxes(moments);211 shape = EllipseAxesToShape(axes);210 axes = psEllipseMomentsToAxes(moments); 211 shape = psEllipseAxesToShape(axes); 212 212 213 213 params[0] = sMoments->Sky; … … 265 265 psF64 pmModelRadius_SGAUSS (const psVector *params, psF64 flux) 266 266 { 267 psF64 r, z , pr, f;267 psF64 r, z = 0.0, pr, f; 268 268 psF32 *PAR = params->data.F32; 269 269 270 EllipseAxes axes;271 EllipseShape shape;270 psEllipseAxes axes; 271 psEllipseShape shape; 272 272 273 273 if (flux <= 0) … … 283 283 shape.sxy = PAR[6]; 284 284 285 axes = EllipseShapeToAxes (shape);285 axes = psEllipseShapeToAxes (shape); 286 286 psF64 dr = 1.0 / axes.major; 287 287 psF64 limit = flux / PAR[1]; … … 327 327 psF32 dP; 328 328 bool status; 329 EllipseAxes axes;330 EllipseShape shape;329 psEllipseAxes axes; 330 psEllipseShape shape; 331 331 332 332 psF32 *PAR = model->params->data.F32; … … 337 337 shape.sxy = PAR[6]; 338 338 339 axes = EllipseShapeToAxes (shape);339 axes = psEllipseShapeToAxes (shape); 340 340 341 341 dP = 0; -
trunk/psModules/src/objects/models/pmModel_ZGAUSS.c
r5257 r6872 85 85 psF32 *PAR = params->data.F32; 86 86 87 EllipseAxes axes;88 EllipseShape shape;87 psEllipseAxes axes; 88 psEllipseShape shape; 89 89 90 90 if (flux <= 0) … … 100 100 shape.sxy = PAR[6]; 101 101 102 axes = EllipseShapeToAxes (shape);102 axes = psEllipseShapeToAxes (shape); 103 103 psF64 dr = 1.0 / axes.major; 104 104 psF64 limit = flux / PAR[1]; … … 124 124 psVector *params = model->params; 125 125 126 EllipseAxes axes;127 EllipseShape shape;128 EllipseMoments moments;126 psEllipseAxes axes; 127 psEllipseShape shape; 128 psEllipseMoments moments; 129 129 130 130 moments.x2 = PS_SQR(source->moments->Sx); … … 132 132 moments.xy = source->moments->Sxy; 133 133 134 axes = EllipseMomentsToAxes(moments);135 shape = EllipseAxesToShape(axes);134 axes = psEllipseMomentsToAxes(moments); 135 shape = psEllipseAxesToShape(axes); 136 136 137 137 params->data.F32[0] = source->moments->Sky; -
trunk/psModules/src/objects/pmModelGroup.c
r5844 r6872 1 # include "pmModelGroup.h" 2 1 /** @file pmModelGroup.c 2 * 3 * Functions to define and manipulate object model attributes 4 * 5 * @author GLG, MHPCC 6 * @author EAM, IfA 7 * 8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-04-17 18:01:05 $ 10 * 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 12 * 13 */ 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include "pslib.h" 19 #include "psEllipse.h" 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmPeaks.h" 23 #include "pmMoments.h" 24 #include "pmGrowthCurve.h" 25 #include "pmModel.h" 26 #include "pmPSF.h" 27 #include "pmSource.h" 28 #include "pmModelGroup.h" 29 30 // XXX shouldn't these be defined for us in pslib.h ??? 3 31 double hypot(double x, double y); 4 32 double sqrt (double x); 5 33 6 #include "psEllipse.h"7 34 #include "models/pmModel_GAUSS.c" 8 35 #include "models/pmModel_PGAUSS.c" … … 25 52 if (modelGroup == NULL) 26 53 return; 27 psFree (modelGroup);28 54 return; 29 55 } … … 60 86 } 61 87 Nmodels = Nnew; 88 return; 89 } 90 91 void pmModelGroupCleanup (void) 92 { 93 94 psFree (models); 62 95 return; 63 96 } … … 153 186 return (models[type].name); 154 187 } 188 189 /****************************************************************************** 190 pmSourceModelGuess(source, model): This function allocates a new 191 pmModel structure based on the given modelType specified in the argument list. 192 The corresponding pmModelGuess function is returned, and used to 193 supply the values of the params array in the pmModel structure. 194 195 XXX: Many parameters are based on the src->moments structure, which is in 196 image, not subImage coords. Therefore, the calls to the model evaluation 197 functions will be in image, not subImage coords. Remember this. 198 *****************************************************************************/ 199 pmModel *pmSourceModelGuess(pmSource *source, 200 pmModelType modelType) 201 { 202 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 203 PS_ASSERT_PTR_NON_NULL(source->moments, false); 204 PS_ASSERT_PTR_NON_NULL(source->peak, false); 205 206 pmModel *model = pmModelAlloc(modelType); 207 208 pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType); 209 modelGuessFunc(model, source); 210 psTrace(__func__, 3, "---- %s() end ----\n", __func__); 211 return(model); 212 } 213 -
trunk/psModules/src/objects/pmModelGroup.h
r5844 r6872 9 9 * @author EAM, IfA 10 10 * 11 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $12 * @date $Date: 200 5-12-24 01:24:32$11 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-04-17 18:01:05 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 * 16 16 */ 17 #include "pmObjects.h" 18 #include "pmPSF.h" 19 /** 20 * 21 * This function returns the number of parameters used by the listed function. 22 * 17 18 # ifndef PM_MODEL_GROUP_H 19 # define PM_MODEL_GROUP_H 20 21 // This function is the model chi-square minimization function for this model. 22 typedef psMinimizeLMChi2Func pmModelFunc; 23 24 // This function returns the integrated flux for the given model parameters. 25 typedef psF64 (*pmModelFlux)(const psVector *params); 26 27 28 // This function returns the radius at which the given model and parameters 29 // achieves the given flux. 30 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 31 32 /* This function sets the model parameter limits vectors for the given model 33 */ 34 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 35 36 /* This function provides the model guess parameters based on the details of 37 * the given source. 38 */ 39 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 40 41 42 /* This function constructs the PSF model for the given source based on the 43 * supplied psf and the EXT model for the object. 44 */ 45 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf); 46 47 /* This function returns the success / failure status of the given model fit 48 */ 49 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 50 51 /* Every model instance belongs to a class of models, defined by the value of 52 * the pmModelType type entry. Various functions need access to information about 53 * each of the models. Some of this information varies from model to model, and 54 * may depend on the current parameter values or other data quantities. In order 55 * to keep the code from requiring the information about each model to be coded 56 * into the low-level fitting routines, we define a collection of functions which 57 * allow us to abstract this type of model-dependent information. These generic 58 * functions take the model type and return the corresponding function pointer 59 * for the specified model. Each model is defined by creating this collection of 60 * specific functions, and placing them in a single file for each model. We 61 * define the following structure to carry the collection of information about 62 * the models. 63 */ 64 typedef struct 65 { 66 char *name; 67 int nParams; 68 pmModelFunc modelFunc; 69 pmModelFlux modelFlux; 70 pmModelRadius modelRadius; 71 pmModelLimits modelLimits; 72 pmModelGuessFunc modelGuessFunc; 73 pmModelFromPSFFunc modelFromPSFFunc; 74 pmModelFitStatusFunc modelFitStatusFunc; 75 } 76 pmModelGroup; 77 78 // allocate a pmModelGroup to hold nModels entries 79 pmModelGroup *pmModelGroupAlloc (int nModels); 80 81 // initialize the internal (static) model group with the default models 82 void pmModelGroupInit (void); 83 84 // free the internal (static) model group 85 void pmModelGroupCleanup (void); 86 87 // add a new model to the internal (static) model group 88 void pmModelGroupAdd (pmModelGroup *model); 89 90 /* This function returns the number of parameters used by the listed function. 23 91 */ 24 92 int pmModelParameterCount( … … 27 95 28 96 29 /** 30 * 31 * This function returns the user-space model names for the specified model type. 32 * 97 /* This function returns the user-space model names for the specified model type. 33 98 */ 34 99 char *pmModelGetType( … … 46 111 ); 47 112 48 49 #ifndef PM_MODEL_GROUP_H50 #define PM_MODEL_GROUP_H51 52 /**53 *54 * This function is the model chi-square minimization function for this model.55 *56 */57 typedef psMinimizeLMChi2Func pmModelFunc;58 59 60 /**61 *62 * This function returns the integrated flux for the given model parameters.63 */64 typedef psF64 (*pmModelFlux)(const psVector *params);65 66 67 /**68 *69 * This function returns the radius at which the given model and parameters70 * achieves the given flux.71 *72 */73 typedef psF64 (*pmModelRadius)(const psVector *params, double flux);74 75 /**76 *77 * This function sets the model parameter limits vectors for the given model78 *79 */80 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max);81 82 /**83 *84 * This function provides the model guess parameters based on the details of85 * the given source.86 *87 */88 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);89 90 91 /**92 *93 * This function constructs the PSF model for the given source based on the94 * supplied psf and the FLT model for the object.95 *96 */97 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf);98 99 /**100 *101 * This function returns the success / failure status of the given model fit102 *103 */104 typedef bool (*pmModelFitStatusFunc)(pmModel *model);105 106 113 /** 107 114 * … … 110 117 * 111 118 */ 112 113 119 114 120 /** … … 177 183 178 184 185 /** pmSourceModelGuess() 186 * 187 * Convert available data to an initial guess for the given model. This 188 * function allocates a pmModel entry for the pmSource structure based on the 189 * provided model selection. The method of defining the model parameter guesses 190 * are specified for each model below. The guess values are placed in the model 191 * parameters. The function returns TRUE on success or FALSE on failure. 192 * 193 */ 194 pmModel *pmSourceModelGuess( 195 pmSource *source, ///< The input pmSource 196 pmModelType model ///< The type of model to be created. 197 ); 179 198 180 181 /** 182 * 183 * Every model instance belongs to a class of models, defined by the value of 184 * the pmModelType type entry. Various functions need access to information about 185 * each of the models. Some of this information varies from model to model, and 186 * may depend on the current parameter values or other data quantities. In order 187 * to keep the code from requiring the information about each model to be coded 188 * into the low-level fitting routines, we define a collection of functions which 189 * allow us to abstract this type of model-dependent information. These generic 190 * functions take the model type and return the corresponding function pointer 191 * for the specified model. Each model is defined by creating this collection of 192 * specific functions, and placing them in a single file for each model. We 193 * define the following structure to carry the collection of information about 194 * the models. 195 * 196 */ 197 typedef struct 198 { 199 char *name; 200 int nParams; 201 pmModelFunc modelFunc; 202 pmModelFlux modelFlux; 203 pmModelRadius modelRadius; 204 pmModelLimits modelLimits; 205 pmModelGuessFunc modelGuessFunc; 206 pmModelFromPSFFunc modelFromPSFFunc; 207 pmModelFitStatusFunc modelFitStatusFunc; 208 } 209 pmModelGroup; 210 211 // allocate a pmModelGroup to hold nModels entries 212 pmModelGroup *pmModelGroupAlloc (int nModels); 213 214 // initialize the internal (static) model group with the default models 215 void pmModelGroupInit (void); 216 217 // add a new model to the internal (static) model group 218 void pmModelGroupAdd (pmModelGroup *model); 219 220 # endif 199 # endif /* PM_MODEL_GROUP_H */ -
trunk/psModules/src/objects/pmObjects.h
r5844 r6872 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $13 * @date $Date: 200 5-12-24 01:24:32$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include <math.h> 28 28 #include "pslib.h" 29 #include "pmAstrometry.h"30 /**31 * In the object analysis process, we will use specific mask values to mark the32 * image pixels. The following structure defines the relevant mask values.33 *34 * XXX: This is probably a bad solution: we will want to set mask values35 * outside of the PSPHOT code. Perhaps we can set up a registered set of mask36 * values with specific meanings that other functions can add to or define?37 */38 typedef enum {39 PSPHOT_MASK_CLEAR = 0x00,40 PSPHOT_MASK_INVALID = 0x01,41 PSPHOT_MASK_SATURATED = 0x02,42 PSPHOT_MASK_MARKED = 0x08,43 } psphotMaskValues;44 45 46 /** pmPeakType47 *48 * A peak pixel may have several features which may be determined when the49 * peak is found or measured. These are specified by the pmPeakType enum.50 * PM_PEAK_LONE represents a single pixel which is higher than its 8 immediate51 * neighbors. The PM_PEAK_EDGE represents a peak pixel which touching the image52 * edge. The PM_PEAK_FLAT represents a peak pixel which has more than a specific53 * number of neighbors at the same value, within some tolarence:54 *55 */56 typedef enum {57 PM_PEAK_LONE, ///< Isolated peak.58 PM_PEAK_EDGE, ///< Peak on edge.59 PM_PEAK_FLAT, ///< Peak has equal-value neighbors.60 PM_PEAK_UNDEF ///< Undefined.61 } pmPeakType;62 63 64 /** pmPeak data structure65 *66 * A source has the capacity for several types of measurements. The67 * simplest measurement of a source is the location and flux of the peak pixel68 * associated with the source:69 *70 */71 typedef struct72 {73 int x; ///< X-coordinate of peak pixel.74 int y; ///< Y-coordinate of peak pixel.75 float counts; ///< Value of peak pixel (above sky?).76 pmPeakType class; ///< Description of peak.77 }78 pmPeak;79 80 81 /** pmMoments data structure82 *83 * One of the simplest measurements which can be made quickly for an object84 * are the object moments. We specify a structure to carry the moment information85 * for a specific source:86 *87 */88 typedef struct89 {90 float x; ///< X-coord of centroid.91 float y; ///< Y-coord of centroid.92 float Sx; ///< x-second moment.93 float Sy; ///< y-second moment.94 float Sxy; ///< xy cross moment.95 float Sum; ///< Pixel sum above sky (background).96 float Peak; ///< Peak counts above sky.97 float Sky; ///< Sky level (background).98 float SN; ///< approx signal-to-noise99 int nPixels; ///< Number of pixels used.100 }101 pmMoments;102 103 104 /** pmPSFClump data structure105 *106 * A collection of object moment measurements can be used to determine107 * approximate object classes. The key to this analysis is the location and108 * statistics (in the second-moment plane,109 *110 */111 typedef struct112 {113 float X;114 float dX;115 float Y;116 float dY;117 }118 pmPSFClump;119 120 // type of model carried by the pmModel structure121 typedef int pmModelType;122 123 typedef enum {124 PM_MODEL_UNTRIED, ///< model fit not yet attempted125 PM_MODEL_SUCCESS, ///< model fit succeeded126 PM_MODEL_NONCONVERGE, ///< model fit did not converge127 PM_MODEL_OFFIMAGE, ///< model fit drove out of range128 PM_MODEL_BADARGS ///< model fit called with invalid args129 } pmModelStatus;130 131 /** pmModel data structure132 *133 * Every source may have two types of models: a PSF model and a FLT (floating)134 * model. The PSF model represents the best fit of the image PSF to the specific135 * object. In this case, the PSF-dependent parameters are specified for the136 * object by the PSF, not by the fit. The FLT model represents the best fit of137 * the given model to the object, with all parameters floating in the fit.138 *139 */140 typedef struct141 {142 pmModelType type; ///< Model to be used.143 psVector *params; ///< Paramater values.144 psVector *dparams; ///< Parameter errors.145 float chisq; ///< Fit chi-squared.146 int nDOF; ///< number of degrees of freedom147 int nIter; ///< number of iterations to reach min148 int status; ///< fit status149 float radius; ///< fit radius actually used150 }151 pmModel;152 153 /** pmSourceType enumeration154 *155 * A given source may be identified as most-likely to be one of several source156 * types. The pmSource entry pmSourceType defines the current best-guess for this157 * source.158 *159 * XXX: The values given below are currently illustrative and will require160 * some modification as the source classification code is developed. (TBD)161 *162 */163 typedef enum {164 PM_SOURCE_DEFECT, ///< a cosmic-ray165 PM_SOURCE_SATURATED, ///< random saturated pixels166 167 PM_SOURCE_SATSTAR, ///< a saturated star168 PM_SOURCE_PSFSTAR, ///< a PSF star169 PM_SOURCE_GOODSTAR, ///< a good-quality star170 171 PM_SOURCE_POOR_FIT_PSF, ///< poor quality PSF fit172 PM_SOURCE_FAIL_FIT_PSF, ///< failed to get a good PSF fit173 PM_SOURCE_FAINTSTAR, ///< below S/N cutoff174 175 PM_SOURCE_GALAXY, ///< an extended object (galaxy)176 PM_SOURCE_FAINT_GALAXY, ///< a galaxy below S/N cutoff177 PM_SOURCE_DROP_GALAXY, ///< ?178 PM_SOURCE_FAIL_FIT_GAL, ///< failed on the galaxy fit179 PM_SOURCE_POOR_FIT_GAL, ///< poor quality galaxy fit180 181 PM_SOURCE_OTHER, ///< unidentified182 } pmSourceType;183 184 /** pmSource data structure185 *186 * This source has the capacity for several types of measurements. The187 * simplest measurement of a source is the location and flux of the peak pixel188 * associated with the source:189 *190 */191 typedef struct192 {193 pmPeak *peak; ///< Description of peak pixel.194 psImage *pixels; ///< Rectangular region including object pixels.195 psImage *weight; ///< Image variance.196 psImage *mask; ///< Mask which marks pixels associated with objects.197 pmMoments *moments; ///< Basic moments measure for the object.198 pmModel *modelPSF; ///< PSF Model fit (parameters and type)199 pmModel *modelFLT; ///< FLT (floating) Model fit (parameters and type).200 pmSourceType type; ///< Best identification of object.201 float apMag;202 float fitMag;203 }204 pmSource;205 206 207 /** pmPeakAlloc()208 *209 * @return pmPeak* newly allocated pmPeak with all internal pointers set to NULL210 */211 pmPeak *pmPeakAlloc(212 int x, ///< Row-coordinate in image space213 int y, ///< Col-coordinate in image space214 float counts, ///< The value of the peak pixel215 pmPeakType class ///< The type of peak pixel216 );217 218 219 /** pmMomentsAlloc()220 *221 */222 pmMoments *pmMomentsAlloc();223 224 225 /** pmModelAlloc()226 *227 */228 pmModel *pmModelAlloc(pmModelType type);229 230 231 /** pmSourceAlloc()232 *233 */234 pmSource *pmSourceAlloc();235 236 237 /** pmFindVectorPeaks()238 *239 * Find all local peaks in the given vector above the given threshold. A peak240 * is defined as any element with a value greater than its two neighbors and with241 * a value above the threshold. Two types of special cases must be addressed.242 * Equal value elements: If an element has the same value as the following243 * element, it is not considered a peak. If an element has the same value as the244 * preceding element (but not the following), then it is considered a peak. Note245 * that this rule (arbitrarily) identifies flat regions by their trailing edge.246 * Edge cases: At start of the vector, the element must be higher than its247 * neighbor. At the end of the vector, the element must be higher or equal to its248 * neighbor. These two rules again places the peak associated with a flat region249 * which touches the image edge at the image edge. The result of this function is250 * a vector containing the coordinates (element number) of the detected peaks251 * (type psU32).252 *253 */254 psVector *pmFindVectorPeaks(255 const psVector *vector, ///< The input vector (float)256 float threshold ///< Threshold above which to find a peak257 );258 259 260 /** pmFindImagePeaks()261 *262 * Find all local peaks in the given image above the given threshold. This263 * function should find all row peaks using pmFindVectorPeaks, then test each row264 * peak and exclude peaks which are not local peaks. A peak is a local peak if it265 * has a higher value than all 8 neighbors. If the peak has the same value as its266 * +y neighbor or +x neighbor, it is NOT a local peak. If any other neighbors267 * have an equal value, the peak is considered a valid peak. Note two points:268 * first, the +x neighbor condition is already enforced by pmFindVectorPeaks.269 * Second, these rules have the effect of making flat-topped regions have single270 * peaks at the (+x,+y) corner. When selecting the peaks, their type must also be271 * set. The result of this function is an array of pmPeak entries.272 *273 */274 psArray *pmFindImagePeaks(275 const psImage *image, ///< The input image where peaks will be found (float)276 float threshold ///< Threshold above which to find a peak277 );278 279 280 /** pmCullPeaks()281 *282 * Eliminate peaks from the psList that have a peak value above the given283 * maximum, or fall outside the valid region.284 *285 */286 psList *pmCullPeaks(287 psList *peaks, ///< The psList of peaks to be culled288 float maxValue, ///< Cull peaks above this value289 const psRegion valid ///< Cull peaks otside this psRegion290 );291 292 293 /** pmPeaksSubset()294 *295 * Create a new peaks array, removing certain types of peaks from the input296 * array of peaks based on the given criteria. Peaks should be eliminated if they297 * have a peak value above the given maximum value limit or if the fall outside298 * the valid region. The result of the function is a new array with a reduced299 * number of peaks.300 *301 */302 psArray *pmPeaksSubset(303 psArray *peaks, ///< Add comment.304 float maxvalue, ///< Add comment.305 const psRegion valid ///< Add comment.306 );307 308 309 /** pmSourceDefinePixels()310 *311 * Define psImage subarrays for the source located at coordinates x,y on the312 * image set defined by readout. The pixels defined by this operation consist of313 * a square window (of full width 2Radius+1) centered on the pixel which contains314 * the given coordinate, in the frame of the readout. The window is defined to315 * have limits which are valid within the boundary of the readout image, thus if316 * the radius would fall outside the image pixels, the subimage is truncated to317 * only consist of valid pixels. If readout->mask or readout->weight are not318 * NULL, matching subimages are defined for those images as well. This function319 * fails if no valid pixels can be defined (x or y less than Radius, for320 * example). This function should be used to define a region of interest around a321 * source, including both source and sky pixels.322 *323 * XXX: must code this.324 *325 */326 // XXX: Uncommenting the pmReadout causes compile errors.327 bool pmSourceDefinePixels(328 pmSource *mySource, ///< Add comment.329 pmReadout *readout, ///< Add comment.330 psF32 x, ///< Add comment.331 psF32 y, ///< Add comment.332 psF32 Radius ///< Add comment.333 );334 335 336 /** pmSourceLocalSky()337 *338 * Measure the local sky in the vicinity of the given source. The Radius339 * defines the square aperture in which the moments will be measured. This340 * function assumes the source pixels have been defined, and that the value of341 * Radius here is smaller than the value of Radius used to define the pixels. The342 * annular region not contained within the radius defined here is used to measure343 * the local background in the vicinity of the source. The local background344 * measurement uses the specified statistic passed in via the statsOptions entry.345 * This function allocates the pmMoments structure. The resulting sky is used to346 * set the value of the pmMoments.sky element of the provided pmSource structure.347 *348 */349 bool pmSourceLocalSky(350 pmSource *source, ///< The input image (float)351 psStatsOptions statsOptions, ///< The statistic used in calculating the background sky352 float Radius ///< The inner radius of the square annulus to exclude353 );354 355 356 /** pmSourceMoments()357 *358 * Measure source moments for the given source, using the value of359 * source.moments.sky provided as the local background value and the peak360 * coordinates as the initial source location. The resulting moment values are361 * applied to the source.moments entry, and the source is returned. The moments362 * are measured within the given circular radius of the source.peak coordinates.363 * The return value indicates the success (TRUE) of the operation.364 *365 */366 bool pmSourceMoments(367 pmSource *source, ///< The input pmSource for which moments will be computed368 float radius ///< Use a circle of pixels around the peak369 );370 371 372 /** pmSourcePSFClump()373 *374 * We use the source moments to make an initial, approximate source375 * classification, and as part of the information needed to build a PSF model for376 * the image. As long as the PSF shape does not vary excessively across the377 * image, the sources which are represented by a PSF (the start) will have very378 * similar second moments. The function pmSourcePSFClump searches a collection of379 * sources with measured moments for a group with moments which are all very380 * similar. The function returns a pmPSFClump structure, representing the381 * centroid and size of the clump in the sigma_x, sigma_y second-moment plane.382 *383 * The goal is to identify and characterize the stellar clump within the384 * sigma_x, sigma_y second-moment plane. To do this, an image is constructed to385 * represent this plane. The units of sigma_x and sigma_y are in image pixels. A386 * pixel in this analysis image represents 0.1 pixels in the input image. The387 * dimensions of the image need only be 10 pixels. The peak pixel in this image388 * (above a threshold of half of the image maximum) is found. The coordinates of389 * this peak pixel represent the 2D mode of the sigma_x, sigma_y distribution.390 * The sources with sigma_x, sigma_y within 0.2 pixels of this value are then391 * * used to calculate the median and standard deviation of the sigma_x, sigma_y392 * values. These resulting values are returned via the pmPSFClump structure.393 *394 * The return value indicates the success (TRUE) of the operation.395 *396 * XXX: Limit the S/N of the candidate sources (part of Metadata)? (TBD).397 * XXX: Save the clump parameters on the Metadata (TBD)398 *399 */400 pmPSFClump pmSourcePSFClump(401 psArray *source, ///< The input pmSource402 psMetadata *metadata ///< Contains classification parameters403 );404 405 406 /** pmSourceRoughClass()407 *408 * Based on the specified data values, make a guess at the source409 * classification. The sources are provides as a psArray of pmSource entries.410 * Definable parameters needed to make the classification are provided to the411 * routine with the psMetadata structure. The rules (in SDRS) refer to values which412 * can be extracted from the metadata using the given keywords. Except as noted,413 * the data type for these parameters are psF32.414 *415 */416 bool pmSourceRoughClass(417 psArray *source, ///< The input pmSource418 psMetadata *metadata, ///< Contains classification parameters419 pmPSFClump clump ///< Statistics about the PSF clump420 );421 422 423 /** pmSourceModelGuess()424 *425 * Convert available data to an initial guess for the given model. This426 * function allocates a pmModel entry for the pmSource structure based on the427 * provided model selection. The method of defining the model parameter guesses428 * are specified for each model below. The guess values are placed in the model429 * parameters. The function returns TRUE on success or FALSE on failure.430 *431 */432 pmModel *pmSourceModelGuess(433 pmSource *source, ///< The input pmSource434 pmModelType model ///< The type of model to be created.435 );436 437 438 /** pmContourType439 *440 * Only one type is defined at present.441 *442 */443 typedef enum {444 PS_CONTOUR_CRUDE,445 PS_CONTOUR_UNKNOWN01,446 PS_CONTOUR_UNKNOWN02447 } pmContourType;448 449 450 /** pmSourceContour()451 *452 * Find points in a contour for the given source at the given level. If type453 * is PM_CONTOUR_CRUDE, the contour is found by starting at the source peak,454 * running along each pixel row until the level is crossed, then interpolating to455 * the level coordinate for that row. This is done for each row, with the456 * starting point determined by the midpoint of the previous row, until the457 * starting point has a value below the contour level. The returned contour458 * consists of two vectors giving the x and y coordinates of the contour levels.459 * This function may be used as part of the model guess inputs. Other contour460 * types may be specified in the future for more refined contours (TBD)461 *462 */463 psArray *pmSourceContour(464 pmSource *source, ///< The input pmSource465 const psImage *image, ///< The input image (float) (this arg should be removed)466 float level, ///< The level of the contour467 pmContourType mode ///< Currently this must be PS_CONTOUR_CRUDE468 );469 470 471 /** pmSourceFitModel()472 *473 * Fit the requested model to the specified source. The starting guess for the474 * model is given by the input source.model parameter values. The pixels of475 * interest are specified by the source.pixelsand source.maskentries. This476 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE477 * on success or FALSE on failure.478 *479 */480 bool pmSourceFitModel(481 pmSource *source, ///< The input pmSource482 pmModel *model, ///< model to be fitted483 const bool PSF ///< Treat model as PSF or FLT?484 );485 486 487 /** pmModelFitStatus()488 *489 * This function wraps the call to the model-specific function returned by490 * pmModelFitStatusFunc_GetFunction. The model-specific function examines the491 * model parameters, parameter errors, Chisq, S/N, and other parameters available492 * from model to decide if the particular fit was successful or not.493 *494 * XXX: Must code this.495 *496 */497 bool pmModelFitStatus(498 pmModel *model ///< Add comment.499 );500 501 502 /** pmSourceAddModel()503 *504 * Add the given source model flux to/from the provided image. The boolean505 * option center selects if the source is re-centered to the image center or if506 * it is placed at its centroid location. The boolean option sky selects if the507 * background sky is applied (TRUE) or not. The pixel range in the target image508 * is at most the pixel range specified by the source.pixels image. The success509 * status is returned.510 *511 */512 bool pmSourceAddModel(513 psImage *image, ///< The output image (float)514 psImage *mask, ///< The image pixel mask (valid == 0)515 pmModel *model, ///< The input pmModel516 bool center, ///< A boolean flag that determines whether pixels are centered517 bool sky ///< A boolean flag that determines if the sky is subtracted518 );519 520 521 /** pmSourceSubModel()522 *523 * Subtract the given source model flux to/from the provided image. The524 * boolean option center selects if the source is re-centered to the image center525 * or if it is placed at its centroid location. The boolean option sky selects if526 * the background sky is applied (TRUE) or not. The pixel range in the target527 * image is at most the pixel range specified by the source.pixels image. The528 * success status is returned.529 *530 */531 bool pmSourceSubModel(532 psImage *image, ///< The output image (float)533 psImage *mask, ///< The image pixel mask (valid == 0)534 pmModel *model, ///< The input pmModel535 bool center, ///< A boolean flag that determines whether pixels are centered536 bool sky ///< A boolean flag that determines if the sky is subtracted537 );538 539 540 /**541 *542 * The function returns both the magnitude of the fit, defined as -2.5log(flux),543 * where the flux is integrated under the model, theoretically from a radius of 0544 * to infinity. In practice, we integrate the model beyond 50sigma. The aperture magnitude is545 * defined as -2.5log(flux) , where the flux is summed for all pixels which are546 * not excluded by the aperture mask. The model flux is calculated by calling the547 * model-specific function provided by pmModelFlux_GetFunction.548 *549 * XXX: must code this.550 *551 */552 bool pmSourcePhotometry(553 float *fitMag, ///< integrated fit magnitude554 float *obsMag, ///< aperture flux magnitude555 pmModel *model, ///< model used for photometry556 psImage *image, ///< image pixels to be used557 psImage *mask ///< mask of pixels to ignore558 );559 560 29 561 30 /** … … 563 32 * This function converts the source classification into the closest available 564 33 * approximation to the Dophot classification scheme: 34 * XXX EAM : fix this to use current source classification scheme 565 35 * 566 36 * PM_SOURCE_DEFECT: 8 … … 598 68 ); 599 69 600 /** pmSourceFitModel_v5()601 *602 * Fit the requested model to the specified source. The starting guess for the603 * model is given by the input source.model parameter values. The pixels of604 * interest are specified by the source.pixelsand source.maskentries. This605 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE606 * on success or FALSE on failure.607 *608 */609 bool pmSourceFitModel_v5(610 pmSource *source, ///< The input pmSource611 pmModel *model, ///< model to be fitted612 const bool PSF ///< Treat model as PSF or FLT?613 );614 615 616 /** pmSourceFitModel_v7()617 *618 * Fit the requested model to the specified source. The starting guess for the619 * model is given by the input source.model parameter values. The pixels of620 * interest are specified by the source.pixelsand source.maskentries. This621 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE622 * on success or FALSE on failure.623 *624 */625 bool pmSourceFitModel_v7(626 pmSource *source, ///< The input pmSource627 pmModel *model, ///< model to be fitted628 const bool PSF ///< Treat model as PSF or FLT?629 );630 631 632 /** pmSourcePhotometry()633 *634 * XXX: Need descriptions635 *636 */637 bool pmSourcePhotometry(638 float *fitMag,639 float *obsMag,640 pmModel *model,641 psImage *image,642 psImage *mask643 );644 645 /** pmModelEval()646 *647 * XXX: Need descriptions648 *649 */650 psF32 pmModelEval(651 pmModel *model,652 psImage *image,653 psS32 col,654 psS32 row655 );656 70 657 71 #endif -
trunk/psModules/src/objects/pmPSF.h
r5255 r6872 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 200 5-10-10 19:53:40$8 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-04-17 18:01:05 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 # ifndef PM_PSF_H 16 16 # define PM_PSF_H 17 18 17 19 18 /** pmPSF data structure … … 33 32 pmModelType type; ///< PSF Model in use 34 33 psArray *params; ///< Model parameters (psPolynomial2D) 35 float chisq; ///< PSF goodness statistic 36 float ApResid; ///< ??? 37 float dApResid; ///< ??? 38 float skyBias; ///< ??? 34 psPolynomial1D *ChiTrend; ///< Chisq vs flux fit (correction for systematic errors) 35 psPolynomial4D *ApTrend; ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst) 36 pmGrowthCurve *growth; ///< apMag vs Radius 37 float ApResid; ///< apMag - psfMag (for PSF stars) 38 float dApResid; ///< scatter of ApResid 39 float skyBias; ///< implied residual sky offset from ApResid fit 40 float skySat; ///< roll-over of ApResid fit 41 float chisq; ///< PSF goodness statistic (unused??) 39 42 int nPSFstars; ///< number of stars used to measure PSF 43 int nApResid; ///< number of stars used to measure ApResid 44 bool poissonErrors; 40 45 } 41 46 pmPSF; 42 47 48 typedef enum { 49 PM_PSF_NONE, 50 PM_PSF_CONSTANT, 51 PM_PSF_SKYBIAS, 52 PM_PSF_SKYSAT, 53 PM_PSF_XY_LIN, 54 PM_PSF_XY_QUAD, 55 PM_PSF_SKY_XY_LIN, 56 PM_PSF_SKYSAT_XY_LIN, 57 PM_PSF_ALL 58 } pmPSF_ApTrendOptions; 43 59 44 60 /** … … 48 64 */ 49 65 pmPSF *pmPSFAlloc( 50 pmModelType type ///< Add comment 66 pmModelType type, // type of model for PSF 67 bool poissonErrors ///< use poissonian errors or not? 51 68 ); 52 69 … … 85 102 ); 86 103 104 bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option); 105 87 106 # endif -
trunk/psModules/src/objects/pmPSFtry.h
r5844 r6872 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 200 5-12-24 01:24:32$8 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-04-17 18:01:05 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 19 19 /** 20 * 20 * 21 21 * This structure contains a pointer to the collection of sources which will 22 22 * be used to test the PSF model form. It lists the pmModelType type of model 23 23 * being tests, and contains an element to store the resulting psf 24 24 * representation. In addition, this structure carries the complete collection of 25 * FLT (floating parameter) and PSF (fixed parameter) model fits to each of the26 * sources model FLT and modelPSF. It also contains a mask which is set by the25 * EXT (floating parameter) and PSF (fixed parameter) model fits to each of the 26 * sources modelEXT and modelPSF. It also contains a mask which is set by the 27 27 * model fitting and psf fitting steps. For each model, the value of the quality 28 28 * metric is stored in the vector metric and the fitted instrumental magnitude is … … 38 38 * ultimate metric to intercompare multiple types of PSF models is the value of 39 39 * the aperture correction scatter. 40 * 40 * 41 41 * XXX: There are many more members in the SDRS then in the prototype code. 42 42 * I stuck with the prototype code. 43 * 44 * 43 * 44 * 45 45 */ 46 46 typedef struct … … 48 48 pmPSF *psf; ///< Add comment. 49 49 psArray *sources; ///< pointers to the original sources 50 psArray *model FLT; ///< model fits, floating parameters50 psArray *modelEXT; ///< model fits, floating parameters 51 51 psArray *modelPSF; ///< model fits, PSF parameters 52 52 psVector *mask; ///< Add comment. … … 58 58 59 59 /** pmPSFtryMaskValues 60 * 60 * 61 61 * The following datatype defines the masks used by the pmPSFtry analysis to 62 62 * identify sources which should or should not be included in the analysis. 63 * 63 * 64 64 */ 65 enum {65 typedef enum { 66 66 PSFTRY_MASK_CLEAR = 0x00, ///< Add comment. 67 67 PSFTRY_MASK_OUTLIER = 0x01, ///< 1: outlier in psf polynomial fit (provided by psPolynomials) 68 PSFTRY_MASK_ FLT_FAIL = 0x02, ///< 2: flt model failed to converge68 PSFTRY_MASK_EXT_FAIL = 0x02, ///< 2: ext model failed to converge 69 69 PSFTRY_MASK_PSF_FAIL = 0x04, ///< 3: psf model failed to converge 70 70 PSFTRY_MASK_BAD_PHOT = 0x08, ///< 4: invalid source photometry … … 74 74 75 75 /** pmPSFtryAlloc() 76 * 76 * 77 77 * Allocate a pmPSFtry data structure. 78 * 78 * 79 79 */ 80 80 pmPSFtry *pmPSFtryAlloc( 81 81 psArray *stars, ///< Add comment. 82 char *modelName ///< Add comment. 82 char *modelName, ///< Add comment. 83 bool poissonErrors // use poissonian or constant errors? 83 84 ); 84 85 85 86 86 87 /** pmPSFtryModel() 87 * 88 * 88 89 * This function takes the input collection of sources and performs a complete 89 90 * analysis to determine a PSF model of the given type (specified by model name). 90 91 * The result is a pmPSFtry with the results of the analysis. 91 * 92 * 92 93 */ 93 94 pmPSFtry *pmPSFtryModel( 94 95 psArray *sources, ///< Add comment. 95 96 char *modelName, ///< Add comment. 96 float radius ///< Add comment. 97 float radius, ///< Add comment. 98 bool poissonErrors // use poissonian or constant errors? 97 99 ); 98 100 99 101 100 102 /** pmPSFtryMetric() 101 * 103 * 102 104 * This function is used to measure the PSF model metric for the set of 103 105 * results contained in the pmPSFtry structure. 104 * 106 * 105 107 */ 106 108 bool pmPSFtryMetric(
Note:
See TracChangeset
for help on using the changeset viewer.
