IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18830


Ignore:
Timestamp:
Jul 31, 2008, 2:01:26 PM (18 years ago)
Author:
eugene
Message:

src/objects/Makefile.am

Location:
trunk/psModules/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPA.c

    r18364 r18830  
    176176    readout->col0 = 0;
    177177    readout->row0 = 0;
    178     readout->imageScan = 0;
    179     readout->maskScan = 0;
    180     readout->weightScan = 0;
     178
     179    readout->thisImageScan = 0;
     180    readout->thisMaskScan = 0;
     181    readout->thisWeightScan = 0;
     182
     183    readout->lastImageScan = 0;
     184    readout->lastMaskScan = 0;
     185    readout->lastWeightScan = 0;
    181186}
    182187
     
    269274    tmpReadout->col0 = 0;
    270275
    271     tmpReadout->imageScan = 0;
    272     tmpReadout->maskScan = 0;
    273     tmpReadout->weightScan = 0;
     276    tmpReadout->thisImageScan = 0;
     277    tmpReadout->thisMaskScan = 0;
     278    tmpReadout->thisWeightScan = 0;
     279
     280    tmpReadout->lastImageScan = 0;
     281    tmpReadout->lastMaskScan = 0;
     282    tmpReadout->lastWeightScan = 0;
    274283
    275284    return(tmpReadout);
  • trunk/psModules/src/camera/pmFPA.h

    r17911 r18830  
    66 * @author Eugene Magnier, IfA
    77 *
    8  * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2008-06-05 01:31:33 $
     8 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2008-08-01 00:01:25 $
    1010 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1111 */
     
    127127    bool file_exists;                   ///< Does the file for this readout exist (read case only)?
    128128    bool data_exists;                   ///< Does the data for this readout exist (read case only)?
    129     int imageScan, maskScan, weightScan;///< Separate tracking numbers for reading images incrementally
     129    int thisImageScan;                  ///< start scan for next/current read
     130    int lastImageScan;                  ///< start scan of the last read
     131    int thisMaskScan;                   ///< start scan for next/current read
     132    int lastMaskScan;                   ///< start scan of the last read
     133    int thisWeightScan;                 ///< start scan for next/current read
     134    int lastWeightScan;                 ///< start scan of the last read
    130135} pmReadout;
    131136
  • trunk/psModules/src/camera/pmFPARead.c

    r18210 r18830  
    4545
    4646// Return pointer to appropriate value for tracking scans
    47 static int *readoutScansByType(pmReadout *readout, // Readout of interest
    48                                fpaReadType type // Type of image
     47static int readoutGetThisScan(pmReadout *readout, // Readout of interest
     48                              fpaReadType type // Type of image
    4949    )
    5050{
    5151    switch (type) {
    5252      case FPA_READ_TYPE_IMAGE:
    53         return &readout->imageScan;
     53        return readout->thisImageScan;
    5454      case FPA_READ_TYPE_MASK:
    55         return &readout->maskScan;
     55        return readout->thisMaskScan;
    5656      case FPA_READ_TYPE_WEIGHT:
    57         return &readout->weightScan;
     57        return readout->thisWeightScan;
    5858      default:
    5959        psAbort("Unknown read type: %x\n", type);
    6060    }
     61}
     62
     63// Return pointer to appropriate value for tracking scans
     64static int readoutSetLastScan(pmReadout *readout, // Readout of interest
     65                              fpaReadType type,   // Type of image
     66                              int numScans        // requested number of scans
     67    )
     68{
     69    switch (type) {
     70      case FPA_READ_TYPE_IMAGE:
     71        readout->lastImageScan = readout->thisImageScan + numScans;
     72        return readout->lastImageScan;
     73      case FPA_READ_TYPE_MASK:
     74        readout->lastMaskScan = readout->thisMaskScan + numScans;
     75        return readout->lastMaskScan;
     76      case FPA_READ_TYPE_WEIGHT:
     77        readout->lastWeightScan = readout->thisWeightScan + numScans;
     78        return readout->lastWeightScan;
     79      default:
     80        psAbort("Unknown read type: %x\n", type);
     81    }
     82    return false;
    6183}
    6284
     
    134156}
    135157
    136 
    137 // Determine readout scan properties: the next and last scans
    138 // Requires that cellNumReadouts() has been called before (for header and concepts to have been read)
    139 // In the process, adjusts the TRIMSEC
    140 static bool readoutScanProperties(int *next, // Index of next scan
    141                                   int *last, // Index of last scan
    142                                   pmReadout *readout, // Readout of interest
    143                                   int numScans, // Number of scans to read at a time
    144                                   fpaReadType type, // Type of image
    145                                   pmConfig *config // Configuration
     158// Does the current readout, with scans set for a new read, represent any real data, or is it
     159// beyond the end?  Requires that cellNumReadouts() has been called before (for header and
     160// concepts to have been read) In the process, adjusts the TRIMSEC
     161static bool readoutHaveMoreScans(bool *result,   // true : more data to read
     162                             pmReadout *readout, // Readout of interest
     163                             int numScans, // Number of scans to read at a time
     164                             fpaReadType type, // Type of image
     165                             pmConfig *config // Configuration
    146166    )
    147167{
    148     assert(next);
    149     assert(last);
     168    assert(result);
    150169    assert(readout);
    151170
    152     psImage *image = *readoutImageByType(readout, type); // Appropriate image from readout
     171    *result = false;
    153172
    154173    if (!pmConceptsReadCell(readout->parent, PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE,
     
    163182    PS_ASSERT_PTR_NON_NULL(cell, false);
    164183    pmHDU *hdu = pmHDUFromCell(cell);   // HDU for data
     184
    165185    bool mdok = true;                   // Status of MD lookup
    166186    psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections
     
    195215    // Calculate the segment offset and upper limit
    196216    if (numScans == 0) {
    197         *next = (readdir == 1) ? trimsec->y0 : trimsec->x0;
    198     } else {
    199         *next = image ? *readoutScansByType(readout, type) + numScans : 0;
    200     }
    201     *last = (readdir == 1) ? trimsec->y1 : trimsec->x1;
    202 
     217        // in the case of numScans == 0, we never call this funtion unless the data has not yet
     218        // been read.  thus, only if the delta is  should we return false (ie, trimsec defines an empty region)
     219        int thisScan = (readdir == 1) ? trimsec->y0 : trimsec->x0;
     220        int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1;
     221        *result = (lastScan > thisScan);
     222        return true;
     223    }
     224
     225    // allow multiple threads to read different segments into different readouts
     226    // this thread may not have read a segment yet; but others have.  trust readout->imageScan
     227
     228    // is the start scan of the read less than the last possible scan?
     229    int thisScan = readoutGetThisScan(readout, type);
     230    int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1;
     231
     232    *result = (lastScan > thisScan);
    203233    return true;
     234    // XXX fold this and the above case together
    204235}
    205236
     
    217248    psImage *image = *readoutImageByType(readout, type);
    218249
     250    // XXX this may not be the valid test in a multithread environment. consider a fileGroup of
     251    // N readouts, but numScans set to 0.  only the first should report that it requires data,
     252    // even if all readouts lack the image pointer.
    219253    if (!image) {
    220254        return true;
    221     } else if (numScans == 0) {
    222         // Can only read the entire image once
     255    }
     256
     257    // If we have already read an image, this result implies we are done (no more to read)
     258    if (numScans == 0) {
    223259        return false;
    224260    }
     
    235271    }
    236272
    237     int next;                           // Next position
    238     int last;                           // Last position
    239     if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) {
     273    bool haveData;
     274    if (!readoutHaveMoreScans(&haveData, readout, numScans, type, config)) {
    240275        psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties.");
    241276        return false;
    242277    }
    243278
    244     return (next < last);
     279    return haveData;
    245280}
    246281
     
    423458    }
    424459
    425     int next;                           // Next position
    426     int last;                           // Last position
    427     if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) {
     460    bool haveData;
     461    if (!readoutHaveMoreScans (&haveData, readout, type, numScans, config)) {
    428462        psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties.");
    429463        return false;
    430464    }
    431     if (next >= last) {
     465    if (!haveData) {
    432466        psError(PS_ERR_IO, true, "No more of the readout to read.");
    433467        return false;
    434468    }
     469
    435470
    436471    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     
    459494    }
    460495
    461 
    462 
    463496    // Check the third dimension
    464497    int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes
     
    478511    }
    479512
    480     // Update number of scans read
    481     int *scansTracker = readoutScansByType(readout, type); // Tracker for how many scans have been read
    482     *scansTracker = next;
    483     if (next == 0) {
     513    // Determine the numbe of scans to read
     514    int thisScan = readoutGetThisScan(readout, type);
     515    int lastScan = readoutSetLastScan (readout, type, numScans);
     516    if (thisScan == 0) {
    484517        overlap = 0;
    485518    }
    486     next -= overlap;
     519    thisScan -= overlap;
    487520
    488521    // Calculate limits, adjust readout->row0,col0
     
    491524    if (readdir == 1) {
    492525        // Reading rows
    493         readout->row0 = next;
     526        readout->row0 = thisScan;
    494527        readout->col0 = trimsec->x0;
    495528        if (numScans == 0) {
     
    498531    } else {
    499532        // Reading cols
    500         readout->col0 = next;
     533        readout->col0 = thisScan;
    501534        readout->row0 = trimsec->y0;
    502535        if (numScans == 0) {
     
    504537        }
    505538    }
    506     int upper = next + numScans + overlap;        // Upper limit to next section
    507539
    508540    // Blow away existing data.
     
    510542    psFree(*image);
    511543    *image = NULL;
    512     *image = readoutReadComponent(*image, fits, trimsec, readdir, next, upper, z, bad, pixelTypes[type]);
     544    *image = readoutReadComponent(*image, fits, trimsec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]);
    513545
    514546    // Read overscans only for "image" type --- weights and masks shouldn't record overscans
     
    528560        psRegion *biassec = NULL;           // Bias section from iteration
    529561        while ((biassec = psListGetAndIncrement(biassecsIter))) {
    530             psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, next, upper, z,
    531                                                  bad, pixelTypes[type]); // The bias
     562            psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); // The bias
    532563            psListAdd(readout->bias, PS_LIST_TAIL, bias);
    533564            psFree(bias);                   // Drop reference
  • trunk/psModules/src/camera/pmReadoutStack.c

    r17228 r18830  
    88
    99#include "pmReadoutStack.h"
     10
     11// generate the specified image
     12// XXX should it be an error for the image to exist?
     13psImage *pmReadoutSetAnalysisImage(pmReadout *readout, // Readout containing image
     14                                   const char *name, // Name of image in analysis metadata
     15                                   int numCols, int numRows, // Expected size of image
     16                                   psElemType type, // Expected type of image
     17                                   double init // Initial value
     18    )
     19{
     20    PS_ASSERT_PTR_NON_NULL(readout, false);
     21    PS_ASSERT_STRING_NON_EMPTY(name, false);
     22
     23    psImage *image = psImageAlloc(numCols, numRows, type);
     24
     25    if (!psMetadataAddImage(readout->analysis, PS_LIST_TAIL, name, 0, "Analysis image from " __FILE__, image)) {
     26        psAbort ("analysis image already exists");
     27    }
     28    psImageInit(image, init);
     29
     30    psFree (image); // we still have a view on readout->analysis
     31    return image;
     32}
     33
     34// retrieve the specified image
     35// XXX not sure why this should call psMemIncrRefCounter
     36psImage *pmReadoutGetAnalysisImage(pmReadout *readout, // Readout containing image
     37                                   const char *name       // Name of image in analysis metadata
     38    )
     39{
     40    PS_ASSERT_PTR_NON_NULL(readout, false);
     41    PS_ASSERT_STRING_NON_EMPTY(name, false);
     42
     43    bool mdok;                          // Status of MD lookup
     44    psImage *image = psMetadataLookupPtr(&mdok, readout->analysis, name);
     45    return image;
     46}
    1047
    1148psImage *pmReadoutAnalysisImage(pmReadout *readout, // Readout containing image
     
    4077}
    4178
    42 bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows,
    43                          int numCols, int numRows, bool mask, bool weight,
    44                          psMaskType blank)
    45 {
    46     PS_ASSERT_PTR_NON_NULL(readout, false);
    47 
    48     if (readout->image) {
    49         readout->col0 = PS_MIN(minCols, readout->col0);
    50         readout->row0 = PS_MIN(minRows, readout->row0);
    51     } else {
    52         readout->col0 = minCols;
    53         readout->row0 = minRows;
    54     }
    55 
    56     // (reAllocate the images
    57     if (!readout->image) {
    58         readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    59         psImageInit(readout->image, NAN);
    60     }
    61     if (readout->image->numCols < numCols || readout->image->numRows < numRows) {
    62         // Generate the new output image by extending the current one, or making a whole new one
    63         psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    64         psImageInit(newImage, NAN);
    65         psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "=");
    66         psFree(readout->image);
    67         readout->image = newImage;
    68     }
     79// XXX for the moment, use col0, row0, numCols, numRows supplied from the outside
     80bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank)
     81{
     82    PS_ASSERT_PTR_NON_NULL(readout, false);
     83
     84    // XXX is this an error?
     85    if (readout->image) return false;
     86    readout->col0 = col0;
     87    readout->row0 = row0;
     88
     89    // allocate the images
     90    readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     91    psImageInit(readout->image, NAN);
    6992
    7093    if (mask) {
    71         if (!readout->mask) {
    72             readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    73             psImageInit(readout->mask, blank);
    74         }
    75         if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) {
    76             psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    77             psImageInit(newMask, blank);
    78             psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "=");
    79             psFree(readout->mask);
    80             readout->mask = newMask;
    81         }
     94        // XXX is this an error?
     95        if (readout->mask) return false;
     96        readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     97        psImageInit(readout->mask, blank);
    8298    }
    8399
    84100    if (weight) {
    85         if (!readout->weight) {
    86             readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    87             psImageInit(readout->weight, NAN);
    88         }
    89         if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) {
    90             psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    91             psImageInit(newWeight, NAN);
    92             psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "=");
    93             psFree(readout->weight);
    94             readout->weight = newWeight;
    95         }
     101        // XXX is this an error?
     102        if (readout->weight) return false;
     103        readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     104        psImageInit(readout->weight, NAN);
    96105    }
    97106
     
    99108}
    100109
    101 bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr,
    102                             int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr,
    103                             const psArray *inputs)
     110bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs)
    104111{
    105112    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
    106     PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false);
    107     PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false);
    108     PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false);
    109     PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false);
    110     PS_ASSERT_PTR_NON_NULL(numColsPtr, false);
    111     PS_ASSERT_PTR_NON_NULL(numRowsPtr, false);
    112 
    113     // Step through each readout in the input image list to determine how big of an output image is needed to
    114     // combine these input images.
    115     int maxInputCols = 0;               // The largest input column value
    116     int maxInputRows = 0;               // The largest input row value
    117     int minInputCols = INT_MAX;         // The smallest input column value
    118     int minInputRows = INT_MAX;         // The smallest input row value
    119     int xSize = 0, ySize = 0;           // The size of the output image
     113    PS_ASSERT_PTR_NON_NULL(col0, false);
     114    PS_ASSERT_PTR_NON_NULL(row0, false);
     115    PS_ASSERT_PTR_NON_NULL(numCols, false);
     116    PS_ASSERT_PTR_NON_NULL(numRows, false);
     117
     118    // Step through each readout in the input image list to determine how big of an output
     119    // image is needed to combine these input images.
    120120
    121121    int xMin = INT_MAX;
     
    123123    int xMax = 0;
    124124    int yMax = 0;
     125    int xSize = 0;
     126    int ySize = 0;           // The size of the output image
    125127
    126128    bool valid = false;                 // Do we have a single valid input?
     
    128130        pmReadout *readout = inputs->data[i]; // Readout of interest
    129131
    130         if (!readout) {
    131             continue;
    132         }
    133         if (!readout->image) {
    134             psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i);
    135             return false;
    136         }
     132        if (!readout) continue;
    137133
    138134        // use the trimsec to define the max full range of the output pixels
     
    150146            yMax  = PS_MAX(yMax,  trimsec->y1);
    151147        }
     148        valid = true;
     149        psTrace("psModules.camera", 7, "Readout %ld: trimsec: %f,%f - %f,%f\n", i, trimsec->x0, trimsec->y0, trimsec->x1, trimsec->y1);
     150    }
     151
     152    *col0 = xMin;
     153    *row0 = yMin;
     154    *numCols = xSize;
     155    *numRows = ySize;
     156
     157    if (!valid) {
     158        psError(PS_ERR_UNKNOWN, false, "No valid input readouts.");
     159    }
     160    return valid;
     161}
     162
     163bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows,
     164                         int numCols, int numRows, bool mask, bool weight,
     165                         psMaskType blank)
     166{
     167    PS_ASSERT_PTR_NON_NULL(readout, false);
     168
     169    if (readout->image) {
     170        readout->col0 = PS_MIN(minCols, readout->col0);
     171        readout->row0 = PS_MIN(minRows, readout->row0);
     172    } else {
     173        readout->col0 = minCols;
     174        readout->row0 = minRows;
     175    }
     176
     177    // (reAllocate the images
     178    if (!readout->image) {
     179        readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     180        psImageInit(readout->image, NAN);
     181    }
     182    if (readout->image->numCols < numCols || readout->image->numRows < numRows) {
     183        // Generate the new output image by extending the current one, or making a whole new one
     184        psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     185        psImageInit(newImage, NAN);
     186        psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "=");
     187        psFree(readout->image);
     188        readout->image = newImage;
     189    }
     190
     191    if (mask) {
     192        if (!readout->mask) {
     193            readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     194            psImageInit(readout->mask, blank);
     195        }
     196        if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) {
     197            psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     198            psImageInit(newMask, blank);
     199            psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "=");
     200            psFree(readout->mask);
     201            readout->mask = newMask;
     202        }
     203    }
     204
     205    if (weight) {
     206        if (!readout->weight) {
     207            readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     208            psImageInit(readout->weight, NAN);
     209        }
     210        if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) {
     211            psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     212            psImageInit(newWeight, NAN);
     213            psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "=");
     214            psFree(readout->weight);
     215            readout->weight = newWeight;
     216        }
     217    }
     218
     219    return true;
     220}
     221
     222bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr,
     223                            int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr,
     224                            const psArray *inputs)
     225{
     226    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
     227    PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false);
     228    PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false);
     229    PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false);
     230    PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false);
     231    PS_ASSERT_PTR_NON_NULL(numColsPtr, false);
     232    PS_ASSERT_PTR_NON_NULL(numRowsPtr, false);
     233
     234    // Step through each readout in the input image list to determine how big of an output image is needed to
     235    // combine these input images.
     236    int maxInputCols = 0;               // The largest input column value
     237    int maxInputRows = 0;               // The largest input row value
     238    int minInputCols = INT_MAX;         // The smallest input column value
     239    int minInputRows = INT_MAX;         // The smallest input row value
     240    int xSize = 0, ySize = 0;           // The size of the output image
     241
     242    int xMin = INT_MAX;
     243    int yMin = INT_MAX;
     244    int xMax = 0;
     245    int yMax = 0;
     246
     247    bool valid = false;                 // Do we have a single valid input?
     248    for (long i = 0; i < inputs->n; i++) {
     249        pmReadout *readout = inputs->data[i]; // Readout of interest
     250
     251        if (!readout) {
     252            continue;
     253        }
     254        if (!readout->image) {
     255            psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i);
     256            return false;
     257        }
     258
     259        // use the trimsec to define the max full range of the output pixels
     260        pmCell *cell = readout->parent; // The parent cell
     261        bool mdok = true;       // Status of MD lookup
     262        psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
     263        if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
     264            psWarning("CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i);
     265        } else {
     266            xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
     267            ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0);
     268            xMin  = PS_MIN(xMin,  trimsec->x0);
     269            xMax  = PS_MAX(xMax,  trimsec->x1);
     270            yMin  = PS_MIN(yMin,  trimsec->y0);
     271            yMax  = PS_MAX(yMax,  trimsec->y1);
     272        }
    152273
    153274        valid = true;
     
    158279        minInputRows = PS_MAX(yMin, PS_MIN(minInputRows, readout->row0));
    159280        maxInputRows = PS_MIN(yMax, PS_MAX(maxInputRows, readout->row0 + readout->image->numRows));
    160         psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i,
    161                 readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
     281
     282        psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i, readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
    162283    }
    163284
  • trunk/psModules/src/camera/pmReadoutStack.h

    r17228 r18830  
    2424    );
    2525
     26psImage *pmReadoutSetAnalysisImage(pmReadout *readout, // Readout containing image
     27                                   const char *name, // Name of image in analysis metadata
     28                                   int numCols, int numRows, // Expected size of image
     29                                   psElemType type, // Expected type of image
     30                                   double init // Initial value
     31    );
     32
     33// retrieve the specified image
     34// XXX not sure why this should call psMemIncrRefCounter
     35psImage *pmReadoutGetAnalysisImage(pmReadout *readout, // Readout containing image
     36                                   const char *name       // Name of image in analysis metadata
     37    );
     38
     39
    2640/// Return an image from analysis metadata, produced while stacking
    2741psImage *pmReadoutAnalysisImage(pmReadout *readout, // Readout containing image
     
    3246    );
    3347
     48// XXX for the moment, use col0, row0, numCols, numRows supplied from the outside
     49bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank);
     50
     51bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs);
     52
    3453#endif
  • trunk/psModules/src/config/pmConfig.c

    r18413 r18830  
    16271627
    16281628        if (trunc) {
    1629             if(truncate(filename, 0) != 0) {
    1630                 psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename);
    1631                 nebServerFree(server);
     1629            if(truncate(path, 0) != 0) {
     1630                psError(PS_ERR_IO, true, "Failed to truncate Nebulous file %s (real name %s)\n", filename, path);
    16321631                return NULL;
    16331632            }
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r17228 r18830  
    4242}
    4343
     44// check the input parameters and set up the output images
     45bool pmReadoutCombinePrepare(pmReadout *output, const psArray *inputs, const pmCombineParams *params)
     46{
     47    // Check inputs
     48    PS_ASSERT_PTR_NON_NULL(output, false);
     49    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
     50    PS_ASSERT_PTR_NON_NULL(params, false);
     51    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false);
     52    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false);
     53
     54    // valid combintion statistic?
     55    bool valid = false;
     56    valid |= (params->combine == PS_STAT_SAMPLE_MEAN);
     57    valid |= (params->combine == PS_STAT_SAMPLE_MEDIAN);
     58    valid |= (params->combine == PS_STAT_ROBUST_MEDIAN);
     59    valid |= (params->combine == PS_STAT_FITTED_MEAN);
     60    valid |= (params->combine == PS_STAT_CLIPPED_MEAN);
     61    if (!valid) {
     62        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, "
     63                "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n");
     64        return false;
     65    }
     66
     67    // weights exist if weights desired?
     68    for (int i = 0; i < inputs->n; i++) {
     69        pmReadout *readout = inputs->data[i]; // Readout of interest
     70        if (params->weights && !readout->weight) {
     71            psError(PS_ERR_UNEXPECTED_NULL, true,
     72                    "Rejection based on weights requested, but no weights supplied for image %d.\n", i);
     73            return false;
     74        }
     75    }
     76
     77    pmHDU *hdu = pmHDUFromReadout(output); // Output HDU
     78    if (!hdu) {
     79        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU for readout.\n");
     80        return false;
     81    }
     82
     83    //  set the output header metadata
     84    psString comment = NULL;        // Comment to add to header
     85    psStringAppend(&comment, "Combining using statistic: %x", params->combine);
     86    if (!hdu->header) {
     87        hdu->header = psMetadataAlloc();
     88    }
     89    psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     90    psFree(comment);
     91
     92    // note the clipping parameters, if used
     93    if (params->combine == PS_STAT_CLIPPED_MEAN) {
     94        psString comment = NULL;    // Comment to add to header
     95        psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);
     96        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     97        psFree(comment);
     98    }
     99
     100    // note the use of weights
     101    if (params->weights) {
     102        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
     103                         "Using input weights to combine images", "");
     104    }
     105
     106    // note the rejection fraction
     107    float keepFrac = 1.0 - params->fracLow - params->fracHigh; // Fraction of pixels to keep
     108    if (keepFrac != 1.0) {
     109        psString comment = NULL;        // Comment to add to header
     110        psStringAppend(&comment, "Min/max rejection: %f high, %f low, keep %d",
     111                       params->fracHigh, params->fracLow, params->nKeep);
     112        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     113        psFree(comment);
     114    }
     115
     116    // note the mask value actually used
     117    psMaskType maskVal = params->maskVal; // The mask value
     118    if (maskVal) {
     119        psString comment = NULL;        // Comment to add to header
     120        psStringAppend(&comment, "Mask for combination: %x", maskVal);
     121        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     122        psFree(comment);
     123    }
     124
     125    // determine the output image size based on the input images
     126    int row0, col0, numCols, numRows;
     127    if (!pmReadoutStackSetOutputSize(&col0, &row0, &numCols, &numRows, inputs)) {
     128        psError(PS_ERR_UNKNOWN, false, "problem setting output readout size.");
     129        return false;
     130    }
     131
     132    // generate the required output images based on the specified sizes
     133    pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->weights, params->blank);
     134    psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);
     135
     136    // these calls allocate and save the requested images on the output analysis metadata
     137    psImage *counts = pmReadoutSetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, PS_TYPE_U16, 0);
     138    if (!counts) {
     139        return false;
     140    }
     141    psImage *sigma = pmReadoutSetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, PS_TYPE_F32, NAN);
     142    if (!sigma) {
     143        return false;
     144    }
     145
     146    // Update the "concepts"
     147    psList *inputCells = psListAlloc(NULL); // List of cells
     148    for (long i = 0; i < inputs->n; i++) {
     149        pmReadout *readout = inputs->data[i]; // Readout of interest
     150        psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
     151    }
     152    bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true);
     153    psFree(inputCells);
     154
     155    // set these even though the values are not yet set
     156    output->data_exists = true;
     157    output->parent->data_exists = true;
     158    output->parent->parent->data_exists = true;
     159
     160    return success;
     161}
    44162
    45163// XXX: Maybe add support for S16 and S32 types.  Currently, only F32 supported.
     
    61179    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false);
    62180    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false);
    63     if (params->combine != PS_STAT_SAMPLE_MEAN && params->combine != PS_STAT_SAMPLE_MEDIAN &&
    64             params->combine != PS_STAT_ROBUST_MEDIAN && params->combine != PS_STAT_FITTED_MEAN &&
    65             params->combine != PS_STAT_CLIPPED_MEAN) {
    66         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, "
    67                 "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n");
    68         return false;
    69     }
    70     for (int i = 0; i < inputs->n; i++) {
    71         pmReadout *readout = inputs->data[i]; // Readout of interest
    72         if (params->weights && !readout->weight) {
    73             psError(PS_ERR_UNEXPECTED_NULL, true,
    74                     "Rejection based on weights requested, but no weights supplied for image %d.\n", i);
    75             return false;
    76         }
    77     }
    78 
    79     bool first = !output->image;        // First pass through?
    80181
    81182    pmHDU *hdu = pmHDUFromReadout(output); // Output HDU
     
    85186    }
    86187
    87     if (first) {
    88         psString comment = NULL;        // Comment to add to header
    89         psStringAppend(&comment, "Combining using statistic: %x", params->combine);
    90         if (!hdu->header) {
    91             hdu->header = psMetadataAlloc();
    92         }
    93         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    94         psFree(comment);
    95     }
     188    pthread_t id = pthread_self();
     189    char name[64];
     190    sprintf (name, "%x", (unsigned int) id);
     191    psTimerStart (name);
    96192
    97193    psStatsOptions combineStdev = 0; // Statistics option for weights
     
    118214        stats->clipSigma = params->rej;
    119215        stats->clipIter = params->iter;
    120 
    121         if (first) {
    122             psString comment = NULL;    // Comment to add to header
    123             psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma",
    124                            params->iter, params->rej);
    125             psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    126             psFree(comment);
    127         }
    128     }
    129     if (params->weights && first) {
    130         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
    131                          "Using input weights to combine images", "");
    132     }
     216    }
     217
     218    psImage *counts = pmReadoutGetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT);
     219    if (!counts) {
     220        return false;
     221    }
     222    psImage *sigma = pmReadoutGetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA);
     223    if (!sigma) {
     224        return false;
     225    }
     226
     227    stats->options |= combineStdev;
    133228
    134229    int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
    135230    int xSize, ySize;                   // Size of the output image
    136     if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize,
    137                                 inputs)) {
     231    if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, inputs)) {
    138232        psError(PS_ERR_UNKNOWN, false, "No valid input readouts.");
    139233        return false;
    140234    }
    141 
    142     pmReadoutUpdateSize(output, minInputCols, minInputRows, xSize, ySize, true, params->weights,
    143                         params->blank);
    144     psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);
    145 
    146     psImage *counts = pmReadoutAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT, xSize, ySize,
    147                                              PS_TYPE_U16, 0);
    148     if (!counts) {
    149         return false;
    150     }
    151     psImage *sigma = pmReadoutAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA, xSize, ySize,
    152                                             PS_TYPE_F32, NAN);
    153     if (!sigma) {
    154         psFree(counts);
    155         return false;
    156     }
    157 
    158     stats->options |= combineStdev;
    159235
    160236    // We loop through each pixel in the output image.  We loop through each input readout.  We determine if
     
    180256
    181257    float keepFrac = 1.0 - params->fracLow - params->fracHigh; // Fraction of pixels to keep
    182     if (keepFrac != 1.0 && first) {
    183         psString comment = NULL;        // Comment to add to header
    184         psStringAppend(&comment, "Min/max rejection: %f high, %f low, keep %d",
    185                        params->fracHigh, params->fracLow, params->nKeep);
    186         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    187         psFree(comment);
    188     }
    189 
    190258    psMaskType maskVal = params->maskVal; // The mask value
    191     if (maskVal && first) {
    192         psString comment = NULL;        // Comment to add to header
    193         psStringAppend(&comment, "Mask for combination: %x", maskVal);
    194         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    195         psFree(comment);
    196     }
    197259
    198260    #ifndef PS_NO_TRACE
     
    226288        int yOut = i - output->row0; // y position on output readout
    227289        #ifdef SHOW_BUSY
    228 
     290       
    229291        if (psTraceGetLevel("psModules.imcombine") > 9) {
    230292            printf("Processing row %d\r", i);
     
    242304                int xIn = j - readout->col0; // x position on input readout
    243305                psImage *image = readout->image; // The readout image
    244 
    245                 #if 0 // This should have been taken care of already:
    246                 // Check bounds
    247                 if (xIn < 0 || xIn >= image->numCols || yIn < 0 || yIn >= image->numRows) {
    248                     continue;
    249                 }
    250                 #endif
    251306
    252307                pixelsData[r] = image->data.F32[yIn][xIn];
     
    348403    }
    349404    #endif
     405
    350406    psFree(index);
    351407    psFree(pixels);
     
    355411    psFree(stats);
    356412    psFree(invScale);
    357     psFree(counts);
    358     psFree(sigma);
    359 
    360     // Update the "concepts"
    361     psList *inputCells = psListAlloc(NULL); // List of cells
    362     for (long i = 0; i < inputs->n; i++) {
    363         pmReadout *readout = inputs->data[i]; // Readout of interest
    364         psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
    365     }
    366     bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true);
    367     psFree(inputCells);
    368 
    369     output->data_exists = true;
    370     output->parent->data_exists = true;
    371     output->parent->parent->data_exists = true;
    372 
    373     return success;
     413
     414    // fprintf (stderr, "done with combine %x : %f sec\n", (unsigned int) id, psTimerMark (name));
     415    return true;
    374416}
    375417
  • trunk/psModules/src/imcombine/pmReadoutCombine.h

    r17228 r18830  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2008-03-29 03:10:17 $
     7 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2008-08-01 00:01:26 $
    99 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    3636                                     );
    3737
     38// check the input parameters and set up the output images
     39bool pmReadoutCombinePrepare(pmReadout *output, const psArray *inputs, const pmCombineParams *params);
     40
    3841/// Combine multiple readouts, applying zero and scale, with optional minmax clipping
    3942bool pmReadoutCombine(pmReadout *output,///< Output readout; altered and returned
  • trunk/psModules/src/objects/Makefile.am

    r15562 r18830  
    44libpsmodulesobjects_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    55libpsmodulesobjects_la_SOURCES  = \
     6     pmDetections.c \
     7     pmSpan.c \
     8     pmFootprint.c \
     9     pmFootprintArrayGrow.c \
     10     pmFootprintArraysMerge.c \
     11     pmFootprintAssignPeaks.c \
     12     pmFootprintFind.c \
     13     pmFootprintFindAtPoint.c \
     14     pmFootprintIDs.c \
    615     pmPeaks.c \
    716     pmMoments.c \
     
    4554
    4655pkginclude_HEADERS = \
     56     pmDetections.h \
     57     pmSpan.h \
     58     pmFootprint.h \
    4759     pmPeaks.h \
    4860     pmMoments.h \
Note: See TracChangeset for help on using the changeset viewer.