IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2009, 11:24:29 AM (18 years ago)
Author:
beaumont
Message:

sync with mainline

Location:
branches/cnb_branches/cnb_branch_20090215
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090215

  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/Makefile.am

    r19337 r23199  
    11bin_PROGRAMS = ppStack
    22
    3 ppStack_CFLAGS  = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PPSTATS_CFLAGS) $(PPSTACK_CFLAGS)
     3PPSTACK_VERSION=`if [ -e ../../VERSION ]; then cat ../../VERSION; else svnversion; fi`
     4PPSTACK_BRANCH=`if [ -e ../../BRANCH ]; then cat ../../BRANCH; else svn info | sed -n -e '/URL:/ h' -e '/Repository Root:/ { x; H; x; s|Repository Root: \(.*\)\nURL: \1\(.*\)|\2| ; s|^/|| ; s|/[a-zA-Z]*/src.*|| ; p }'; fi`
     5PPSTACK_SOURCE=`if [ -e ../../SOURCE ]; then cat ../../SOURCE; else svn info | sed -n -e 's/Repository UUID: // p'; fi`
     6
     7# Force recompilation of ppStackVersion.c, since it gets the version information
     8ppStackVersion.c: FORCE
     9        touch ppStackVersion.c
     10FORCE: ;
     11
     12ppStack_CFLAGS  = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PPSTATS_CFLAGS) $(PPSTACK_CFLAGS) -DPPSTACK_VERSION=\"$(PPSTACK_VERSION)\" -DPPSTACK_BRANCH=\"$(PPSTACK_BRANCH)\" -DPPSTACK_SOURCE=\"$(PPSTACK_SOURCE)\"
    413ppStack_LDFLAGS = $(PSLIB_LIBS)   $(PSMODULE_LIBS)   $(PSPHOT_LIBS)   $(PPSTATS_LIBS)   $(PPSTACK_LIBS)
    514
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStack.c

    r21536 r23199  
    3333        goto die;
    3434    }
     35
     36    ppStackVersionPrint();
    3537
    3638    if (!pmModelClassInit()) {
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStack.h

    r21477 r23199  
    1010// Mask values for inputs
    1111typedef enum {
    12     PPSTACK_MASK_MATCH  = 0x01,         // PSF-matching failed
    13     PPSTACK_MASK_CHI2   = 0x02,         // Chi^2 too deviant
    14     PPSTACK_MASK_REJECT = 0x04,         // Rejection failed
    15     PPSTACK_MASK_BAD    = 0x08,         // Bad image (too many pixels rejected)
     12    PPSTACK_MASK_CAL    = 0x01,         // Photometric calibration failed
     13    PPSTACK_MASK_MATCH  = 0x02,         // PSF-matching failed
     14    PPSTACK_MASK_CHI2   = 0x04,         // Chi^2 too deviant
     15    PPSTACK_MASK_REJECT = 0x08,         // Rejection failed
     16    PPSTACK_MASK_BAD    = 0x10,         // Bad image (too many pixels rejected)
    1617    PPSTACK_MASK_ALL    = 0xff          // All errors
    1718} ppStackMask;
    … …  
    8182pmPSF *ppStackPSF(const pmConfig *config, // Configuration
    8283                  int numCols, int numRows, // Size of image
    83                   const psArray *psfs   // List of input PSFs
     84                  const psArray *psfs,  // List of input PSFs
     85                  const psVector *inputMask // Mask for inputs
    8486    );
    8587
    … …  
    134136psString ppStackVersion(void);
    135137
     138/// Return software source
     139psString ppStackSource(void);
     140
    136141// Return long description of software version
    137142psString ppStackVersionLong(void);
    138143
    139 // Supplement metadata with software version
    140 void ppStackVersionMetadata(psMetadata *metadata // Metadata to supplement
     144// Supplement header with software version
     145bool ppStackVersionHeader(psMetadata *header // Header to supplement
    141146    );
     147
     148/// Print version information
     149void ppStackVersionPrint(void);
    142150
    143151/// Convolve image to match specified seeing
    … …  
    158166/// Corrects the source PSF photometry to a common system.  Return the sum of the exposure times.
    159167float ppStackSourcesTransparency(const psArray *sourceLists, // Sources for each input
     168                                 psVector *inputMask, // Indicates bad input
    160169                                 const pmFPAview *view, // View to readout
    161170                                 const pmConfig *config // Configuration
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackArguments.c

    r22722 r23199  
    294294    if (dump_file) {
    295295        pmConfigCamerasCull(config, NULL);
    296         pmConfigRecipesCull(config, "PPSTACK,PPSUB,PPSTATS,PSPHOT,MASKS");
     296        pmConfigRecipesCull(config, "PPSTACK,PPSUB,PPSTATS,PSPHOT,MASKS,JPEG");
    297297
    298298        pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSTACK.INPUT"); // Input file
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackLoop.c

    r22214 r23199  
    257257    pmPSF *targetPSF = NULL;            // Target PSF
    258258    float sumExposure = NAN;            // Sum of exposure times
     259    psVector *inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
     260    psVectorInit(inputMask, 0);
    259261    if (psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) {
    260262        pmFPAfileActivate(config->files, false, NULL);
    … …  
    283285                psFree(fileIter);
    284286                psFree(psfs);
     287                psFree(inputMask);
    285288                return false;
    286289            }
    … …  
    299302                psFree(fileIter);
    300303                psFree(psfs);
     304                psFree(inputMask);
    301305                return false;
    302306            }
    … …  
    324328                    psFree(sourceLists);
    325329                    psFree(targetPSF);
    326                     return false;
     330                    psFree(inputMask);
     331                   return false;
    327332                }
    328333
    … …  
    333338                    psFree(sourceLists);
    334339                    psFree(targetPSF);
     340                    psFree(inputMask);
    335341                    return false;
    336342                }
    … …  
    340346                    psFree(sourceLists);
    341347                    psFree(targetPSF);
     348                    psFree(inputMask);
    342349                    return false;
    343350                }
    … …  
    351358
    352359        // Zero point calibration
    353         sumExposure = ppStackSourcesTransparency(sourceLists, view, config);
     360        sumExposure = ppStackSourcesTransparency(sourceLists, inputMask, view, config);
    354361        if (!isfinite(sumExposure) || sumExposure <= 0) {
    355362            psError(PS_ERR_UNKNOWN, false, "Unable to calculate transparency differences");
    356363            psFree(sourceLists);
    357364            psFree(targetPSF);
     365            psFree(inputMask);
    358366            return false;
    359367        }
    360368
    361369        // Generate target PSF
    362         targetPSF = ppStackPSF(config, numCols, numRows, psfs);
     370        targetPSF = ppStackPSF(config, numCols, numRows, psfs, inputMask);
    363371        psFree(psfs);
    364372        if (!targetPSF) {
    … …  
    366374            psFree(sourceLists);
    367375            psFree(view);
     376            psFree(inputMask);
    368377            return false;
    369378        }
    … …  
    409418    int numGood = 0;                    // Number of good frames
    410419    int numCols = 0, numRows = 0;       // Size of image
    411     psVector *inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
    412     psVectorInit(inputMask, 0);
    413420    psVector *matchChi2 = psVectorAlloc(num, PS_TYPE_F32); // chi^2 for stamps when matching
    414421    psVectorInit(matchChi2, NAN);
    … …  
    419426    psArray *covariances = psArrayAlloc(num); // Covariance matrices
    420427    for (int i = 0; i < num; i++) {
     428        if (inputMask->data.U8[i]) {
     429            continue;
     430        }
    421431        psTrace("ppStack", 2, "Convolving input %d of %d to target PSF....\n", i, num);
    422432        pmFPAfileActivate(config->files, false, NULL);
    … …  
    11681178        fileActivation(config, photFiles, true);
    11691179        pmFPAview *photView = filesIterateDown(config);
     1180        fileActivation(config, combineFiles, true);
     1181
    11701182        if (!ppStackPhotometry(config, outRO, photView)) {
    11711183            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on output.");
     1184            filesIterateUp(config);
    11721185            psFree(outRO);
    11731186            psFree(photView);
    … …  
    11751188        }
    11761189        psFree(photView);
    1177 
    1178         fileActivation(config, combineFiles, true);
    11791190
    11801191        if (stats) {
    … …  
    12171228        hdu->header = psMetadataAlloc();
    12181229    }
    1219     ppStackVersionMetadata(hdu->header);
     1230    ppStackVersionHeader(hdu->header);
    12201231
    12211232    psFree(outRO);
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackPSF.c

    r18918 r23199  
    99#include "ppStack.h"
    1010
    11 pmPSF *ppStackPSF(const pmConfig *config, int numCols, int numRows, const psArray *psfs)
     11pmPSF *ppStackPSF(const pmConfig *config, int numCols, int numRows,
     12                  const psArray *psfs, const psVector *inputMask)
    1213{
    1314    // Get the recipe values
    … …  
    1920    const char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF
    2021    int psfOrder = psMetadataLookupS32(NULL, recipe, "PSF.ORDER"); // Spatial order for PSF
     22
     23    for (int i = 0; i < psfs->n; i++) {
     24        if (inputMask->data.U8[i]) {
     25            psFree(psfs->data[i]);
     26            psfs->data[i] = NULL;
     27        }
     28    }
    2129
    2230    // Solve for the target PSF
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackPhotometry.c

    r21536 r23199  
    149149    if (!psphotReadoutKnownSources(config, view, inSources)) {
    150150        // Clear the error, so that the output files are written.
    151         psWarning("Unable to perform photometry on stacked image.");
    152         psErrorStackPrint(stderr, "Error stack from photometry:");
    153         psErrorClear();
     151        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on stacked image.");
     152        return false;
    154153    }
    155154
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackSources.c

    r21536 r23199  
    1313#define FAKE_ROWS 4913
    1414
    15 float ppStackSourcesTransparency(const psArray *sourceLists, const pmFPAview *view, const pmConfig *config)
     15#ifdef TESTING
     16// Dump matches to a file
     17static void dumpMatches(const char *filename, // File to which to dump
     18                        int num,        // Number of inputs
     19                        psArray *matches, // Star matches
     20                        psVector *zp,   // Zero points
     21                        psVector *trans // Transparencies
     22                        )
     23{
     24    FILE *outMatches = fopen(filename, "w"); // Output matches
     25    psVector *mag = psVectorAlloc(num, PS_TYPE_F32); // Magnitudes for each star
     26    psVector *magErr = psVectorAlloc(num, PS_TYPE_F32); // Errors for each star
     27    for (int i = 0; i < matches->n; i++) {
     28        pmSourceMatch *match = matches->data[i]; // Match of interest
     29        psVectorInit(mag, NAN);
     30        psVectorInit(magErr, NAN);
     31        for (int j = 0; j < match->num; j++) {
     32            if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
     33                continue;
     34            }
     35            int index = match->image->data.U32[j]; // Image index
     36            mag->data.F32[index] = match->mag->data.F32[j] - zp->data.F32[index];
     37            if (trans) {
     38                mag->data.F32[index] -= trans->data.F32[index];
     39            }
     40            magErr->data.F32[index] = match->magErr->data.F32[j];
     41        }
     42        for (int j = 0; j < num; j++) {
     43            fprintf(outMatches, "%f (%f) ", mag->data.F32[j], magErr->data.F32[j]);
     44        }
     45        fprintf(outMatches, "\n");
     46    }
     47    psFree(mag);
     48    psFree(magErr);
     49    fclose(outMatches);
     50    return;
     51}
     52#endif
     53
     54
     55float ppStackSourcesTransparency(const psArray *sourceLists, psVector *inputMask,
     56                                 const pmFPAview *view, const pmConfig *config)
    1657{
    1758    PS_ASSERT_ARRAY_NON_NULL(sourceLists, NAN);
     59    PS_ASSERT_VECTOR_NON_NULL(inputMask, NAN);
     60    PS_ASSERT_VECTOR_TYPE(inputMask, PS_TYPE_U8, NAN);
     61    PS_ASSERT_VECTOR_SIZE(inputMask, sourceLists->n, NAN);
    1862    PS_ASSERT_PTR_NON_NULL(view, NAN);
    1963    PS_ASSERT_PTR_NON_NULL(config, NAN);
    2064
    21 #ifdef TESTING
     65#if defined(TESTING) && 0
    2266    {
    2367        // Deliberately induce a major transparency difference
    … …  
    63107        pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest
    64108
    65 #ifdef TESTING
     109#if defined(TESTING) && 0
    66110        pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout
    67111        pmPSF *psf = psMetadataLookupPtr(NULL, config->arguments, "PSF.TARGET"); // PSF for fake image
    … …  
    115159        return NAN;
    116160    }
     161
     162#ifdef TESTING
     163    dumpMatches("source_match.dat", num, matches, zp, NULL);
     164#endif
     165
    117166    psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej,
    118167                                           transThresh, starRej, starSys); // Transparencies for each image
    119 
    120 #ifdef TESTING
    121     {
    122         // Dump the corrected magnitudes
    123         FILE *outMatches = fopen("source_match.dat", "w"); // Output matches
    124         psVector *mag = psVectorAlloc(num, PS_TYPE_F32); // Magnitudes for each star
    125         psVector *magErr = psVectorAlloc(num, PS_TYPE_F32); // Errors for each star
    126         for (int i = 0; i < matches->n; i++) {
    127             pmSourceMatch *match = matches->data[i]; // Match of interest
    128             psVectorInit(mag, NAN);
    129             psVectorInit(magErr, NAN);
    130             for (int j = 0; j < match->num; j++) {
    131                 if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) {
    132                     continue;
    133                 }
    134                 int index = match->image->data.U32[j]; // Image index
    135                 mag->data.F32[index] = match->mag->data.F32[j] - zp->data.F32[index] - trans->data.F32[index];
    136                 magErr->data.F32[index] = match->magErr->data.F32[j];
    137             }
    138             for (int j = 0; j < num; j++) {
    139                 fprintf(outMatches, "%f (%f) ", mag->data.F32[j], magErr->data.F32[j]);
    140             }
    141             fprintf(outMatches, "\n");
    142         }
    143         psFree(mag);
    144         psFree(magErr);
    145         fclose(outMatches);
    146     }
    147 #endif
     168    if (!trans) {
     169        psError(PS_ERR_UNKNOWN, false, "Unable to measure transparencies");
     170        return NAN;
     171    }
     172
     173#ifdef TESTING
     174    dumpMatches("source_mags.dat", num, matches, zp, trans);
     175#endif
     176
     177    for (int i = 0; i < trans->n; i++) {
     178        if (!isfinite(trans->data.F32[i])) {
     179            inputMask->data.U8[i] = PPSTACK_MASK_CAL;
     180        }
     181    }
    148182
    149183    // Save best matches SOMEWHERE for future photometry
    … …  
    172206
    173207    psFree(matches);
    174     if (!trans) {
    175         psError(PS_ERR_UNKNOWN, false, "Unable to measure transparencies");
    176         return NAN;
    177     }
    178208
    179209    // M = m + c0 + c1 * airmass - 2.5log(t) + transparency
    … …  
    183213    // We don't need to know the magnitude zero point for the filter, since it cancels out
    184214    for (int i = 0; i < num; i++) {
     215        if (!isfinite(trans->data.F32[i])) {
     216            continue;
     217        }
    185218        psArray *sources = sourceLists->data[i]; // Sources of interest
    186219        float magCorr = airmassTerm - 2.5*log10(sumExpTime) - zp->data.F32[i] - trans->data.F32[i];
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackThread.c

    r21477 r23199  
    3636    psFree(stack->threads);
    3737    for (int i = 0; i < stack->imageFits->n; i++) {
    38         psFitsClose(stack->imageFits->data[i]);
    39         psFitsClose(stack->maskFits->data[i]);
    40         psFitsClose(stack->varianceFits->data[i]);
     38        if (stack->imageFits->data[i]) {
     39            psFitsClose(stack->imageFits->data[i]);
     40        }
     41        if (stack->maskFits->data[i]) {
     42            psFitsClose(stack->maskFits->data[i]);
     43        }
     44        if (stack->varianceFits->data[i]) {
     45            psFitsClose(stack->varianceFits->data[i]);
     46        }
    4147        stack->imageFits->data[i] = stack->maskFits->data[i] = stack->varianceFits->data[i] = NULL;
    4248    }
  • branches/cnb_branches/cnb_branch_20090215/ppStack/src/ppStackVersion.c

    r18419 r23199  
    77#include <psmodules.h>
    88#include <ppStats.h>
     9#include <psphot.h>
    910
    1011#include "ppStack.h"
    1112
    12 static const char *cvsTag = "$Name: not supported by cvs2svn $";// CVS tag name
    13 
    1413psString ppStackVersion(void)
    1514{
    16     psString version = NULL;            // Version, to return
    17     psStringAppend(&version, "%s-%s",PACKAGE_NAME,PACKAGE_VERSION);
    18     return version;
     15#ifndef PPSTACK_VERSION
     16#error "PPSTACK_VERSION is not set"
     17#endif
     18#ifndef PPSTACK_BRANCH
     19#error "PPSTACK_BRANCH is not set"
     20#endif
     21    return psStringCopy(PPSTACK_BRANCH "@" PPSTACK_VERSION);
     22}
     23
     24psString ppStackSource(void)
     25{
     26#ifndef PPSTACK_SOURCE
     27#error "PPSTACK_SOURCE is not set"
     28#endif
     29    return psStringCopy(PPSTACK_SOURCE);
    1930}
    2031
    2132psString ppStackVersionLong(void)
    2233{
    23     psString version = ppStackVersion(); // Version, to return
    24     psString tag = psStringStripCVS(cvsTag, "Name"); // CVS tag
    25     psStringAppend(&version, " (cvs tag %s) %s, %s", tag, __DATE__, __TIME__);
    26     psFree(tag);
     34    psString version = ppStackVersion();  // Version, to return
     35    psString source = ppStackSource();    // Source
     36
     37    psStringPrepend(&version, "ppStack ");
     38    psStringAppend(&version, " from %s, built %s, %s", source, __DATE__, __TIME__);
     39    psFree(source);
     40
     41#ifdef __OPTIMIZE__
     42    psStringAppend(&version, " optimised");
     43#else
     44    psStringAppend(&version, " unoptimised");
     45#endif
     46
    2747    return version;
    28 }
     48};
    2949
    3050
    31 void ppStackVersionMetadata(psMetadata *metadata)
     51bool ppStackVersionHeader(psMetadata *header)
    3252{
    33     PS_ASSERT_METADATA_NON_NULL(metadata,);
    34 
    35     psString pslib = psLibVersionLong();// psLib version
    36     psString psmodules = psModulesVersionLong(); // psModules version
    37     psString ppStats = ppStatsVersionLong(); // ppStats version
    38     psString ppStack = ppStackVersionLong(); // ppStack version
     53    PS_ASSERT_METADATA_NON_NULL(header, false);
    3954
    4055    psTime *time = psTimeGetNow(PS_TIME_TAI); // The time now
    4156    psString timeString = psTimeToISO(time); // The time in an ISO string
    4257    psFree(time);
    43     psString head = NULL;               // Head string
    44     psStringAppend(&head, "ppStack processing at %s. Component information:", timeString);
     58    psString history = NULL;               // History string
     59    psStringAppend(&history, "ppStack at %s", timeString);
     60    psFree(timeString);
     61    psMetadataAddStr(header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, NULL, history);
     62    psFree(history);
     63
     64    psLibVersionHeader(header);
     65    psModulesVersionHeader(header);
     66    psphotVersionHeader(header);
     67    ppStatsVersionHeader(header);
     68
     69    psString version = ppStackVersion(); // Software version
     70    psString source  = ppStackSource();  // Software source
     71
     72    psMetadataAddStr(header, PS_LIST_TAIL, "IPP.PPSTACK.VERSION", PS_META_REPLACE,
     73                     "Software version", version);
     74    psMetadataAddStr(header, PS_LIST_TAIL, "IPP.PPSTACK.SOURCE", PS_META_REPLACE,
     75                     "S/W source", source);
     76
     77    psFree(version);
     78    psFree(source);
     79
     80    return true;
     81}
     82
     83void ppStackVersionPrint(void)
     84{
     85    psTime *time = psTimeGetNow(PS_TIME_TAI); // The time now
     86    psString timeString = psTimeToISO(time); // The time in an ISO string
     87    psFree(time);
     88    psLogMsg("ppStack", PS_LOG_INFO, "ppStack at %s", timeString);
    4589    psFree(timeString);
    4690
    47     psMetadataAddStr(metadata, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, "", head);
    48     psMetadataAddStr(metadata, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, "", pslib);
    49     psMetadataAddStr(metadata, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, "", psmodules);
    50     psMetadataAddStr(metadata, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, "", ppStats);
    51     psMetadataAddStr(metadata, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, "", ppStack);
     91    psString pslib = psLibVersionLong();// psLib version
     92    psString psmodules = psModulesVersionLong(); // psModules version
     93    psString psphot = psphotVersionLong(); // psphot version
     94    psString ppStats = ppStatsVersionLong(); // psastro version
     95    psString ppStack = ppStackVersionLong(); // ppStack version
    5296
    53     psFree(head);
     97    psLogMsg("ppStack", PS_LOG_INFO, "%s", pslib);
     98    psLogMsg("ppStack", PS_LOG_INFO, "%s", psmodules);
     99    psLogMsg("ppStack", PS_LOG_INFO, "%s", psphot);
     100    psLogMsg("ppStack", PS_LOG_INFO, "%s", ppStats);
     101    psLogMsg("ppStack", PS_LOG_INFO, "%s", ppStack);
     102
    54103    psFree(pslib);
    55104    psFree(psmodules);
     105    psFree(psphot);
    56106    psFree(ppStats);
    57107    psFree(ppStack);
Note: See TracChangeset for help on using the changeset viewer.