IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33329


Ignore:
Timestamp:
Feb 22, 2012, 8:20:17 AM (14 years ago)
Author:
eugene
Message:

adding option to setphot to supply a per-filter offset to the entire system

Location:
branches/eam_branches/ipp-20111122/Ohana/src/uniphot
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h

    r33303 r33329  
    6969ZptTable     *load_zpt_ubercal_nometadata PROTO((char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable));
    7070int           match_flatcorr_to_images    PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable));
     71
     72int           parse_zpt_offsets           PROTO((char *ZPT_OFFSET_FILTERS, char *ZPT_OFFSET_VALUES));
     73float         apply_zpt_offset            PROTO((short code));
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot.c

    r33303 r33329  
    8484  }
    8585
     86  // -zpt-offsets code[,code,etc] value[,value,etc]
     87  // eg: -zpt-offsets g,r,i 0.01,0.02,-0.02
     88  char *ZPT_OFFSETS_FILTERS = NULL;
     89  char *ZPT_OFFSETS_VALUES = NULL;
     90  if ((N = get_argument (argc, argv, "-zpt-offsets"))) {
     91    remove_argument (N, &argc, argv);
     92    ZPT_OFFSETS_FILTERS = strcreate (argv[N]);
     93    remove_argument (N, &argc, argv);
     94    ZPT_OFFSETS_VALUES = strcreate (argv[N]);
     95    remove_argument (N, &argc, argv);
     96   
     97    parse_zpt_offsets (ZPT_OFFSETS_FILTERS, ZPT_OFFSETS_VALUES);
     98  }
     99 
     100
    86101  if (argc != 2) {
    87102    fprintf (stderr, "USAGE: setphot (zptfile) [options]\n");
     
    89104    fprintf (stderr, "    -v : verbose mode\n");
    90105    fprintf (stderr, "    -ubercal : interpret zpt file as a GPC1 ubercal FITS table\n");
     106    fprintf (stderr, "    -no-metadata : assume the ubercal FITS table has the layout defined by Eddie Schlafly in Dec 2011\n");
    91107    fprintf (stderr, "    -update : actually write results to detections tables\n");
    92108    fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c

    r33241 r33329  
    350350  return zpts;
    351351}
     352
     353static short maxCode = 0;
     354static short *zpt_codeval = NULL;
     355static float *zpt_offsets = NULL;
     356static short *zpt_index = NULL;
     357
     358int parse_zpt_offsets (char *ZPT_OFFSET_FILTERS, char *ZPT_OFFSET_VALUES) {
     359
     360  assert (ZPT_OFFSET_FILTERS);
     361  assert (ZPT_OFFSET_VALUES);
     362
     363  char *filters = strcreate(ZPT_OFFSET_FILTERS);
     364  char *values = strcreate(ZPT_OFFSET_VALUES);
     365
     366  char *p1 = filters;
     367  char *p2 = values;
     368
     369  char *filter = NULL;
     370  char *value = NULL;
     371
     372  char *s1 = NULL;
     373  char *s2 = NULL;
     374
     375  // save an array of the zero point offsets and their photcodes
     376  int Ncode = 0;
     377  int NCODE = 8;
     378  ALLOCATE (zpt_codeval, short, NCODE);
     379  ALLOCATE (zpt_offsets, float, NCODE);
     380
     381  while (1) {
     382    filter = strtok_r (p1, ",", &s1);
     383    if (!filter) break;
     384
     385    value  = strtok_r (p2, ",", &s2);
     386    if (!value) {
     387      fprintf (stderr, "ERROR: mismatch between list of photcodes and list of offsets\n");
     388      exit (1);
     389    }
     390
     391    // do something here
     392    PhotCode *code = GetPhotcodebyName (filter);
     393    if (!code) {
     394      fprintf (stderr, "ERROR: unknown photcode %s\n", filter);
     395      exit (1);
     396    }
     397    if (code->type != PHOT_SEC) {
     398      fprintf (stderr, "ERROR: photcode %s is not an average (SEC) type\n", filter);
     399      exit (1);
     400    }
     401
     402    zpt_codeval[Ncode] = code->code;
     403    zpt_offsets[Ncode] = atof(value);
     404    Ncode ++;
     405
     406    if (Ncode >= NCODE) {
     407      NCODE += 8;
     408      REALLOCATE (zpt_codeval, short, NCODE);
     409      REALLOCATE (zpt_offsets, float, NCODE);
     410    }
     411   
     412    maxCode = MAX(code->code, maxCode);
     413
     414    p1 = NULL;
     415    p2 = NULL;
     416  }
     417   
     418  // generate an index to the zpt offsets by the photcode
     419  ALLOCATE (zpt_index, short, maxCode + 1);
     420
     421  int i;
     422  for (i = 0; i < maxCode + 1; i++) {
     423    zpt_index[i] = -1;
     424  }
     425
     426  for (i = 0; i < Ncode; i++) {
     427    short seq = zpt_codeval[i];
     428    if (zpt_index[seq] != -1) {
     429      fprintf (stderr, "duplicate photcode in -zpt-offset list\n");
     430      exit (2);
     431    }
     432    zpt_index[seq] = i;
     433  }
     434  return TRUE;
     435}
     436
     437float apply_zpt_offset (short code) {
     438
     439  if (!zpt_offsets) return 0.0;
     440
     441  // code is a primary photcode (but may be out of range, in which case no correction is supplied)
     442  if (code <= 0) return 0.0;
     443  if (code > maxCode) return 0.0;
     444
     445  short index = zpt_index[code];
     446  if (index == -1) return 0.0;
     447
     448  float offset = zpt_offsets[index];
     449  return offset;
     450}
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_zpts_to_images.c

    r33303 r33329  
    8484      image[Ni].Mcal = SCALE*code[0].C - zpts[Nz].zpt;
    8585    }
     86
     87    // if we have defined zero point offsets, then apply them here
     88    float offset = apply_zpt_offset (code[0].equiv);
     89    assert (isfinite(offset));
     90    image[Ni].Mcal += offset;
     91
    8692    image[Ni].dMcal = zpts[Nz].zpt_err;
    8793    image[Ni].flags &= ~ID_IMAGE_PHOTOM_NOCAL; // clear the NOCAL flag
Note: See TracChangeset for help on using the changeset viewer.