IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5371


Ignore:
Timestamp:
Oct 18, 2005, 4:19:41 PM (21 years ago)
Author:
Paul Price
Message:

Current state before I go on holiday. Not sure if it works or not. Not current for pslib8.

Location:
trunk/archive/scripts/src/phase2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/papPhase2.c

    r5104 r5371  
    4545static psMemId memPrintAlloc(const psMemBlock *mb)
    4646{
    47     printf("Allocated memory block %lld (%lld):\n"
     47    printf("Allocated memory block %ld (%ld):\n"
    4848           "\tFile %s, line %d, size %d\n"
    4949           "\tPosts: %x %x %x\n",
     
    5454static psMemId memPrintFree(const psMemBlock *mb)
    5555{
    56     printf("Freed memory block %lld (%lld):\n"
     56    printf("Freed memory block %ld (%ld):\n"
    5757           "\tFile %s, line %d, size %d\n"
    5858           "\tPosts: %x %x %x\n",
     
    6464{
    6565    psMemBlock *mb = ((psMemBlock*)ptr) - 1;
    66     printf("Memory block %lld (%lld):\n"
     66    printf("Memory block %ld (%ld):\n"
    6767           "\tFile %s, line %d, size %d\n"
    6868           "\tPosts: %x %x %x\n",
     
    7575#if 0
    7676    // Hunting memory leaks
    77     psMemAllocateCallbackSetID(23289);
    78     psMemFreeCallbackSetID(23289);
    79     psMemAllocateCallbackSet(memPrintAlloc);
     77    psMemAllocCallbackSetID(22367);
     78    psMemFreeCallbackSetID(22367);
     79    psMemAllocCallbackSet(memPrintAlloc);
    8080    psMemFreeCallbackSet(memPrintFree);
    8181#endif
     
    198198    bool doAstrom = false;              // Astrometry
    199199    pmOverscanAxis overscanMode = PM_OVERSCAN_NONE; // Axis for overscan
    200     pmFit overscanFit = PM_FIT_NONE;    // Fit type for overscan
     200    pmFit overscanFitType = PM_FIT_NONE; // Fit type for overscan
    201201    int overscanBins = 1;               // Number of pixels per bin for overscan
    202202    psStats *overscanStats = NULL;      // Statistics for overscan
     203    void *overscanFit = NULL;           // Overscan fit (polynomial or spline)
    203204
    204205    if (psMetadataLookupBool(NULL, recipe, "MASK")) {
     
    243244        psString fit = psMetadataLookupString(NULL, recipe, "OVERSCAN.FIT");
    244245        if (strcasecmp(fit, "POLYNOMIAL") == 0) {
    245             overscanFit = PM_FIT_POLYNOMIAL;
     246            overscanFitType = PM_FIT_POLYNOMIAL;
     247            int order = psMetadataLookupS32(NULL, recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
     248            overscanFit = psPolynomial1DAlloc(order, PS_POLYNOMIAL_ORD);
    246249        } else if (strcasecmp(fit, "SPLINE") == 0) {
    247             overscanFit = PM_FIT_SPLINE;
     250            overscanFitType = PM_FIT_SPLINE;
     251            int order = psMetadataLookupS32(NULL, recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
     252//          overscanFit = psSpline1DAlloc(order, PS_POLYNOMIAL_ORD);
    248253        } else if (strcasecmp(fit, "NONE") != 0) {
    249254            psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
     
    297302#endif
    298303
    299     pmFPAPrint(input);
     304    //pmFPAPrint(input);
    300305
    301306    // Load the calibration frames, if required
     
    475480                pmReadout *inputReadout = inputReadouts->data[k]; // Readout of interest in input image
    476481                psImage *inputImage = inputReadout->image; // The actual image
    477                 psList *inputOverscans = inputReadout->overscans; // List of overscan bias regions
    478482
    479483                // Mask bad pixels
     
    656660                }
    657661
    658                 printf("mode: %d\n", overscanMode);
    659 
    660662                if (doBias || doOverscan || doDark) {
    661                     void *overscanResult = NULL; // Result of overscan fit
    662 #ifdef PRODUCTION
    663                     (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode,
    664                                          overscanStats, overscanBins, overscanFit, pedestal);
    665 #else
    666                     (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode,
    667                                          overscanStats, overscanBins, overscanFit, biasReadout);
    668 #endif
    669                    
     663                    psList *inputOverscans = pmReadoutGetBias(inputReadout); // List of overscan bias regions
     664#ifdef PRODUCTION
     665                    (void)pmSubtractBias(inputReadout, overscanFit, inputOverscans, overscanMode,
     666                                         overscanStats, overscanBins, overscanFitType, pedestal);
     667#else
     668                    (void)pmSubtractBias(inputReadout, overscanFit, inputOverscans, overscanMode,
     669                                         overscanStats, overscanBins, overscanFitType, biasReadout);
     670#endif
     671                    psFree(inputOverscans);
     672
    670673                    // Output overscan fit results, if required
    671674                    if (doOverscan) {
    672                         switch (overscanFit) {
     675                        switch (overscanFitType) {
    673676                          case PM_FIT_POLYNOMIAL:
    674677                            {
    675                                 psPolynomial1D *poly = (psPolynomial1D*)overscanResult; // The polynomial
     678                                psPolynomial1D *poly = (psPolynomial1D*)overscanFit;    // The polynomial
    676679                                psString coeffs = NULL; // String containing the coefficients
    677680                                for (int i = 0; i < poly->n; i++) {
    678                                     psStringAppend(&coeffs, "%.2f ", poly->coeff[i]);
     681                                    psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    679682                                }
    680683                                psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",
     
    685688                          case PM_FIT_SPLINE:
    686689                            {
    687                                 psSpline1D *spline = (psSpline1D*)overscanResult; // The spline
     690                                psSpline1D *spline = (psSpline1D*)overscanFit; // The spline
    688691                                psString coeffs = NULL; // String containing the coefficients
    689692                                for (int i = 0; i < spline->n; i++) {
     
    691694                                    psStringAppend(&coeffs, "%d: ", i);
    692695                                    for (int j = 0; j < poly->n; j++) {
    693                                         psStringAppend(&coeffs, "%.2f ", poly->coeff[i]);
     696                                        psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    694697                                    }
    695698                                    psStringAppend(&coeffs, "\n");
     
    755758    psFree(dark);
    756759    psFree(flat);
     760    psFree(overscanFit);
    757761    psFree(overscanStats);
    758762
     
    764768#if 1
    765769    for (int i = 0; i < nLeaks; i++) {
    766         printf("Memory leak detection: memBlock %lld (%lld)\n"
    767                "\tFile %s, line %d, size %d\n",
    768                leaks[i]->id, leaks[i]->refCounter, leaks[i]->file, leaks[i]->lineno,
    769                leaks[i]->userMemorySize);
     770        psMemBlock *mb = leaks[i];
     771        printf("Memory leak %ld (%ld):\n"
     772               "\tFile %s, line %d, size %d\n"
     773               "\tPosts: %x %x %x\n",
     774               mb->id, mb->refCounter, mb->file, mb->lineno, mb->userMemorySize, mb->startblock, mb->endblock,
     775               *(void**)((int8_t *)(mb + 1) + mb->userMemorySize));
    770776    }
    771777#endif
  • trunk/archive/scripts/src/phase2/phase2.config

    r5105 r5371  
    5858# Overscan subtraction
    5959OVERSCAN.MODE           STR     INDIVIDUAL      # NONE | INDIVIDUAL | ALL
    60 OVERSCAN.FIT            STR     NONE            # NONE | POLYNOMIAL | SPLINE
    61 OVERSCAN.BIN            S32     4               # Number of pixels per bin
     60OVERSCAN.FIT            STR     SPLINE          # NONE | POLYNOMIAL | SPLINE
     61OVERSCAN.ORDER          S32     10              # Order of polynomial fit
     62OVERSCAN.BIN            S32     0               # Number of pixels per bin
    6263OVERSCAN.STAT           STR     MEAN            # MEAN | MEDIAN
  • trunk/archive/scripts/src/phase2/pmFPA.c

    r5104 r5371  
    77#include "pmFPA.h"
    88
     9// Get the bias images for a readout, using the CELL.BIASSEC
     10psList *pmReadoutGetBias(pmReadout *readout // Readout for which to get the bias sections
     11    )
     12{
     13    pmCell *cell = readout->parent;     // The parent cell
     14    psList *sections = (psList*)psMetadataLookupPtr(NULL, cell->concepts, "CELL.BIASSEC"); // CELL.BIASSEC
     15
     16    psImage *image = readout->image;    // The image that contains both the biassec and the trimsec
     17
     18    psList *images = psListAlloc(NULL); // List of images from bias sections
     19    psListIterator *sectionsIter = psListIteratorAlloc(sections, PS_LIST_HEAD, true); // Iterator
     20    psRegion *region = NULL;            // Bias region from list
     21    while (region = psListGetAndIncrement(sectionsIter)) {
     22#if 0
     23        // Convert from FITS standard to PS standard
     24        // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
     25        region->x0 -= 1;
     26        region->y0 -= 1;
     27#endif
     28
     29        psImage *bias = psImageSubset(image, *region); // Image from bias section
     30        psListAdd(images, PS_LIST_TAIL, bias);
     31        psFree(bias);
     32    }
     33    psFree(sectionsIter);
     34
     35    return images;
     36}
     37
    938//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1039// Allocators
    1140//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1241
    13 p_pmHDU *p_pmHDUAlloc(const char *extname)
    14 {
    15     p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU));
    16     psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree);
    17 
    18     hdu->extname = extname;
    19     hdu->pixels = NULL;
    20     hdu->header = NULL;
    21 
    22     return hdu;
    23 }
    24 
    25 void p_pmHDUFree(p_pmHDU *hdu)
    26 {
    27     psFree(hdu->pixels);
    28     psFree(hdu->header);
     42pmPixelData *pmPixelDataAlloc(const char *extname)
     43{
     44    pmPixelData *pd = psAlloc(sizeof(pmPixelData));
     45    psMemSetDeallocator(pd, (psFreeFunc)p_pmPixelDataFree);
     46
     47    pd->extname = extname;
     48    pd->header = NULL;
     49    pd->images = NULL;
     50    pd->masks = NULL;
     51    pd->weights = NULL;
     52
     53    return pd;
     54}
     55
     56void p_pmPixelDataFree(pmPixelData *pd)
     57{
     58    psFree(pd->header);
     59    psFree(pd->images);
     60    psFree(pd->masks);
     61    psFree(pd->weights);
    2962}
    3063
     
    4477    fpa->chips = psArrayAlloc(0);
    4578
    46     fpa->private = NULL;
     79    fpa->data = NULL;
    4780
    4881    return fpa;
     
    5992    psFree(fpa->chips);
    6093
    61     psFree(fpa->private);
     94    psFree(fpa->data);
    6295}
    6396
     
    86119    chip->valid = true;   
    87120
    88     chip->private = NULL;
     121    chip->data = NULL;
    89122
    90123    psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name);
     
    101134    psFree(chip->cells);
    102135
    103     psFree(chip->private);
     136    psFree(chip->data);
    104137
    105138    // We don't free the parent member, since that would generate a circular call.  We don't increment the
     
    138171    cell->valid = true;
    139172
    140     cell->private = NULL;
     173    cell->data = NULL;
    141174
    142175    return cell;
     
    155188    psFree(cell->readouts);
    156189
    157     psFree(cell->private);
     190    psFree(cell->data);
    158191
    159192    // We don't free the parent member, since that would generate a circular call.  We don't increment the
     
    163196pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs
    164197                          psImage *image, // The pixels
    165                           psList *overscans, // The overscan images
     198                          psImage *mask,// The mask pixels
    166199                          int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
    167200    )
     
    173206    // Set the components
    174207    readout->image = psMemIncrRefCounter(image);
    175     readout->mask = NULL;
    176     readout->overscans = psMemIncrRefCounter(overscans);
     208    readout->mask = psMemIncrRefCounter(mask);
     209    readout->weight = NULL;
    177210   
    178211    //readout->concepts = psMetadataAlloc();
     
    185218    *(int*)&readout->rowBins = rowBin;
    186219
     220    readout->parent = cell;
     221
    187222    return readout;
    188223}
     
    191226{
    192227    psFree(readout->image);
    193     psFree(readout->mask); 
    194     psFree(readout->overscans);
     228    psFree(readout->mask);
     229    psFree(readout->weight);
    195230    //psFree(readout->concepts);
    196231}
  • trunk/archive/scripts/src/phase2/pmFPA.h

    r5104 r5371  
    1111typedef struct {
    1212    const char *extname;                // Extension name, if it corresponds to this level
    13     psArray *pixels;                    // The pixel data, if it corresponds to this level
    1413    psMetadata *header;                 // The FITS header, if it corresponds to this level
    15 } p_pmHDU;
     14    psArray *images;                    // The pixel data, if it corresponds to this level
     15    psArray *masks;                     // The mask data, if it corresponds to this level
     16    psArray *weights;                   // The weight data, if it corresponds to this level
     17} pmPixelData;
    1618
    1719typedef struct {
     
    2527    psMetadata *phu;                    // Primary Header
    2628    psArray *chips;                     // The chips
    27     p_pmHDU *private;                   // FITS data
     29    pmPixelData *data;                  // FITS data
    2830} pmFPA;
    2931
     
    4042    pmFPA *parent;                      // Parent FPA
    4143    bool valid;                         // Valid for reading in?
    42     p_pmHDU *private;                   // FITS data
     44    pmPixelData *data;                  // FITS data
    4345} pmChip;
    4446
     
    5961    pmChip *parent;                     // Parent chip
    6062    bool valid;                         // Valid for operating on?
    61     p_pmHDU *private;                   // FITS data
     63    pmPixelData *data;                  // FITS data
    6264} pmCell;
    6365
     
    7274    const unsigned int rowBins;         // Amount of binning in y-dimension
    7375    // Information
     76    psMetadata *concepts;               // Concepts for readouts
     77    pmCell *parent;                     // Parent cell
    7478    psImage *image;                     // The pixels
    7579    psImage *mask;                      // Mask image
    76     psList *overscans;                  // List of subimages containing the overscan regions
    77     psMetadata *concepts;               // Concepts for readouts
     80    psImage *weight;                    // Weight image
    7881} pmReadout;
    7982
     83
     84psList *pmReadoutGetBias(pmReadout *readout // Readout for which to get the bias sections
     85    );
     86
     87
    8088// Allocators and deallocators
    81 p_pmHDU *p_pmHDUAlloc(const char *extname);
    82 void p_pmHDUFree(p_pmHDU *hdu);
     89pmPixelData *pmPixelDataAlloc(const char *extname);
     90void p_pmPixelDataFree(pmPixelData *pd);
    8391pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration
    8492    );
     
    96104void p_pmCellFree(pmCell *cell);
    97105
    98 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs
     106pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs
    99107                          psImage *image, // The pixels
    100                           psList *overscans, // The overscan images
     108                          psImage *mask,// The mask pixels
    101109                          int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
    102110    );
  • trunk/archive/scripts/src/phase2/pmFPAConceptsGet.c

    r5105 r5371  
    4646    if (mdStatus && strlen(keyword) > 0) {
    4747        // We have a FITS header to look up --- search each level
    48         if (cell && cell->private) {
    49             psMetadataItem *cellItem = psMetadataLookup(cell->private->header, keyword);
     48        if (cell && cell->data) {
     49            psMetadataItem *cellItem = psMetadataLookup(cell->data->header, keyword);
    5050            if (cellItem) {
    5151                // XXX: Need to clean up before returning
     
    5454        }
    5555
    56         if (chip && chip->private) {
    57             psMetadataItem *chipItem = psMetadataLookup(chip->private->header, keyword);
     56        if (chip && chip->data) {
     57            psMetadataItem *chipItem = psMetadataLookup(chip->data->header, keyword);
    5858            if (chipItem) {
    5959                // XXX: Need to clean up before returning
     
    6262        }
    6363
    64         if (fpa->private) {
    65             psMetadataItem *fpaItem = psMetadataLookup(fpa->private->header, keyword);
     64        if (fpa->data) {
     65            psMetadataItem *fpaItem = psMetadataLookup(fpa->data->header, keyword);
    6666            if (fpaItem) {
    6767                // XXX: Need to clean up before returning
     
    653653                } else if (strcasecmp(source, "HEADER") == 0) {
    654654                    psMetadata *header = NULL; // The FITS header
    655                     if (cell->private) {
    656                         header = cell->private->header;
    657                     } else if (chip->private) {
    658                         header = chip->private->header;
    659                     } else if (fpa->private) {
    660                             header = fpa->private->header;
     655                    if (cell->data) {
     656                        header = cell->data->header;
     657                    } else if (chip->data) {
     658                        header = chip->data->header;
     659                    } else if (fpa->data) {
     660                            header = fpa->data->header;
    661661                    }
    662662                    if (! header) {
     
    718718                    } else if (strcasecmp(source, "HEADER") == 0) {
    719719                        psMetadata *header = NULL; // The FITS header
    720                         if (cell->private) {
    721                             header = cell->private->header;
    722                         } else if (chip->private) {
    723                             header = chip->private->header;
    724                         } else if (fpa->private) {
    725                             header = fpa->private->header;
     720                        if (cell->data) {
     721                            header = cell->data->header;
     722                        } else if (chip->data) {
     723                            header = chip->data->header;
     724                        } else if (fpa->data) {
     725                            header = fpa->data->header;
    726726                        }
    727727                        if (! header) {
     
    753753
    754754        psMetadataAdd(cell->concepts, PS_LIST_TAIL, "CELL.BIASSEC", PS_META_LIST, "Bias sections", biassecs);
     755        psFree(biassecs);
    755756    }
    756757
     
    847848                                // timeString contains headers for the date and time
    848849                                psMetadata *header = NULL; // The FITS header
    849                                 if (cell->private) {
    850                                     header = cell->private->header;
    851                                 } else if (chip->private) {
    852                                     header = chip->private->header;
    853                                 } else if (fpa->private) {
    854                                     header = fpa->private->header;
     850                                if (cell->data) {
     851                                    header = cell->data->header;
     852                                } else if (chip->data) {
     853                                    header = chip->data->header;
     854                                } else if (fpa->data) {
     855                                    header = fpa->data->header;
    855856                                }
    856857                                if (! header) {
     
    966967        psMetadataAdd(cell->concepts, PS_LIST_TAIL, "CELL.TIME", PS_META_UNKNOWN, "Time of exposure", time);
    967968        psFree(time);
    968 
    969969    }
    970970
  • trunk/archive/scripts/src/phase2/pmFPAConceptsSet.c

    r5105 r5371  
    130130
    131131        // We have a FITS header to look up --- search each level
    132         if (cell && cell->private) {
    133             psMetadataItem *cellItem = psMetadataLookup(cell->private->header, keyword);
     132        if (cell && cell->data) {
     133            psMetadataItem *cellItem = psMetadataLookup(cell->data->header, keyword);
    134134            if (cellItem) {
    135135                // XXX: Need to clean up before returning
    136                 psMetadataAddItem(cell->private->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
     136                psMetadataAddItem(cell->data->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
    137137                status = true;
    138138            }
    139         } else if (chip && chip->private) {
    140             psMetadataItem *chipItem = psMetadataLookup(chip->private->header, keyword);
     139        } else if (chip && chip->data) {
     140            psMetadataItem *chipItem = psMetadataLookup(chip->data->header, keyword);
    141141            if (chipItem) {
    142142                // XXX: Need to clean up before returning
    143                 psMetadataAddItem(chip->private->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
     143                psMetadataAddItem(chip->data->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
    144144                status = true;
    145145            }
    146         } else if (fpa->private) {
    147             psMetadataItem *fpaItem = psMetadataLookup(fpa->private->header, keyword);
     146        } else if (fpa->data) {
     147            psMetadataItem *fpaItem = psMetadataLookup(fpa->data->header, keyword);
    148148            if (fpaItem) {
    149149                // XXX: Need to clean up before returning
    150                 psMetadataAddItem(fpa->private->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
     150                psMetadataAddItem(fpa->data->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
    151151                status = true;
    152152            }
     
    571571                psString keyword = psMetadataLookupString(NULL, cell->camera, "CELL.TRIMSEC");
    572572                psMetadata *header = NULL; // The FITS header
    573                 if (cell->private) {
    574                     header = cell->private->header;
    575                 } else if (chip->private) {
    576                     header = chip->private->header;
    577                 } else if (fpa->private) {
    578                     header = fpa->private->header;
     573                if (cell->data) {
     574                    header = cell->data->header;
     575                } else if (chip->data) {
     576                    header = chip->data->header;
     577                } else if (fpa->data) {
     578                    header = fpa->data->header;
    579579                }
    580580                if (! header) {
     
    651651                } else {
    652652                    psMetadata *header = NULL; // The FITS header
    653                     if (cell->private) {
    654                         header = cell->private->header;
    655                     } else if (chip->private) {
    656                         header = chip->private->header;
    657                     } else if (fpa->private) {
    658                         header = fpa->private->header;
     653                    if (cell->data) {
     654                        header = cell->data->header;
     655                    } else if (chip->data) {
     656                        header = chip->data->header;
     657                    } else if (fpa->data) {
     658                        header = fpa->data->header;
    659659                    }
    660660                    if (! header) {
     
    707707                                                             binString);
    708708            psMetadata *header = NULL; // The FITS header
    709             if (cell->private) {
    710                 header = cell->private->header;
    711             } else if (chip->private) {
    712                 header = chip->private->header;
    713             } else if (fpa->private) {
    714                 header = fpa->private->header;
     709            if (cell->data) {
     710                header = cell->data->header;
     711            } else if (chip->data) {
     712                header = chip->data->header;
     713            } else if (fpa->data) {
     714                header = fpa->data->header;
    715715            }
    716716            if (! header) {
     
    784784                // We're working with two separate headers
    785785                psMetadata *header = NULL; // The FITS header
    786                 if (cell->private) {
    787                     header = cell->private->header;
    788                 } else if (chip->private) {
    789                     header = chip->private->header;
    790                 } else if (fpa->private) {
    791                     header = fpa->private->header;
     786                if (cell->data) {
     787                    header = cell->data->header;
     788                } else if (chip->data) {
     789                    header = chip->data->header;
     790                } else if (fpa->data) {
     791                    header = fpa->data->header;
    792792                }
    793793                if (! header) {
  • trunk/archive/scripts/src/phase2/pmFPAConstruct.c

    r5104 r5371  
    8888                psString extName = contentItem->name; // The name of the extension
    8989                pmChip *chip = pmChipAlloc(fpa, extName); // The chip
    90                 chip->private = p_pmHDUAlloc(extName); // Prepare chip to receive FITS data
     90                chip->data = pmPixelDataAlloc(extName); // Prepare chip to receive FITS data
    9191                if (contentItem->type != PS_META_STR) {
    9292                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     
    146146                    pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell
    147147//                  psFree(cellData);
    148                     cell->private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data
     148                    cell->data = pmPixelDataAlloc(extName); // Prepare cell to receive FITS data
    149149
    150150                    psFree(chip);
     
    157157        } else if (strcasecmp(extType, "NONE") == 0) {
    158158            // No extensions; Content contains metadata, each entry is a chip with its component cells
    159             fpa->private = p_pmHDUAlloc("PHU"); // Prepare FPA to receive FITS data
     159            fpa->data = pmPixelDataAlloc("PHU"); // Prepare FPA to receive FITS data
    160160            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    161161                psString chipName = contentItem->name; // The name of the chip
     
    196196        if (strcasecmp(extType, "NONE") == 0) {
    197197            // There are no extensions --- only the PHU
    198             chip->private = p_pmHDUAlloc("PHU");
     198            chip->data = pmPixelDataAlloc("PHU");
    199199
    200200            const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS");
     
    247247                pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell
    248248//              psFree(cellData);
    249                 cell->private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data
     249                cell->data = pmPixelDataAlloc(extName); // Prepare cell to receive FITS data
    250250            } // Iterating through contents
    251251            psFree(contentsIter);
     
    273273{
    274274    psTrace(__func__, 0, "FPA:\n");
    275     if (fpa->private) {
    276         psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->private->extname);
    277         if (! fpa->private->pixels) {
    278             psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->private->extname);
     275    if (fpa->data) {
     276        psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->data->extname);
     277        if (! fpa->data->images) {
     278            psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->data->extname);
    279279        }
    280280    }
     
    285285        psTrace(__func__, 1, "Chip: %d\n", i);
    286286        pmChip *chip = chips->data[i]; // The chip
    287         if (chip->private) {
    288             psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->private->extname);
    289             if (! chip->private->pixels) {
    290                 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->private->extname);
     287        if (chip->data) {
     288            psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->data->extname);
     289            if (! chip->data->images) {
     290                psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->data->extname);
    291291            }
    292292        }
     
    296296            psTrace(__func__, 2, "Cell: %d\n", j);
    297297            pmCell *cell = cells->data[j]; // The cell
    298             if (cell->private) {
    299                 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->private->extname);
    300                 if (! cell->private->pixels) {
    301                     psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->private->extname);
     298            if (cell->data) {
     299                psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->data->extname);
     300                if (! cell->data->images) {
     301                    psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->data->extname);
    302302                }
    303303            }
     
    311311                        image->numCols, image->row0, image->row0 + image->numRows, image->numCols,
    312312                        image->numRows);
    313                 psList *overscans = readout->overscans; // The list of overscans
    314                 psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false);
    315                 while (image = psListGetAndIncrement(overscansIter)) {
    316                     psTrace(__func__, 4, "Overscan: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +
    317                             image->numCols, image->row0, image->row0 + image->numRows, image->numCols,
    318                             image->numRows);
    319                 }
    320                 psFree(overscansIter);
    321 
    322313            } // Iterating over cell
    323314        } // Iterating over chip
  • trunk/archive/scripts/src/phase2/pmFPARead.c

    r5105 r5371  
    1717
    1818// Read a FITS extension into a chip
    19 static bool readExtension(p_pmHDU *hdu, // HDU to read
     19static bool readExtension(pmPixelData *pixelData, // Pixel data into which to read
    2020                          psFits *fits  // The FITS file from which to read
    2121    )
    2222{
    23     const char *extName = hdu->extname; // Extension name
     23    const char *extName = pixelData->extname; // Extension name
    2424
    2525    psTrace(__func__, 7, "Moving to extension %s...\n", extName);
     
    7474        if (image->type.type != PS_TYPE_F32) {
    7575            pixels->data[i] = psImageCopy(NULL, image, PS_TYPE_F32);
     76
     77#ifndef PRODUCTION
     78            // XXX: Temporary fix for writing images, until psFits gets cleaned up
     79            psMetadataItem *bitpixItem = psMetadataLookup(header, "BITPIX");
     80            bitpixItem->data.S32 = -32;
     81            psMetadataRemove(header, 0, "BZERO");
     82            psMetadataRemove(header, 0, "BSCALE");
     83#endif
     84
    7685            psFree(image);
    7786        } else {
     
    8695
    8796    // Update the HDU with the new data
    88     hdu->pixels = pixels;
    89     hdu->header = header;
     97    pixelData->images = pixels;
     98    pixelData->header = header;
     99
     100    // XXX: Insert mask and weight reading here
    90101
    91102    return true;
    92103}
    93104
    94 
    95105// Portion out an image into the cell
    96 static bool portionCell(pmCell *cell,   // The cell that gets its bits
    97                         psArray *images // Array of images from which the readouts are assigned
     106static bool generateReadouts(pmCell *cell, // The cell that gets its bits
     107                             pmPixelData *data // Pixel data, containing image, mask, weights
    98108    )
    99109{
    100     bool mdStatus = false;              // Status of MD lookup
    101 
    102     // Get the trim and bias sections
    103     psMetadataItem *mdItem = psMetadataLookup(cell->concepts, "CELL.TRIMSEC");
    104     psRegion *trimRegion = mdItem->data.V;
    105     mdItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC");
    106     psList *biasRegionList = mdItem->data.V;
    107 
     110    psArray *images = data->images;     // Array of images (each of which is a readout)
     111    psArray *masks = data->masks;       // Array of masks (one for each readout)
    108112    // Iterate over each of the image planes
    109113    for (int i = 0; i < images->n; i++) {
    110114        psImage *image = images->data[i]; // The i-th plane
    111 
    112         // Convert from FITS standard to PS standard
    113         // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    114         //trimRegion->x0 -= 1;
    115         //trimRegion->y0 -= 1;
    116 
    117         psImage *trimImage = psImageSubset(image, *trimRegion); // Image from trim section
    118 
    119         psList *biasImages = psListAlloc(NULL); // List of images from bias sections
    120         psListIterator *biasRegionIter = psListIteratorAlloc(biasRegionList, PS_LIST_HEAD, true); // Iterator
    121         psRegion *biasRegion = NULL;    // Bias region from list
    122         while (biasRegion = psListGetAndIncrement(biasRegionIter)) {
    123             // Convert from FITS standard to PS standard
    124             // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    125             //biasRegion->x0 -= 1;
    126             //biasRegion->y0 -= 1;
    127            
    128             psImage *biasImage = psImageSubset(image, *biasRegion); // Image from bias section
    129             psListAdd(biasImages, PS_LIST_TAIL, biasImage);
    130             psFree(biasImage);
    131         }
    132         psFree(biasRegionIter);
    133 
    134         pmReadout *readout = pmReadoutAlloc(cell, trimImage, biasImages, 0,0,0,0,1,1);
     115        psImage *mask = NULL;           // The mask
     116        if (masks) {
     117            mask = masks->data[i];
     118        }
     119
     120        pmReadout *readout = pmReadoutAlloc(cell, image, mask, 0,0,0,0,1,1);
    135121        psFree(readout);                // This seems silly, but the alloc registers it with the cell, so we
    136122                                        // don't have to do anything with it.  Perhaps we should change
    137123                                        // pmReadoutAlloc to pmReadoutAdd?
    138         psFree(trimImage);
    139         psFree(biasImages);
    140     }
    141     psFree(biasRegionList);
     124    }
    142125
    143126    return true;
     
    154137    )
    155138{
    156     p_pmHDU *hdu = NULL;                // Current HDU from FITS file
     139    pmPixelData *pixelData = NULL;      // Pixel data from FITS file
    157140
    158141    // Read the PHU, if required
     
    169152    // Read in....
    170153    psTrace(__func__, 1, "Working on FPA...\n");
    171     if (fpa->private) {
    172         hdu = fpa->private;
    173         psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", hdu->extname);
    174         if (! readExtension(hdu, fits)) {
    175             psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     154    if (fpa->data) {
     155        pixelData= fpa->data;
     156        psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", pixelData->extname);
     157        if (! readExtension(pixelData, fits)) {
     158            psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname);
    176159            return false;
    177160        }
     
    191174        psTrace(__func__, 2, "Reading in chip %d...\n", i);
    192175
    193         if (chip->private) {
    194             hdu = chip->private;
    195             psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", hdu->extname, i);
    196             if (! readExtension(hdu, fits)) {
    197                 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     176        if (chip->data) {
     177            pixelData = chip->data;
     178            psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", pixelData->extname, i);
     179            if (! readExtension(pixelData, fits)) {
     180                psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname);
    198181                return false;
    199182            }
     
    213196            psTrace(__func__, 3, "Reading in cell %d...\n", j);
    214197
    215             if (cell->private) {
    216                 hdu = cell->private;
    217                 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", hdu->extname, j);
    218                 if (! readExtension(hdu, fits)) {
    219                     psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     198            if (cell->data) {
     199                pixelData = cell->data;
     200                psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", pixelData->extname,
     201                        j);
     202                if (! readExtension(pixelData, fits)) {
     203                    psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n",
     204                            pixelData->extname);
    220205                    return false;
    221206                }
     
    225210            psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n",
    226211                    i, j);
    227             portionCell(cell, hdu->pixels);
     212            generateReadouts(cell, pixelData);
    228213        }
    229214    }
  • trunk/archive/scripts/src/phase2/pmFPAWrite.c

    r5105 r5371  
    77
    88static bool writeHDU(psFits *fits,      // FITS file to which to write
    9                      p_pmHDU *hdu       // HDU to write
     9                     pmPixelData *pixelData // Pixel data to write
    1010    )
    1111{
    1212    bool status = true;                 // Status of write, to return
    13     for (int i = 0; i < hdu->pixels->n; i++) {
    14         status &= psFitsWriteImage(fits, hdu->header, hdu->pixels->data[i], i);
     13    for (int i = 0; i < pixelData->images->n; i++) {
     14        status &= psFitsWriteImage(fits, pixelData->header, pixelData->images->data[i], i);
     15        // XXX: Insert here the writing on mask and weight images
    1516    }
    1617
     
    4647                    pmCellOutgestConcepts(cell, db);
    4748
    48                     if (cell->private && strlen(cell->private->extname) > 0) {
    49                         status &= writeHDU(fits, cell->private);
     49                    if (cell->data && strlen(cell->data->extname) > 0) {
     50                        status &= writeHDU(fits, cell->data);
    5051                    }
    5152                }
    5253            }
    5354           
    54             if (chip->private && strlen(chip->private->extname) > 0) {
    55                 status &= writeHDU(fits, chip->private);
     55            if (chip->data && strlen(chip->data->extname) > 0) {
     56                status &= writeHDU(fits, chip->data);
    5657            }
    5758        }
     
    5960    }
    6061
    61     if (fpa->private && strlen(fpa->private->extname) > 0) {
    62         status &= writeHDU(fits, fpa->private);
     62    if (fpa->data && strlen(fpa->data->extname) > 0) {
     63        status &= writeHDU(fits, fpa->data);
    6364    }
    6465
Note: See TracChangeset for help on using the changeset viewer.