IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15299


Ignore:
Timestamp:
Oct 11, 2007, 5:18:11 PM (19 years ago)
Author:
Paul Price
Message:

Attempt to set TRIMSEC and BIASSEC from the camera format if they are specified by value.

Location:
trunk/psModules/src
Files:
3 edited

Legend:

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

    r14955 r15299  
    1313#include "pmFPALevel.h"
    1414#include "pmHDUUtils.h"
     15#include "pmConcepts.h"
     16#include "pmConceptsStandard.h"
    1517#include "pmHDUGenerate.h"
    1618
     
    169171    return true;
    170172}
     173
     174// Attempt to read CELL.TRIMSEC and CELL.BIASSEC from the cell format if they are specified by VALUE
     175static bool readTrimBias(psList *cells // List of cells below the HDU
     176    )
     177{
     178    bool mdok;                          // Status of MD lookup
     179    psListIterator *cellsIter = psListIteratorAlloc(cells, PS_LIST_HEAD, false); // Iterator for cells
     180    pmCell *cell = NULL;                // Cell from iteration
     181    bool allFixed = true;               // We're able to fix all TRIMSEC and BIASSEC
     182    while ((cell = psListGetAndIncrement(cellsIter))) {
     183        psMetadataItem *trimsecItem = psMetadataLookup(cell->concepts, "CELL.TRIMSEC"); // Item with trimsec
     184        if (!trimsecItem || trimsecItem->type != PS_DATA_REGION) {
     185            psWarning("CELL.TRIMSEC has not been initialised in cell --- ignored.\n");
     186            return false;
     187        }
     188        psRegion *trimsec = trimsecItem->data.V; // Trim section
     189        if (psRegionIsNaN(*trimsec)) {
     190            const char *trimsecSource = psMetadataLookupStr(&mdok, cell->config, "CELL.TRIMSEC.SOURCE");
     191            if (strcmp(trimsecSource, "VALUE") == 0) {
     192
     193                const char *trimsecStr = psMetadataLookupStr(&mdok, cell->config, "CELL.TRIMSEC");
     194                *trimsec = psRegionFromString(trimsecStr);
     195            } else {
     196                allFixed = false;
     197            }
     198        }
     199
     200        psMetadataItem *biassecItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC"); // Bias sections
     201        if (!biassecItem) {
     202            psWarning("CELL.BIASSEC has not been initialised in cell --- ignored.\n");
     203            return false;
     204        }
     205        psList *biassecs = biassecItem->data.V;
     206        if (biassecs->n != 0) {
     207            allFixed = false;
     208            continue;
     209        }
     210
     211        const char *biassecSource = psMetadataLookupStr(&mdok, cell->config, "CELL.BIASSEC.SOURCE");
     212        if (strcmp(biassecSource, "VALUE") == 0) {
     213            const char *biassecStr = psMetadataLookupStr(&mdok, cell->config, "CELL.BIASSEC");
     214            psFree(biassecItem->data.V);
     215            biassecItem->data.V = p_pmConceptParseRegions(biassecStr);
     216        } else {
     217            allFixed = false;
     218        }
     219    }
     220    psFree(cellsIter);
     221
     222    return allFixed;
     223}
     224
    171225
    172226// Generate CELL.TRIMSEC and CELL.BIASSEC for the cells
     
    341395    // Get the size of the HDU, either from existing trimsec and biassec, or generate these and try again
    342396    int xSize = 0, ySize = 0;           // Size of HDU
    343     if (!sizeHDU(&xSize, &ySize, cells) && !(generateTrimBias(cells) && sizeHDU(&xSize, &ySize, cells))) {
     397    if (!sizeHDU(&xSize, &ySize, cells) &&
     398        !(readTrimBias(cells) && sizeHDU(&xSize, &ySize, cells)) &&
     399        !(generateTrimBias(cells) && sizeHDU(&xSize, &ySize, cells))) {
    344400        psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
    345401        return false;
  • trunk/psModules/src/concepts/pmConceptsStandard.c

    r15229 r15299  
    329329}
    330330
     331
     332psList *p_pmConceptParseRegions(const char *region)
     333{
     334    assert(region && strlen(region) > 0);
     335
     336    psList *list = psListAlloc(NULL);   // List of regions
     337
     338    // a single BIASSEC is of the form [AAAA]
     339    // we may have multiple BIASSEC entries separated by space, commas, or semicolons
     340    int xParity = 0, yParity = 0;       // Parity of region
     341    char *p = strchr (region, '[');
     342    while (p) {
     343        char *q = strchr (p, ']');
     344        if (!q) {
     345            break;
     346        }
     347        char *regionString = psStringAlloc(q - p + 2);
     348        strncpy (regionString, p, q - p + 1);
     349        regionString[q - p + 1] = 0;
     350
     351        psRegion *region = psAlloc(sizeof(psRegion)); // The region
     352        *region = psRegionAndParityFromString(&xParity, &yParity, regionString);
     353        psListAdd(list, PS_LIST_TAIL, region);
     354        psFree(region);           // Drop reference
     355        psFree(regionString);     // Drop reference
     356
     357        p = strchr (q, '[');
     358    }
     359
     360    return list;
     361}
     362
    331363psMetadataItem *p_pmConceptParse_CELL_BIASSEC(const psMetadataItem *concept,
    332364                                              const psMetadataItem *pattern,
     
    341373    assert(pattern);
    342374
    343     psList *biassecs = psListAlloc(NULL); // List of bias sections
     375    psList *biassecs; // List of bias sections
    344376
    345377    switch (concept->type) {
    346378      case PS_DATA_STRING: {
    347           // a single BIASSEC is of the form [AAAA]
    348           // we may have multiple BIASSEC entries separated by space, commas, or semicolons
    349           int xParity = 0;
    350           int yParity = 0;
    351           char *p = strchr (concept->data.V, '[');
    352           while (p != NULL) {
    353               char *q = strchr (p, ']');
    354               if (q == NULL) break;
    355               char *regionString = psAlloc (q - p + 2);
    356               strncpy (regionString, p, q - p + 1);
    357               regionString[q - p + 1] = 0;
    358 
    359               psRegion *region = psAlloc(sizeof(psRegion)); // The region
    360               *region = psRegionAndParityFromString(&xParity, &yParity, regionString);
    361               psListAdd(biassecs, PS_LIST_TAIL, region);
    362               psFree(region);           // Drop reference
    363               psFree(regionString);     // Drop reference
    364 
    365               p = strchr (q, '[');
    366           }
     379          biassecs = p_pmConceptParseRegions(concept->data.V);
    367380          break;
    368381      }
    369382      case PS_DATA_LIST: {
     383          biassecs = psListAlloc(NULL);
    370384          psList *regions = concept->data.V; // The list of regions
    371385          psListIterator *regionsIter = psListIteratorAlloc(regions, PS_LIST_HEAD, false); // Iterator
  • trunk/psModules/src/concepts/pmConceptsStandard.h

    r12696 r15299  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-03-30 21:12:56 $
     6 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-10-12 03:18:11 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    1414/// @addtogroup Concepts Data Abstraction Concepts
    1515/// @{
     16
     17/// Parse a list of region specifiers on a line
     18psList *p_pmConceptParseRegions(const char *region ///< Regions, separated by whitespace
     19    );
    1620
    1721/// Parse the FPA.FILTER concept to apply a lookup table
Note: See TracChangeset for help on using the changeset viewer.