IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6872


Ignore:
Timestamp:
Apr 17, 2006, 8:01:05 AM (20 years ago)
Author:
magnier
Message:

updates relative to rel10_ifa_1

Location:
trunk/psModules
Files:
100 added
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/configure.ac

    r6298 r6872  
    88AM_MAINTAINER_MODE
    99
    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 
     10dnl otherise AC_PROG_CC will default CFLAGS to "-g -02"
     11if test -z ${CFLAGS} ; then
     12  CFLAGS=""
     13fi
    2614AC_SUBST([CFLAGS])
    2715
     
    2917AC_PROG_CC
    3018dnl FIXME document why GNU_SOURCE is being set
    31 dnl AC_GNU_SOURCE
     19AC_GNU_SOURCE
    3220AC_PROG_INSTALL
    3321AM_PROG_LIBTOOL
    34 AC_SYS_LARGEFILE
    3522
    3623AC_PREFIX_DEFAULT([`pwd`])
     
    6249
    6350SRCPATH='${top_srcdir}/src'
    64 SRCDIRS="astrom camera config detrend imcombine imsubtract objects photom"
     51SRCDIRS="astrom config detrend imcombine imsubtract objects pslib"
    6552# escape two escapes at this level so \\ gets passed to the shell and \ to perl
    6653SRCINC=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|-I\\\\${SRCPATH=}/\1|g"`
    6754SRCINC="-I${SRCPATH=} ${SRCINC=}"
    6855SRCSUBLIBS=`echo "${SRCDIRS=}" | ${PERL} -pe "s|(\w+)|\1/libpsmodule\1.la|g"`
    69 AC_SUBST([SRCSUBLIBS],${SRCSUBLIBS=})
    70 AC_SUBST([SRCINC],${SRCINC=})
     56AC_SUBST(SRCSUBLIBS,${SRCSUBLIBS=})
     57AC_SUBST(SRCINC,${SRCINC=})
    7158AC_SUBST([SRCDIRS],${SRCDIRS=})
     59
     60dnl handle debug building
     61AC_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
     69dnl handle profiler building
     70AC_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
     76dnl CFLAGS="${CFLAGS=} -fprofile-arcs -ftest-coverage -pg"]
    7277
    7378dnl doxygen -------------------------------------------------------------------
     
    7580AC_CHECK_PROG([doxygen], [doxygen], [true], [false])
    7681AM_CONDITIONAL(DOXYGEN, test x$doxygen = xtrue)
     82
     83dnl libjpeg -------------------------------------------------------------------
     84
     85AC_CHECK_LIB(jpeg,jpeg_CreateCompress,[],[AC_MSG_ERROR([jpeg library not found.])])
    7786
    7887dnl pslib ---------------------------------------------------------------------
     
    8291
    8392if test -z ${PSLIB_CONFIG} ; then
    84   PKG_CHECK_MODULES([PSLIB], [pslib >= 0.10.0])
     93  PKG_CHECK_MODULES([PSLIB], [pslib >= 0.9.0])
    8594else
    8695  AC_CHECK_FILE($PSLIB_CONFIG,[],
     
    105114  src/Makefile
    106115  src/astrom/Makefile
    107   src/camera/Makefile
    108116  src/config/Makefile
    109117  src/detrend/Makefile
     
    111119  src/imsubtract/Makefile
    112120  src/objects/Makefile
    113   src/photom/Makefile
     121  src/pslib/Makefile
    114122  test/Makefile
    115123  test/astrom/Makefile
    116   test/camera/Makefile
    117124  test/config/Makefile
    118125  test/detrend/Makefile
     
    120127  test/imsubtract/Makefile
    121128  test/objects/Makefile
    122   test/photom/Makefile
     129  test/pslib/Makefile
    123130  Doxyfile
    124131  psmodule-config
  • trunk/psModules/src/Makefile.am

    r5685 r6872  
    77libpsmodule_la_DEPENDENCIES = $(SRCSUBLIBS)
    88
     9include_HEADERS = \
     10        psmodules.h
     11
    912EXTRA_DIST = psErrorCodes.dat
  • trunk/psModules/src/astrom/Makefile.am

    r6301 r6872  
    11noinst_LTLIBRARIES = libpsmoduleastrom.la
    22
    3 libpsmoduleastrom_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
     3libpsmoduleastrom_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) -I../pslib/
    44libpsmoduleastrom_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    55libpsmoduleastrom_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
    827
    928psmoduleincludedir = $(includedir)
    1029psmoduleinclude_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  
    1010* XXX: We should review the extent of the warning messages on these functions
    1111* when the transformations are not successful.
    12 * 
     12*
    1313* XXX: Should we implement non-linear cell->chip transforms?
    14 * 
    15 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    16 *  @date $Date: 2006-01-26 21:10:50 $
     14*
     15*  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     16*  @date $Date: 2006-04-17 18:01:04 $
    1717*
    1818*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2525#include <math.h>
    2626#include "pslib.h"
     27
    2728#include "pmAstrometry.h"
     29#include "pmConcepts.h"
    2830
    2931/*****************************************************************************
     
    6062        psFree(readout->mask);
    6163        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, we
    65         // 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);
    7764        psFree(readout->analysis);
     65        #if 0
     66
    7867        psFree(readout->parent);
     68        #endif
     69
     70        readout->parent = NULL;
    7971    }
    8072}
     
    8880        psFree(cell->concepts);
    8981        psFree(cell->analysis);
     82        psFree(cell->camera);
    9083        //
    9184        // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
    9285        // in order to avoid memory reference counter problems.
    9386        //
     87        #if 0
     88
    9489        for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
    9590            pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
     
    9994            }
    10095        }
     96        psFree(cell->parent);
     97        #endif
     98
     99        cell->parent = NULL;
     100
    101101        psFree(cell->readouts);
    102         psFree(cell->parent);
    103102        psFree(cell->hdu);
     103
    104104    }
    105105}
     
    116116        // in order to avoid memory reference counter problems.
    117117        //
     118        #if 0
     119
    118120        for (psS32 i = 0 ; i < chip->cells->n ; i++) {
    119121            pmCell *tmpCell = (pmCell *) chip->cells->data[i];
     
    123125            }
    124126        }
     127        psFree(chip->parent);
     128        #endif
     129
     130        chip->parent = NULL;
    125131        psFree(chip->cells);
    126         psFree(chip->parent);
    127132        psFree(chip->hdu);
    128133    }
     
    143148        // in order to avoid memory reference counter problems.
    144149        //
     150        #if 0
     151
    145152        for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
    146153            pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
     
    150157            }
    151158        }
     159        #endif
    152160        psFree(fpa->chips);
    153161        psFree(fpa->hdu);
     
    156164}
    157165
     166void 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
    158177// 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?
    159179pmReadout *pmReadoutAlloc(pmCell *cell)
    160180{
    161181    pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
    162182
    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;
    167187    tmpReadout->image = NULL;
    168188    tmpReadout->mask = NULL;
    169189    tmpReadout->weight = NULL;
    170     tmpReadout->bias = NULL;
    171190    tmpReadout->analysis = psMetadataAlloc();
    172191    tmpReadout->parent = cell;
     
    179198
    180199// XXX: Verify these default values for row0, col0.
     200// PAP: These values may disappear in the future in favour of values in the "concepts"?
    181201pmCell *pmCellAlloc(
    182202    pmChip *chip,
    183     psMetadata *cameradata,
    184     psString name)
     203    psMetadata *cameraData,
     204    const char *name)
    185205{
    186206    pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
    187207
    188     tmpCell->col0 = -1;
    189     tmpCell->row0 = -1;
     208    tmpCell->col0 = 0;
     209    tmpCell->row0 = 0;
    190210    tmpCell->toChip = NULL;
    191211    tmpCell->toFPA = NULL;
     
    196216        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n");
    197217    }
    198     tmpCell->camera = cameradata;
    199     tmpCell->analysis = NULL;
     218    tmpCell->camera = psMemIncrRefCounter(cameraData);
     219    tmpCell->analysis = psMetadataAlloc();
    200220    tmpCell->readouts = psArrayAlloc(0);
    201221    tmpCell->parent = chip;
     
    203223        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
    204224    }
    205     tmpCell->valid = false;
     225    tmpCell->process = true;            // All cells are processed by default
     226    tmpCell->exists = false;            // Not yet read in
    206227    tmpCell->hdu = NULL;
     228
     229    pmConceptsBlankCell(tmpCell);
    207230
    208231    psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
     
    211234
    212235// 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".
    213237pmChip *pmChipAlloc(
    214238    pmFPA *fpa,
    215     psString name)
     239    const char *name)
    216240{
    217241    pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
    218242
    219     tmpChip->col0 = -1;
    220     tmpChip->row0 = -1;
     243    tmpChip->col0 = 0;
     244    tmpChip->row0 = 0;
    221245    tmpChip->toFPA = NULL;
    222246    tmpChip->fromFPA = NULL;
     
    226250        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME to metadata.\n");
    227251    }
    228     tmpChip->analysis = NULL;
     252    tmpChip->analysis = psMetadataAlloc();
    229253    tmpChip->cells = psArrayAlloc(0);
    230254    tmpChip->parent = fpa;
     
    232256        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
    233257    }
    234     tmpChip->valid = false;
     258    tmpChip->process = true;            // Work on all chips, by default
     259    tmpChip->exists = false;            // Not read in yet
    235260    tmpChip->hdu = NULL;
     261
     262    pmConceptsBlankChip(tmpChip);
    236263
    237264    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
     
    248275    tmpFPA->concepts = psMetadataAlloc();
    249276    tmpFPA->analysis = NULL;
    250     tmpFPA->camera = camera;
     277    tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
    251278    tmpFPA->chips = psArrayAlloc(0);
    252279    tmpFPA->hdu = NULL;
    253280    tmpFPA->phu = NULL;
    254281
     282    pmConceptsBlankFPA(tmpFPA);
     283
    255284    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
    256285    return(tmpFPA);
     286}
     287
     288p_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;
    257300}
    258301
     
    317360
    318361
    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 FPA
    372     // coordinates to chip coordinates for that chip.  Then, determine if any
    373     // cells in that chip contain those chip coordinates.
    374     // XXX: Depending on the number of chips, and their topology, there may be
    375     // 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 into
    412     // 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 be
    415     // 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 wrapper
    598 for p_psDeproject().  The reason: p_psDeproject() and p_psProject() combined
    599 do not seem to produce the original coordinates when they even though they
    600 should.  XXXDeproject() simply negates the ->r and ->d members of the output
    601 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 
    641362/*****************************************************************************
    642363 *****************************************************************************/
    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
     366static 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;
    800384}
    801385
     
    807391{
    808392    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)) {
    810396        return(false);
    811397    }
    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];
    816401        if (tmpChip == NULL) {
    817             rc = false;
     402            continue;
     403        }
     404        if (i == chipNum) {
     405            tmpChip->process = true;
     406            setCellsProcess(tmpChip, true);
    818407        } 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;
    828415}
    829416
     
    831418/*****************************************************************************
    832419XXX: 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]
    835422 *****************************************************************************/
    836423/**
    837  * 
    838  * pmFPAExcludeChip shall set valid to false only for the specified chip
     424 *
     425 * pmFPAExcludeChip shall set process to false only for the specified chip
    839426 * number (chipNum). In the event that the specified chip number does not exist
    840427 * 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 valid
     428 * The function shall return the number of chips within the fpa that have process
    842429 * set to true.
    843  * 
     430 *
    844431 */
    845432int pmFPAExcludeChip(
     
    849436    PS_ASSERT_PTR_NON_NULL(fpa, false);
    850437
    851     if (fpa->chips == NULL) {
     438    psArray *chips = fpa->chips;        // Component chips
     439    if (chips == NULL) {
    852440        psLogMsg(__func__, PS_LOG_WARN, "WARNING: fpa->chips == NULL\n");
    853441        return(0);
    854442    }
    855     if ((chipNum >= fpa->chips->n) || (NULL == (pmChip *) fpa->chips->data[chipNum])) {
     443    if ((chipNum >= chips->n) || (NULL == (pmChip *) chips->data[chipNum])) {
    856444        psLogMsg(__func__, PS_LOG_WARN, "WARNING: the specified chip (%d) does not exist.\n", chipNum);
    857445        return(0);
    858446    }
    859447
    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
    863451        if (tmpChip != NULL) {
    864452            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) {
    868456                numChips++;
    869457            }
     
    874462}
    875463
     464
     465bool 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  
    88*  @author GLG, MHPCC
    99*
    10 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-01-26 21:10:50 $
     10*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-04-17 18:01:04 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030{
    3131    const char *extname;                // Extension name, if it corresponds to this level
    32     psArray *pixels;                    // The pixel data, if it corresponds to this level
    3332    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
    3436}
    3537p_pmHDU;
    3638
    37 p_pmHDU *pmHDUAlloc();
    38 void *pmHDUFree(p_pmHDU *hdu);
    39 
    4039/** Focal plane data structure
    41  * 
     40 *
    4241 *  A focal plane consists of one or more chips (according to the number of
    4342 *  pieces of contiguous silicon). It contains metadata containers for the
     
    5251 *  transformation which will be derived from numerically inverting the forward
    5352 *  transformation.
    54  * 
     53 *
    5554 */
    5655typedef struct
     
    7170
    7271/** Chip data structure
    73  * 
     72 *
    7473 *  A chip consists of one or more cells (according to the number of amplifiers
    7574 *  on the device). The chip contains metadata containers for the concepts and
     
    8281 *  inverting the forward transformation. A boolean indicates whether the chip is
    8382 *  of interest, allowing it to be excluded from analysis.
    84  * 
     83 *
    8584 */
    8685typedef struct
     
    9796    psArray *cells;                     ///< The cells (referred to by name)
    9897    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?
    100100    p_pmHDU *hdu;                       ///< FITS data
    101101}
     
    126126    psArray *readouts;                  ///< The readouts (referred to by number)
    127127    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?
    129130    p_pmHDU *hdu;                       ///< FITS data
    130131}
     
    144145{
    145146    // Position on the cell
     147    // XXX: These may be removed in the future; use parent->concepts instead?
    146148    int col0;                           ///< Offset from the left of chip.
    147149    int row0;                           ///< Offset from the bottom of chip.
     
    152154    psImage *mask;                      ///< Mask of input image
    153155    psImage *weight;                    ///< Weight of input image
    154     psList *bias;                       ///< List of bias section (sub-)images
    155156    psMetadata *analysis;               ///< Readout-level analysis metadata
    156157    pmCell *parent;                     ///< Parent cell
     
    183184 */
    184185pmCell *pmCellAlloc(
    185     pmChip *chip,                        ///< Parent chip
    186     psMetadata *cameradata,
    187     psString name
     186    pmChip *chip,       ///< Parent chip
     187    psMetadata *cameraData, ///< Camera data
     188    const char *name    ///< Name of cell
    188189);
    189190
    190191/** Allocates a pmChip
    191  * 
     192 *
    192193 *  The constructor shall make an empty pmChip. If the parent fpa is not NULL,
    193194 *  the parent link is made and the chip shall be placed in the parent's array
     
    199200 */
    200201pmChip *pmChipAlloc(
    201     pmFPA *fpa,
    202     psString name
    203 
     202    pmFPA *fpa,                         ///< FPA to which the chip belongs
     203    const char *name                    ///< Name of chip
    204204);
    205205
    206206/** Allocates a pmFPA
    207  * 
     207 *
    208208 *  The constructor shall make an empty pmFPA. The chips array shall be
    209209 *  allocated with a zero size, the camera and db pointers set to the values
    210210 *  provided, and the concepts metadata constructed. All other pointers in the
    211211 *  structure shall be initialized to NULL.
    212  * 
     212 *
    213213 */
    214214pmFPA *pmFPAAlloc(
     
    216216);
    217217
     218/** Allocates a p_pmHDU
     219 *
     220 * XXX: More detailed description
     221 *
     222 * @return p_pmHDU*    newly allocated p_pmHDU
     223 */
     224p_pmHDU *p_pmHDUAlloc(const char *extname // Extension name
     225                     );
     226
    218227
    219228/** Verify parent links.
    220  * 
     229 *
    221230 *  This function checks the validity of the parent links in the FPA hierarchy.
    222231 *  If a parent link is not set (or not set correctly), it is corrected, and the
    223232 *  function shall return false. If all the parent pointers were correct, the
    224233 *  function shall return true.
    225  * 
     234 *
    226235 */
    227236bool pmFPACheckParents(
     
    232241
    233242/** 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 */
     259bool 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 */
     273int pmFPAExcludeChip(
     274    pmFPA *fpa,
     275    int chipNum
     276);
    240277
    241278
     
    426463);
    427464
    428 /**
    429  *
    430  * pmFPASelectChip shall set valid to true for the specified chip number
    431  * (chipNum), and all other chips shall have valid set to false. In the event
    432  * that the specified chip number does not exist within the fpa, the function
    433  * shall return false.
    434  * 
    435  */
    436 bool pmFPASelectChip(
    437     pmFPA *fpa,
    438     int chipNum
    439 );
    440 
    441 
    442 /**
    443  *
    444  * pmFPAExcludeChip shall set valid to false only for the specified chip
    445  * number (chipNum). In the event that the specified chip number does not exist
    446  * 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 valid
    448  * set to true.
    449  * 
    450  */
    451 int pmFPAExcludeChip(
    452     pmFPA *fpa,
    453     int chipNum
    454 );
    455 
    456 
    457 /**
    458  *
    459  * pmFPAConstruct shall construct a focal plane hierarchy from a camera
    460  * 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 a
    462  * FITS file into it by setting the extname pointers at the appropriate levels to
    463  * the appropriate FITS extension name.
    464  * 
    465  */
    466 pmFPA *pmFPAConstruct(
    467     const psMetadata *camera,
    468     psDB *db
    469 );
    470 
    471465
    472466#endif // #ifndef PS_ASTROMETRY_H
  • trunk/psModules/src/astrom/pmAstrometryObjects.c

    r6511 r6872  
    88*  @author EAM, IfA
    99*
    10 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-03-04 01:01:33 $
     10*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-04-17 18:01:04 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020#include <math.h>
    2121#include "pslib.h"
    22 #include "pmAstrometry.h"
     22#include "pmFPA.h"
    2323#include "pmAstrometryObjects.h"
    2424
     
    540540    psArray *rot;
    541541
    542     pmAstromStats minStat, newStat;
     542    pmAstromStats minStat;
     543    pmAstromStats newStat = {{0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0};
    543544    psPlane center;
    544545
  • trunk/psModules/src/astrom/pmAstrometryObjects.h

    r6205 r6872  
    88*  @author EAM, IfA
    99*
    10 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-01-26 21:10:50 $
     10*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-04-17 18:01:04 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2121# include <unistd.h>   // for unlink
    2222# include <pslib.h>
    23 # include <pmAstrometry.h>
    24 
    25 /*
    26  * 
     23# include <pmFPA.h>
     24
     25/*
     26 *
    2727 * This structure specifies the coordinate of the detection in each of the
    2828 * four necessary coordinate frames: pix defines the position in the psReadout
     
    3535 * coordinates, while the reference detections will be projected to the other
    3636 * frames from the sky coordinates.
    37  * 
     37 *
    3838 * XXX: There are more members here than in the SDRS.
    39  * 
     39 *
    4040 */
    4141typedef struct
     
    5555
    5656/*
    57  * 
     57 *
    5858 * The pmAstromMatch structure defines the cross-correlation between two
    5959 * arrays. A single such data item specifies that item number pmAstromMatch.idx1
    6060 * in the first list corresponds to pmAstromMatch.idx2 in the second list.
    61  * 
     61 *
    6262 */
    6363typedef struct
     
    7070
    7171/*
    72  * 
     72 *
    7373 * XXX: Not in SDRS.
    74  * 
     74 *
    7575 */
    7676typedef struct
     
    8888
    8989/*
    90  * 
     90 *
    9191 * If the two sets of coordinates are expected to agree very well (ie, the
    9292 * current best-guess astrometric solution is quite close to the radius. The
     
    9797 * ASTROM.MATCH.RADIUS). The output consists an array of pmAstromMatch values,
    9898 * defined below.
    99  * 
     99 *
    100100 */
    101101psArray *pmAstromRadiusMatch(
     
    108108
    109109/*
    110  * 
     110 *
    111111 * This function accepts an array of pmAstromObj objects and rotates them by
    112112 * the given angle about the given center coordinate pCenter,qCenter in the Focal
    113113 * Plane Array coordinates.
    114  * 
     114 *
    115115 * XXX: This differs from the SDRS
    116  * 
     116 *
    117117 */
    118118/* SDRS
     
    132132
    133133/*
    134  * 
     134 *
    135135 * If the two sets of coordinates are not known to agree well, but the
    136136 * relative scale and approximate relative rotation is known, then a much faster
     
    147147 * allowing the procedure to scan over a range of rotations. We define the
    148148 * following function to apply this matching algorithm:
    149  * 
     149 *
    150150 * XXX: In the SDRS, this function is a pointer.
    151  * 
     151 *
    152152 */
    153153pmAstromStats pmAstromGridMatch(
     
    159159
    160160/*
    161  * 
     161 *
    162162 * The result of a pmAstromGridMatch may be used to modify the astrometry
    163163 * transformation information for a pmFPA image hierarchy structure. The result
     
    167167 * the linear terms of the pmFPA.toTangentPlane transformation. These two
    168168 * adjustments are made using the function:
    169  * 
     169 *
    170170 * XXX: This function name is different in the SDRS.
    171  * 
     171 *
    172172 */
    173173psPlaneTransform *pmAstromGridApply(
     
    178178
    179179/*
    180  * 
     180 *
    181181 * This function is identical to pmAstromGridMatch, but is valid for only a
    182182 * single relative rotation. The input config information need not contain any of
    183183 * the GRID.*.ANGLE entries (they will be ignored).
    184  *
     184 *
     185 * XXX: This function name is different in the SDRS.
     186 *
    185187 */
    186188/* in pmAstromGrid.c */
     
    193195
    194196/*
    195  * 
     197 *
    196198 * This function accepts the raw and reference source lists and the list of
    197199 * matched entries. It uses the matched list to determine a polynomial
     
    207209 * modifications to pmFPA.toTangentPlane incorporate the rotation component of
    208210 * the linear terms and the higher-order terms of the polynomial fits.
    209  * 
     211 *
    210212 * XXX: No prototype code.
    211  * 
     213 *
    212214 */
    213215bool pmAstromFitFPA(
     
    233235 *ASTROM.ORDER).  The result of this fit is a set of modifications of the
    234236 *components of the pmChip.toFPA transformation.
    235  * 
     237 *
    236238 * XXX: No prototype code.
    237  * 
     239 *
    238240 */
    239241bool pmAstromFitChip(
     
    247249
    248250/*
    249  * 
     251 *
    250252 * The following function determines the position residual, in the tangent
    251253 * plane, as a function of position in the focal plane, for a collection of raw
     
    253255 * the bin size over which the gradient is measured (keyword: ASTROM.GRAD.BOX).
    254256 * The function returns an array of pmAstromGradient structures, defined below.
    255  * 
     257 *
    256258 * XXX: No prototype code.
    257  * 
     259 *
    258260 */
    259261psArray pmAstromMeasureGradients(
     
    267269
    268270/*
    269  * 
     271 *
    270272 * The following data structure carries the information about the residual
    271273 * gradient of source positions in the tangent plane (pmAstromObj.TP) as a
    272274 * function of position in the focal plane (pmAstromObj.FP).
    273  * 
     275 *
    274276 */
    275277typedef struct
     
    283285
    284286/*
    285  * 
     287 *
    286288 * The gradient set measured above can be fitted with a pair of 2D
    287289 * polynomials. The resulting fits can then be related back to the implied
     
    290292 * supplied pmFPA structure. The configuration variable supplies the polynomial
    291293 * order (keyword: ASTROM.DISTORT.ORDER).
    292  * 
     294 *
    293295 * XXX: No prototype code.
    294  * 
     296 *
    295297 */
    296298psArray pmAstromFitDistortion(
     
    308310 ******************************************************************************/
    309311/*
    310  * 
    311  * 
    312  * 
    313  * 
    314  */
    315 
    316 
    317 /*
    318  * 
     312 *
     313 *
     314 *
     315 *
     316 */
     317
     318
     319/*
     320 *
    319321 * Allocates a pmAstromObj struct.
    320  * 
     322 *
    321323 */
    322324pmAstromObj *pmAstromObjAlloc (void);
     
    325327
    326328/*
    327  * 
     329 *
    328330 * Copies a pmAstromObj struct.
    329  * 
     331 *
    330332 */
    331333pmAstromObj *pmAstromObjCopy(
     
    336338
    337339/*
    338  * 
    339  * 
    340  * 
     340 *
     341 *
     342 *
    341343 */
    342344pmAstromMatch *pmAstromMatchAlloc(
     
    349351
    350352/*
    351  * 
    352  * 
    353  * 
     353 *
     354 *
     355 *
    354356 */
    355357psPlaneTransform *pmAstromMatchFit(
     
    364366
    365367/*
    366  * 
    367  * 
    368  * 
     368 *
     369 *
     370 *
    369371 */
    370372int pmAstromObjSortByFPX(
     
    376378
    377379/*
    378  * 
    379  * 
    380  * 
     380 *
     381 *
     382 *
    381383 */
    382384int pmAstromObjSortByMag(
  • trunk/psModules/src/camera/Makefile.am

    r5170 r6872  
    33libpsmodulecamera_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
    44libpsmodulecamera_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    5 libpsmodulecamera_la_SOURCES  =
     5libpsmodulecamera_la_SOURCES  = \
     6        pmChipMosaic.c \
     7        pmFPAConceptsGet.c \
     8        pmFPAConceptsSet.c \
     9        pmFPAConstruct.c \
     10        pmFPAMorph.c \
     11        pmFPARead.c \
     12        pmFPAWrite.c
    613
    714psmoduleincludedir = $(includedir)
    8 psmoduleinclude_HEADERS =
    9 
     15psmoduleinclude_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  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-02-02 04:51:14 $
     5 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-04-17 18:01:05 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515
    1616
     17// Configuration information
     18typedef 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}
     28pmConfig;
     29
     30pmConfig *pmConfigAlloc(void);
     31
     32// Free static variables
     33void pmConfigDone(void);
    1734
    1835/** pmConfigRead
    19  * 
     36 *
    2037 * pmConfigRead shall load the site configuration (according to the above rule
    2138 * for determining the source). The camera configuration shall also be loaded if
     
    3249 *
    3350 */
    34 bool pmConfigRead(
    35     psMetadata **site,
    36     psMetadata **camera,
    37     psMetadata **recipe,
     51pmConfig *pmConfigRead(
    3852    int *argc,
    39     char **argv,
    40     const char *recipeName
     53    char **argv);
     54
     55/** we need this elsewhere; make it public **/
     56bool readConfig(
     57    psMetadata **config,                // Config to output
     58    const char *name,                   // Name of file
     59    const char *description             // Description of file
    4160);
    4261
    43 
    44 
    4562/** pmConfigValidateCamera
    46  * 
     63 *
    4764 * This function, used by pmConfigCameraFromHeader, shall return true if the
    4865 * FITS header matches the rule contained in the camera configuration (see
    4966 * x2.2.2.3); otherwise it shall return false.
    50  * 
     67 *
    5168 */
    52 bool pmConfigValidateCamera(
    53     const psMetadata *camera,
    54     const psMetadata *header
    55 );
    56 
     69bool pmConfigValidateCameraFormat(
     70    const psMetadata *cameraFormat,
     71    const psMetadata *header);
    5772
    5873
    5974/** pmConfigCameraFromHeader
    60  * 
     75 *
    6176 * pmConfigCameraFromHeader shall load the camera configuration based on the
    6277 * contents of the FITS header, using the list of known cameras contained in the
    6378 * site configuration. If more than one camera matches the FITS header, a warning
    6479 * shall be generated and the first matching camera returned.
    65  * 
     80 *
    6681 */
    67 psMetadata *pmConfigCameraFromHeader(
    68     const psMetadata *site,
    69     const psMetadata *header
     82psMetadata *pmConfigCameraFormatFromHeader(
     83    pmConfig *config,                   // The configuration
     84    const psMetadata *header           // The FITS header
    7085);
    7186
    7287
    73 
    7488/** 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
    7891 * configuration.
    79  * 
     92 *
    8093 */
    81 psMetadata *pmConfigRecipeFromCamera(
    82     const psMetadata *camera,
    83     const char *recipeName
     94bool pmConfigReadRecipes(
     95    pmConfig *config
    8496);
    8597
    8698/** pmConfigDB
    87  * 
     99 *
    88100 * pmConfigDB shall use the site configuration data to open a database handle.
    89101 * This is fairly straightforward at the moment, but will change when we beef up
    90102 * security. (TBD)
    91  * 
     103 *
    92104 */
    93105#ifdef DOMIT_PSDB
     
    99111);
    100112
     113/** pmConfigConformHeader
     114 *
     115 * Make the supplied header conform to the nominated camera format.
     116 */
     117bool pmConfigConformHeader(psMetadata *header, // Header to conform
     118                           const psMetadata *format // Camera format
     119                          );
     120
     121
     122psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list);
     123bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list);
     124
    101125
    102126#endif
  • trunk/psModules/src/detrend/Makefile.am

    r5170 r6872  
    33libpsmoduledetrend_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
    44libpsmoduledetrend_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    5 libpsmoduledetrend_la_SOURCES  = pmFlatField.c \
    6     pmMaskBadPixels.c \
    7     pmNonLinear.c
     5libpsmoduledetrend_la_SOURCES  = \
     6        pmFlatField.c \
     7        pmFringeStats.c \
     8        pmMaskBadPixels.c \
     9        pmNonLinear.c
    810
    911psmoduleincludedir = $(includedir)
    1012psmoduleinclude_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
    1619
    1720EXTRA_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
    17/** @file  pmFlatField.c
    28 *
     
    1824 *  @author Ross Harman, MHPCC
    1925 *
    20  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    21  *  @date $Date: 2005-11-18 19:43:14 $
     26 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2228 *
    2329 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3036#include<stdio.h>
    3137#include<math.h>
    32 #include <string.h>
     38#include <strings.h>
    3339
    3440#include "pslib.h"
     
    3642#include "pmMaskBadPixels.h"
    3743#include "pmFlatFieldErrors.h"
    38 #include "pmSubtractBias.h"
    3944
    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 } \
    4545
    46 bool pmFlatField(
    47     pmReadout *in,
    48     const pmReadout *flat)
     46bool pmFlatField(pmReadout *in, const pmReadout *flat)
    4947{
    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     }
    6648    int i = 0;
    6749    int j = 0;
     
    7153    psElemType flatType;
    7254    psElemType maskType;
    73     psImage *inMask = NULL;
    74     psImage *flatImage = NULL;
    7555
    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    }
    8284
    8385    // Check input image and its mask are not larger than flat image
    8486
    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) {
    9188        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    9289                 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE,
    93                  trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols);
     90                 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols);
    9491        return false;
    9592    }
    96     if (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols) {
     93    if (inMask && (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols)) {
    9794        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    9895                 PS_ERRORTEXT_pmFlatField_SIZE_MASK_IMAGE,
     
    10299
    103100    // 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;
    106103
    107104    // Check that offsets are within image limits
     
    111108                 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols);
    112109        return false;
    113     } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
     110    } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    114111        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    115112                 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE,
    116                  totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
     113                 totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    117114        return false;
    118     } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     115    } else if(inMask && (totOffRow>=inMask->numRows || totOffCol>=inMask->numCols)) {
    119116        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    120117                 PS_ERRORTEXT_pmFlatField_OFFSET_MASK_IMAGE,
     
    124121
    125122    // Check for incorrect types
    126     inType = trimmedImg->type.type;
     123    inType = inImage->type.type;
    127124    flatType = flatImage->type.type;
    128125    maskType = inMask->type.type;
     
    137134                 flatType);
    138135        return false;
    139     } else if(maskType != PS_TYPE_MASK) {
     136    } else if(inMask && inMask->type.type != PS_TYPE_MASK) {
    140137        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    141138                 PS_ERRORTEXT_pmFlatField_TYPE_MASK_IMAGE,
     
    153150case PS_TYPE_##TYPE:                                                                                         \
    154151    /* 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++) {                                                      \
    157154            if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
    158155                /* 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                }                                                                                            \
    160159                flatImage->data.TYPE[j][i] = 0.0;                                                            \
    161160            }                                                                                                \
    162161        }                                                                                                    \
    163162    }                                                                                                        \
    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]) {                                            \
    167166                /* 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];                                      \
    169168            }                                                                                                \
    170169        }                                                                                                    \
  • 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
    17/** @file  pmFlatField.h
    28 *
     
    1824 *  @author Ross Harman, MHPCC
    1925 *
    20  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    21  *  @date $Date: 2005-10-20 23:06:24 $
     26 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2228 *
    2329 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2531
    2632#include "pslib.h"
    27 #include "pmAstrometry.h"
     33#include "pmFPA.h"
    2834
    2935
  • 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
    16/** @file  pmMaskBadPixels.c
    27 *
     
    1924 *  @author Ross Harman, MHPCC
    2025 *
    21  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-11-18 19:43:14 $
     26 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2328 *
    2429 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3136#include<stdio.h>
    3237#include<math.h>
    33 #include<string.h>
     38#include<strings.h>
    3439
    3540#include "pmMaskBadPixels.h"
    3641#include "pmMaskBadPixelsErrors.h"
    37 #include "pmSubtractBias.h"
    3842
    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 } \
     43bool 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;
    4462
    4563
    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    }
    6372
    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));
    15681    }
    15782    inMask = in->mask;
    15883
    15984    // 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) {
    16186        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    16287                 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);
    16489        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) {
    16691        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    16792                 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);
    16994        return false;
    17095    }
    17196
    17297    // 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;
    175100
    176101    // 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) {
    178103        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    179104                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE,
    180                  totOffRow, totOffCol, mask->image->numRows, mask->image->numCols);
     105                 totOffRow, totOffCol, mask->numRows, mask->numCols);
    181106        return false;
    182     } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
     107    } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    183108        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    184109                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE,
    185                  totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
     110                 totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    186111        return false;
    187112    } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     
    193118
    194119    // 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;
    197122    if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
    198123        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
     
    207132    }
    208133
    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)                                                                              \
     136case 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;
    223168
    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);
    237185    }
    238186
    239     return true;
     187    return false;
    240188}
  • 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
    16/** @file  pmMaskBadPixels.h
    27 *
     
    1924 *  @author Ross Harman, MHPCC
    2025 *
    21  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-11-15 20:09:03 $
     26 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2328 *
    2429 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2631
    2732#include "pslib.h"
    28 #include "pmAstrometry.h"
     33#include "pmFPA.h"
    2934
    3035/** Mask values */
     
    3338    PM_MASK_BADCOL  = 0x0002,   ///< The pixel is a bad column.
    3439    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.
    3642} pmMaskValue;
    3743
    38 // XXX: Use PS_MIN, PS_MAX
    3944/** Macro to find maximum of two numbers */
    4045#define MAX(A,B)((A)>=(B)?(A):(B))
     
    5459bool pmMaskBadPixels(
    5560    pmReadout *in,          ///< Readout containing input image data.
    56     const pmReadout *mask,   ///< Mask data to be added to readout mask data.
     61    const psImage *mask,    ///< Mask data to be added to readout mask data.
    5762    unsigned int maskVal,   ///< Mask value to determine what to add to input mask.
    5863    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
    16/** @file  pmMaskBadPixelsErrors.h
    27 *
     
    712 *  @author Ross Harman, MHPCC
    813 *
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-28 20:43:52 $
     14 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-04-17 18:01:05 $
    1116 *
    1217 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2328 *     $2  The error text (rest of the line in pmMaskBadPixelsErrors.h)
    2429 *     $n  The order of the source line in pmMaskBadPixelsErrors.h (comments excluded)
    25  * 
     30 *
    2631 * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
    2732 */
  • 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
    16/** @file  pmNonLinear.c
    27 *
     
    510 *  @author GLG, MHPCC
    611 *
    7  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-12-05 20:49:40 $
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-17 18:01:05 $
    914 *
    1015 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2227
    2328#include "pmNonLinear.h"
    24 #include "pmSubtractBias.h"
    2529
    26 // XXX: Remove, autoconf must be
    27 #define PS_WARN_PTR_NON_NULL(NAME) \
    28 if ((NAME) == NULL) { \
    29     psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
    30 } \
    3130/******************************************************************************
    3231pmNonLinearityLookup(): This routine will take an pmReadout image as input
    3332and 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
     33be evaluated at that pixels value, and the image pixel will then be set to
    3634that value.
    37 *****************************************************************************/
     35 *****************************************************************************/
    3836
    39 pmReadout *pmNonLinearityPolynomial(
    40     pmReadout *inputReadout,
    41     const psPolynomial1D *input1DPoly)
     37pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout,
     38                                    const psPolynomial1D *input1DPoly)
    4239{
    4340    PS_ASSERT_PTR_NON_NULL(inputReadout, NULL);
     
    4542    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
    4643    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     }
    5144
    52     //
    53     // Determine trimmed image from metadata.
    54     //
    55     psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout);
     45    psS32 i;
     46    psS32 j;
    5647
    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]);
    6151        }
    6252    }
     
    7161inFluxe, and the corresponding value in outFlux.  The image pixel will then
    7262be set to the value from outFlux.
    73  
    74 XXX: Must assert that filename exists.  This should probably happen in
    75 the lookup files.
    7663 *****************************************************************************/
    77 pmReadout *pmNonLinearityLookup(
    78     pmReadout *inputReadout,
    79     const char *filename
    80 )
     64pmReadout *pmNonLinearityLookup(pmReadout *inputReadout,
     65                                const psVector *inFlux,
     66                                const psVector *outFlux)
    8167{
    8268    PS_ASSERT_PTR_NON_NULL(inputReadout,NULL);
    8369    PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL);
    8470    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);
    8875    }
    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);
    9385
    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;
    9690    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);
    109120            }
    110121        }
    111         if (numPixels > 0) {
    112             psLogMsg(__func__, PS_LOG_WARN,
    113                      "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
    114         }
    115122    }
    116 
     123    if (numPixels > 0) {
     124        psLogMsg(__func__, PS_LOG_WARN,
     125                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
     126    }
    117127    return(inputReadout);
    118128}
  • 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
    16/** @file  pmNonLinear.h
    27 *
     
    510 *  @author GLG, MHPCC
    611 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-10-20 23:06:24 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-17 18:01:05 $
    914 *
    1015 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1621
    1722#include "pslib.h"
    18 #include "pmAstrometry.h"
     23#include "pmFPA.h"
    1924
    20 pmReadout *pmNonLinearityPolynomial(
    21     pmReadout *in,
    22     const psPolynomial1D *coeff
    23 );
     25pmReadout *pmNonLinearityPolynomial(pmReadout *in,
     26                                    const psPolynomial1D *coeff);
    2427
    25 pmReadout *pmNonLinearityLookup(
    26     pmReadout *in,
    27     const char *filename
    28 );
     28pmReadout *pmNonLinearityLookup(pmReadout *in,
     29                                const psVector *inFlux,
     30                                const psVector *outFlux);
    2931
    3032#endif
  • trunk/psModules/src/imcombine/Makefile.am

    r5170 r6872  
    33libpsmoduleimcombine_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
    44libpsmoduleimcombine_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    5 libpsmoduleimcombine_la_SOURCES  = pmImageCombine.c \
    6     pmReadoutCombine.c
     5libpsmoduleimcombine_la_SOURCES  = pmImageCombine.c
     6#    pmReadoutCombine.c
    77
    88psmoduleincludedir = $(includedir)
    99psmoduleinclude_HEADERS = \
    10     pmImageCombine.h \
    11     pmReadoutCombine.h
     10    pmImageCombine.h
     11#    pmReadoutCombine.h
  • trunk/psModules/src/imcombine/pmReadoutCombine.h

    r6205 r6872  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-01-26 21:10:50 $
     7 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-04-17 18:01:05 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pslib.h"
    2424#include "psConstants.h"
    25 #include "pmAstrometry.h"
     25#include "pmFPA.h"
    2626
    2727typedef struct
     
    3333    int nKeep;
    3434}
    35 psCombineParams;
     35pmCombineParams;
     36
     37pmCombineParams *pmCombineParamsAlloc (psStatsOptions statsOptions);
    3638
    3739psImage *pmReadoutCombine(psImage *output,
    38                           const psList *inputs,
    39                           psCombineParams *params,
     40                          const psArray *inputs,
    4041                          const psVector *zero,
    4142                          const psVector *scale,
     43                          pmCombineParams *params,
    4244                          bool applyZeroScale,
    4345                          float gain,
     
    7274pmFringePoint;
    7375
    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 input
    79  * flat-field image flux levels. All of these vectors must be constructed with
    80  * the same number of elements, or the function will return an error. If a chip
    81  * is missing from a particular image, that element should be set to NaN. The
    82  * vector chipGains supplies initial guesses for the chip gains. If the vector
    83  * contains the values 0.0 or NaN for any of the elements, the gain is set to the
    84  * mean of the valid values. If the vector length does not match the number of
    85  * chips, an warning is raised, all chip gain guesses will be set to 1.0, and the
    86  * vector length modified to match the number of chips defined by the supplied
    87  * fluxLevels. The sourceFlux input vector must be allocated (not NULL), but the
    88  * routine will set the vector length to the number of source images regardless
    89  * of the initial state of the vector. All vectors used by this function must be
    90  * of type PS_DATA_F64.
    91  *
    92  */
    93 bool pmFlatNormalization(
    94     psVector *sourceFlux,
    95     psVector *chipGains,
    96     psArray *fluxLevels
    97 );
    98 
    99 
    10076#endif
  • trunk/psModules/src/imsubtract/Makefile.am

    r5170 r6872  
    44libpsmoduleimsubtract_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    55libpsmoduleimsubtract_la_SOURCES  = pmImageSubtract.c \
    6     pmSubtractBias.c \
    7     pmSubtractSky.c
     6    pmSubtractBias.c
     7#    pmSubtractSky.c
    88
    99psmoduleincludedir = $(includedir)
    1010psmoduleinclude_HEADERS = \
    1111    pmImageSubtract.h \
    12     pmSubtractBias.h \
    13     pmSubtractSky.h
     12    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
    16/** @file  pmSubtractBias.h
    27 *
     
    611 *  @author GLG, MHPCC
    712 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-11-23 23:54:30 $
     13 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-04-17 18:01:05 $
    1015 *
    1116 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2328#include<math.h>
    2429#include "pslib.h"
    25 #include "pmAstrometry.h"
     30
     31#include "pmFPA.h"
    2632
    2733typedef enum {
    2834    PM_OVERSCAN_NONE,                         ///< No overscan subtraction
     35    PM_OVERSCAN_EDGE,                         ///< Subtract the statistic of pixels along the to-be-determined readout direction
    2936    PM_OVERSCAN_ROWS,                         ///< Subtract rows
    3037    PM_OVERSCAN_COLUMNS,                      ///< Subtract columns
     
    3340
    3441typedef 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
    3846} pmFit;
    3947
    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 );
     48typedef 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}
     59pmOverscanOptions;
    5060
    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 );
     61pmOverscanOptions *pmOverscanOptionsAlloc(bool single, pmFit fitType, unsigned int order, psStats *stat);
     62
     63pmReadout *pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
     64                          const pmReadout *bias, const pmReadout *dark);
     65
     66#if 0
     67pmReadout *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
    6176
    6277#endif
  • trunk/psModules/src/imsubtract/pmSubtractSky.h

    r5170 r6872  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-09-28 20:43:52 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-17 18:01:05 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include<math.h>
    2424#include "pslib.h"
    25 #include "pmAstrometry.h"
     25#include "pmFPA.h"
    2626
    2727// XXX: this is pmFit in pmSubtractBias.c, named psFit here.
  • trunk/psModules/src/objects/Makefile.am

    r5844 r6872  
    11noinst_LTLIBRARIES = libpsmoduleobjects.la
    22
    3 libpsmoduleobjects_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
     3libpsmoduleobjects_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) -I../pslib/
    44libpsmoduleobjects_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    55libpsmoduleobjects_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
    1125
    1226EXTRA_DIST = \
     
    1832psmoduleincludedir = $(includedir)
    1933psmoduleinclude_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  
    2626
    2727    if (deriv != NULL) {
    28         // note difference from a pure gaussian: q = PAR[1]*r
     28        psF32 *dPAR = deriv->data.F32;
    2929        psF32 q = PAR[1]*r*r*t;
    30         deriv->data.F32[0] = +1.0;
    31         deriv->data.F32[1] = +r;
    32         deriv->data.F32[2] = q*(2.0*px*PAR[4] + PAR[6]*Y);
    33         deriv->data.F32[3] = q*(2.0*py*PAR[5] + PAR[6]*X);
    34         deriv->data.F32[4] = -2.0*q*px*X;
    35         deriv->data.F32[5] = -2.0*q*py*Y;
    36         deriv->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;
    3737    }
    3838    return(f);
     
    5050
    5151    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;
    5353    beta_lim[0][0].data.F32[2] = 5;
    5454    beta_lim[0][0].data.F32[3] = 5;
     
    6666
    6767    params_max[0][0].data.F32[0] = 1e5;
    68     params_max[0][0].data.F32[1] = 1e6;
     68    params_max[0][0].data.F32[1] = 1e8;
    6969    params_max[0][0].data.F32[2] = 1e4;  // this should be set by image dimensions!
    7070    params_max[0][0].data.F32[3] = 1e4;  // this should be set by image dimensions!
     
    133133    params[5] = 1.2 / moments->Sy;
    134134    params[6] = 0.0;
     135
    135136    return(true);
    136137}
  • trunk/psModules/src/objects/models/pmModel_QGAUSS.c

    r6511 r6872  
    2626    psF32 py = PAR[5]*Y;
    2727    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];
    3134
    3235    if (deriv != NULL) {
     36        psF32 *dPAR = deriv->data.F32;
     37
    3338        // 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;
    4551    }
    4652    return(f);
     
    5864
    5965    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;
    6167    beta_lim[0][0].data.F32[2] = 5;
    6268    beta_lim[0][0].data.F32[3] = 5;
     
    7682
    7783    params_max[0][0].data.F32[0] = 1e5;
    78     params_max[0][0].data.F32[1] = 1e6;
     84    params_max[0][0].data.F32[1] = 1e8;
    7985    params_max[0][0].data.F32[2] = 1e4;  // this should be set by image dimensions!
    8086    params_max[0][0].data.F32[3] = 1e4;  // this should be set by image dimensions!
     
    102108    params[6] = 0.0;
    103109    params[7] = 1.0;
     110
    104111    return(true);
    105112}
     
    119126    // the area needs to be multiplied by the integral of f(z)
    120127    norm = 0.0;
    121     for (z = 0.005; z < 50; z += 0.01) {
     128    for (z = 0.05; z < 50; z += 0.1) {
    122129        f = 1.0 / (1 + PAR[7]*z + pow(z, 2.25));
     130        // test: f = 1.0 / (1 + PAR[7]*z + PS_SQR(z));
    123131        norm += f;
    124132    }
    125     norm *= 0.01;
     133    norm *= 0.1;
    126134
    127135    psF64 Flux = PAR[1] * Area * norm;
     
    150158
    151159    // 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) {
    153161        f = 1.0 / (1 + PAR[7]*z + pow(z, 2.25));
     162        // test: f = 1.0 / (1 + PAR[7]*z + PS_SQR(z));
    154163        if (f < limit)
    155164            break;
     
    201210    status &= ((dPAR[1]/PAR[1]) < 0.5);
    202211
    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  
    117117    psVector *params = model->params;
    118118
    119     EllipseAxes axes;
    120     EllipseShape shape;
    121     EllipseMoments moments;
     119    psEllipseAxes axes;
     120    psEllipseShape shape;
     121    psEllipseMoments moments;
    122122
    123123    moments.x2 = PS_SQR(source->moments->Sx);
     
    125125    moments.xy = source->moments->Sxy;
    126126
    127     axes = EllipseMomentsToAxes(moments);
    128     shape = EllipseAxesToShape(axes);
     127    axes = psEllipseMomentsToAxes(moments);
     128    shape = psEllipseAxesToShape(axes);
    129129
    130130    params->data.F32[0] = source->moments->Sky;
  • trunk/psModules/src/objects/models/pmModel_SGAUSS.c

    r6511 r6872  
    1717
    1818# define SQ(A)((A)*(A))
    19 psF64 psImageEllipseContour (EllipseAxes axes, double xc, double yc, psImage *image);
     19psF64 psImageEllipseContour (psEllipseAxes axes, double xc, double yc, psImage *image);
    2020psF64 p_psImageGetElementF64(psImage *a, int i, int j);
    2121
     
    102102
    103103// measure the flux for the elliptical contour
    104 psF64 psImageEllipseContour (EllipseAxes axes, double xc, double yc, psImage *image)
     104psF64 psImageEllipseContour (psEllipseAxes axes, double xc, double yc, psImage *image)
    105105{
    106106
     
    149149    psF32     *params   = model->params->data.F32;
    150150
    151     EllipseAxes axes;
    152     EllipseShape shape;
    153     EllipseMoments moments;
     151    psEllipseAxes axes;
     152    psEllipseShape shape;
     153    psEllipseMoments moments;
    154154
    155155    moments.x2 = PS_SQR(sMoments->Sx);
     
    158158
    159159    // 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);
    162162
    163163    params[0] = sMoments->Sky;
     
    199199    float f1, f2;
    200200
    201     EllipseAxes axes;
    202     EllipseShape shape;
    203     EllipseMoments moments;
     201    psEllipseAxes axes;
     202    psEllipseShape shape;
     203    psEllipseMoments moments;
    204204
    205205    moments.x2 = PS_SQR(sMoments->Sx);
     
    208208
    209209    // 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);
    212212
    213213    params[0] = sMoments->Sky;
     
    265265psF64 pmModelRadius_SGAUSS  (const psVector *params, psF64 flux)
    266266{
    267     psF64 r, z, pr, f;
     267    psF64 r, z = 0.0, pr, f;
    268268    psF32 *PAR = params->data.F32;
    269269
    270     EllipseAxes axes;
    271     EllipseShape shape;
     270    psEllipseAxes axes;
     271    psEllipseShape shape;
    272272
    273273    if (flux <= 0)
     
    283283    shape.sxy = PAR[6];
    284284
    285     axes = EllipseShapeToAxes (shape);
     285    axes = psEllipseShapeToAxes (shape);
    286286    psF64 dr = 1.0 / axes.major;
    287287    psF64 limit = flux / PAR[1];
     
    327327    psF32 dP;
    328328    bool  status;
    329     EllipseAxes axes;
    330     EllipseShape shape;
     329    psEllipseAxes axes;
     330    psEllipseShape shape;
    331331
    332332    psF32 *PAR  = model->params->data.F32;
     
    337337    shape.sxy = PAR[6];
    338338
    339     axes = EllipseShapeToAxes (shape);
     339    axes = psEllipseShapeToAxes (shape);
    340340
    341341    dP = 0;
  • trunk/psModules/src/objects/models/pmModel_ZGAUSS.c

    r5257 r6872  
    8585    psF32 *PAR = params->data.F32;
    8686
    87     EllipseAxes axes;
    88     EllipseShape shape;
     87    psEllipseAxes axes;
     88    psEllipseShape shape;
    8989
    9090    if (flux <= 0)
     
    100100    shape.sxy = PAR[6];
    101101
    102     axes = EllipseShapeToAxes (shape);
     102    axes = psEllipseShapeToAxes (shape);
    103103    psF64 dr = 1.0 / axes.major;
    104104    psF64 limit = flux / PAR[1];
     
    124124    psVector *params = model->params;
    125125
    126     EllipseAxes axes;
    127     EllipseShape shape;
    128     EllipseMoments moments;
     126    psEllipseAxes axes;
     127    psEllipseShape shape;
     128    psEllipseMoments moments;
    129129
    130130    moments.x2 = PS_SQR(source->moments->Sx);
     
    132132    moments.xy = source->moments->Sxy;
    133133
    134     axes = EllipseMomentsToAxes(moments);
    135     shape = EllipseAxesToShape(axes);
     134    axes = psEllipseMomentsToAxes(moments);
     135    shape = psEllipseAxesToShape(axes);
    136136
    137137    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 ???
    331double hypot(double x, double y);
    432double sqrt (double x);
    533
    6 #include "psEllipse.h"
    734#include "models/pmModel_GAUSS.c"
    835#include "models/pmModel_PGAUSS.c"
     
    2552    if (modelGroup == NULL)
    2653        return;
    27     psFree (modelGroup);
    2854    return;
    2955}
     
    6086    }
    6187    Nmodels = Nnew;
     88    return;
     89}
     90
     91void pmModelGroupCleanup (void)
     92{
     93
     94    psFree (models);
    6295    return;
    6396}
     
    153186    return (models[type].name);
    154187}
     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*****************************************************************************/
     199pmModel *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  
    99 *  @author EAM, IfA
    1010 *
    11  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-12-24 01:24:32 $
     11 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-04-17 18:01:05 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 *
    1616 */
    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.
     22typedef psMinimizeLMChi2Func pmModelFunc;
     23
     24// This function returns the integrated flux for the given model parameters.
     25typedef 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.
     30typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
     31
     32/*  This function sets the model parameter limits vectors for the given model
     33 */
     34typedef 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 */
     39typedef 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 */
     45typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
     46
     47/*  This function returns the success / failure status of the given model fit
     48 */
     49typedef 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 */
     64typedef 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}
     76pmModelGroup;
     77
     78// allocate a pmModelGroup to hold nModels entries
     79pmModelGroup *pmModelGroupAlloc (int nModels);
     80
     81// initialize the internal (static) model group with the default models
     82void pmModelGroupInit (void);
     83
     84// free the internal (static) model group
     85void pmModelGroupCleanup (void);
     86
     87// add a new model to the internal (static) model group
     88void pmModelGroupAdd (pmModelGroup *model);
     89
     90/* This function returns the number of parameters used by the listed function.
    2391 */
    2492int pmModelParameterCount(
     
    2795
    2896
    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.
    3398 */
    3499char *pmModelGetType(
     
    46111);
    47112
    48 
    49 #ifndef PM_MODEL_GROUP_H
    50 #define PM_MODEL_GROUP_H
    51 
    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 parameters
    70  *  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 model
    78  *
    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 of
    85  *   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 the
    94  *  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 fit
    102  *
    103  */
    104 typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    105 
    106113/**
    107114 *
     
    110117 *
    111118 */
    112 
    113119
    114120/**
     
    177183
    178184
     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 */
     194pmModel *pmSourceModelGuess(
     195    pmSource *source,   ///< The input pmSource
     196    pmModelType model   ///< The type of model to be created.
     197);
    179198
    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  
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-12-24 01:24:32 $
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-17 18:01:05 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include <math.h>
    2828#include "pslib.h"
    29 #include "pmAstrometry.h"
    30 /**
    31  * In the object analysis process, we will use specific mask values to mark the
    32  * 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 values
    35  * outside of the PSPHOT code.  Perhaps we can set up a registered set of mask
    36  * 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 /** pmPeakType
    47  *
    48  *  A peak pixel may have several features which may be determined when the
    49  *  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 immediate
    51  *  neighbors.  The PM_PEAK_EDGE represents a peak pixel which touching the image
    52  *  edge. The PM_PEAK_FLAT represents a peak pixel which has more than a specific
    53  *  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 structure
    65  *
    66  *  A source has the capacity for several types of measurements. The
    67  *  simplest measurement of a source is the location and flux of the peak pixel
    68  *  associated with the source:
    69  *
    70  */
    71 typedef struct
    72 {
    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 structure
    82  *
    83  * One of the simplest measurements which can be made quickly for an object
    84  * are the object moments. We specify a structure to carry the moment information
    85  * for a specific source:
    86  *
    87  */
    88 typedef struct
    89 {
    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-noise
    99     int nPixels;   ///< Number of pixels used.
    100 }
    101 pmMoments;
    102 
    103 
    104 /** pmPSFClump data structure
    105  *
    106  * A collection of object moment measurements can be used to determine
    107  * approximate object classes. The key to this analysis is the location and
    108  * statistics (in the second-moment plane,
    109  *
    110  */
    111 typedef struct
    112 {
    113     float X;
    114     float dX;
    115     float Y;
    116     float dY;
    117 }
    118 pmPSFClump;
    119 
    120 // type of model carried by the pmModel structure
    121 typedef int pmModelType;
    122 
    123 typedef enum {
    124     PM_MODEL_UNTRIED,               ///< model fit not yet attempted
    125     PM_MODEL_SUCCESS,               ///< model fit succeeded
    126     PM_MODEL_NONCONVERGE,           ///< model fit did not converge
    127     PM_MODEL_OFFIMAGE,              ///< model fit drove out of range
    128     PM_MODEL_BADARGS                ///< model fit called with invalid args
    129 } pmModelStatus;
    130 
    131 /** pmModel data structure
    132  *
    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 specific
    135  * object. In this case, the PSF-dependent parameters are specified for the
    136  * object by the PSF, not by the fit. The FLT model represents the best fit of
    137  * the given model to the object, with all parameters floating in the fit.
    138  *
    139  */
    140 typedef struct
    141 {
    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 freedom
    147     int nIter;    ///< number of iterations to reach min
    148     int status;         ///< fit status
    149     float radius;   ///< fit radius actually used
    150 }
    151 pmModel;
    152 
    153 /** pmSourceType enumeration
    154  *
    155  * A given source may be identified as most-likely to be one of several source
    156  * types. The pmSource entry pmSourceType defines the current best-guess for this
    157  * source.
    158  *
    159  * XXX: The values given below are currently illustrative and will require
    160  * some modification as the source classification code is developed. (TBD)
    161  *
    162  */
    163 typedef enum {
    164     PM_SOURCE_DEFECT,                   ///< a cosmic-ray
    165     PM_SOURCE_SATURATED,                ///< random saturated pixels
    166 
    167     PM_SOURCE_SATSTAR,                  ///< a saturated star
    168     PM_SOURCE_PSFSTAR,                  ///< a PSF star
    169     PM_SOURCE_GOODSTAR,                 ///< a good-quality star
    170 
    171     PM_SOURCE_POOR_FIT_PSF,             ///< poor quality PSF fit
    172     PM_SOURCE_FAIL_FIT_PSF,             ///< failed to get a good PSF fit
    173     PM_SOURCE_FAINTSTAR,                ///< below S/N cutoff
    174 
    175     PM_SOURCE_GALAXY,                   ///< an extended object (galaxy)
    176     PM_SOURCE_FAINT_GALAXY,             ///< a galaxy below S/N cutoff
    177     PM_SOURCE_DROP_GALAXY,              ///< ?
    178     PM_SOURCE_FAIL_FIT_GAL,             ///< failed on the galaxy fit
    179     PM_SOURCE_POOR_FIT_GAL,             ///< poor quality galaxy fit
    180 
    181     PM_SOURCE_OTHER,                    ///< unidentified
    182 } pmSourceType;
    183 
    184 /** pmSource data structure
    185  *
    186  *  This source has the capacity for several types of measurements. The
    187  *  simplest measurement of a source is the location and flux of the peak pixel
    188  *  associated with the source:
    189  *
    190  */
    191 typedef struct
    192 {
    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 NULL
    210  */
    211 pmPeak *pmPeakAlloc(
    212     int x,    ///< Row-coordinate in image space
    213     int y,    ///< Col-coordinate in image space
    214     float counts,   ///< The value of the peak pixel
    215     pmPeakType class   ///< The type of peak pixel
    216 );
    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 peak
    240  * is defined as any element with a value greater than its two neighbors and with
    241  * 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 following
    243  * element, it is not considered a peak. If an element has the same value as the
    244  * preceding element (but not the following), then it is considered a peak. Note
    245  * 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 its
    247  * neighbor. At the end of the vector, the element must be higher or equal to its
    248  * neighbor. These two rules again places the peak associated with a flat region
    249  * which touches the image edge at the image edge. The result of this function is
    250  * a vector containing the coordinates (element number) of the detected peaks
    251  * (type psU32).
    252  *
    253  */
    254 psVector *pmFindVectorPeaks(
    255     const psVector *vector,  ///< The input vector (float)
    256     float threshold   ///< Threshold above which to find a peak
    257 );
    258 
    259 
    260 /** pmFindImagePeaks()
    261  *
    262  * Find all local peaks in the given image above the given threshold. This
    263  * function should find all row peaks using pmFindVectorPeaks, then test each row
    264  * peak and exclude peaks which are not local peaks. A peak is a local peak if it
    265  * has a higher value than all 8 neighbors. If the peak has the same value as its
    266  * +y neighbor or +x neighbor, it is NOT a local peak. If any other neighbors
    267  * 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 single
    270  * peaks at the (+x,+y) corner. When selecting the peaks, their type must also be
    271  * 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 peak
    277 );
    278 
    279 
    280 /** pmCullPeaks()
    281  *
    282  * Eliminate peaks from the psList that have a peak value above the given
    283  * maximum, or fall outside the valid region.
    284  *
    285  */
    286 psList *pmCullPeaks(
    287     psList *peaks,   ///< The psList of peaks to be culled
    288     float maxValue,   ///< Cull peaks above this value
    289     const psRegion valid                ///< Cull peaks otside this psRegion
    290 );
    291 
    292 
    293 /** pmPeaksSubset()
    294  *
    295  * Create a new peaks array, removing certain types of peaks from the input
    296  * array of peaks based on the given criteria. Peaks should be eliminated if they
    297  * have a peak value above the given maximum value limit or if the fall outside
    298  * the valid region.  The result of the function is a new array with a reduced
    299  * 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 the
    312  * image set defined by readout. The pixels defined by this operation consist of
    313  * a square window (of full width 2Radius+1) centered on the pixel which contains
    314  * the given coordinate, in the frame of the readout. The window is defined to
    315  * have limits which are valid within the boundary of the readout image, thus if
    316  * the radius would fall outside the image pixels, the subimage is truncated to
    317  * only consist of valid pixels. If readout->mask or readout->weight are not
    318  * NULL, matching subimages are defined for those images as well. This function
    319  * fails if no valid pixels can be defined (x or y less than Radius, for
    320  * example). This function should be used to define a region of interest around a
    321  * 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 Radius
    339  * defines the square aperture in which the moments will be measured. This
    340  * function assumes the source pixels have been defined, and that the value of
    341  * Radius here is smaller than the value of Radius used to define the pixels. The
    342  * annular region not contained within the radius defined here is used to measure
    343  * the local background in the vicinity of the source. The local background
    344  * measurement uses the specified statistic passed in via the statsOptions entry.
    345  * This function allocates the pmMoments structure. The resulting sky is used to
    346  * 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 sky
    352     float Radius   ///< The inner radius of the square annulus to exclude
    353 );
    354 
    355 
    356 /** pmSourceMoments()
    357  *
    358  * Measure source moments for the given source, using the value of
    359  * source.moments.sky provided as the local background value and the peak
    360  * coordinates as the initial source location. The resulting moment values are
    361  * applied to the source.moments entry, and the source is returned. The moments
    362  * 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 computed
    368     float radius   ///< Use a circle of pixels around the peak
    369 );
    370 
    371 
    372 /** pmSourcePSFClump()
    373  *
    374  * We use the source moments to make an initial, approximate source
    375  * classification, and as part of the information needed to build a PSF model for
    376  * the image. As long as the PSF shape does not vary excessively across the
    377  * image, the sources which are represented by a PSF (the start) will have very
    378  * similar second moments. The function pmSourcePSFClump searches a collection of
    379  * sources with measured moments for a group with moments which are all very
    380  * similar. The function returns a pmPSFClump structure, representing the
    381  * 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 the
    384  * sigma_x, sigma_y second-moment plane.  To do this, an image is constructed to
    385  * represent this plane.  The units of sigma_x and sigma_y are in image pixels. A
    386  * pixel in this analysis image represents 0.1 pixels in the input image. The
    387  * dimensions of the image need only be 10 pixels. The peak pixel in this image
    388  * (above a threshold of half of the image maximum) is found. The coordinates of
    389  * 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 then
    391  *  * used to calculate the median and standard deviation of the sigma_x, sigma_y
    392  * 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 pmSource
    402     psMetadata *metadata  ///< Contains classification parameters
    403 );
    404 
    405 
    406 /** pmSourceRoughClass()
    407  *
    408  * Based on the specified data values, make a guess at the source
    409  * classification. The sources are provides as a psArray of pmSource entries.
    410  * Definable parameters needed to make the classification are provided to the
    411  * routine with the psMetadata structure. The rules (in SDRS) refer to values which
    412  * 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 pmSource
    418     psMetadata *metadata,  ///< Contains classification parameters
    419     pmPSFClump clump   ///< Statistics about the PSF clump
    420 );
    421 
    422 
    423 /** pmSourceModelGuess()
    424  *
    425  * Convert available data to an initial guess for the given model. This
    426  * function allocates a pmModel entry for the pmSource structure based on the
    427  * provided model selection. The method of defining the model parameter guesses
    428  * are specified for each model below. The guess values are placed in the model
    429  * parameters. The function returns TRUE on success or FALSE on failure.
    430  *
    431  */
    432 pmModel *pmSourceModelGuess(
    433     pmSource *source,   ///< The input pmSource
    434     pmModelType model   ///< The type of model to be created.
    435 );
    436 
    437 
    438 /** pmContourType
    439  *
    440  * Only one type is defined at present.
    441  *
    442  */
    443 typedef enum {
    444     PS_CONTOUR_CRUDE,
    445     PS_CONTOUR_UNKNOWN01,
    446     PS_CONTOUR_UNKNOWN02
    447 } pmContourType;
    448 
    449 
    450 /** pmSourceContour()
    451  *
    452  * Find points in a contour for the given source at the given level. If type
    453  * 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 to
    455  * the level coordinate for that row. This is done for each row, with the
    456  * starting point determined by the midpoint of the previous row, until the
    457  * starting point has a value below the contour level. The returned contour
    458  * 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 contour
    460  * types may be specified in the future for more refined contours (TBD)
    461  *
    462  */
    463 psArray *pmSourceContour(
    464     pmSource *source,   ///< The input pmSource
    465     const psImage *image,  ///< The input image (float) (this arg should be removed)
    466     float level,   ///< The level of the contour
    467     pmContourType mode   ///< Currently this must be PS_CONTOUR_CRUDE
    468 );
    469 
    470 
    471 /** pmSourceFitModel()
    472  *
    473  * Fit the requested model to the specified source. The starting guess for the
    474  * model is given by the input source.model parameter values. The pixels of
    475  * interest are specified by the source.pixelsand source.maskentries. This
    476  * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    477  * on success or FALSE on failure.
    478  *
    479  */
    480 bool pmSourceFitModel(
    481     pmSource *source,   ///< The input pmSource
    482     pmModel *model,   ///< model to be fitted
    483     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 by
    490  * pmModelFitStatusFunc_GetFunction.  The model-specific function examines the
    491  * model parameters, parameter errors, Chisq, S/N, and other parameters available
    492  * 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 boolean
    505  * option center selects if the source is re-centered to the image center or if
    506  * it is placed at its centroid location. The boolean option sky selects if the
    507  * background sky is applied (TRUE) or not. The pixel range in the target image
    508  * is at most the pixel range specified by the source.pixels image. The success
    509  * 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 pmModel
    516     bool center,    ///< A boolean flag that determines whether pixels are centered
    517     bool sky        ///< A boolean flag that determines if the sky is subtracted
    518 );
    519 
    520 
    521 /** pmSourceSubModel()
    522  *
    523  * Subtract the given source model flux to/from the provided image. The
    524  * boolean option center selects if the source is re-centered to the image center
    525  * or if it is placed at its centroid location. The boolean option sky selects if
    526  * the background sky is applied (TRUE) or not. The pixel range in the target
    527  * image is at most the pixel range specified by the source.pixels image. The
    528  * 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 pmModel
    535     bool center,    ///< A boolean flag that determines whether pixels are centered
    536     bool sky        ///< A boolean flag that determines if the sky is subtracted
    537 );
    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 0
    544  * to infinity. In practice, we integrate the model beyond 50sigma.  The aperture magnitude is
    545  * defined as -2.5log(flux) , where the flux is summed for all pixels which are
    546  * not excluded by the aperture mask. The model flux is calculated by calling the
    547  * model-specific function provided by pmModelFlux_GetFunction.
    548  *
    549  * XXX: must code this.
    550  *
    551  */
    552 bool pmSourcePhotometry(
    553     float *fitMag,                      ///< integrated fit magnitude
    554     float *obsMag,   ///< aperture flux magnitude
    555     pmModel *model,                     ///< model used for photometry
    556     psImage *image,                     ///< image pixels to be used
    557     psImage *mask                       ///< mask of pixels to ignore
    558 );
    559 
    56029
    56130/**
     
    56332 * This function converts the source classification into the closest available
    56433 * approximation to the Dophot classification scheme:
     34 * XXX EAM : fix this to use current source classification scheme
    56535 *
    56636 * PM_SOURCE_DEFECT: 8
     
    59868);
    59969
    600 /** pmSourceFitModel_v5()
    601  *
    602  * Fit the requested model to the specified source. The starting guess for the
    603  * model is given by the input source.model parameter values. The pixels of
    604  * interest are specified by the source.pixelsand source.maskentries. This
    605  * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    606  * on success or FALSE on failure.
    607  *
    608  */
    609 bool pmSourceFitModel_v5(
    610     pmSource *source,   ///< The input pmSource
    611     pmModel *model,   ///< model to be fitted
    612     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 the
    619  * model is given by the input source.model parameter values. The pixels of
    620  * interest are specified by the source.pixelsand source.maskentries. This
    621  * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    622  * on success or FALSE on failure.
    623  *
    624  */
    625 bool pmSourceFitModel_v7(
    626     pmSource *source,   ///< The input pmSource
    627     pmModel *model,   ///< model to be fitted
    628     const bool PSF   ///< Treat model as PSF or FLT?
    629 );
    630 
    631 
    632 /** pmSourcePhotometry()
    633  *
    634  * XXX: Need descriptions
    635  *
    636  */
    637 bool pmSourcePhotometry(
    638     float *fitMag,
    639     float *obsMag,
    640     pmModel *model,
    641     psImage *image,
    642     psImage *mask
    643 );
    644 
    645 /** pmModelEval()
    646  *
    647  *  XXX: Need descriptions
    648  *
    649  */
    650 psF32 pmModelEval(
    651     pmModel *model,
    652     psImage *image,
    653     psS32 col,
    654     psS32 row
    655 );
    65670
    65771#endif
  • trunk/psModules/src/objects/pmPSF.h

    r5255 r6872  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-10-10 19:53:40 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-17 18:01:05 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515# ifndef PM_PSF_H
    1616# define PM_PSF_H
    17 
    1817
    1918/** pmPSF data structure
     
    3332    pmModelType type;   ///< PSF Model in use
    3433    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??)
    3942    int nPSFstars;   ///< number of stars used to measure PSF
     43    int nApResid;   ///< number of stars used to measure ApResid
     44    bool poissonErrors;
    4045}
    4146pmPSF;
    4247
     48typedef 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;
    4359
    4460/**
     
    4864 */
    4965pmPSF *pmPSFAlloc(
    50     pmModelType type                    ///< Add comment
     66    pmModelType type,   // type of model for PSF
     67    bool poissonErrors   ///< use poissonian errors or not?
    5168);
    5269
     
    85102);
    86103
     104bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option);
     105
    87106# endif
  • trunk/psModules/src/objects/pmPSFtry.h

    r5844 r6872  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-12-24 01:24:32 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-04-17 18:01:05 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919/**
    20  *
     20 * 
    2121 * This structure contains a pointer to the collection of sources which will
    2222 * be used to test the PSF model form. It lists the pmModelType type of model
    2323 * being tests, and contains an element to store the resulting psf
    2424 * representation. In addition, this structure carries the complete collection of
    25  * FLT (floating parameter) and PSF (fixed parameter) model fits to each of the
    26  * sources modelFLT and modelPSF. It also contains a mask which is set by the
     25 * 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
    2727 * model fitting and psf fitting steps. For each model, the value of the quality
    2828 * metric is stored in the vector metric and the fitted instrumental magnitude is
     
    3838 * ultimate metric to intercompare multiple types of PSF models is the value of
    3939 * the aperture correction scatter.
    40  *
     40 * 
    4141 * XXX: There are many more members in the SDRS then in the prototype code.
    4242 * I stuck with the prototype code.
    43  *
    44  *
     43 * 
     44 * 
    4545 */
    4646typedef struct
     
    4848    pmPSF      *psf;                    ///< Add comment.
    4949    psArray    *sources;                ///< pointers to the original sources
    50     psArray    *modelFLT;               ///< model fits, floating parameters
     50    psArray    *modelEXT;               ///< model fits, floating parameters
    5151    psArray    *modelPSF;               ///< model fits, PSF parameters
    5252    psVector   *mask;                   ///< Add comment.
     
    5858
    5959/** pmPSFtryMaskValues
    60  *
     60 * 
    6161 * The following datatype defines the masks used by the pmPSFtry analysis to
    6262 * identify sources which should or should not be included in the analysis.
    63  *
     63 * 
    6464 */
    65 enum {
     65typedef enum {
    6666    PSFTRY_MASK_CLEAR    = 0x00,        ///< Add comment.
    6767    PSFTRY_MASK_OUTLIER  = 0x01,        ///< 1: outlier in psf polynomial fit (provided by psPolynomials)
    68     PSFTRY_MASK_FLT_FAIL = 0x02,        ///< 2: flt model failed to converge
     68    PSFTRY_MASK_EXT_FAIL = 0x02,        ///< 2: ext model failed to converge
    6969    PSFTRY_MASK_PSF_FAIL = 0x04,        ///< 3: psf model failed to converge
    7070    PSFTRY_MASK_BAD_PHOT = 0x08,        ///< 4: invalid source photometry
     
    7474
    7575/** pmPSFtryAlloc()
    76  *
     76 * 
    7777 * Allocate a pmPSFtry data structure.
    78  *
     78 * 
    7979 */
    8080pmPSFtry *pmPSFtryAlloc(
    8181    psArray *stars,                     ///< Add comment.
    82     char *modelName                     ///< Add comment.
     82    char *modelName,                     ///< Add comment.
     83    bool poissonErrors   // use poissonian or constant errors?
    8384);
    8485
    8586
    8687/** pmPSFtryModel()
    87  *
     88 * 
    8889 * This function takes the input collection of sources and performs a complete
    8990 * analysis to determine a PSF model of the given type (specified by model name).
    9091 * The result is a pmPSFtry with the results of the analysis.
    91  *
     92 * 
    9293 */
    9394pmPSFtry *pmPSFtryModel(
    9495    psArray *sources,                   ///< Add comment.
    9596    char *modelName,                    ///< Add comment.
    96     float radius                        ///< Add comment.
     97    float radius,                     ///< Add comment.
     98    bool poissonErrors   // use poissonian or constant errors?
    9799);
    98100
    99101
    100102/** pmPSFtryMetric()
    101  *
     103 * 
    102104 * This function is used to measure the PSF model metric for the set of
    103105 * results contained in the pmPSFtry structure.
    104  *
     106 * 
    105107 */
    106108bool pmPSFtryMetric(
Note: See TracChangeset for help on using the changeset viewer.