IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 8, 2008, 11:43:52 AM (18 years ago)
Author:
Paul Price
Message:

Code compiles and is ready for preliminary testing. Some features (e.g., rejection based on initial combination) are disabled for now, marked with XXX in the code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_080207/ppStack/src/ppStackLoop.c

    r16367 r16382  
    1313// Here follows lists of files for activation/deactivation at various stages.  Each must be NULL-terminated.
    1414
     15#if 0
    1516// All files in the system
    1617static char *allFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.WEIGHT",
     
    2324                            "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID", "PSPHOT.INPUT.CMF",
    2425                            0 };
     26#endif
    2527
    2628// Files required in preparation for convolution
    2729static char *prepareFiles[] = { "PSPHOT.PSF.LOAD", "PPSTACK.SOURCES", 0 };
    2830
    29 // Files for convolution; these should be turned on one by one
    30 static char *convolutionFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.WEIGHT",
    31                                     "PPSTACK.OUTCONV", "PPSTACK.OUTCONV.MASK", "PPSTACK.OUTCONV.WEIGHT",
    32                                     0 };
    33 
    3431// Input files for the combination
    35 static char *inCombineFiles = { "PPSTACK.INCONV", "PPSTACK.INCONV.MASK", "PPSTACK.INCONV.WEIGHT", 0 };
     32static char *inCombineFiles[] = { "PPSTACK.INCONV", "PPSTACK.INCONV.MASK", "PPSTACK.INCONV.WEIGHT", 0 };
    3633
    3734// Output files for the combination and photometry
    38 static char *outCombineFiles = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.WEIGHT",
    39                                  "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL",
    40                                  "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",
    41                                  "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID",
    42                                  "PSPHOT.INPUT.CMF", 0 };
     35static char *outCombineFiles[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.WEIGHT",
     36                                   "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL",
     37                                   "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",
     38                                   "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID",
     39                                   "PSPHOT.INPUT.CMF", 0 };
    4340
    4441
     
    103100
    104101
    105 
    106102// Iterate down the hierarchy, loading files; we can get away with this because we're working on skycells
    107103static pmFPAview *filesIterateDown(pmConfig *config // Configuration
     
    158154bool ppStackLoop(pmConfig *config)
    159155{
     156    assert(config);
     157
    160158    psMaskType maskBlank = psMetadataLookupU8(NULL, config->arguments, "MASK.BLANK"); // Mask for blank reg.
    161159
     
    182180        return false;
    183181    }
     182    int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs
     183    int numScans = psMetadataLookupS32(NULL, config->arguments, "ROWS"); // Number of scans to read at once
     184
     185
     186
     187    // XXX Will need to adjust this when we're doing the convolution
     188    int overlap = 0;                    // Overlap between consecutive scans
     189
     190
     191
    184192
    185193    // Preparation iteration: Load the sources, and get a target PSF model
    186     psArray *sources = NULL;            // Sources to use for PSF matching
     194    pmReadout *sources = NULL;          // Readout with sources to use for PSF matching
    187195    pmPSF *targetPSF = NULL;            // Target PSF
    188196    {
     
    194202        }
    195203
    196         pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.SOURCES"); // Readout
    197204        // We want to hang on to the 'sources' even when its host FPA is blown away
    198         sources = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"));
     205        sources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view, "PPSTACK.SOURCES"));
    199206        if (!sources) {
    200207            psError(PS_ERR_UNKNOWN, true, "Unable to find sources.");
     
    207214                                                               "^PPSTACK.INPUT$"); // Iterator
    208215        psMetadataItem *fileItem; // Item from iteration
    209         int fileNum = 0;        // Number of file
    210216        psList *psfList = psListAlloc(NULL); // List of PSFs for PSF envelope
     217        int numCols = 0, numRows = 0;   // Size of image
    211218        while ((fileItem = psMetadataGetAndIncrement(fileIter))) {
    212219            assert(fileItem->type == PS_DATA_UNKNOWN);
    213220            pmFPAfile *inputFile = fileItem->data.V; // An input file
    214221            pmChip *chip = pmFPAviewThisChip(view, inputFile->fpa); // The chip: holds the PSF
    215             pmPSF *psf = psMetadataLookupPtr(NULL, ro->parent->parent->analysis, "PSPHOT.PSF"); // PSF
     222            pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF
    216223            if (!psf) {
    217224                psError(PS_ERR_UNKNOWN, false, "Unable to find PSF.");
    218225                psFree(view);
    219226                psFree(sources);
     227                psFree(fileIter);
     228                psFree(psfList);
    220229                return false;
    221230            }
    222231            psListAdd(psfList, PS_LIST_TAIL, psf);
     232
     233            pmCell *cell = pmFPAviewThisCell(view, inputFile->fpa); // Cell of interest
     234            pmHDU *hdu = pmHDUFromCell(cell);
     235            assert(hdu && hdu->header);
     236            int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
     237            int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
     238            if (naxis1 <= 0 || naxis2 <= 0) {
     239                psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF.");
     240                psFree(view);
     241                psFree(sources);
     242                psFree(fileIter);
     243                psFree(psfList);
     244                return false;
     245            }
     246            if (numCols == 0 && numRows == 0) {
     247                numCols = naxis1;
     248                numRows = naxis2;
     249            }
    223250        }
    224251        psFree(fileIter);
    225252        psFree(view);
    226253
    227         psArray *psfArray = psListToArray(psfList); // Array of PSFs
     254        targetPSF = ppStackPSF(config, numCols, numRows, psfList);
    228255        psFree(psfList);
    229         targetPSF = pmPSFEnvelope(numCols, numRows, psfArray, psfInstances, psfRadius, psfModel,
    230                                   psfOrder, psfOrder);
    231         psFree(psfArray);
    232256        if (!targetPSF) {
    233257            psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");
     
    241265
    242266    // Generate convolutions and write them to disk
    243     psArray *cells = psArrayAlloc(numFiles);    // Cells for convolved images --- a handle for reading again
    244     for (int i = 0; i < numFiles; i++) {
     267    psArray *cells = psArrayAlloc(num); // Cells for convolved images --- a handle for reading again
     268    for (int i = 0; i < num; i++) {
    245269        pmFPAfileActivate(config->files, false, NULL);
    246270        psArray *files = fileActivationSingle(config, prepareFiles, true, i);
    247271        pmFPAview *view = filesIterateDown(config);
    248272        if (!view) {
     273            psFree(sources);
     274            psFree(targetPSF);
    249275            return false;
    250276        }
     
    254280
    255281        // Background subtraction, scaling and normalisation is performed automatically by the image matching
    256         if (!ppStackMatch(ro, sources, outPSF, config)) {
     282        if (!ppStackMatch(readout, sources, targetPSF, config)) {
    257283            psError(PS_ERR_UNKNOWN, false, "Unable to match image %d --- ignoring.", i);
    258             psFree(convolved);
     284            psFree(sources);
     285            psFree(targetPSF);
    259286            return false;
    260287        }
     
    290317        filesIterateUp(config);
    291318    }
     319    psFree(sources);
     320    psFree(targetPSF);
    292321
    293322    // Set files to read at the readout level --- then when we iterate down, the pmFPAfileIO stuff should take
     
    295324    fileSetDataLevel(config, inCombineFiles, PM_FPA_LEVEL_CHUNK);
    296325    pmFPAfileActivate(config->files, false, NULL);
    297     fileActivation(inCombineFiles, true);
    298     fileActivation(outCombineFiles, true);
     326    fileActivation(config, inCombineFiles, true);
     327    fileActivation(config, outCombineFiles, true);
    299328
    300329    {
     
    304333            return false;
    305334        }
    306         pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.OUTPUT"); // Output readout
    307         psFree(view);
    308 
    309         psArray *readouts = psArrayAlloc(numFiles); // Readouts for convolved images
    310         for (int i = 0; i < numFiles; i++) {
     335        pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT"); // Output cell
     336        pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout
     337
     338        psArray *readouts = psArrayAlloc(num); // Readouts for convolved images
     339        for (int i = 0; i < num; i++) {
    311340            readouts->data[i] = pmReadoutAlloc(cells->data[i]); // Readout into which to read
    312341        }
     342        psFree(cells);
    313343
    314344        // Read convolutions by chunks
    315         int numRead = 0;                    // Number of inputs read
    316         int numChunk = 0;                   // Chunk number
    317345        bool more = true;               // More to read?
    318346        for (int numChunk = 0; more; numChunk++) {
    319             for (int i = 0; i < numFiles; i++) {
     347            for (int i = 0; i < num; i++) {
    320348                pmReadout *readout = readouts->data[i];
    321349                assert(readout);
     
    336364                    psError(PS_ERR_IO, false, "Unable to read chunk %d for file %d", numChunk, i);
    337365                    psFree(readouts);
    338                     psFree(cells);
     366                    psFree(outRO);
     367                    psFree(view);
     368                    return false;
    339369                }
    340370            }
    341371
     372#if 0
    342373            if (!ppStackReadout(config, outRO, readouts)) {
    343374                psError(PS_ERR_UNKNOWN, false, "Unable to stack images.\n");
     375                psFree(readouts);
     376                psFree(outRO);
     377                psFree(view);
    344378                return false;
    345379            }
    346 
    347             for (int i = 0; i < numFiles && more; i++) {
     380#else
     381            printf("Stack...\n");
     382#endif
     383
     384            for (int i = 0; i < num && more; i++) {
    348385                pmReadout *readout = readouts->data[i];
    349386                assert(readout);
     
    364401            }
    365402        }
     403        psFree(readouts);
    366404
    367405        // Get rid of the input files
    368         fileActivation(outCombineFiles, false);
     406        fileActivation(config, outCombineFiles, false);
    369407        filesIterateUp(config);
    370408
    371         ppStackPhotometry(config, outRO);
     409        if (psMetadataLookupBool(&mdok, config->arguments, "PHOTOMETRY") &&
     410            !ppStackPhotometry(config, outRO, view)) {
     411            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on output.");
     412            psFree(outRO);
     413            psFree(view);
     414            return false;
     415        }
     416
     417        // Statistics on output
     418        if (stats) {
     419            ppStatsFPA(stats, outCell->parent->parent, view, maskBlank, config);
     420        }
    372421
    373422        // Put version information into the header
    374423        pmHDU *hdu = pmHDUFromCell(outRO->parent);
    375424        if (!hdu) {
    376             psError(PS_ERR_UNKNOWN, true, "Unable to find HDU for output.");
     425            psError(PS_ERR_UNKNOWN, false, "Unable to find HDU for output.");
    377426            return false;
    378427        }
     
    382431        ppStackVersionMetadata(hdu->header);
    383432
    384         // Statistics on output
    385         if (stats) {
    386             ppStatsFPA(stats, output->fpa, view, maskBlank, config);
    387         }
    388 
    389433        // Write out the output files
    390         filesActivation(outCombineFiles, true);
     434        fileActivation(config, outCombineFiles, true);
    391435        filesIterateUp(config);
    392     }
    393 
    394     psFree(view);
     436
     437        psFree(outRO);
     438        psFree(view);
     439    }
     440
    395441
    396442    // Write out summary statistics
Note: See TracChangeset for help on using the changeset viewer.