IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26367


Ignore:
Timestamp:
Dec 8, 2009, 8:30:42 AM (16 years ago)
Author:
Paul Price
Message:

Add ability to generate a single PSF as a small postage stamp.

Location:
trunk/ppViz/src/ppVizPSF
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppViz/src/ppVizPSF/ppVizPSF.c

    r26352 r26367  
    1111int main(int argc, char *argv[])
    1212{
     13    ppVizPSFVersionPrint();
     14
    1315    ppVizPSFData *data = ppVizPSFDataInit(&argc, argv);
    1416    if (!data) {
  • trunk/ppViz/src/ppVizPSF/ppVizPSF.h

    r26362 r26367  
    1313    psString outRoot;                   // Output root name
    1414    float minFlux;                      // Minimum flux for sources
     15    int size;                           // Size of PSF image
     16    float x, y;                         // Position of fake source
    1517    pmConfig *config;                   // Configuration
    1618} ppVizPSFData;
  • trunk/ppViz/src/ppVizPSF/ppVizPSFArguments.c

    r26366 r26367  
    5050    psMetadataAddStr(arguments, PS_LIST_TAIL, "-psf", 0, "Filename of PSF", NULL);
    5151    psMetadataAddStr(arguments, PS_LIST_TAIL, "-sources", 0, "Filename of sources", NULL);
     52    psMetadataAddF32(arguments, PS_LIST_TAIL, "-x", 0, "x position of fake source [0..1]", NAN);
     53    psMetadataAddF32(arguments, PS_LIST_TAIL, "-y", 0, "y position of fake source [0..1]", NAN);
    5254    if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 2) {
    5355        usage(argv[0], arguments, data);
    5456    }
    5557
     58    bool mdok;                          // Status of MD lookup
    5659    data->psfName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-psf"));
    57     data->sourcesName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-sources"));
     60    data->sourcesName = psMemIncrRefCounter(psMetadataLookupStr(&mdok, arguments, "-sources"));
    5861    data->outRoot = psStringCopy(argv[1]);
     62    data->x = psMetadataLookupF32(NULL, arguments, "-x");
     63    data->y = psMetadataLookupF32(NULL, arguments, "-y");
    5964    psMetadataAddStr(data->config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root name", data->outRoot);
    6065
     
    6368
    6469    PS_ASSERT_STRING_NON_EMPTY(data->psfName, false);
    65     PS_ASSERT_STRING_NON_EMPTY(data->sourcesName, false);
    6670    PS_ASSERT_STRING_NON_EMPTY(data->outRoot, false);
    6771
  • trunk/ppViz/src/ppVizPSF/ppVizPSFCamera.c

    r26364 r26367  
    3939    }
    4040
    41     fileArguments("SOURCES", data->sourcesName, "Input sources", data->config);
    42     pmFPAfile *srcs = pmFPAfileBindFromArgs(&status, psf, data->config,
    43                                             "PSPHOT.INPUT.CMF", "SOURCES"); // File
    44     if (!status || !srcs) {
    45         psError(PS_ERR_IO, false, "Failed to build file from PSPHOT.INPUT.CMF");
    46         return false;
     41    if (data->sourcesName) {
     42        fileArguments("SOURCES", data->sourcesName, "Input sources", data->config);
     43        pmFPAfile *srcs = pmFPAfileBindFromArgs(&status, psf, data->config,
     44                                                "PSPHOT.INPUT.CMF", "SOURCES"); // File
     45        if (!status || !srcs) {
     46            psError(PS_ERR_IO, false, "Failed to build file from PSPHOT.INPUT.CMF");
     47            return false;
     48        }
    4749    }
    4850
     
    6769    }
    6870
     71    if (!data->sourcesName) {
     72        data->size = psMetadataLookupS32(NULL, recipe, "SIZE"); // Size of PSF
     73        if (data->size <= 0) {
     74            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find legitimate value for SIZE");
     75            return false;
     76        }
     77    }
     78
    6979    return true;
    7080}
  • trunk/ppViz/src/ppVizPSF/ppVizPSFData.c

    r26355 r26367  
    3131    data->config = NULL;
    3232    data->minFlux = NAN;
     33    data->size = 0;
     34    data->x = NAN;
     35    data->y = NAN;
    3336
    3437    return data;
  • trunk/ppViz/src/ppVizPSF/ppVizPSFLoop.c

    r26363 r26367  
    1313    )
    1414{
    15     ppVizPSFVersionPrint();
    16 
    1715    pmConfig *config = data->config;                                        // Configuration data
    1816    pmFPAfile *psfFile = pmFPAfileSelectSingle(config->files, "PSPHOT.PSF.LOAD", 0); // File with PSF
     
    4745            }
    4846
    49             if (cell->readouts->n != 1) {
     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 reference
     53            }
     54
     55            if (cell->readouts->n > 1) {
    5056                psWarning("More than one readout present for chip %d, cell %d", view->chip, view->cell);
    5157            }
     
    6167                }
    6268
    63                 psArray *sources = psMetadataLookupPtr(NULL, readout->analysis, "PSPHOT.SOURCES"); // Sources
    6469                pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF");              // PSF
     70                assert(psf);
    6571
    66                 int numCols = psf->fieldNx, numRows = psf->fieldNy; // Size of image
     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
     76                if (sources) {
     77                    psMemIncrRefCounter(sources);
     78                    numCols = psf->fieldNx;
     79                    numRows = psf->fieldNy;
     80                    psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image from %ld input sources",
     81                             numCols, numRows, sources->n);
     82                } else {
     83                    sources = psArrayAlloc(1);
     84                    pmSource *source = pmSourceAlloc(); // Fake source
     85                    sources->data[0] = source;
     86                    float xRel = isfinite(data->x) ? data->x : 0.5; // Relative position in x
     87                    float yRel = isfinite(data->y) ? data->y : 0.5; // Relative position in y
     88                    float xSrc = xRel * psf->fieldNx, ySrc = yRel * psf->fieldNy; // Position of source
     89                    source->peak = pmPeakAlloc(xSrc, ySrc, 1.0, PM_PEAK_LONE);
     90                    pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
     91                    float flux = model->modelFlux(model->params);               // Flux for peak=1
     92                    psFree(model);
     93                    source->psfMag = -2.5 * log10(flux);
     94                    xOffset = psVectorAlloc(1, PS_TYPE_S32);
     95                    yOffset = psVectorAlloc(1, PS_TYPE_S32);
     96                    xOffset->data.S32[0] = data->size - xSrc;
     97                    yOffset->data.S32[0] = data->size - ySrc;
     98                    numCols = 2 * data->size + 1;
     99                    numRows = 2 * data->size + 1;
     100                    psLogMsg("ppVizPSF", PS_LOG_INFO, "Generating %dx%d image with single PSF",
     101                             numCols, numRows);
     102                }
     103
    67104                if (numCols <= 0 || numRows <= 0) {
    68105                    psError(PS_ERR_UNKNOWN, true, "Image size isn't set: %dx%d.", numCols, numRows);
     
    70107                }
    71108
    72                 if (!pmReadoutFakeFromSources(readout, numCols, numRows, sources, 0, NULL, NULL, psf,
     109                if (!pmReadoutFakeFromSources(readout, numCols, numRows, sources, 0, xOffset, yOffset, psf,
    73110                                              data->minFlux, 0, false, true)) {
    74111                    psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout.");
    75112                    return false;
    76113                }
     114
     115                psFree(sources);
     116                psFree(xOffset);
     117                psFree(yOffset);
    77118
    78119                pmHDU *hdu = pmHDUGetLowest(psfFile->fpa, chip, cell); // HDU for readout
Note: See TracChangeset for help on using the changeset viewer.