IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23711


Ignore:
Timestamp:
Apr 3, 2009, 6:25:39 PM (17 years ago)
Author:
Paul Price
Message:

Still moving stuff around to support 'inverse' mode. Need to define separate output files for the sources. Still doesn't compile.

Location:
branches/pap/ppSub/src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/ppSub/src/ppSub.h

    r23704 r23711  
    2424// Output files, for activation/deactivation
    2525typedef enum {
    26     PPSUB_FILES_INPUT    = 0x01,         // Input files
    27     PPSUB_FILES_CONV     = 0x02,         // Convolved files (output)
    28     PPSUB_FILES_SUB      = 0x04,         // Subtracted files (output)
    29     PPSUB_FILES_INV      = 0x08,         // Inverse subtracted files (output)
    30     PPSUB_FILES_PHOT_SUB = 0x10,         // Photometry files (output)
    31     PPSUB_FILES_PHOT_INV = 0x20,        // Photometry files (
    32     PPSUB_FILES_ALL      = 0xFF,         // All files
     26    PPSUB_FILES_INPUT    = 0x01,        // Input files
     27    PPSUB_FILES_CONV     = 0x02,        // Convolved files (output)
     28    PPSUB_FILES_SUB      = 0x04,        // Subtracted files (output)
     29    PPSUB_FILES_INV      = 0x08,        // Inverse subtracted files (output)
     30    PPSUB_FILES_PHOT     = 0x10,        // psphot photometry files
     31    PPSUB_FILES_PHOT_SUB = 0x20,        // Subtraction photometry files (output)
     32    PPSUB_FILES_PHOT_INV = 0x40,        // Inverse subtraction photometry files (output)
     33    PPSUB_FILES_ALL      = 0xFF,        // All files
    3334} ppSubFiles;
    3435
  • branches/pap/ppSub/src/ppSubCamera.c

    r23704 r23711  
    167167        return false;
    168168    }
    169     data->invert = psMetadataLookupBool(NULL, recipe, "INVERSE");
     169    data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE");
    170170    data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
    171171
     
    192192    if (data->inverse) {
    193193        // Inverse output image
    194         pmFPAfile *outinv = defineOutputFile(config, input, true, "PPSUB.OUTINV", PM_FPA_FILE_IMAGE);
    195         pmFPAfile *outinvMask = defineOutputFile(config, outinv, false, "PPSUB.OUTINV.MASK",
    196                                                  PM_FPA_FILE_MASK);
    197         if (!outinv || !outinvMask) {
     194        pmFPAfile *inverse = defineOutputFile(config, input, true, "PPSUB.INV", PM_FPA_FILE_IMAGE);
     195        pmFPAfile *invMask = defineOutputFile(config, inverse, false, "PPSUB.INVERSE.MASK",
     196                                              PM_FPA_FILE_MASK);
     197        if (!inv || !invMask) {
    198198            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    199199            return false;
    200200        }
    201         outinv->save = true;
    202         outinvMask->save = true;
     201        inverse->save = true;
     202        invMask->save = true;
    203203        if (inVar && refVar) {
    204             pmFPAfile *outinvVar = defineOutputFile(config, outinv, false, "PPSUB.OUTINV.VARIANCE",
    205                                                     PM_FPA_FILE_VARIANCE);
    206             if (!outinvVar) {
     204            pmFPAfile *invVar = defineOutputFile(config, inverse, false, "PPSUB.INVERSE.VARIANCE",
     205                                                 PM_FPA_FILE_VARIANCE);
     206            if (!invVar) {
    207207                psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    208208                return false;
    209209            }
    210             outinvVar->save = true;
     210            invVar->save = true;
    211211        }
    212212    }
     
    312312            return false;
    313313        }
     314
     315        // Deactivate psphot output sources --- we want to define output source files of our own
     316        pmFPAfile *psphotOutput = pmFPAfileSelectSingle(config->files, "PSPHOT.OUTPUT", 0);
     317        psphotOutput->save = false;
     318
     319        pmFPAfile *outSources = defineOutputFile(config, output, false, "PPSUB.OUTPUT.SOURCES",
     320                                                 PM_FPA_FILE_CMF);
     321        if (!outSources) {
     322            psError(PS_ERR_UNKNOWN, false, "Unable to set up output source file.");
     323            return false;
     324        }
     325        outSources->save = true;
     326
     327        if (data->inverse) {
     328            pmFPAfile *invSources = defineOutputFile(config, inverse, false, "PPSUB.OUTPUT.SOURCES",
     329                                                     PM_FPA_FILE_CMF);
     330            if (!invSources) {
     331                psError(PS_ERR_UNKNOWN, false, "Unable to set up inverse source file.");
     332                return false;
     333            }
     334        }
     335        invSources->save = true;
    314336    }
    315337
  • branches/pap/ppSub/src/ppSubDefineOutput.c

    r23704 r23711  
    2929    pmCell *outCell = pmFPAfileThisCell(config->files, view, name); // Output cell
    3030    pmFPA *outFPA = outCell->parent->parent; // Output FPA
    31     pmHDU *outHDU = outFPA->hdu; // Output HDU
     31    pmHDU *outHDU = outFPA->hdu;        // Output HDU
    3232    if (!outHDU->header) {
    3333        outHDU->header = psMetadataAlloc();
    3434    }
    3535
     36    // The output readout may already be present if we read in the convolution kernel
    3637    pmReadout *outRO = NULL;            // Output readout
    3738    if (outCell->readouts && outCell->readouts->n > 0 && outCell->readouts->data[0]) {
     
    4142    }
    4243
    43     // convolved input images
     44    // Convolved input images
    4445    pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input readout
    4546    pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference readout
     
    6364                     kernels->description);
    6465
     66    // Add additional data to the header
     67    pmFPAfile *refFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); // Reference file
     68    pmFPAfile *inFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
     69    psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.REFERENCE", 0,
     70                     "Subtraction reference", refFile->filename);
     71    psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.INPUT", 0,
     72                     "Subtraction input", inFile->filename);
     73    ppSubVersionHeader(outHDU->header);
     74
     75
    6576    outRO->analysis = psMetadataCopy(outRO->analysis, analysis);
    6677
  • branches/pap/ppSub/src/ppSubFiles.c

    r23704 r23711  
    2626                                  NULL };
    2727
     28// Subtraction photometry
     29static const char *subPhotFiles[] = { "PPSUB.OUTPUT.SOURCES", NULL };
     30
    2831// Inverse subtraction files
    2932static const char *invFiles[] = { "PPSUB.OUTINV", "PPSUB.OUTINV.MASK", "PPSUB.OUTINV.VARIANCE",
    3033                                  "PPSUB.OUTINV.KERNELS", "PPSUB.OUTINV.JPEG1", "PPSUB.OUTINV.JPEG2",
    3134                                  NULL };
     35
     36// Inverse subtraction photometry
     37static const char *subPhotFiles[] = { "PPSUB.OUTINV.SOURCES", NULL };
    3238
    3339// Calculation (may be either input or output) files
     
    3642
    3743// Activate/deactivate a list of files
    38 static void filesActivate(const char **files, // List of files
     44static void filesActivate(pmConfig *config, // Configuration
     45                          const char **files, // List of files
    3946                          bool state    // Activation status to set
    4047    )
     
    4956//  This is so we can activate/deactivate the 'calculation' files, which may be either input or output, which
    5057// is indicated by their 'save' boolean.
    51 static void filesActivateSave(const char **files, // List of files
     58static void filesActivateSave(pmConfig *config, // Configuration
     59                              const char **files, // List of files
    5260                              bool save, // Activate when this save state is set
    5361                              bool state // Activation status to set
     
    6977    if (files & PPSUB_FILES_INPUT) {
    7078        filesActivate(inputFiles, state);
    71         filesActivateSave(calcFiles, false, state);
     79        filesActivateSave(config, calcFiles, false, state);
    7280    }
    7381    if (files & PPSUB_FILES_CONV) {
    74         filesActivate(convFiles, state);
     82        filesActivate(config, convFiles, state);
    7583    }
    7684    if (files & PPSUB_FILES_SUB) {
    77         filesActivate(subFiles, state);
    78         filesActivateSave(calcFiles, true, state);
     85        filesActivate(config, subFiles, state);
     86        filesActivateSave(config, calcFiles, true, state);
    7987    }
    8088    if (files & PPSUB_FILES_INV) {
    81         filesActivate(invFiles, state);
     89        filesActivate(config, invFiles, state);
     90    }
     91    if (files & PPSUB_FILES_PHOT_SUB) {
     92        filesActivate(config, subPhotFiles, state);
     93    }
     94    if (files & PPSUB_FILES_PHOT_INV) {
     95        filesActivate(config, invPhotFiles, state);
    8296    }
    8397    if (files & PPSUB_FILES_PHOT) {
    84         psphotFilesActivate(config, state);
     98        psphotFilesActivate(config, false);
    8599    }
    86100
  • branches/pap/ppSub/src/ppSubLoop.c

    r23704 r23711  
    5555    }
    5656
     57    psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
     58                     psTimerClear("PPSUB_MATCH"));
     59
    5760    // Close input files
    5861    if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
     
    7275    }
    7376
    74     if (data->inverse && !ppSubDefineOutput("PPSUB.OUTINV", config, data, view)) {
    75         psError(PS_ERR_UNKNOWN, false, "Unable to define inverse.");
     77    if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.INVERSE", config, data, view)) {
     78        psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
    7679        return false;
    7780    }
    7881
    79     if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.OUTINV", config, data, view)) {
    80         psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
     82    if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) {
     83        psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
    8184        return false;
    8285    }
     
    8891    }
    8992
    90     if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) {
    91         psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
    92         return false;
    93     }
    94 
    9593    // Higher order background subtraction using psphot
    96     if (!ppSubBackground("PPSUB.OUTPUT", config, view)) {
     94    if (!ppSubBackground(config, view)) {
    9795        psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
    9896        return false;
    9997    }
    10098
    101     if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data, view)) {
     99    if (!data->quality && ppSubReadoutPhotometry("PPSUB.OUTPUT", PPSUB_FILES_PHOT_SUB, config, data, view)) {
    102100        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    103101        return false;
    104102    }
    105103
    106     if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) {
    107         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
     104    // Perform statistics on the cell
     105    if (!ppSubReadoutStats(config, data, view)) {
     106        psError(PS_ERR_UNKNOWN, false, "Unable to collect statistics");
    108107        return false;
    109108    }
    110109
    111     // Perform statistics on the cell
    112     if (statsFile) {
    113         pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file
    114         if (!output) {
    115             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n");
    116             goto ERROR;
    117         }
    118         psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);
    119         ppStatsFPA(data->stats, output->fpa, view, maskValue, config);
     110    if (!ppSubReadoutJpeg("PPSUB.OUTPUT", config, data, view)) {
     111        psError(PS_ERR_UNKNOWN, false, "Unable to update.");
     112        return false;
    120113    }
    121114
     
    127120        }
    128121
    129         if (!ppSubReadoutInverse("PPSUB.OUTINV", "PPSUB.OUTPUT", config, view)) {
     122        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config, data, view)) {
     123            psError(PS_ERR_UNKNOWN, false, "Unable to define inverse.");
     124            return false;
     125        }
     126
     127        if (!ppSubReadoutInverse("PPSUB.INVERSE", "PPSUB.OUTPUT", config, view)) {
    130128            psError(PS_ERR_UNKNOWN, false, "Unable to invert images.");
    131129            return false;
     
    138136        }
    139137
    140         if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTINV", config, data, view)) {
    141         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    142         return false;
     138        if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.INVERSE", PPSUB_FILES_PHOT_INV,
     139                                                            config, data, view)) {
     140            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
     141            return false;
     142        }
     143
     144        // Close inverse subtraction files
     145        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV)) {
     146            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
     147            return false;
    143148        }
    144149    } else {
     
    149154        }
    150155    }
    151 
    152 
    153     if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) {
    154         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
    155         return false;
    156     }
    157 
    158156
    159157    psFree(view);
  • branches/pap/ppSub/src/ppSubReadoutUpdate.c

    r23688 r23711  
    3232    psAssert(recipe, "We checked this earlier, so it should be here.");
    3333
    34     pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
    35     pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image
    36     pmFPA *outFPA = outFile->fpa;       // Output FPA
    37     pmHDU *outHDU = outFPA->hdu;        // Output HDU
    38 
    39     // Add additional data to the header
    40     pmFPAfile *refFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); // Reference file
    41     pmFPAfile *inFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
    42     psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.REFERENCE", 0,
    43                      "Subtraction reference", refFile->filename);
    44     psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.INPUT", 0,
    45                      "Subtraction input", inFile->filename);
    46     ppSubVersionHeader(outHDU->header);
    47 
    48     // Statistics on the matching
    49     if (data->stats) {
    50         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);
    51         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);
    52         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);
    53         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);
    54         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);
    55         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);
    56         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);
    57         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);
    58         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);
    59         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);
    60         psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);
    61 
    62         psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
    63                          psTimerClear("PPSUB_MATCH"));
    64     }
    65 
    6634    // Generate binned JPEGs
    6735    {
     
    9260    }
    9361
    94 #ifdef TESTING
    95     // Significance image
    96     {
    97         psImage *sig = (psImage*)psBinaryOp(NULL, outRO->image, "*", outRO->image);
    98         psBinaryOp(sig, sig, "/", outRO->variance);
    99         psFits *fits = psFitsOpen("significance.fits", "w");
    100         psFitsWriteImage(fits, NULL, sig, 0, NULL);
    101         psFitsClose(fits);
    102         psFree(sig);
    103     }
    104 #endif
    105 
    10662    return true;
    10763}
Note: See TracChangeset for help on using the changeset viewer.