- Timestamp:
- Feb 9, 2010, 8:24:35 PM (16 years ago)
- Location:
- branches/eam_branches/20091201/ppViz
- Files:
-
- 3 copied
-
. (copied) (copied from trunk/ppViz ) (1 prop)
-
src/ppVizPattern (copied) (copied from trunk/ppViz/src/ppVizPSF )
-
src/ppVizPattern/ppVizPatternLoop.c (copied) (copied from trunk/ppViz/src/ppVizPSF/ppVizPSFLoop.c ) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ppViz
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/eam_branches/20091113/ppViz 26119-26255 /branches/pap/ppViz 26320
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/eam_branches/20091201/ppViz/src/ppVizPattern/ppVizPatternLoop.c
r26827 r26837 7 7 #include <psmodules.h> 8 8 9 #include "ppVizP SF.h"9 #include "ppVizPattern.h" 10 10 11 #define MASK_BAD 0xFFFF // Mask for bad pixels 11 12 12 bool ppVizP SFLoop(ppVizPSFData *data // Run-time data13 bool ppVizPatternLoop(ppVizPatternData *data // Run-time data 13 14 ) 14 15 { 15 16 pmConfig *config = data->config; // Configuration data 16 pmFPAfile * psfFile = pmFPAfileSelectSingle(config->files, "PSPHOT.PSF.LOAD", 0); // File with PSF17 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPVIZPATTERN.INPUT", 0); // File with PSF 17 18 18 19 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy … … 22 23 23 24 pmChip *chip; // Chip from FPA 24 while ((chip = pmFPAviewNextChip(view, psfFile->fpa, 1))) {25 while ((chip = pmFPAviewNextChip(view, input->fpa, 1))) { 25 26 if (!chip->process || !chip->file_exists) { 26 27 continue; … … 31 32 } 32 33 33 if (chip->cells->n != 1) {34 psWarning("More than one cell present for chip %d", view->chip);35 }36 37 34 pmCell *cell; // Cell from chip 38 while ((cell = pmFPAviewNextCell(view, psfFile->fpa, 1))) {35 while ((cell = pmFPAviewNextCell(view, input->fpa, 1))) { 39 36 if (!cell->process || !cell->file_exists) { 40 37 continue; … … 45 42 } 46 43 47 if (cell->readouts->n == 0) {48 pmReadout *ro = pmReadoutAlloc(cell);49 ro->data_exists = true;50 cell->data_exists = true;51 chip->data_exists = true;52 psFree(ro); // Drop reference53 }54 55 if (cell->readouts->n > 1) {56 psWarning("More than one readout present for chip %d, cell %d", view->chip, view->cell);57 }58 59 44 pmReadout *readout; // Readout from cell 60 while ((readout = pmFPAviewNextReadout(view, psfFile->fpa, 1))) {45 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1))) { 61 46 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 62 47 psError(PS_ERR_UNKNOWN, false, "Error loading data from files."); … … 67 52 } 68 53 69 pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF 70 assert(psf); 54 int numCols = 0, numRows = 0; // Size of image 71 55 72 bool mdok; // Status of MD lookup 73 psArray *sources = psMetadataLookupPtr(&mdok, readout->analysis, "PSPHOT.SOURCES"); // Sources 74 int numCols = 0, numRows = 0; // Size of image 75 psVector *xOffset = NULL, *yOffset = NULL; // Offset from source to true position 56 // Get size of image from concepts 57 if (numCols == 0 || numRows == 0) { 58 numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE"); 59 numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE"); 60 } 76 61 77 if (sources || (data->fakeNum > 0 && isfinite(data->fakeMag))) { 78 numCols = psf->fieldNx; 79 numRows = psf->fieldNy; 80 psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image", numCols, numRows); 81 } 82 if (sources) { 83 psMemIncrRefCounter(sources); 84 psLogMsg("ppVizPSF", PS_LOG_INFO, "Using %ld input sources", sources->n); 85 } 86 if (data->fakeNum > 0 && isfinite(data->fakeMag)) { 87 long numOld = 0; // Old number of sources 88 long numNew = -1; // New number of sources 89 psLogMsg("ppVizPSF", PS_LOG_INFO, "Adding %d fake sources", data->fakeNum); 90 if (sources) { 91 numOld = sources->n; 92 numNew = numOld + data->fakeNum; 93 sources = psArrayRealloc(sources, numNew); 94 sources->n = numNew; 95 } else { 96 numNew = data->fakeNum; 97 sources = psArrayAlloc(numNew); 98 } 99 100 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 101 102 for (int i = numOld; i < numNew; i++) { 103 pmSource *source = pmSourceAlloc(); // Fake source 104 sources->data[i] = source; 105 float xSrc = psRandomUniform(rng) * numCols, ySrc = psRandomUniform(rng) * numRows; // Position of source 106 107 pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation 108 float fluxNorm = model->modelFlux(model->params); // Flux for peak=1 109 float fluxPeak = powf(10.0, -0.4 * data->fakeMag) / fluxNorm; // Peak flux 110 source->peak = pmPeakAlloc(xSrc, ySrc, fluxPeak, PM_PEAK_LONE); 111 source->psfMag = data->fakeMag; 112 psFree(model); 113 } 114 } 115 if (!sources) { 116 // Generate fake image with only a single realisation of the PSF 117 sources = psArrayAlloc(1); 118 pmSource *source = pmSourceAlloc(); // Fake source 119 sources->data[0] = source; 120 float xRel = isfinite(data->x) ? data->x : 0.5; // Relative position in x 121 float yRel = isfinite(data->y) ? data->y : 0.5; // Relative position in y 122 float xSrc = xRel * psf->fieldNx, ySrc = yRel * psf->fieldNy; // Position of source 123 source->peak = pmPeakAlloc(xSrc, ySrc, 1.0, PM_PEAK_LONE); 124 pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation 125 float flux = model->modelFlux(model->params); // Flux for peak=1 126 psFree(model); 127 source->psfMag = -2.5 * log10(flux); 128 xOffset = psVectorAlloc(1, PS_TYPE_S32); 129 yOffset = psVectorAlloc(1, PS_TYPE_S32); 130 xOffset->data.S32[0] = data->size - xSrc; 131 yOffset->data.S32[0] = data->size - ySrc; 132 numCols = 2 * data->size + 1; 133 numRows = 2 * data->size + 1; 134 psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image with single PSF", 135 numCols, numRows); 62 // Get size of image from TRIMSEC 63 if (numCols == 0 || numRows == 0) { 64 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); 65 numCols = trimsec->x1 - trimsec->x0; 66 numRows = trimsec->y1 - trimsec->y0; 136 67 } 137 68 … … 141 72 } 142 73 143 if (!pmReadoutFakeFromSources(readout, numCols, numRows, sources, 0, xOffset, yOffset, psf, 144 data->minFlux, 0, false, true)) { 145 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout."); 74 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 75 psImageInit(readout->image, 0.0); 76 77 if (!pmPatternRowApply(readout, MASK_BAD) || !pmPatternCellApply(readout, MASK_BAD)) { 78 psError(PS_ERR_UNKNOWN, false, "Unable to apply pattern correction."); 146 79 return false; 147 80 } 148 81 149 psFree(sources); 150 psFree(xOffset); 151 psFree(yOffset); 152 153 pmHDU *hdu = pmHDUGetLowest(psfFile->fpa, chip, cell); // HDU for readout 82 pmHDU *hdu = pmHDUGetLowest(input->fpa, chip, cell); // HDU for readout 154 83 if (!hdu) { 155 84 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU for data."); … … 159 88 hdu->header = psMetadataAlloc(); 160 89 } 161 ppVizP SFVersionHeader(hdu->header);90 ppVizPatternVersionHeader(hdu->header); 162 91 163 92
Note:
See TracChangeset
for help on using the changeset viewer.
