IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2009, 5:20:29 PM (17 years ago)
Author:
watersc1
Message:

Finished up my edits to the detrend cleanup, and some changes to my
copy of burntool and the pslib astrometry. Detrend cleanup has not
been tested yet. That's up next.

Location:
branches/czw_branch/cleanup
Files:
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup

  • branches/czw_branch/cleanup/psModules/src/camera/Makefile.am

    r19695 r24951  
    2323        pmFPAfileIO.c \
    2424        pmFPAfileFitsIO.c \
     25        pmFPAfileFringeIO.c \
    2526        pmFPAFlags.c \
    2627        pmFPALevel.c \
    … …  
    5152        pmFPAfileIO.h \
    5253        pmFPAfileFitsIO.h \
     54        pmFPAfileFringeIO.h \
    5355        pmFPAFlags.h \
    5456        pmFPALevel.h \
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPABin.c

    r24479 r24951  
    6060                        continue;
    6161                    }
     62                    if (!isfinite(inImage->data.F32[y][x])) {
     63                        continue;
     64                    }
    6265                    sum += inImage->data.F32[y][x];
    6366                    numPix++;
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPAMaskWeight.c

    r24483 r24951  
    109109    float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level
    110110    if (!mdok || isnan(saturation)) {
    111         psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n");
    112         return false;
     111        // psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n");
     112        // return false;
     113        psWarning("CELL.SATURATION is not set --- completely masking cell.\n");
     114        saturation = NAN;
    113115    }
    114116    float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level
    115117    if (!mdok || isnan(bad)) {
    116         psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n");
    117         return false;
     118        // psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n");
     119        // return false;
     120        psWarning("CELL.BAD is not set --- completely masking cell.\n");
     121        bad = NAN;
    118122    }
    119123    psTrace("psModules.camera", 5, "Saturation: %f, bad: %f\n", saturation, bad);
    120124
     125    // if CELL.GAIN or CELL.READNOISE are not set, then the variance will be set to NAN;
     126    // in this case, we have to set the mask as well
     127    float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain
     128    if (!mdok) { gain = NAN; }
     129    float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise
     130    if (!mdok) { readnoise = NAN; }
    121131
    122132    // Set up the mask
    … …  
    127137    }
    128138    psImage *mask = readout->mask;      // The mask pixels
     139
     140    // completely mask if SATURATION or BAD are invalid
     141    if (isnan(saturation) || isnan(bad) || isnan(gain) || isnan(readnoise)) {
     142        psImageInit(mask, badMask);
     143        return true;
     144    }
     145
    129146    psImageInit(mask, 0);
    130147
    … …  
    210227    float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain
    211228    if (!mdok || isnan(gain)) {
    212         psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n");
    213         return false;
     229        // psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n");
     230        // return false;
     231        psWarning("CELL.GAIN is not set --- setting variance to NAN\n");
     232        gain = NAN;
    214233    }
    215234    float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise
    216235    if (!mdok || isnan(readnoise)) {
    217         psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n");
    218         return false;
    219     }
    220     if (psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) {
     236        // psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n");
     237        // return false;
     238        psWarning("CELL.READNOISE is not set --- setting variance to NAN\n");
     239        readnoise = NAN;
     240    }
     241    // if we have a non-NAN readnoise, then we need to ensure it has been updated (not necessary if NAN)
     242    if (!isnan(gain) && psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) {
    221243        psError(PS_ERR_IO, true, "CELL.READNOISE has not yet been updated for the gain");
    222244        return false;
     245    }
     246
     247    // for invalid input data, set the readout variance to NAN
     248    if (isnan(gain) || isnan(readnoise)) {
     249        if (!readout->variance) {
     250            // generate the image if needed
     251            readout->variance = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32);
     252        }
     253        // XXX need to set the mask, if defined
     254        psImageInit(readout->variance, NAN);
     255        return true;
    223256    }
    224257
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPARead.c

    r24058 r24951  
    141141// Determine number of readouts in the FITS file
    142142// In the process, reads the header and concepts
    143 static bool cellNumReadouts(pmCell *cell,    // Cell of interest
     143static int cellNumReadouts(pmCell *cell,    // Cell of interest
    144144                            psFits *fits,    // FITS file
    145145                            pmConfig *config // Configuration
    … …  
    153153    if (!hdu || hdu->blankPHU) {
    154154        psError(PS_ERR_IO, true, "Unable to find HDU");
    155         return false;
     155        return 0;
    156156    }
    157157    if (!pmCellReadHeader(cell, fits, config)) {
    158158        psError(PS_ERR_IO, false, "Unable to read header for cell!\n");
    159         return false;
     159        return 0;
    160160    }
    161161    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS, true, NULL)) {
    162162        psError(PS_ERR_IO, false, "Failed to read concepts for cell.\n");
    163         return false;
     163        return 0;
    164164    }
    165165
    … …  
    169169    if (!mdok) {
    170170        psError(PS_ERR_IO, true, "Unable to find NAXIS in header for extension %s\n", hdu->extname);
    171         return false;
    172     }
     171        return 0;
     172    }
     173
    173174    if (naxis == 0) {
    174175        // No pixels to read
    175176        psError(PS_ERR_IO, true, "No pixels in extension %s.", hdu->extname);
    176         return false;
     177        return 0;
    177178    }
    178179    if (naxis < 2 || naxis > 3) {
    179180        psError(PS_ERR_IO, true, "NAXIS in header of extension %s (= %d) is not valid.\n",
    180181                hdu->extname, naxis);
    181         return false;
     182        return 0;
    182183    }
    183184    int naxis3;                     // Number of image planes
    … …  
    186187        if (!mdok) {
    187188            psError(PS_ERR_IO, true, "Unable to find NAXIS3 in header for extension %s\n", hdu->extname);
    188             return false;
     189            return 0;
    189190        }
    190191    } else {
    … …  
    294295static bool readoutMore(pmReadout *readout, // Readout of interest
    295296                        psFits *fits,    // FITS file
    296                         int z,          // Plane number
     297                        int z,          // Plane number to read
     298                        int *zMax,      // Max plane number in this cell
    297299                        int numScans,   // Number of scans to read at a time
    298300                        fpaReadType type, // Type of image
    … …  
    308310    // N readouts, but numScans set to 0.  only the first should report that it requires data,
    309311    // even if all readouts lack the image pointer.
    310     if (!image) {
     312    if (numScans == 0) {
     313      if (!image) {
    311314        return true;
    312     }
    313 
    314     // If we have already read an image, this result implies we are done (no more to read)
    315     if (numScans == 0) {
    316         return false;
     315      } else {
     316        return false;
     317      }
    317318    }
    318319
    … …  
    322323        return false;
    323324    }
    324     int naxis3 = cellNumReadouts(cell, fits, config); // Number of planes
    325     if (z >= naxis3) {
     325    *zMax = cellNumReadouts(cell, fits, config); // Number of planes
     326    if (z >= *zMax) {
    326327        // No more to read
    327328        return false;
    … …  
    484485                             psFits *fits, // FITS file
    485486                             int z,     // Desired image plane
     487                             int *zMax, // Max plane number in this cell
    486488                             int numScans, // Number of scans (row or col depends on CELL.READDIR); 0 for all
    487489                             int overlap, // Number of scans (row/col) to overlap between scans
    … …  
    509511
    510512    int naxis3 = cellNumReadouts(cell, fits, config); // Number of image planes
     513    if (zMax) *zMax = naxis3;
     514
    511515    if (z >= naxis3) {
    512516        psError(PS_ERR_IO, false, "Desired image plane (%d) exceeds available number (%d).",
    … …  
    10211025
    10221026
    1023 bool pmReadoutMore(pmReadout *readout, psFits *fits, int z, int numScans, pmConfig *config)
     1027bool pmReadoutMore(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, pmConfig *config)
    10241028{
    10251029    PS_ASSERT_PTR_NON_NULL(readout, false);
    10261030    PS_ASSERT_FITS_NON_NULL(fits, false);
    10271031
    1028     return readoutMore(readout, fits, z, numScans, FPA_READ_TYPE_IMAGE, config);
    1029 }
    1030 
    1031 bool pmReadoutReadChunk(pmReadout *readout, psFits *fits, int z, int numScans, int overlap, pmConfig *config)
     1032    return readoutMore(readout, fits, z, zMax, numScans, FPA_READ_TYPE_IMAGE, config);
     1033}
     1034
     1035bool pmReadoutReadChunk(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, int overlap, pmConfig *config)
    10321036{
    10331037    PS_ASSERT_PTR_NON_NULL(readout, false);
    … …  
    10361040    PS_ASSERT_INT_NONNEGATIVE(numScans, false);
    10371041
    1038     return readoutReadChunk(readout, fits, z, numScans, overlap, FPA_READ_TYPE_IMAGE, config);
     1042    return readoutReadChunk(readout, fits, z, zMax, numScans, overlap, FPA_READ_TYPE_IMAGE, config);
    10391043}
    10401044
    … …  
    10441048    PS_ASSERT_FITS_NON_NULL(fits, false);
    10451049
    1046     return readoutReadChunk(readout, fits, z, 0, 0, FPA_READ_TYPE_IMAGE, config);
     1050    return readoutReadChunk(readout, fits, z, NULL, 0, 0, FPA_READ_TYPE_IMAGE, config);
    10471051}
    10481052
    … …  
    10841088//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    10851089
    1086 bool pmReadoutMoreMask(pmReadout *readout, psFits *fits, int z, int numScans, pmConfig *config)
     1090bool pmReadoutMoreMask(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, pmConfig *config)
    10871091{
    10881092    PS_ASSERT_PTR_NON_NULL(readout, false);
    10891093    PS_ASSERT_FITS_NON_NULL(fits, false);
    10901094
    1091     return readoutMore(readout, fits, z, numScans, FPA_READ_TYPE_MASK, config);
    1092 }
    1093 
    1094 bool pmReadoutReadChunkMask(pmReadout *readout, psFits *fits, int z, int numScans, int overlap,
     1095    return readoutMore(readout, fits, z, zMax, numScans, FPA_READ_TYPE_MASK, config);
     1096}
     1097
     1098bool pmReadoutReadChunkMask(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, int overlap,
    10951099                            pmConfig *config)
    10961100{
    … …  
    11001104    PS_ASSERT_INT_NONNEGATIVE(numScans, false);
    11011105
    1102     return readoutReadChunk(readout, fits, z, numScans, overlap, FPA_READ_TYPE_MASK, config);
     1106    return readoutReadChunk(readout, fits, z, zMax, numScans, overlap, FPA_READ_TYPE_MASK, config);
    11031107}
    11041108
    … …  
    11081112    PS_ASSERT_FITS_NON_NULL(fits, false);
    11091113
    1110     return readoutReadChunk(readout, fits, z, 0, 0, FPA_READ_TYPE_MASK, config);
     1114    return readoutReadChunk(readout, fits, z, NULL, 0, 0, FPA_READ_TYPE_MASK, config);
    11111115}
    11121116
    … …  
    11391143//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    11401144
    1141 bool pmReadoutMoreVariance(pmReadout *readout, psFits *fits, int z, int numScans, pmConfig *config)
     1145bool pmReadoutMoreVariance(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, pmConfig *config)
    11421146{
    11431147    PS_ASSERT_PTR_NON_NULL(readout, false);
    11441148    PS_ASSERT_FITS_NON_NULL(fits, false);
    11451149
    1146     return readoutMore(readout, fits, z, numScans, FPA_READ_TYPE_VARIANCE, config);
    1147 }
    1148 
    1149 bool pmReadoutReadChunkVariance(pmReadout *readout, psFits *fits, int z, int numScans, int overlap,
     1150    return readoutMore(readout, fits, z, zMax, numScans, FPA_READ_TYPE_VARIANCE, config);
     1151}
     1152
     1153bool pmReadoutReadChunkVariance(pmReadout *readout, psFits *fits, int z, int *zMax, int numScans, int overlap,
    11501154                              pmConfig *config)
    11511155{
    … …  
    11551159    PS_ASSERT_INT_NONNEGATIVE(numScans, false);
    11561160
    1157     return readoutReadChunk(readout, fits, z, numScans, overlap, FPA_READ_TYPE_VARIANCE, config);
     1161    return readoutReadChunk(readout, fits, z, zMax, numScans, overlap, FPA_READ_TYPE_VARIANCE, config);
    11581162}
    11591163
    … …  
    11631167    PS_ASSERT_FITS_NON_NULL(fits, false);
    11641168
    1165     return readoutReadChunk(readout, fits, z, 0, 0, FPA_READ_TYPE_VARIANCE, config);
     1169    return readoutReadChunk(readout, fits, z, NULL, 0, 0, FPA_READ_TYPE_VARIANCE, config);
    11661170}
    11671171
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPARead.h

    r21363 r24951  
    2121                   psFits *fits,        ///< FITS file from which to read
    2222                   int z,               ///< Readout number/plane; zero-offset indexing
     23                   int *zMax,           ///< Max plane number in this cell
    2324                   int numScans,        ///< Number of scans (rows/cols) to read
    2425                   pmConfig *config     ///< Configuration
    … …  
    3132                        psFits *fits,   ///< FITS file from which to read
    3233                        int z,          ///< Readout number/plane; zero-offset indexing
     34                   int *zMax,           ///< Max plane number in this cell
    3335                        int numScans,   ///< Number of scans (rows/cols) to read
    3436                        int overlap,    ///< Overlap between consecutive reads
    … …  
    98100                       psFits *fits,    ///< FITS file from which to read
    99101                       int z,           ///< Readout number/plane; zero-offset indexing
     102                       int *zMax,       ///< Max plane number in this cell
    100103                       int numScans,    ///< Number of scans (rows/cols) to read
    101104                       pmConfig *config ///< Configuration
    … …  
    108111                            psFits *fits, ///< FITS file from which to read
    109112                            int z,      ///< Readout number/plane; zero-offset indexing
     113                            int *zMax,          ///< Max plane number in this cell
    110114                            int numScans, ///< Number of scans (rows/cols) to read
    111115                            int overlap, ///< Overlap between consecutive reads
    … …  
    150154                           psFits *fits, ///< FITS file from which to read
    151155                           int z,       ///< Readout number/plane; zero-offset indexing
     156                           int *zMax,   ///< Max plane number in this cell
    152157                           int numScans, ///< Number of scans (rows/cols) to read
    153158                           pmConfig *config ///< Configuration
    … …  
    160165                                psFits *fits, ///< FITS file from which to read
    161166                                int z,    ///< Readout number/plane; zero-offset indexing
     167                   int *zMax,           ///< Max plane number in this cell
    162168                                int numScans, ///< Number of scans (rows/cols) to read
    163169                                int overlap, ///< Overlap between consecutive reads
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPAWrite.c

    r23428 r24951  
    160160    psArray **imageArray = appropriateImageArray(hdu, type); // Array of images in the HDU
    161161
     162    // XXX detect missing variance & mask images...
     163
    162164    // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not
    163165    // generate the HDU, but only copies the structure.
    164     if (!blank && !hdu->blankPHU && !*imageArray && (!pmHDUGenerateForCell(cell) || !*imageArray)) {
    165         psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error.");
    166         return false;
     166    if (!blank && !hdu->blankPHU && !*imageArray) {
     167        if (!pmHDUGenerateForCell(cell)) {
     168            psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error.");
     169            return false;
     170        }
     171        if (!*imageArray) {
     172            if (type == FPA_WRITE_TYPE_IMAGE) {
     173                psError(PS_ERR_UNKNOWN, false, "Expected to write an image, but it is missing...programming error?.");
     174                return false;
     175            }
     176            if (type == FPA_WRITE_TYPE_MASK) {
     177                psWarning("No mask image for this cell; skipping");
     178            }
     179            if (type == FPA_WRITE_TYPE_VARIANCE) {
     180                psWarning("No variance image for this cell; skipping");
     181            }
     182            return true;
     183        }
    167184    }
    168185
    … …  
    724741    }
    725742    if (!psFitsCompressionApply(fits, compress)) {
    726         psError(PS_ERR_UNKNOWN, false, "Unable to set FITS compression to NONE");
     743        psError(PS_ERR_UNKNOWN, false, "Unable to restore FITS compression");
    727744        psFree(compress);
    728745        return false;
  • branches/czw_branch/cleanup/psModules/src/camera/pmFPAfileIO.c

    r23576 r24951  
    2323#include "pmFPAWrite.h"
    2424#include "pmFPAfileFitsIO.h"
     25#include "pmFPAfileFringeIO.h"
    2526#include "pmSpan.h"
    2627#include "pmFootprint.h"
    … …  
    192193        status = pmFPAviewReadFitsImage(view, file, config);
    193194        if (status) {
    194             if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) {
     195            if (!pmFPAviewReadFringes(view, file)) {
    195196                psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename);
    196197                return false;
    … …  
    451452        status = pmFPAviewWriteFitsImage (view, file, config);
    452453        if (status) {
    453             if (!pmFPAviewWriteFitsTable(view, file, "FRINGE", config)) {
     454            if (!pmFPAviewWriteFringes(view, file, config)) {
    454455                psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);
    455456                return false;
  • branches/czw_branch/cleanup/psModules/src/camera/pmHDUGenerate.c

    r23318 r24951  
    390390    if (numReadouts == 0 || (imageType == 0 && maskType == 0 && varianceType == 0)) {
    391391        // Nothing from which to create an HDU
    392         psFree(cells);
    393         psError(PS_ERR_IO, true, "Nothing from which to create an HDU\n");
    394         return false;
     392        // psError(PS_ERR_IO, true, "Nothing from which to create an HDU\n");
     393        psWarning("Nothing from which to create an HDU, must be empty\n");
     394        return true;
    395395    }
    396396
    … …  
    504504        psFree(iter);
    505505    }
    506     psFree(cells);
    507 
    508506    return true;
    509507}
    … …  
    615613                return true;
    616614            }
    617 
    618             return generateHDU(hdu, cells);
     615            bool status = generateHDU(hdu, cells);
     616            psFree (cells);
     617            return status;
    619618        }
    620619    case PM_FPA_LEVEL_CHIP:
    … …  
    664663            }
    665664
    666             return generateHDU(hdu, cells);
     665            bool status = generateHDU(hdu, cells);
     666            psFree (cells);
     667            return status;
    667668        }
    668669    case PM_FPA_LEVEL_FPA:
  • branches/czw_branch/cleanup/psModules/src/camera/pmReadoutStack.c

    r21363 r24951  
    252252            continue;
    253253        }
     254        if (!readout->process) {
     255            continue;
     256        }
    254257        if (!readout->image) {
    255258            psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i);
    … …  
    260263        pmCell *cell = readout->parent; // The parent cell
    261264        bool mdok = true;       // Status of MD lookup
    262         psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
     265        psRegion *trimsec = cell ? psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC") : NULL; // Trim section
    263266        if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
    264             psWarning("CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i);
     267            psWarning("CELL.TRIMSEC is not set for readout %ld --- attempting to use image size.\n", i);
     268            xSize = PS_MAX(xSize, readout->image->numCols);
     269            ySize = PS_MAX(ySize, readout->image->numRows);
     270            xMin = PS_MIN(xMin, 0);
     271            xMax = PS_MAX(xMax, readout->image->numCols - 1);
     272            yMin = PS_MIN(yMin, 0);
     273            yMax = PS_MAX(yMax, readout->image->numRows - 1);
    265274        } else {
    266275            xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
Note: See TracChangeset for help on using the changeset viewer.