IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23719 for branches/pap/ppSub


Ignore:
Timestamp:
Apr 6, 2009, 6:52:51 PM (17 years ago)
Author:
Paul Price
Message:

Making ppSub inverse mode work. Seems to work now --- produces the correct output files for inverse mode on and off, photometry on and off.

Location:
branches/pap/ppSub/src
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/ppSub/src

    • Property svn:ignore
      •  

        old new  
        1010stamp-h1
        1111ppSubKernel
         12ppSubErrorCodes.h
         13ppSubErrorCodes.c
  • branches/pap/ppSub/src/Makefile.am

    r23704 r23719  
    1313ppSub_LDFLAGS  = $(PSLIB_LIBS)   $(PSMODULE_LIBS)   $(PPSTATS_LIBS)   $(PSPHOT_LIBS)   $(PPSUB_LIBS)
    1414
    15 ppSub_SOURCES =                  \
    16         ppSub.c                  \
    17         ppSubArguments.c         \
    18         ppSubVersion.c           \
    19         ppSubBackground.c        \
    20         ppSubCamera.c            \
    21         ppSubData.c              \
    22         ppSubLoop.c              \
    23         ppSubReadout.c           \
    24         ppSubDefineOutput.c      \
    25         ppSubExtras.c            \
    26         ppSubMakePSF.c           \
    27         ppSubMatchPSFs.c         \
    28         ppSubReadoutPhotometry.c \
    29         ppSubReadoutSubtract.c   \
    30         ppSubReadoutUpdate.c     \
    31         ppSubSetMasks.c          \
    32         ppSubReadoutRenorm.c     \
     15ppSub_SOURCES =                         \
     16        ppSub.c                         \
     17        ppSubArguments.c                \
     18        ppSubVersion.c                  \
     19        ppSubBackground.c               \
     20        ppSubCamera.c                   \
     21        ppSubData.c                     \
     22        ppSubErrorCodes.c               \
     23        ppSubFiles.c                    \
     24        ppSubLoop.c                     \
     25        ppSubDefineOutput.c             \
     26        ppSubExtras.c                   \
     27        ppSubMakePSF.c                  \
     28        ppSubMatchPSFs.c                \
     29        ppSubReadoutInverse.c           \
     30        ppSubReadoutJpeg.c              \
     31        ppSubReadoutPhotometry.c        \
     32        ppSubReadoutStats.c             \
     33        ppSubReadoutSubtract.c          \
     34        ppSubSetMasks.c                 \
     35        ppSubReadoutRenorm.c            \
    3336        ppSubVarianceFactors.c
    3437
  • branches/pap/ppSub/src/ppSub.c

    r23704 r23719  
    5151    ppSubData *data = ppSubDataAlloc(); // Processing data
    5252
    53     if (!ppSubArgumentsSetup(argc, argv, config, data)) {
     53    if (!ppSubArguments(argc, argv, config, data)) {
    5454        psErrorStackPrint(stderr, "Error reading arguments.\n");
    5555        exitValue = PS_EXIT_CONFIG_ERROR;
  • branches/pap/ppSub/src/ppSub.h

    r23711 r23719  
    1414#define PP_SUB_H
    1515
     16#include <stdio.h>
    1617#include <pslib.h>
    1718#include <psmodules.h>
     19
     20#include "ppSubErrorCodes.h"
    1821
    1922/// @addtogroup ppSub
     
    2831    PPSUB_FILES_SUB      = 0x04,        // Subtracted files (output)
    2932    PPSUB_FILES_INV      = 0x08,        // Inverse subtracted files (output)
    30     PPSUB_FILES_PHOT     = 0x10,        // psphot photometry files
     33    PPSUB_FILES_PSF      = 0x10,        // PSF files (output)
    3134    PPSUB_FILES_PHOT_SUB = 0x20,        // Subtraction photometry files (output)
    3235    PPSUB_FILES_PHOT_INV = 0x40,        // Inverse subtraction photometry files (output)
     36    PPSUB_FILES_PHOT     = 0x80,        // General photometry files (internal)
    3337    PPSUB_FILES_ALL      = 0xFF,        // All files
    3438} ppSubFiles;
     
    3943    bool photometry;                    // Perform photometry?
    4044    bool inverse;                       // Output inverse subtraction as well?
    41     const char *statsFile;              // Statistics file
     45    psString stamps;                    // Stamps file
     46    pmPSF *psf;                         // Point Spread Function
     47    FILE *statsFile;                    // Statistics file
    4248    psMetadata *stats;                  // Statistics
    4349} ppSubData;
     
    4753
    4854/// Setup the arguments parsing
    49 bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments
    50                          pmConfig *config    ///< Configuration
    51     );
    52 
    53 /// Parse the arguments
    54 bool ppSubArgumentsParse(pmConfig *config ///< Configuration
     55bool ppSubArguments(int argc, char *argv[], ///< Command-line arguments
     56                    pmConfig *config, ///< Configuration
     57                    ppSubData *data ///< Processing data
    5558    );
    5659
    5760/// Parse the camera input
    58 bool ppSubCamera(pmConfig *config       ///< Configuration
     61bool ppSubCamera(pmConfig *config,      ///< Configuration
     62                 ppSubData *data        ///< Processing data
    5963    );
    6064
    6165/// Loop over the FPA hierarchy
    62 bool ppSubLoop(pmConfig *config         ///< Configuration
     66bool ppSubLoop(pmConfig *config,        ///< Configuration
     67               ppSubData *data          ///< Processing data
    6368    );
    6469
    6570/// Perform PSF-matched image subtraction on the readout
    6671bool ppSubReadout(pmConfig *config,     ///< Configuration
    67                   ppSubData *data,      ///< Processing data
    68                   const pmFPAview *view ///< View of readout to subtract
     72                  ppSubData *data       ///< Processing data
    6973    );
    7074
    7175/// Generate (if needed) and set or update the masks for input and reference images
    72 bool ppSubSetMasks(pmConfig *config,     ///< Configuration
    73                    const pmFPAview *view ///< View of active readout
     76bool ppSubSetMasks(pmConfig *config     ///< Configuration
    7477    );
    7578
    7679/// Generate the PSF-matching kernel and convolve the images as needed.  Most of this function involves
    7780/// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch()
    78 bool ppSubMatchPSFs(pmConfig *config,    ///< Configuration
    79                     ppSubData *data,    ///< Processing data
    80                     const pmFPAview *view ///< View of active readout
     81bool ppSubMatchPSFs(pmConfig *config,   ///< Configuration
     82                    ppSubData *data     ///< Processing data
    8183    );
    8284
    8385/// Generate the output readout and pass the kernel info to the header
    84 bool ppSubDefineOutput(pmConfig *config, ///< Configuration
    85                        const pmFPAview *view ///< View of active readout
     86bool ppSubDefineOutput(const char *name,///< Name of output to define
     87                       pmConfig *config ///< Configuration
    8688    );
    8789
    8890/// Photometry stage 1: measure the PSF from the minuend image
    89 bool ppSubMakePSF(pmConfig *config,       ///< Configuration
    90                   ppSubData *data,    ///< Processing data
    91                   const pmFPAview *view ///< View of active readout
     91bool ppSubMakePSF(pmConfig *config,     ///< Configuration
     92                  ppSubData *data       ///< Processing data
    9293    );
    9394
    9495/// Perform the actual image subtraction, update output concepts
    95 bool ppSubReadoutSubtract(pmConfig *config,       ///< Configuration
    96                           const pmFPAview *view ///< View of active readout
     96bool ppSubReadoutSubtract(pmConfig *config ///< Configuration
    9797    );
    9898
    9999
    100100/// Photometry stage 2: find and measure sources on the subtracted image
    101 bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
    102                             ppSubData *data,    ///< Processing data
    103                             const pmFPAview *view ///< View of active readout
     101bool ppSubReadoutPhotometry(const char *name, ///< Name of file to photometer
     102                            pmConfig *config, ///< Configuration
     103                            ppSubData *data ///< Processing data
    104104    );
    105105
    106106/// Renormalize, update headers and generate JPEGs
    107107bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration
    108                         ppSubData *data,    ///< Processing data
    109                         const pmFPAview *view ///< View of active readout
     108                        ppSubData *data ///< Processing data
    110109    );
    111110
    112111/// Higher-order background subtraction
    113 bool ppSubBackground(pmConfig *config,  ///< Configuration
    114                      const pmFPAview *view ///< View to readout
     112bool ppSubBackground(pmConfig *config   ///< Configuration
    115113    );
    116114
     
    129127    );
    130128
     129
     130/// Activate or deactivate files
     131void ppSubFilesActivate(pmConfig *config, // Configuration
     132                        ppSubFiles files, // File to activate/deactivate
     133                        bool state      // Activation state
     134    );
     135
     136/// Generate a view suitable for a readout
     137///
     138/// Assumes we're working with skycells
     139pmFPAview *ppSubViewReadout(void);
     140
     141/// Iterate down the FPA hierarchy, opening files
     142bool ppSubFilesIterateDown(pmConfig *config, // Configuration
     143                           ppSubFiles files // Files to open
     144    );
     145
     146/// Iterate up the FPA hierarchy, closing files
     147bool ppSubFilesIterateUp(pmConfig *config, // Configuration
     148                         ppSubFiles files // Files to open
     149    );
     150
     151/// Collect statistics
     152bool ppSubReadoutStats(pmConfig *config,// Configuration
     153                       ppSubData *data  // Processing data
     154    );
     155
     156/// Generate JPEG images
     157bool ppSubReadoutJpeg(pmConfig *config  // Configuration
     158    );
     159
     160/// Generate inverse subtraction
     161bool ppSubReadoutInverse(pmConfig *config // Configuration
     162    );
     163
     164
    131165// Copy every instance of a single keyword from one metadata to another
    132166bool psMetadataCopySingle(psMetadata *target, psMetadata *source, const char *name);
  • branches/pap/ppSub/src/ppSubArguments.c

    r23704 r23719  
    3939    psLibFinalize();
    4040    exit(PS_EXIT_CONFIG_ERROR);
    41 }
    42 
    43 // Get a float-point value from the command-line or recipe, and add it to the arguments
    44 #define VALUE_ARG_RECIPE_FLOAT(ARGNAME, RECIPENAME, TYPE) { \
    45     ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \
    46     if (isnan(value)) { \
    47         bool mdok; \
    48         value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \
    49         if (!mdok) { \
    50             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \
    51                 RECIPENAME, PPSUB_RECIPE); \
    52             goto ERROR; \
    53         } \
    54     } \
    55     psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
    56 }
    57 
    58 // Get an integer value from the command-line or recipe, and add it to the arguments
    59 #define VALUE_ARG_RECIPE_INT(ARGNAME, RECIPENAME, TYPE, UNSET) { \
    60     ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \
    61     if (value == UNSET) { \
    62         bool mdok; \
    63         value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \
    64         if (!mdok) { \
    65             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \
    66                 RECIPENAME, PPSUB_RECIPE); \
    67             goto ERROR; \
    68         } \
    69     } \
    70     psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \
    71 }
    72 
    73 /**
    74  * Get a string value from the command-line and add it to the target
    75  */
    76 static bool valueArgStr(psMetadata *arguments, // Command-line arguments
    77                         const char *argName, // Argument name in the command-line arguments
    78                         const char *mdName, // Name for value in the metadata
    79                         psMetadata *target // Target metadata to which to add value
    80                         )
    81 {
    82     psString value = psMetadataLookupStr(NULL, arguments, argName); // Value of interest
    83     if (value && strlen(value) > 0) {
    84         return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);
    85     }
    86     return false;
    87 }
    88 
    89 /**
    90  * Get a string value from the command-line or recipe and add it to the target
    91  */
    92 static bool valueArgRecipeStr(psMetadata *arguments, // Command-line arguments
    93                               psMetadata *recipe, // Recipe
    94                               const char *argName, // Argument name in the command-line arguments
    95                               const char *mdName, // Name for value in the metadata and recipe
    96                               psMetadata *target // Target metadata to which to add value
    97                               )
    98 {
    99     bool mdok;                          // Status of MD lookup
    100     psString value = psMetadataLookupStr(&mdok, arguments, argName); // Value of interest
    101     if (!value) {
    102         value = psMetadataLookupStr(&mdok, recipe, mdName);
    103         if (!value) {
    104             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s",
    105                     mdName, PPSUB_RECIPE);
    106             return false;
    107         }
    108     }
    109     return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);
    110 }
    111 
    112 /**
    113  * Get a vector from the command-line or recipe, and add it to the target
    114  */
    115 static bool vectorArgRecipe(psMetadata *arguments, // Command-line arguments
    116                             const char *argName, // Argument name in the command-line arguments
    117                             const psMetadata *recipe, // Recipe
    118                             const char *recipeName, // Name for value in the recipe
    119                             psMetadata *target, // Target to which to add value
    120                             psElemType type // Type for vector
    121     )
    122 {
    123     psVector *vector;                   // Vector
    124     psString string = psMetadataLookupStr(NULL, arguments, argName); // String from arguments
    125     if (string) {
    126         psArray *array = psStringSplitArray(string, ", ", false); // Array of strings
    127         vector = psVectorAlloc(array->n, type);
    128         for (int i = 0; i < array->n; i++) {
    129             const char *subString = array->data[i]; // String with a value
    130             char *end;                  // Ptr to end of string parsed
    131 
    132             switch (type) {
    133               case PS_TYPE_F32:
    134                 vector->data.F32[i] = strtof(subString, &end);
    135                 break;
    136               case PS_TYPE_S32: {
    137                   long value = strtol(subString, &end, 10);
    138                   if (value > PS_MAX_S32 || value < PS_MIN_S32) {
    139                       psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    140                               "%s list includes value beyond S32 representation: %s",
    141                               argName, string);
    142                       psFree(vector);
    143                       return false;
    144                   }
    145                   vector->data.S32[i] = value;
    146                   break;
    147               }
    148               default:
    149                 psAbort("Unsupported type: %x\n", type);
    150             }
    151             if (end == subString) {
    152                 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to decipher %s list: %s",
    153                         argName, string);
    154                 psFree(vector);
    155                 return false;
    156             }
    157         }
    158         psFree(array);
    159     } else {
    160         vector = psMetadataLookupPtr(NULL, recipe, recipeName);
    161         if (!psMemCheckVector(vector) || vector->type.type != type) {
    162             psError(PS_ERR_BAD_PARAMETER_TYPE, false, "%s in recipe %s is not a vector of type F32.",
    163                     recipeName, PPSUB_RECIPE);
    164             return false;
    165         }
    166         psMemIncrRefCounter(vector);
    167     }
    168 
    169     psMetadataAddVector(target, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, vector);
    170     psFree(vector);                     // Drop reference
    171 
    172     return true;
    17341}
    17442
     
    255123    }
    256124
    257     data->stamps = psMetadataLookupStr(NULL, arguments, "-stamps");
     125    data->stamps = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-stamps"));
    258126
    259127    const char *statsName = psMetadataLookupStr(NULL, arguments, "-stats"); // Filename for statistics
     
    281149    }
    282150
    283     return true;
    284 }
    285 
    286 
    287 
    288151    psTrace("ppSub", 1, "Done reading command-line arguments\n");
    289152
  • branches/pap/ppSub/src/ppSubBackground.c

    r23287 r23719  
    2222#include "ppSub.h"
    2323
    24 bool ppSubBackground(pmConfig *config, const pmFPAview *view)
     24bool ppSubBackground(pmConfig *config)
    2525{
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
    2827
    2928    bool mdok; // Status of metadata lookups
     
    3635    psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask
    3736
     37    pmFPAview *view = ppSubViewReadout(); // View to readout
    3838    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image
    3939    pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); // Background model
     
    4444        if (!psphotModelBackground(config, view, "PPSUB.OUTPUT")) {
    4545            psError(PS_ERR_UNKNOWN, false, "Unable to model background");
     46            psFree(view);
    4647            return false;
    4748        }
     
    5051        if (!modelRO) {
    5152            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find background model");
     53            psFree(view);
    5254            return false;
    5355        }
    5456    }
     57    psFree(view);
     58
    5559    psImageBinning *binning = psMetadataLookupPtr(&mdok, modelRO->analysis,
    5660                                                  "PSPHOT.BACKGROUND.BINNING"); // Binning for model
  • branches/pap/ppSub/src/ppSubCamera.c

    r23711 r23719  
    134134
    135135
    136 bool ppSubCamera(pmConfig *config)
     136bool ppSubCamera(pmConfig *config, ppSubData *data)
    137137{
    138138    psAssert(config, "Require configuration");
     
    147147    pmFPAfile *inVar = defineInputFile(config, input, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE",
    148148                                       PM_FPA_FILE_VARIANCE);
    149     defineInputFile(config, input, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES", PM_FPA_FILE_CMF);
     149    defineInputFile(config, NULL, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES", PM_FPA_FILE_CMF);
    150150
    151151    // Reference image
     
    158158    pmFPAfile *refVar = defineInputFile(config, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE",
    159159                                        PM_FPA_FILE_VARIANCE);
    160     defineInputFile(config, ref, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
     160    defineInputFile(config, NULL, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
     161
     162
     163    // Convolved input image
     164    pmFPAfile *inConvImage = defineOutputFile(config, input, true, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE);
     165    pmFPAfile *inConvMask = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.MASK",
     166                                             PM_FPA_FILE_MASK);
     167    if (!inConvImage || !inConvMask) {
     168        psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     169        return false;
     170    }
     171    if (inVar) {
     172        pmFPAfile *inConvVar = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.VARIANCE",
     173                                                PM_FPA_FILE_VARIANCE);
     174        if (!inConvVar) {
     175            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     176            return false;
     177        }
     178    }
     179
     180    // Convolved ref image
     181    pmFPAfile *refConvImage = defineOutputFile(config, input, true, "PPSUB.REF.CONV", PM_FPA_FILE_IMAGE);
     182    pmFPAfile *refConvMask = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.MASK",
     183                                              PM_FPA_FILE_MASK);
     184    if (!refConvImage || !refConvMask) {
     185        psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     186        return false;
     187    }
     188    if (refVar) {
     189        pmFPAfile *refConvVar = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.VARIANCE",
     190                                                 PM_FPA_FILE_VARIANCE);
     191        if (!refConvVar) {
     192            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     193            return false;
     194        }
     195    }
    161196
    162197
     
    172207
    173208    // Output image
    174     pmFPAfile *output = defineOutputFile(config, input, true, "PPSUB.OUTPUT", PM_FPA_FILE_IMAGE);
     209    pmFPAfile *output = defineOutputFile(config, inConvImage, true, "PPSUB.OUTPUT", PM_FPA_FILE_IMAGE);
    175210    pmFPAfile *outMask = defineOutputFile(config, output, false, "PPSUB.OUTPUT.MASK", PM_FPA_FILE_MASK);
    176211    if (!output || !outMask) {
     
    190225    }
    191226
     227    pmFPAfile *inverse = NULL;          // Inverse output image
    192228    if (data->inverse) {
    193229        // Inverse output image
    194         pmFPAfile *inverse = defineOutputFile(config, input, true, "PPSUB.INV", PM_FPA_FILE_IMAGE);
     230        inverse = defineOutputFile(config, output, true, "PPSUB.INVERSE", PM_FPA_FILE_IMAGE);
    195231        pmFPAfile *invMask = defineOutputFile(config, inverse, false, "PPSUB.INVERSE.MASK",
    196232                                              PM_FPA_FILE_MASK);
    197         if (!inv || !invMask) {
     233        if (!inverse || !invMask) {
    198234            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    199235            return false;
     
    212248    }
    213249
    214     // Convolved input image
    215     pmFPAfile *inConvImage = defineOutputFile(config, input, true, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE);
    216     pmFPAfile *inConvMask = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.MASK",
    217                                              PM_FPA_FILE_MASK);
    218     if (!inConvImage || !inConvMask) {
    219         psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    220         return false;
    221     }
    222     if (inVar) {
    223         pmFPAfile *inConvVar = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.VARIANCE",
    224                                                 PM_FPA_FILE_VARIANCE);
    225         if (!inConvVar) {
    226             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    227             return false;
    228         }
    229     }
    230 
    231     // Convolved ref image
    232     pmFPAfile *refConvImage = defineOutputFile(config, input, true, "PPSUB.REF.CONV", PM_FPA_FILE_IMAGE);
    233     pmFPAfile *refConvMask = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.MASK",
    234                                               PM_FPA_FILE_MASK);
    235     if (!refConvImage || !refConvMask) {
    236         psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    237         return false;
    238     }
    239     if (refVar) {
    240         pmFPAfile *refConvVar = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.VARIANCE",
    241                                                  PM_FPA_FILE_VARIANCE);
    242         if (!refConvVar) {
    243             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    244             return false;
    245         }
    246     }
    247 
    248250
    249251    // Output JPEGs
     
    276278    }
    277279
    278     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    279     if (!recipe) {
    280         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);
    281         return false;
    282     }
    283 
    284280    // psPhot input
    285281    if (data->photometry) {
    286282        psphotModelClassInit();        // load implementation-specific models
    287283
    288         // Internal-ish file for getting the PSF from the minuend
    289         pmFPAfile *psf = pmFPAfileDefineOutputFromFile(config, output, "PSPHOT.PSF.LOAD");
    290         if (!psf) {
    291             psError(PS_ERR_IO, false, "Failed to build FPA from PSPHOT.PSF.LOAD");
    292             return false;
    293         }
    294         if (psf->type != PM_FPA_FILE_PSF) {
    295             psError(PS_ERR_IO, true, "PSPHOT.PSF.LOAD is not of type PSF");
    296             return false;
    297         }
    298         pmFPAfileActivate(config->files, false, "PSPHOT.PSF.LOAD");
    299 
    300284        pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
    301285        if (!psphot) {
     
    307291            return false;
    308292        }
     293        pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
     294
     295        // Internal-ish file for getting the PSF from the minuend
     296        pmFPAfile *psf = pmFPAfileDefineOutputFromFile(config, psphot, "PSPHOT.PSF.LOAD");
     297        if (!psf) {
     298            psError(PS_ERR_IO, false, "Failed to build FPA from PSPHOT.PSF.LOAD");
     299            return false;
     300        }
     301        if (psf->type != PM_FPA_FILE_PSF) {
     302            psError(PS_ERR_IO, true, "PSPHOT.PSF.LOAD is not of type PSF");
     303            return false;
     304        }
     305        pmFPAfileActivate(config->files, false, "PSPHOT.PSF.LOAD");
    309306
    310307        if (!psphotDefineFiles(config, psphot)) {
     
    326323
    327324        if (data->inverse) {
    328             pmFPAfile *invSources = defineOutputFile(config, inverse, false, "PPSUB.OUTPUT.SOURCES",
     325            pmFPAfile *invSources = defineOutputFile(config, inverse, false, "PPSUB.INVERSE.SOURCES",
    329326                                                     PM_FPA_FILE_CMF);
    330327            if (!invSources) {
     
    332329                return false;
    333330            }
    334         }
    335         invSources->save = true;
     331            invSources->save = true;
     332        }
    336333    }
    337334
  • branches/pap/ppSub/src/ppSubData.c

    r23704 r23719  
    99
    1010#include "ppSub.h"
    11 
    12 
    13 // Image files to activate/deactivate
    14 static const char *imageFiles[] = { "PPSUB.OUTPUT", "PPSUB.OUTPUT.MASK", "PPSUB.OUTPUT.VARIANCE",
    15                                     "PPSUB.OUTPUT.KERNELS", "PPSUB.OUTPUT.JPEG1", "PPSUB.OUTPUT.JPEG2",
    16                                     "PPSUB.INPUT.CONV", "PPSUB.INPUT.CONV.MASK", "PPSUB.INPUT.CONV.VARIANCE",
    17                                     "PPSUB.REF.CONV", "PPSUB.REF.CONV.MASK", "PPSUB.REF.CONV.VARIANCE",
    18                                     NULL };
    19 
    2011
    2112
     
    3223        fclose(data->statsFile);
    3324    }
     25    psFree(data->stamps);
     26    psFree(data->psf);
     27    psFree(data->statsFile);
    3428    psFree(data->stats);
    3529    return;
     
    4438    data->photometry = false;
    4539    data->inverse = false;
     40    data->stamps = NULL;
     41    data->psf = NULL;
    4642    data->statsFile = NULL;
    4743    data->stats = psMetadataAlloc();
    4844    psMetadataAddS32(data->stats, PS_LIST_TAIL, "QUALITY", 0, "Data quality", 0);
    4945
    50     return options;
     46    return data;
    5147}
    5248
     
    6258    }
    6359
    64     if (files & PPSUB_FILES_IMAGE) {
    65         for (int i = 0; imageFiles[i]; i++) {
    66             pmFPAfileActivate(config->files, imageFiles[i], false);
    67         }
    68     }
    69     if (files & PPSUB_FILES_PHOT) {
    70         psphotFilesActivate(config, false);
    71     }
     60    ppSubFilesActivate(config, files, false);
    7261
    7362    psErrorClear();
  • branches/pap/ppSub/src/ppSubDefineOutput.c

    r23711 r23719  
    2121#include "ppSub.h"
    2222
    23 bool ppSubDefineOutput(const char *name, pmConfig *config, const ppSubData *data, const pmFPAview *view)
     23bool ppSubDefineOutput(const char *name, pmConfig *config)
    2424{
    2525    psAssert(name, "Require name");
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
    2827
     28    pmFPAview *view = ppSubViewReadout(); // View to readout
    2929    pmCell *outCell = pmFPAfileThisCell(config->files, view, name); // Output cell
    3030    pmFPA *outFPA = outCell->parent->parent; // Output FPA
     
    4545    pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input readout
    4646    pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference readout
     47    psFree(view);
    4748
    4849    // Add kernel descrption to header.
  • branches/pap/ppSub/src/ppSubErrorCodes.c.in

    r23704 r23719  
    1 /** @file pswarpErrorCodes.c.in
     1/** @file ppSubErrorCodes.c.in
    22 *
    33 *  @brief
    44 *
    5  *  @ingroup pswarp
     5 *  @ingroup ppSub
    66 *
    77 *  @author IfA
     
    1212
    1313#include "pslib.h"
    14 #include "pswarpErrorCodes.h"
     14#include "ppSubErrorCodes.h"
    1515
    1616/*
    1717 * The line
    18     { PSWARP_ERR_$X{ErrorCode}, "$X{ErrorDescription}"},
     18    { PPSUB_ERR_$X{ErrorCode}, "$X{ErrorDescription}"},
    1919 * (without the Xs)
    2020 * will be replaced by values from errorCodes.dat
    2121 */
    22 void pswarpErrorRegister(void)
     22void ppSubErrorRegister(void)
    2323{
    2424    static psErrorDescription errors[] = {
    25        { PSWARP_ERR_BASE, "First value we use; lower values belong to psLib" },
    26        { PSWARP_ERR_${ErrorCode}, "${ErrorDescription}"},
     25       { PPSUB_ERR_BASE, "First value we use; lower values belong to psLib" },
     26       { PPSUB_ERR_${ErrorCode}, "${ErrorDescription}"},
    2727    };
    28     static int nerror = PSWARP_ERR_NERROR - PSWARP_ERR_BASE; ///< number of values in enum
     28    static int nerror = PPSUB_ERR_NERROR - PPSUB_ERR_BASE; ///< number of values in enum
    2929
    3030    for (int i = 0; i < nerror; i++) {
  • branches/pap/ppSub/src/ppSubErrorCodes.h.in

    r23704 r23719  
    1 /** @file pswarpErrorCodes.h.in
     1/** @file ppSubErrorCodes.h.in
    22 *
    33 *  @brief
    44 *
    5  *  @ingroup pswarp
     5 *  @ingroup ppSub
    66 *
    77 *  @author IfA
     
    1111 */
    1212
    13 #if !defined(PSWARP_ERROR_CODES_H)
    14 #define PSWARP_ERROR_CODES_H
     13#if !defined(PPSUB_ERROR_CODES_H)
     14#define PPSUB_ERROR_CODES_H
    1515/*
    1616 * The line
    17  *  PSWARP_ERR_$X{ErrorCode},
     17 *  PPSUB_ERR_$X{ErrorCode},
    1818 * (without the X)
    1919 *
     
    2121 */
    2222typedef enum {
    23     PSWARP_ERR_BASE = 14000,
    24     PSWARP_ERR_${ErrorCode},
    25     PSWARP_ERR_NERROR
    26 } pswarpErrorCode;
     23    PPSUB_ERR_BASE = 14000,
     24    PPSUB_ERR_${ErrorCode},
     25    PPSUB_ERR_NERROR
     26} ppSubErrorCode;
    2727
    28 void pswarpErrorRegister(void);
     28void ppSubErrorRegister(void);
    2929
    3030#endif
  • branches/pap/ppSub/src/ppSubFiles.c

    r23711 r23719  
    1212
    1313// Input files
    14 static const char *inputFiles[] = { "PPSUB.OUTPUT", "PPSUB.OUTPUT.MASK", "PPSUB.OUTPUT.VARIANCE",
    15                                     "PPSUB.OUTPUT.KERNELS", "PPSUB.OUTPUT.JPEG1", "PPSUB.OUTPUT.JPEG2",
    16                                     NULL };
     14static const char *inputFiles[] = { "PPSUB.INPUT", "PPSUB.INPUT.MASK", "PPSUB.INPUT.VARIANCE",
     15                                    "PPSUB.INPUT.SOURCES", "PPSUB.REF", "PPSUB.REF.MASK",
     16                                    "PPSUB.REF.VARIANCE", "PPSUB.REF.SOURCES", NULL };
    1717
    1818// Convolved files
     
    2323// Subtraction files
    2424static const char *subFiles[] = { "PPSUB.OUTPUT", "PPSUB.OUTPUT.MASK", "PPSUB.OUTPUT.VARIANCE",
    25                                   "PPSUB.OUTPUT.KERNELS", "PPSUB.OUTPUT.JPEG1", "PPSUB.OUTPUT.JPEG2",
     25                                  "PPSUB.OUTPUT.JPEG1", "PPSUB.OUTPUT.JPEG2",
    2626                                  NULL };
    2727
     
    3030
    3131// Inverse subtraction files
    32 static const char *invFiles[] = { "PPSUB.OUTINV", "PPSUB.OUTINV.MASK", "PPSUB.OUTINV.VARIANCE",
    33                                   "PPSUB.OUTINV.KERNELS", "PPSUB.OUTINV.JPEG1", "PPSUB.OUTINV.JPEG2",
    34                                   NULL };
     32static const char *invFiles[] = { "PPSUB.INVERSE", "PPSUB.INVERSE.MASK", "PPSUB.INVERSE.VARIANCE", NULL };
    3533
    3634// Inverse subtraction photometry
    37 static const char *subPhotFiles[] = { "PPSUB.OUTINV.SOURCES", NULL };
     35static const char *invPhotFiles[] = { "PPSUB.INVERSE.SOURCES", NULL };
     36
     37// PSF files
     38static const char *psfFiles[] = { "PSPHOT.PSF.SAVE", NULL };
    3839
    3940// Calculation (may be either input or output) files
     
    4748    )
    4849{
    49     for (int i = 0; imageFiles[i]; i++) {
    50         pmFPAfileActivate(config->files, files[i], state);
     50    for (int i = 0; files[i]; i++) {
     51        pmFPAfileActivate(config->files, state, files[i]);
    5152    }
    5253    return;
     
    6263    )
    6364{
    64     for (int i = 0; imageFiles[i]; i++) {
     65    for (int i = 0; files[i]; i++) {
    6566        pmFPAfile *file = pmFPAfileSelectSingle(config->files, files[i], 0);
    6667        if (file && file->save == save) {
    67             pmFPAfileActivate(config->files, files[i], state);
     68            pmFPAfileActivate(config->files, state, files[i]);
    6869        }
    6970    }
     
    7677
    7778    if (files & PPSUB_FILES_INPUT) {
    78         filesActivate(inputFiles, state);
     79        filesActivate(config, inputFiles, state);
    7980        filesActivateSave(config, calcFiles, false, state);
    8081    }
     
    9596        filesActivate(config, invPhotFiles, state);
    9697    }
     98    if (files & PPSUB_FILES_PSF) {
     99        filesActivate(config, psfFiles, state);
     100    }
    97101    if (files & PPSUB_FILES_PHOT) {
    98         psphotFilesActivate(config, false);
     102        psphotFilesActivate(config, state);
    99103    }
    100104
     
    110114}
    111115
    112 bool ppSubFilesIterateDown(pmConfig *config)
     116bool ppSubFilesIterateDown(pmConfig *config, ppSubFiles files)
    113117{
    114118    psAssert(config, "Require configuration");
     119
     120    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
     121    ppSubFilesActivate(config, files, true);
    115122
    116123    pmFPAview *view = pmFPAviewAlloc(0);// View to FPA top
     
    139146    }
    140147
     148    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
     149
    141150    return true;
    142151}
    143152
    144 bool ppSubFilesIterateUp(pmConfig *config)
     153bool ppSubFilesIterateUp(pmConfig *config, ppSubFiles files)
    145154{
    146155    psAssert(config, "Require configuration");
     156
     157    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
     158    ppSubFilesActivate(config, files, true);
    147159
    148160    pmFPAview *view = ppSubViewReadout(); // View to readout
     
    171183    }
    172184
     185    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
     186
    173187    return true;
    174188}
  • branches/pap/ppSub/src/ppSubLoop.c

    r23711 r23719  
    1717#include <pslib.h>
    1818#include <psmodules.h>
    19 #include <ppStats.h>
    2019
    2120#include "ppSub.h"
     
    7069    }
    7170
    72     if (!ppSubDefineOutput("PPSUB.OUTPUT", config, data, view)) {
     71    if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
    7372        psError(PS_ERR_UNKNOWN, false, "Unable to define output.");
    7473        return false;
    7574    }
    7675
    77     if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.INVERSE", config, data, view)) {
     76    if (!data->quality && !ppSubMakePSF(config, data)) {
    7877        psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
    7978        return false;
    8079    }
    8180
    82     if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) {
     81    if (!ppSubReadoutSubtract(config)) {
    8382        psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
    8483        return false;
     
    8685
    8786    // Close convolved files
    88     if (!ppSubFilesIterateUp(config, PPSUB_FILES_CONV)) {
     87    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) {
    8988        psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    9089        return false;
     
    9291
    9392    // Higher order background subtraction using psphot
    94     if (!ppSubBackground(config, view)) {
     93    if (!ppSubBackground(config)) {
    9594        psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
    9695        return false;
    9796    }
    9897
    99     if (!data->quality && ppSubReadoutPhotometry("PPSUB.OUTPUT", PPSUB_FILES_PHOT_SUB, config, data, view)) {
     98    if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) {
     99        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
     100        return false;
     101    }
     102
     103    if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data)) {
    100104        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    101105        return false;
    102106    }
    103107
     108    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
     109        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
     110        return false;
     111    }
     112
    104113    // Perform statistics on the cell
    105     if (!ppSubReadoutStats(config, data, view)) {
     114    if (!ppSubReadoutStats(config, data)) {
    106115        psError(PS_ERR_UNKNOWN, false, "Unable to collect statistics");
    107116        return false;
    108117    }
    109118
    110     if (!ppSubReadoutJpeg("PPSUB.OUTPUT", config, data, view)) {
     119    if (!ppSubReadoutJpeg(config)) {
    111120        psError(PS_ERR_UNKNOWN, false, "Unable to update.");
    112121        return false;
     
    120129        }
    121130
    122         if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config, data, view)) {
     131        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
    123132            psError(PS_ERR_UNKNOWN, false, "Unable to define inverse.");
    124133            return false;
    125134        }
    126135
    127         if (!ppSubReadoutInverse("PPSUB.INVERSE", "PPSUB.OUTPUT", config, view)) {
     136        if (!ppSubReadoutInverse(config)) {
    128137            psError(PS_ERR_UNKNOWN, false, "Unable to invert images.");
    129138            return false;
     
    136145        }
    137146
    138         if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.INVERSE", PPSUB_FILES_PHOT_INV,
    139                                                             config, data, view)) {
     147        if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) {
     148            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
     149            return false;
     150        }
     151
     152        if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", config, data)) {
    140153            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    141154            return false;
     
    143156
    144157        // Close inverse subtraction files
    145         if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV)) {
     158        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) {
    146159            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    147160            return false;
     
    155168    }
    156169
    157     psFree(view);
    158 
    159     psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig");
     170    psString dump_file = psMetadataLookupStr(NULL, config->arguments, "-dumpconfig");
    160171    if (dump_file) {
    161172        pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
     
    164175
    165176    return true;
    166 
    167 ERROR:
    168     return false;
    169177}
  • branches/pap/ppSub/src/ppSubMakePSF.c

    r23688 r23719  
    2222#include "ppSub.h"
    2323
    24 bool ppSubMakePSF(pmConfig *config, ppSubData *data, const pmFPAview *view)
     24bool ppSubMakePSF(pmConfig *config, ppSubData *data)
    2525{
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
     27
     28    if (!data->photometry) {
     29        return true;
     30    }
    2831
    2932    psTimerStart("PPSUB_PHOT");
     
    4447    pmReadout *minuend = NULL;          // Image that will be positive following subtraction
    4548    pmFPAfile *minuendFile = NULL;      // File for minuend image
     49    pmFPAview *view = ppSubViewReadout(); // View to readout
    4650    if (reverse) {
    4751        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
     
    5357
    5458#if 1
     59    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     60#if 0
     61    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    5562    pmReadout *template = minuend;
    56     pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
    57     pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    5863    if (!photRO) {
    5964        pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer
     
    7479    }
    7580#else
     81    if (!pmFPACopy(photFile->fpa, minuendFile->fpa)) {
     82        psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry");
     83        psFree(view);
     84        return false;
     85    }
     86    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
     87    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
     88        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
     89    }
     90#endif
     91
     92
     93#else
    7694    // Supply the minuend pmFPAfile to psphot as PSPHOT.INPUT:
    7795    psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
     
    87105        psErrorStackPrint(stderr, "Unable to determine PSF");
    88106        psWarning("Unable to determine PSF --- suspect bad data quality.");
    89         ppSubDataQuality(config, data, PSPHOT_ERR_PSF, PPSUB_FILES_PHOT);
     107        ppSubDataQuality(config, data, PSPHOT_ERR_PSF, PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
     108        psFree(view);
    90109        return true;
    91110    }
     
    93112    // Record the FWHM in the output header
    94113    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output readout
     114    psFree(view);
    95115    pmHDU *hdu = pmHDUFromCell(outRO->parent); // HDU with header
    96116    psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MAJ");
     
    100120    psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER");
    101121
     122    data->psf = psMemIncrRefCounter(psMetadataLookupPtr(NULL, photRO->parent->parent->analysis,
     123                                                        "PSPHOT.PSF"));
     124
    102125    return true;
    103126}
  • branches/pap/ppSub/src/ppSubMatchPSFs.c

    r23688 r23719  
    2222#include "ppSub.h"
    2323
    24 bool ppSubMatchPSFs(pmConfig *config, ppSubData *data, const pmFPAview *view)
     24bool ppSubMatchPSFs(pmConfig *config, ppSubData *data)
    2525{
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
    2827
    2928    // Look up recipe values
    3029    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    3130    psAssert(recipe, "We checked this earlier, so it should be here.");
     31
     32    pmFPAview *view = ppSubViewReadout(); // View to readout
    3233
    3334    // Input images
     
    5253    pmReadout *kernelRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT.KERNELS"); // RO with kernel
    5354
     55    psFree(view);
     56
    5457    // Sources in image, used for stamps: these must be loaded from previous analysis stages
    55     psArray *inSources = psMetadataLookupPtr(&mdok, inRO->analysis, "PSPHOT.SOURCES"); // Input source list
    56     psArray *refSources = psMetadataLookupPtr(&mdok, refRO->analysis, "PSPHOT.SOURCES"); // Ref source list
     58    pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES");
     59    pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES");
     60    psArray *inSources = psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES"); // Source list
     61    psArray *refSources = psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES"); // Source list
    5762
    5863    psArray *sources = NULL;            // Merged list of sources
  • branches/pap/ppSub/src/ppSubReadoutJpeg.c

    r23711 r23719  
    99#include "ppSub.h"
    1010
    11 bool ppSubReadoutJpeg(pmConfig *config, ppSubData *data, const pmFPAview *view)
     11bool ppSubReadoutJpeg(pmConfig *config)
    1212{
    1313    psAssert(config, "Require configuration");
    14     psAssert(view, "Require view");
    1514
    16     bool mdok = false;                  // Status of MD lookup
     15    pmFPAview *view = ppSubViewReadout(); // View to readout
     16    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Readout to jpeg
    1717
    1818    // Look up recipe values
    19     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     19    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    2020    psAssert(recipe, "We checked this earlier, so it should be here.");
    2121
    2222    // Generate binned JPEGs
    23     {
    24         psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
     23    psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
    2524
    26         int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
    27         int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
     25    int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
     26    int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
    2827
    29         // Target cells
    30         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); // Rebinned cell once
    31         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); // Rebinned cell twice
     28    // Target cells
     29    pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); // Rebinned cell once
     30    pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); // Rebinned cell twice
     31    psFree(view);
    3232
    33         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    34         if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) {
    35             psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)");
    36             psFree(ro1);
    37             psFree(ro2);
    38             return false;
    39         }
    40         if (!pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    41             psError(PS_ERR_UNKNOWN, false, "Unable to bin output (2nd binning)");
    42             psFree(ro1);
    43             psFree(ro2);
    44             return false;
    45         }
     33    pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
     34    if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) {
     35        psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)");
    4636        psFree(ro1);
    4737        psFree(ro2);
     38        return false;
    4839    }
     40    if (!pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
     41        psError(PS_ERR_UNKNOWN, false, "Unable to bin output (2nd binning)");
     42        psFree(ro1);
     43        psFree(ro2);
     44        return false;
     45    }
     46    psFree(ro1);
     47    psFree(ro2);
    4948
    5049    return true;
  • branches/pap/ppSub/src/ppSubReadoutPhotometry.c

    r23688 r23719  
    2222#include "ppSub.h"
    2323
    24 bool ppSubReadoutPhotometry (pmConfig *config, ppSubData *data, const pmFPAview *view)
     24bool ppSubReadoutPhotometry(const char *name, pmConfig *config, ppSubData *data)
    2525{
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
     27
     28    if (!data->photometry) {
     29        return false;
     30    }
    2831
    2932    // Look up recipe values
     
    3942    // The PSF (measured in ppSubMakePSF) is stored on the chip->analysis of PSPHOT.INPUT
    4043    // In order to use an incoming PSF, it must be stored on the chip->analysis of PSPHOT.PSF.LOAD
     44    pmFPAview *view = ppSubViewReadout(); // View to readout
    4145    pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); // Chip with PSF
    4246    psAssert (psfInputChip, "should have been generated for ppSubMakePSF");
     
    4751        psErrorStackPrint(stderr, "No PSF available");
    4852        psWarning("No PSF available --- suspect bad data quality.");
    49         ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT);
     53        ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
    5054        return true;
    5155    }
     
    5862    // around the pointers so PSPHOT.INPUT corresponds to the output image; previously, it was
    5963    // equivalent to the minuend image.
    60     pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
    61     pmReadout *outRO = pmFPAviewThisReadout(view, outputFile->fpa); // Readout with the sources
     64    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
    6265
    63     // XXX possibly rename this to PPSUB.RESID?
    6466    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
    6567    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
     
    6870        photRO = pmReadoutAlloc(cell); // Output readout: subtraction
    6971    }
    70     photRO->image = psImageCopy(photRO->image, outRO->image, PS_TYPE_F32);
    71     if (outRO->variance) {
    72         photRO->variance = psImageCopy(photRO->variance, outRO->variance, PS_TYPE_F32);
     72    photRO->image = psImageCopy(photRO->image, inRO->image, PS_TYPE_F32);
     73    if (inRO->variance) {
     74        photRO->variance = psImageCopy(photRO->variance, inRO->variance, PS_TYPE_F32);
    7375    } else {
    7476        psFree(photRO->variance);
    7577        photRO->variance = NULL;
    7678    }
    77     if (outRO->mask) {
    78         photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK);
     79    if (inRO->mask) {
     80        photRO->mask = psImageCopy(photRO->mask, inRO->mask, PS_TYPE_IMAGE_MASK);
    7981    } else {
    8082        psFree(photRO->mask);
    8183        photRO->mask = NULL;
    8284    }
     85    psMetadataAddPtr(photRO->parent->parent->analysis, PS_LIST_TAIL, "PSPHOT.PSF",
     86                     PS_META_REPLACE | PS_DATA_UNKNOWN, "Point-spread function", data->psf);
     87
     88    psFree(photRO->analysis);
     89    photRO->analysis = psMetadataAlloc();
    8390
    8491    if (!psphotReadoutMinimal(config, view)) {
     
    8794        psErrorStackPrint(stderr, "Unable to perform photometry on image");
    8895        psWarning("Unable to perform photometry on image --- suspect bad data quality.");
    89         ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT);
     96        ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
    9097    }
    9198
    92     photRO->data_exists = true;
    93     photRO->parent->data_exists = true;
    94     photRO->parent->parent->data_exists = true;
     99    if (!data->quality && !psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.SOURCES")) {
     100        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.SOURCES");
     101        return false;
     102    }
    95103
    96104    if (data->stats) {
    97105        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
    98         psMetadataAddS32(data->stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
    99                          sources ? sources->n : 0);
    100         psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
    101                          psTimerClear("PPSUB_PHOT"));
     106        bool mdok;
     107        int numSources = psMetadataLookupS32(&mdok, data->stats, "NUM_SOURCES"); // Number of sources
     108        numSources += sources ? sources->n : 0;
     109        psMetadataAddS32(data->stats, PS_LIST_TAIL, "NUM_SOURCES", PS_META_REPLACE,
     110                         "Total number of sources detected", numSources);
     111        float newTime = psTimerClear("PPSUB_PHOT"); // Time for photometry
     112        float oldTime = psMetadataLookupF32(&mdok, data->stats, "TIME_PHOT"); // Previous time for photometry
     113        psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", PS_META_REPLACE, "Time to do photometry",
     114                         isfinite(oldTime) ? oldTime + newTime : newTime);
    102115    }
    103116
  • branches/pap/ppSub/src/ppSubReadoutStats.c

    r23711 r23719  
     1#ifdef HAVE_CONFIG_H
     2#include <config.h>
     3#endif
    14
    2 bool ppSubReadoutStats(pmConfig *config, ppSubData *data, const pmFPAview *view)
     5#include <pslib.h>
     6#include <psmodules.h>
     7#include <ppStats.h>
     8
     9#include "ppSub.h"
     10
     11
     12bool ppSubReadoutStats(pmConfig *config, ppSubData *data)
    313{
    414    psAssert(config, "Require configuration");
    515    psAssert(data, "Require data");
    6     psAssert(view, "Require view");
    716
    817    if (!data->statsFile) {
     
    1423    if (!output) {
    1524        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n");
    16         goto ERROR;
     25        return false;
    1726    }
    1827    psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);
     28    pmFPAview *view = ppSubViewReadout(); // View to readout
    1929    ppStatsFPA(data->stats, output->fpa, view, maskValue, config);
     30
     31    pmReadout *outRO = pmFPAviewThisReadout(view, output->fpa); // Readout of interest
     32    psFree(view);
    2033
    2134    // Statistics on the matching
  • branches/pap/ppSub/src/ppSubReadoutSubtract.c

    r23642 r23719  
    2323#define WCS_TOLERANCE 0.001             // Tolerance for WCS
    2424
    25 bool ppSubReadoutSubtract(pmConfig *config, const pmFPAview *view)
     25bool ppSubReadoutSubtract(pmConfig *config)
    2626{
    2727    psAssert(config, "Require configuration");
    28     psAssert(view, "Require view");
    29 
    3028
    3129    // Look up recipe values
     
    3533
    3634    bool reverse = psMetadataLookupBool(&mdok, config->arguments, "REVERSE"); // Reverse sense of subtraction?
     35
     36    pmFPAview *view = ppSubViewReadout(); // View to readout
    3737
    3838    // Subtraction is: minuend - subtrahend
     
    9191        psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
    9292        psFree(outRO);
     93        psFree(view);
    9394        return false;
    9495    }
     
    99100    pmHDU *outHDU = outFPA->hdu;        // Output HDU
    100101    pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip
     102    psFree(view);
    101103    if (!outHDU || !inHDU) {
    102104        psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry.");
  • branches/pap/ppSub/src/ppSubReadoutUpdate.c

    r23711 r23719  
    2020
    2121#include "ppSub.h"
    22 
    23 bool ppSubReadoutUpdate(pmConfig *config, ppSubData *data, const pmFPAview *view)
    24 {
    25     psAssert(config, "Require configuration");
    26     psAssert(view, "Require view");
    27 
    28     bool mdok = false;                  // Status of MD lookup
    29 
    30     // Look up recipe values
    31     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    32     psAssert(recipe, "We checked this earlier, so it should be here.");
    33 
    34     // Generate binned JPEGs
    35     {
    36         psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
    37 
    38         int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
    39         int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
    40 
    41         // Target cells
    42         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); // Rebinned cell once
    43         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); // Rebinned cell twice
    44 
    45         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    46         if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) {
    47             psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)");
    48             psFree(ro1);
    49             psFree(ro2);
    50             return false;
    51         }
    52         if (!pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    53             psError(PS_ERR_UNKNOWN, false, "Unable to bin output (2nd binning)");
    54             psFree(ro1);
    55             psFree(ro2);
    56             return false;
    57         }
    58         psFree(ro1);
    59         psFree(ro2);
    60     }
    61 
    62     return true;
    63 }
  • branches/pap/ppSub/src/ppSubSetMasks.c

    r23535 r23719  
    2222#include "ppSub.h"
    2323
    24 bool ppSubSetMasks(pmConfig *config, const pmFPAview *view)
     24bool ppSubSetMasks(pmConfig *config)
    2525{
    2626    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
    2827
    2928    psImageMaskType maskValue, markValue; // Mask values
     
    5049    psAssert(lowValue, "LOW or BAD must be non-zero");
    5150
    52     // input images
     51    // Input images
     52    pmFPAview *view = ppSubViewReadout(); // View to readout
    5353    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout
    5454    pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout
Note: See TracChangeset for help on using the changeset viewer.