IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 5, 2015, 12:39:17 PM (11 years ago)
Author:
bills
Message:

add function psphotLoadBackgroundModel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotModelBackground.c

    r37940 r38387  
    519519}
    520520
     521// load a background model for readout number index; save an associated pmFPAfile for possible output
     522bool psphotLoadBackgroundModelReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index)
     523{
     524    // find the currently selected readout
     525    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     526    psAssert (file, "missing file?");
     527
     528    pmFPA *inFPA = file->fpa;
     529    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
     530    psAssert (readout, "missing readout?");
     531
     532    // Set up the background model file
     533    // Here we are assuming that the recipe being used is the same as when the original analysis that generated
     534    // the background model was done
     535    psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters
     536    psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
     537    psFree(binning);
     538    pmReadout *model = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL"), inFPA, binning, index);
     539    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, psphotGetFilerule("PSPHOT.BACKMDL.STDEV"), inFPA, binning, index);
     540
     541    // Copy the image from the input model file to the model file
     542    // XXX: Check for nulls and that the image sizes match
     543    pmFPAfile *bgFile = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.BACKMDL.RAW", 0);   // File with bg
     544    pmChip    *bgChip  = pmFPAviewThisChip(view, bgFile->fpa);
     545    pmReadout *bgReadout = pmFPAviewThisReadout(view, bgChip->parent);
     546
     547    // Copy the image from the input model readout to the model readout
     548    model->image = psImageCopy(model->image, bgReadout->image, model->image->type.type);
     549    // For now also copy the input into the stdev image. Is this used for anything?
     550    modelStdev->image = psImageCopy(modelStdev->image, bgReadout->image, modelStdev->image->type.type);
     551
     552    return true;
     553}
     554
     555bool psphotLoadBackgroundModel (pmConfig *config, const pmFPAview *view, const char *filerule)
     556{
     557    int num = psphotFileruleCount(config, filerule);
     558
     559    fprintf (stdout, "\n");
     560    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Model Background ---");
     561
     562    // loop over the available readouts
     563    for (int i = 0; i < num; i++) {
     564        if (!psphotLoadBackgroundModelReadoutFileIndex(config, view, filerule, i)) {
     565            int lastError = psErrorCodeLast();
     566            psError (lastError ? lastError : PSPHOT_ERR_CONFIG, false, "failed to model background for %s entry %d", filerule, i);
     567            return false;
     568        }
     569    }
     570    return true;
     571}
     572
    521573// code for in-line plotting from above
    522574// turn on stats tracing in desired cells
Note: See TracChangeset for help on using the changeset viewer.