Changeset 5371
- Timestamp:
- Oct 18, 2005, 4:19:41 PM (21 years ago)
- Location:
- trunk/archive/scripts/src/phase2
- Files:
-
- 9 edited
-
papPhase2.c (modified) (13 diffs)
-
phase2.config (modified) (1 diff)
-
pmFPA.c (modified) (11 diffs)
-
pmFPA.h (modified) (6 diffs)
-
pmFPAConceptsGet.c (modified) (8 diffs)
-
pmFPAConceptsSet.c (modified) (5 diffs)
-
pmFPAConstruct.c (modified) (9 diffs)
-
pmFPARead.c (modified) (8 diffs)
-
pmFPAWrite.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/papPhase2.c
r5104 r5371 45 45 static psMemId memPrintAlloc(const psMemBlock *mb) 46 46 { 47 printf("Allocated memory block %l ld (%lld):\n"47 printf("Allocated memory block %ld (%ld):\n" 48 48 "\tFile %s, line %d, size %d\n" 49 49 "\tPosts: %x %x %x\n", … … 54 54 static psMemId memPrintFree(const psMemBlock *mb) 55 55 { 56 printf("Freed memory block %l ld (%lld):\n"56 printf("Freed memory block %ld (%ld):\n" 57 57 "\tFile %s, line %d, size %d\n" 58 58 "\tPosts: %x %x %x\n", … … 64 64 { 65 65 psMemBlock *mb = ((psMemBlock*)ptr) - 1; 66 printf("Memory block %l ld (%lld):\n"66 printf("Memory block %ld (%ld):\n" 67 67 "\tFile %s, line %d, size %d\n" 68 68 "\tPosts: %x %x %x\n", … … 75 75 #if 0 76 76 // Hunting memory leaks 77 psMemAlloc ateCallbackSetID(23289);78 psMemFreeCallbackSetID(2 3289);79 psMemAlloc ateCallbackSet(memPrintAlloc);77 psMemAllocCallbackSetID(22367); 78 psMemFreeCallbackSetID(22367); 79 psMemAllocCallbackSet(memPrintAlloc); 80 80 psMemFreeCallbackSet(memPrintFree); 81 81 #endif … … 198 198 bool doAstrom = false; // Astrometry 199 199 pmOverscanAxis overscanMode = PM_OVERSCAN_NONE; // Axis for overscan 200 pmFit overscanFit = PM_FIT_NONE;// Fit type for overscan200 pmFit overscanFitType = PM_FIT_NONE; // Fit type for overscan 201 201 int overscanBins = 1; // Number of pixels per bin for overscan 202 202 psStats *overscanStats = NULL; // Statistics for overscan 203 void *overscanFit = NULL; // Overscan fit (polynomial or spline) 203 204 204 205 if (psMetadataLookupBool(NULL, recipe, "MASK")) { … … 243 244 psString fit = psMetadataLookupString(NULL, recipe, "OVERSCAN.FIT"); 244 245 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); 246 249 } 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); 248 253 } else if (strcasecmp(fit, "NONE") != 0) { 249 254 psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:" … … 297 302 #endif 298 303 299 pmFPAPrint(input);304 //pmFPAPrint(input); 300 305 301 306 // Load the calibration frames, if required … … 475 480 pmReadout *inputReadout = inputReadouts->data[k]; // Readout of interest in input image 476 481 psImage *inputImage = inputReadout->image; // The actual image 477 psList *inputOverscans = inputReadout->overscans; // List of overscan bias regions478 482 479 483 // Mask bad pixels … … 656 660 } 657 661 658 printf("mode: %d\n", overscanMode);659 660 662 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 670 673 // Output overscan fit results, if required 671 674 if (doOverscan) { 672 switch (overscanFit ) {675 switch (overscanFitType) { 673 676 case PM_FIT_POLYNOMIAL: 674 677 { 675 psPolynomial1D *poly = (psPolynomial1D*)overscan Result; // The polynomial678 psPolynomial1D *poly = (psPolynomial1D*)overscanFit; // The polynomial 676 679 psString coeffs = NULL; // String containing the coefficients 677 680 for (int i = 0; i < poly->n; i++) { 678 psStringAppend(&coeffs, "% .2f", poly->coeff[i]);681 psStringAppend(&coeffs, "%e ", poly->coeff[i]); 679 682 } 680 683 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n", … … 685 688 case PM_FIT_SPLINE: 686 689 { 687 psSpline1D *spline = (psSpline1D*)overscan Result; // The spline690 psSpline1D *spline = (psSpline1D*)overscanFit; // The spline 688 691 psString coeffs = NULL; // String containing the coefficients 689 692 for (int i = 0; i < spline->n; i++) { … … 691 694 psStringAppend(&coeffs, "%d: ", i); 692 695 for (int j = 0; j < poly->n; j++) { 693 psStringAppend(&coeffs, "% .2f", poly->coeff[i]);696 psStringAppend(&coeffs, "%e ", poly->coeff[i]); 694 697 } 695 698 psStringAppend(&coeffs, "\n"); … … 755 758 psFree(dark); 756 759 psFree(flat); 760 psFree(overscanFit); 757 761 psFree(overscanStats); 758 762 … … 764 768 #if 1 765 769 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)); 770 776 } 771 777 #endif -
trunk/archive/scripts/src/phase2/phase2.config
r5105 r5371 58 58 # Overscan subtraction 59 59 OVERSCAN.MODE STR INDIVIDUAL # NONE | INDIVIDUAL | ALL 60 OVERSCAN.FIT STR NONE # NONE | POLYNOMIAL | SPLINE 61 OVERSCAN.BIN S32 4 # Number of pixels per bin 60 OVERSCAN.FIT STR SPLINE # NONE | POLYNOMIAL | SPLINE 61 OVERSCAN.ORDER S32 10 # Order of polynomial fit 62 OVERSCAN.BIN S32 0 # Number of pixels per bin 62 63 OVERSCAN.STAT STR MEAN # MEAN | MEDIAN -
trunk/archive/scripts/src/phase2/pmFPA.c
r5104 r5371 7 7 #include "pmFPA.h" 8 8 9 // Get the bias images for a readout, using the CELL.BIASSEC 10 psList *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 9 38 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 10 39 // Allocators 11 40 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 41 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); 42 pmPixelData *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 56 void p_pmPixelDataFree(pmPixelData *pd) 57 { 58 psFree(pd->header); 59 psFree(pd->images); 60 psFree(pd->masks); 61 psFree(pd->weights); 29 62 } 30 63 … … 44 77 fpa->chips = psArrayAlloc(0); 45 78 46 fpa-> private= NULL;79 fpa->data = NULL; 47 80 48 81 return fpa; … … 59 92 psFree(fpa->chips); 60 93 61 psFree(fpa-> private);94 psFree(fpa->data); 62 95 } 63 96 … … 86 119 chip->valid = true; 87 120 88 chip-> private= NULL;121 chip->data = NULL; 89 122 90 123 psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name); … … 101 134 psFree(chip->cells); 102 135 103 psFree(chip-> private);136 psFree(chip->data); 104 137 105 138 // We don't free the parent member, since that would generate a circular call. We don't increment the … … 138 171 cell->valid = true; 139 172 140 cell-> private= NULL;173 cell->data = NULL; 141 174 142 175 return cell; … … 155 188 psFree(cell->readouts); 156 189 157 psFree(cell-> private);190 psFree(cell->data); 158 191 159 192 // We don't free the parent member, since that would generate a circular call. We don't increment the … … 163 196 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs 164 197 psImage *image, // The pixels 165 ps List *overscans, // The overscan images198 psImage *mask,// The mask pixels 166 199 int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data 167 200 ) … … 173 206 // Set the components 174 207 readout->image = psMemIncrRefCounter(image); 175 readout->mask = NULL;176 readout-> overscans = psMemIncrRefCounter(overscans);208 readout->mask = psMemIncrRefCounter(mask); 209 readout->weight = NULL; 177 210 178 211 //readout->concepts = psMetadataAlloc(); … … 185 218 *(int*)&readout->rowBins = rowBin; 186 219 220 readout->parent = cell; 221 187 222 return readout; 188 223 } … … 191 226 { 192 227 psFree(readout->image); 193 psFree(readout->mask); 194 psFree(readout-> overscans);228 psFree(readout->mask); 229 psFree(readout->weight); 195 230 //psFree(readout->concepts); 196 231 } -
trunk/archive/scripts/src/phase2/pmFPA.h
r5104 r5371 11 11 typedef struct { 12 12 const char *extname; // Extension name, if it corresponds to this level 13 psArray *pixels; // The pixel data, if it corresponds to this level14 13 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; 16 18 17 19 typedef struct { … … 25 27 psMetadata *phu; // Primary Header 26 28 psArray *chips; // The chips 27 p _pmHDU *private; // FITS data29 pmPixelData *data; // FITS data 28 30 } pmFPA; 29 31 … … 40 42 pmFPA *parent; // Parent FPA 41 43 bool valid; // Valid for reading in? 42 p _pmHDU *private; // FITS data44 pmPixelData *data; // FITS data 43 45 } pmChip; 44 46 … … 59 61 pmChip *parent; // Parent chip 60 62 bool valid; // Valid for operating on? 61 p _pmHDU *private; // FITS data63 pmPixelData *data; // FITS data 62 64 } pmCell; 63 65 … … 72 74 const unsigned int rowBins; // Amount of binning in y-dimension 73 75 // Information 76 psMetadata *concepts; // Concepts for readouts 77 pmCell *parent; // Parent cell 74 78 psImage *image; // The pixels 75 79 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 78 81 } pmReadout; 79 82 83 84 psList *pmReadoutGetBias(pmReadout *readout // Readout for which to get the bias sections 85 ); 86 87 80 88 // Allocators and deallocators 81 p _pmHDU *p_pmHDUAlloc(const char *extname);82 void p_pm HDUFree(p_pmHDU *hdu);89 pmPixelData *pmPixelDataAlloc(const char *extname); 90 void p_pmPixelDataFree(pmPixelData *pd); 83 91 pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration 84 92 ); … … 96 104 void p_pmCellFree(pmCell *cell); 97 105 98 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs106 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs 99 107 psImage *image, // The pixels 100 ps List *overscans, // The overscan images108 psImage *mask,// The mask pixels 101 109 int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data 102 110 ); -
trunk/archive/scripts/src/phase2/pmFPAConceptsGet.c
r5105 r5371 46 46 if (mdStatus && strlen(keyword) > 0) { 47 47 // 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); 50 50 if (cellItem) { 51 51 // XXX: Need to clean up before returning … … 54 54 } 55 55 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); 58 58 if (chipItem) { 59 59 // XXX: Need to clean up before returning … … 62 62 } 63 63 64 if (fpa-> private) {65 psMetadataItem *fpaItem = psMetadataLookup(fpa-> private->header, keyword);64 if (fpa->data) { 65 psMetadataItem *fpaItem = psMetadataLookup(fpa->data->header, keyword); 66 66 if (fpaItem) { 67 67 // XXX: Need to clean up before returning … … 653 653 } else if (strcasecmp(source, "HEADER") == 0) { 654 654 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; 661 661 } 662 662 if (! header) { … … 718 718 } else if (strcasecmp(source, "HEADER") == 0) { 719 719 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; 726 726 } 727 727 if (! header) { … … 753 753 754 754 psMetadataAdd(cell->concepts, PS_LIST_TAIL, "CELL.BIASSEC", PS_META_LIST, "Bias sections", biassecs); 755 psFree(biassecs); 755 756 } 756 757 … … 847 848 // timeString contains headers for the date and time 848 849 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; 855 856 } 856 857 if (! header) { … … 966 967 psMetadataAdd(cell->concepts, PS_LIST_TAIL, "CELL.TIME", PS_META_UNKNOWN, "Time of exposure", time); 967 968 psFree(time); 968 969 969 } 970 970 -
trunk/archive/scripts/src/phase2/pmFPAConceptsSet.c
r5105 r5371 130 130 131 131 // 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); 134 134 if (cellItem) { 135 135 // 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); 137 137 status = true; 138 138 } 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); 141 141 if (chipItem) { 142 142 // 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); 144 144 status = true; 145 145 } 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); 148 148 if (fpaItem) { 149 149 // 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); 151 151 status = true; 152 152 } … … 571 571 psString keyword = psMetadataLookupString(NULL, cell->camera, "CELL.TRIMSEC"); 572 572 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; 579 579 } 580 580 if (! header) { … … 651 651 } else { 652 652 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; 659 659 } 660 660 if (! header) { … … 707 707 binString); 708 708 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; 715 715 } 716 716 if (! header) { … … 784 784 // We're working with two separate headers 785 785 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; 792 792 } 793 793 if (! header) { -
trunk/archive/scripts/src/phase2/pmFPAConstruct.c
r5104 r5371 88 88 psString extName = contentItem->name; // The name of the extension 89 89 pmChip *chip = pmChipAlloc(fpa, extName); // The chip 90 chip-> private = p_pmHDUAlloc(extName); // Prepare chip to receive FITS data90 chip->data = pmPixelDataAlloc(extName); // Prepare chip to receive FITS data 91 91 if (contentItem->type != PS_META_STR) { 92 92 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", … … 146 146 pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell 147 147 // psFree(cellData); 148 cell-> private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data148 cell->data = pmPixelDataAlloc(extName); // Prepare cell to receive FITS data 149 149 150 150 psFree(chip); … … 157 157 } else if (strcasecmp(extType, "NONE") == 0) { 158 158 // 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 data159 fpa->data = pmPixelDataAlloc("PHU"); // Prepare FPA to receive FITS data 160 160 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 161 161 psString chipName = contentItem->name; // The name of the chip … … 196 196 if (strcasecmp(extType, "NONE") == 0) { 197 197 // There are no extensions --- only the PHU 198 chip-> private = p_pmHDUAlloc("PHU");198 chip->data = pmPixelDataAlloc("PHU"); 199 199 200 200 const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS"); … … 247 247 pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell 248 248 // psFree(cellData); 249 cell-> private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data249 cell->data = pmPixelDataAlloc(extName); // Prepare cell to receive FITS data 250 250 } // Iterating through contents 251 251 psFree(contentsIter); … … 273 273 { 274 274 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); 279 279 } 280 280 } … … 285 285 psTrace(__func__, 1, "Chip: %d\n", i); 286 286 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); 291 291 } 292 292 } … … 296 296 psTrace(__func__, 2, "Cell: %d\n", j); 297 297 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); 302 302 } 303 303 } … … 311 311 image->numCols, image->row0, image->row0 + image->numRows, image->numCols, 312 312 image->numRows); 313 psList *overscans = readout->overscans; // The list of overscans314 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 322 313 } // Iterating over cell 323 314 } // Iterating over chip -
trunk/archive/scripts/src/phase2/pmFPARead.c
r5105 r5371 17 17 18 18 // Read a FITS extension into a chip 19 static bool readExtension(p _pmHDU *hdu, // HDUto read19 static bool readExtension(pmPixelData *pixelData, // Pixel data into which to read 20 20 psFits *fits // The FITS file from which to read 21 21 ) 22 22 { 23 const char *extName = hdu->extname;// Extension name23 const char *extName = pixelData->extname; // Extension name 24 24 25 25 psTrace(__func__, 7, "Moving to extension %s...\n", extName); … … 74 74 if (image->type.type != PS_TYPE_F32) { 75 75 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 76 85 psFree(image); 77 86 } else { … … 86 95 87 96 // 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 90 101 91 102 return true; 92 103 } 93 104 94 95 105 // Portion out an image into the cell 96 static bool portionCell(pmCell *cell,// The cell that gets its bits97 psArray *images // Array of images from which the readouts are assigned106 static bool generateReadouts(pmCell *cell, // The cell that gets its bits 107 pmPixelData *data // Pixel data, containing image, mask, weights 98 108 ) 99 109 { 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) 108 112 // Iterate over each of the image planes 109 113 for (int i = 0; i < images->n; i++) { 110 114 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); 135 121 psFree(readout); // This seems silly, but the alloc registers it with the cell, so we 136 122 // don't have to do anything with it. Perhaps we should change 137 123 // pmReadoutAlloc to pmReadoutAdd? 138 psFree(trimImage); 139 psFree(biasImages); 140 } 141 psFree(biasRegionList); 124 } 142 125 143 126 return true; … … 154 137 ) 155 138 { 156 p _pmHDU *hdu = NULL; // Current HDUfrom FITS file139 pmPixelData *pixelData = NULL; // Pixel data from FITS file 157 140 158 141 // Read the PHU, if required … … 169 152 // Read in.... 170 153 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); 176 159 return false; 177 160 } … … 191 174 psTrace(__func__, 2, "Reading in chip %d...\n", i); 192 175 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); 198 181 return false; 199 182 } … … 213 196 psTrace(__func__, 3, "Reading in cell %d...\n", j); 214 197 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); 220 205 return false; 221 206 } … … 225 210 psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n", 226 211 i, j); 227 portionCell(cell, hdu->pixels);212 generateReadouts(cell, pixelData); 228 213 } 229 214 } -
trunk/archive/scripts/src/phase2/pmFPAWrite.c
r5105 r5371 7 7 8 8 static bool writeHDU(psFits *fits, // FITS file to which to write 9 p _pmHDU *hdu // HDUto write9 pmPixelData *pixelData // Pixel data to write 10 10 ) 11 11 { 12 12 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 15 16 } 16 17 … … 46 47 pmCellOutgestConcepts(cell, db); 47 48 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); 50 51 } 51 52 } 52 53 } 53 54 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); 56 57 } 57 58 } … … 59 60 } 60 61 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); 63 64 } 64 65
Note:
See TracChangeset
for help on using the changeset viewer.
