Changeset 6817 for trunk/ppImage/src/ppImageLoop.c
- Timestamp:
- Apr 7, 2006, 5:57:23 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageLoop.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageLoop.c
r6775 r6817 1 #include <stdio.h> 2 #include "pslib.h" 3 #include "psmodules.h" 4 #include "ppImageDetrend.h" 5 #include "ppImage.h" 6 #include "ppMem.h" 1 # include "ppImage.h" 7 2 8 #define MEM_LEAKS 1 3 bool ppImageLoop (ppImageOptions *options, pmConfig *config) { 9 4 10 // Read the entire FPA 11 void readFPA(ppFile *file, // File to read 12 pmConfig *config // Configuration, containing the DB handle 13 ) 14 { 15 if (file->fpa && file->fits) { 16 pmFPARead(file->fpa, file->fits, config->database); 5 bool status; 6 pmChip *chip; 7 pmCell *cell; 8 pmReadout *readout; 9 10 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT"); 11 if (!status) { 12 psErrorStackPrint(stderr, "Can't find input data!\n"); 13 exit(EXIT_FAILURE); 17 14 } 15 16 pmFPAview *view = pmFPAviewAlloc (0); 17 18 // files associated with the science image 19 pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE); 20 21 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 22 psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 23 if (!chip->process || !chip->file_exists) { continue; } 24 pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE); 25 26 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 27 psLogMsg ("psphot", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 28 if (!cell->process || !cell->file_exists) { continue; } 29 pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE); 30 31 // process each of the readouts 32 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 33 pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE); 34 if (! readout->data_exists) { continue; } 35 36 // perform the detrend analysis 37 ppImageDetrendReadout (options, config, view); 38 39 pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER); 40 } 41 pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER); 42 } 43 44 // ppImageChipMosaic (config, view); 45 // ppImagePSPhot (config, view); 46 // ppImagePSAstro (config, view); 47 48 pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER); 49 50 // XXX paul added these frees: make sure the same is happening in the pmFileIOChecks 51 // Now I can blow away the mosaic so I can then read more. 52 // psFree(inputChip); 53 // psFree(biasChip); 54 // psFree(darkChip); 55 // psFree(maskChip); 56 // psFree(flatChip); 57 // ppMemUsed(); 58 } 59 60 // ppImageFPAMosaic (config, view); 61 // ppImageJpegFPA (config, view); 62 63 pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER); 64 65 psFree (view); 66 return true; 18 67 } 19 68 20 // Read a specified chip only21 void readChip(ppFile *file, // File to read22 pmConfig *config, // Configuration23 int chipNum // Chip number to read24 )25 {26 pmFPA *fpa = file->fpa; // The FPA27 if (fpa && file->fits) {28 pmChip *chip = fpa->chips->data[chipNum]; // The chip29 pmChipRead(chip, file->fits, config->database);30 }31 }32 33 34 void readCell(ppFile *file, pmConfig *config, int chipNum, int cellNum)35 {36 pmFPA *fpa = file->fpa; // The FPA37 if (fpa && file->fits) {38 pmChip *chip = fpa->chips->data[chipNum]; // The chip39 if (chip) {40 pmCell *cell = chip->cells->data[cellNum]; // The cell41 pmCellRead(cell, file->fits, config->database);42 }43 }44 }45 46 47 bool ppImageLoop(ppImageData *data, ppImageOptions *options, pmConfig *config)48 {49 ppImageDetrend detrend;50 51 int processChip = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to process or -152 53 // Load at FPA level if requested54 if (processChip < 0 && options->imageLoadDepth == PP_LOAD_FPA) {55 psTrace(__func__, 1, "Loading pixels for FPA...\n");56 readFPA(data->input, config);57 readFPA(data->bias, config);58 readFPA(data->dark, config);59 readFPA(data->mask, config);60 readFPA(data->flat, config);61 }62 63 psArray *chips = data->input->fpa->chips; // Component chips64 for (int i = 0; i < chips->n; i++) {65 66 if (processChip >= 0 && i != processChip) {67 continue;68 }69 if (options->imageLoadDepth == PP_LOAD_CHIP) {70 psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);71 readChip(data->input, config, i);72 readChip(data->bias, config, i);73 readChip(data->dark, config, i);74 readChip(data->mask, config, i);75 readChip(data->flat, config, i);76 }77 78 pmChip *inputChip = chips->data[i];79 pmChip *biasChip = data->bias->fpa->chips->data[i];80 pmChip *darkChip = data->dark->fpa->chips->data[i];81 pmChip *maskChip = data->mask->fpa->chips->data[i];82 pmChip *flatChip = data->flat->fpa->chips->data[i];83 84 psArray *cells = inputChip->cells;85 for (int j = 0; j < cells->n; j++) {86 detrend.input = inputChip->cells->data[j]; // Cell of interest in input image87 detrend.bias = biasChip->cells->data[j]; // Cell of interest in bias image88 detrend.dark = darkChip->cells->data[j]; // Cell of interest in dark imag89 detrend.mask = maskChip->cells->data[j]; // Cell of interest in mask image90 detrend.flat = flatChip->cells->data[j]; // Cell of interest in flat image91 92 if (! detrend.input->process) { continue; }93 94 if (options->imageLoadDepth == PP_LOAD_CELL) {95 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);96 readCell(data->input, config, i, j);97 readCell(data->bias, config, i, j);98 readCell(data->dark, config, i, j);99 readCell(data->mask, config, i, j);100 readCell(data->flat, config, i, j);101 }102 103 ppImageDetrendCell(&detrend, options, config);104 105 // Need to free detrend cells here so we have enough memory to do other stuff106 psFree(detrend.bias);107 psFree(detrend.dark);108 psFree(detrend.mask);109 psFree(detrend.flat);110 }111 112 #if 0113 int numMosaicked = pmChipMosaic(inputChip, 1, 1); // Number of cells mosaicked together114 psLogMsg(__func__, PS_LOG_INFO, "%d cells mosaicked.\n", numMosaicked);115 116 // XXX A kludge to get the write to behave w.r.t. the concepts --- we've changed the camera format, so117 // the concepts don't know what on earth to do.118 const psMetadata *camera = data->input->fpa->camera;119 data->input->fpa->camera = NULL;120 #endif121 122 // XXX Photometry goes here!123 124 pmChipWrite(inputChip, data->output, config->database);125 126 #if 0127 data->input->fpa->camera = camera;128 #endif129 130 // Now I can blow away the mosaic so I can then read more.131 psFree(inputChip);132 psFree(biasChip);133 psFree(darkChip);134 psFree(maskChip);135 psFree(flatChip);136 137 ppMemUsed();138 }139 140 return true;141 }
Note:
See TracChangeset
for help on using the changeset viewer.
