IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14465


Ignore:
Timestamp:
Aug 10, 2007, 3:03:30 PM (19 years ago)
Author:
Paul Price
Message:

Adding pmConceptsAverageFPAs to average concepts over FPAs.

Location:
trunk/psModules/src/concepts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/concepts/pmConceptsAverage.c

    r12696 r14465  
    55#include <stdio.h>
    66#include <pslib.h>
     7#include <string.h>
    78
    89#include "pmHDU.h"
     
    1718    psMetadataItem *item = psMetadataLookup(MD, NAME); \
    1819    item->data.TYPE = VALUE; \
     20}
     21
     22bool pmConceptsAverageFPAs(pmFPA *target, psList *sources)
     23{
     24    PS_ASSERT_PTR_NON_NULL(target, false);
     25    PS_ASSERT_PTR_NON_NULL(sources, false);
     26    PS_ASSERT_INT_POSITIVE(sources->n, false);
     27    bool success = true;                // Result of setting everything
     28
     29    float exposure   = 0.0;             // Exposure time
     30    double time      = 0.0;             // Time of observation
     31    psTimeType timeSys = 0;             // Time system
     32    char *filter     = NULL;            // Filter
     33
     34    int num = 0;                        // Number of FPAs
     35    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     36    pmFPA *fpa = NULL;                  // Source FPA from iteration
     37    while ((fpa = psListGetAndIncrement(sourcesIter))) {
     38        if (!fpa) {
     39            continue;
     40        }
     41
     42        num++;
     43        exposure   += psMetadataLookupF32(NULL, fpa->concepts, "FPA.EXPOSURE");
     44
     45        psTime *fpaTime = psMetadataLookupPtr(NULL, fpa->concepts, "FPA.TIME");
     46        time       += psTimeToMJD(fpaTime);
     47        if (num == 1) {
     48            timeSys = psMetadataLookupS32(NULL, fpa->concepts, "FPA.TIMESYS");
     49            filter = psMetadataLookupStr(NULL, fpa->concepts, "FPA.FILTER");
     50        } else {
     51            if (timeSys != psMetadataLookupS32(NULL, fpa->concepts, "FPA.TIMESYS")) {
     52                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing FPA.TIMESYS in use: %d vs %d\n",
     53                        timeSys, psMetadataLookupS32(NULL, fpa->concepts, "FPA.TIMESYS"));
     54                success = false;
     55            }
     56            if (strcmp(filter, psMetadataLookupStr(NULL, fpa->concepts, "FPA.FILTER")) != 0) {
     57                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing FPA.FILTER in use: %s vs %s\n",
     58                        filter, psMetadataLookupStr(NULL, fpa->concepts, "FPA.FILTER"));
     59                success = false;
     60            }
     61        }
     62    }
     63    psFree(sourcesIter);
     64
     65    exposure  /= (float)num;
     66    time      /= (double)num;
     67
     68    MD_UPDATE(target->concepts, "FPA.EXPOSURE", F32, exposure);
     69    MD_UPDATE(target->concepts, "FPA.TIMESYS", S32, timeSys);
     70    MD_UPDATE(target->concepts, "FPA.FILTER", str, filter);
     71
     72    // FPA.TIME needs special care
     73    {
     74        psMetadataItem *timeItem = psMetadataLookup(target->concepts, "FPA.TIME");
     75        psFree(timeItem->data.V);
     76        timeItem->data.V = psTimeFromMJD(time);
     77    }
     78
     79    return success;
    1980}
    2081
  • trunk/psModules/src/concepts/pmConceptsAverage.h

    r12696 r14465  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-03-30 21:12:56 $
     6 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-08-11 01:03:30 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    1414/// @addtogroup Concepts Data Abstraction Concepts
    1515/// @{
     16
     17/// Set a variety of concepts in an FPA by averaging over several
     18///
     19/// This function averages the values of the following concepts:
     20/// FPA.TIME
     21/// FPA.EXPOSURE
     22/// And ensure the following concepts are consistent:
     23/// FPA.FILTER
     24/// FPA.TIMESYS
     25bool pmConceptsAverageFPAs(pmFPA *target,///< Target FPA
     26                           psList *sources ///< List of source FPAs
     27    );
    1628
    1729/// Set a variety of concepts in a cell by averaging over several
Note: See TracChangeset for help on using the changeset viewer.