IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20270


Ignore:
Timestamp:
Oct 19, 2008, 1:53:56 PM (18 years ago)
Author:
eugene
Message:

select ref data from matching filter; use zero point and inst mag cut off to select max number of stars

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroLoadRefstars.c

    r19289 r20270  
    22# define ELIXIR_MODE 1
    33
    4 // XXX other comment
     4char *psastroSetMagLimit (float *minMag, float *maxRho, pmConfig *config);
    55
    66psArray *psastroLoadRefstars (pmConfig *config) {
     
    5353    PS_ASSERT (outformat, NULL);
    5454
    55     char *photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");
     55    // we have an exposure with a certain filter and exposure time: choose the maximum
     56    // reference star density for stars fainter than an equivalent instrumental mag limit
     57    float minMag;
     58    float maxRho;
     59    char *photcode = psastroSetMagLimit (&minMag, &maxRho, config);
    5660    PS_ASSERT (photcode, NULL);
    57 
    58     float MAGmax = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MAG.MAX");
    5961
    6062    // issue the following command:
     
    8688    // supply the max magnitude, the output format, and the photcode
    8789    if (strcasecmp (photcode, "NONE")) {
    88         psStringAppend (&getstarCommand, " -maglim %f", MAGmax);
    89     }
    90     if (strcasecmp (photcode, "NONE")) {
    91         psStringAppend (&getstarCommand, " -photcode %s", photcode);
     90
     91        psStringAppend (&getstarCommand, " -photcode %s -minmag %f -max-density %f", photcode, minMag, maxRho);
    9292    }
    9393    psStringAppend (&getstarCommand, " -format %s", outformat);
     
    222222    return refstars;
    223223}
     224
     225# define ESCAPE(MSG) { \
     226  psLogMsg ("psastro", PS_LOG_INFO, MSG); \
     227  goto escape; }
     228
     229char *psastroSetMagLimit (float *minMag, float *maxRho, pmConfig *config) {
     230
     231    bool status;
     232    char *photcode;
     233
     234    // select the current recipe
     235    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);
     236
     237    // select the input data sources
     238    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     239    if (!input) {
     240        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
     241        return NULL;
     242    }
     243    assert (input->fpa);
     244
     245    *maxRho = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MAX.RHO");
     246    if (!status) {
     247        psError(PSASTRO_ERR_CONFIG, false, "DVO.GETSTAR.MAX.RHO missing from recipe");
     248        return NULL;
     249    }
     250
     251    // select the filter; default to fixed photcode and mag limit otherwise
     252    char *filter = psMetadataLookupStr (&status, input->fpa->concepts, "FPA.FILTERID");
     253    if (!status) ESCAPE ("missing FPA.FILTER in concepts");
     254
     255    float exptime = psMetadataLookupF32 (&status, input->fpa->concepts, "FPA.EXPOSURE");
     256    if (!status) ESCAPE ("missing FPA.EXPOSURE in concepts");
     257
     258    // we need to select the PHOTCODE.DATA folder that matches our filter
     259    psMetadataItem *item = psMetadataLookup (recipe, "PHOTCODE.DATA");
     260    if (!item) ESCAPE ("PHOTCODE.DATA folders missing");
     261    if (item->type != PS_DATA_METADATA_MULTI) ESCAPE ("PHOTCODE.DATA not a multi");
     262
     263    float minInst = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MIN.MAG.INST");
     264    if (!status) ESCAPE ("missing DVO.GETSTAR.MIN.MAG.INST");
     265
     266    // PHOTCODE.DATA is a multi of metadata items
     267    psListIterator *iter = psListIteratorAlloc(item->data.list, PS_LIST_HEAD, false);
     268
     269    psMetadataItem *refItem = NULL;
     270    while ((refItem = psListGetAndIncrement (iter))) {
     271        if (refItem->type != PS_DATA_METADATA) ESCAPE ("PHOTCODE.DATA entry is not a metadata folder");
     272   
     273        char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
     274        if (!status) {
     275            psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     276            continue;
     277        }
     278
     279        // does this entry match the current filter?
     280        if (strcmp (refFilter, filter)) continue;
     281
     282        psLogMsg ("psastro", PS_LOG_DETAIL, "PHOTCODE.DATA found for filter %s", filter);
     283
     284        float zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT");
     285        if (!status) {
     286            psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     287            continue;
     288        }
     289        photcode = psMetadataLookupStr (&status, refItem->data.md, "PHOTCODE");
     290        if (!status) {
     291            psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     292            continue;
     293        }
     294
     295        // convert the minInst to a calibrated minimum magnitude
     296        *minMag = minInst + 2.5*log10(exptime) + zeropt;
     297
     298        psFree (iter);
     299        return photcode;
     300    }   
     301    psFree (iter);
     302
     303  escape:
     304    photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");
     305    PS_ASSERT (photcode, NULL);
     306       
     307    // give up and use fixed value
     308    *minMag = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MIN.MAG");
     309    return photcode;
     310}
Note: See TracChangeset for help on using the changeset viewer.