IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40199


Ignore:
Timestamp:
Oct 30, 2017, 2:34:03 PM (9 years ago)
Author:
watersc1
Message:

Semi-clean version of the glint and ghost code, but with those turned off in the config. Still finalizing the magnitude limits.

Location:
branches/czw_branch/20170908
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20170908/ippconfig/hsc/Makefile.am

    r40179 r40199  
    88        format_mef.config \
    99        format_cmf.config \
     10        ghost.model.mdc \
    1011        ppImage.config \
    1112        ppMerge.config \
  • branches/czw_branch/20170908/ippconfig/hsc/ghost.model.mdc

    r40179 r40199  
     1
     2
    13# The R_TERMS polynomials have been converted from um units to mm units to be consistent with C_TERMS polynomials.
    24
    35GHOST.MODEL.HSC MULTI
    4   GHOST.MODEL.HSC       METADATA
     6GHOST.MODEL.HSC METADATA
    57    FILTER      STR     g
    68    @C_TERMS    F32     3.86129097e-04  -4.56480396e+02  5.94514717e+02  -8.20984903e+03  4.35455723e+04  -1.19834803e+05  1.60789252e+05  -8.66581086e+04    # a comment
    79    @R_TERMS    F32     2.80257250e+00  -1.14163334e+01  6.25378363e+02  -6.59305008e+03  3.21678893e+04  -7.68658356e+04  8.71449290e+04  -3.66203193e+04  # a comment
    8     LIMIT       F32     12.0
    910    SCALE       F32     3.49794238e-06
    1011# WRONG ORDER
    1112#    @C_TERMS   F32     -8.66581086e+04  1.60789252e+05  -1.19834803e+05  4.35455723e+04  -8.20984903e+03  5.94514717e+02  -4.56480396e+02  3.86129097e-04
    1213#    @R_TERMS   F32     -3.66203193e+04  8.71449290e+04  -7.68658356e+04  3.21678893e+04  -6.59305008e+03  6.25378363e+02  -1.14163334e+01  2.80257250e+00
    13   END
    14   GHOST.MODEL.HSC       METADATA
     14END
     15GHOST.MODEL.HSC METADATA
    1516    FILTER      STR     r
    1617    @C_TERMS    F32     1.10217740e-03  -4.13994264e+02  -1.08162329e+02  -1.75333116e+02  -1.44358813e+03  7.03878935e+03  -1.55470840e+04  1.05167578e+04  # a comment
    1718    @R_TERMS    F32     7.84632263e+00  -1.34007061e-02  9.57272709e+01   -9.45421731e+02   5.64254906e+03  -1.97396910e+04  3.55382290e+04  -2.46004825e+04 # a comment
    18     LIMIT       F32     11.5
    1919    SCALE       F32     3.49794238e-06
    2020    # @C_TERMS for original r 8.14947896e+03  -1.24163720e+04  5.41143508e+03  -1.02024286e+03  -2.39667209e+02  -1.00805716e+02  -4.16757016e+02  -1.48799186e-03
     
    2323#    @C_TERMS   F32     1.05167578e+04  -1.55470840e+04  7.03878935e+03  -1.44358813e+03  -1.75333116e+02  -1.08162329e+02  -4.13994264e+02  1.10217740e-03
    2424#    @R_TERMS   F32     -2.46004825e+04  3.55382290e+04  -1.97396910e+04  5.64254906e+03  -9.45421731e+02   9.57272709e+01  -1.34007061e-02  7.84632263e+00
    25   END
    26   GHOST.MODEL.HSC       METADATA
     25END
     26GHOST.MODEL.HSC METADATA
    2727    FILTER      STR     i
    2828    @C_TERMS    F32     -3.95203567e-03  -4.55641159e+02  5.73358984e+02  -8.75512267e+03  5.43205903e+04  -1.74052246e+05  2.70933733e+05  -1.66554502e+05  # a comment
    2929    @R_TERMS    F32     2.24351724e+00   -1.59383063e+01  8.56547254e+02  -1.09461298e+04  6.86646484e+04  -2.19342516e+05  3.46712176e+05  -2.15706075e+05  # a comment
    30     LIMIT       F32     11.0
    3130    SCALE       F32     3.49794238e-06
    3231    # @C_TERMS for original i 7.09135701e+03  -1.08899009e+04  4.53311864e+03  -7.45070274e+02  -2.86196488e+02  -9.58537252e+01  -4.15997892e+02  -2.10038501e-03
     
    3534#    @C_TERMS   F32     -1.66554502e+05  2.70933733e+05  -1.74052246e+05  5.43205903e+04  -8.75512267e+03  5.73358984e+02  -4.55641159e+02  -3.95203567e-03
    3635#    @R_TERMS   F32     -2.15706075e+05  3.46712176e+05  -2.19342516e+05  6.86646484e+04  -1.09461298e+04  8.56547254e+02  -1.59383063e+01   2.24351724e+00
    37   END
    38   GHOST.MODEL.HSC       METADATA
     36END
     37GHOST.MODEL.HSC METADATA
    3938    FILTER      STR     z
    4039    @C_TERMS    F32     -1.79546522e-03  -4.13201008e+02  -1.08898155e+02  -1.51535018e+02  -1.51139264e+03   6.94362981e+03  -1.47396976e+04   9.59579373e+03  # a comment
    4140    @R_TERMS    F32     7.39449641e+00    7.28959803e-01   1.06569049e+02  -1.18036333e+03   7.42160510e+03  -2.62797780e+04   4.70124953e+04  -3.23514338e+04  # a comment
    42     LIMIT       F32     11.0
    4341    SCALE       F32     3.49794238e-06
    4442# WRONG ORDER
    4543#    @C_TERMS   F32     9.59579373e+03  -1.47396976e+04  6.94362981e+03  -1.51139264e+03  -1.51535018e+02  -1.08898155e+02  -4.13201008e+02  -1.79546522e-03
    4644#    @R_TERMS   F32     -3.23514338e+04  4.70124953e+04  -2.62797780e+04  7.42160510e+03  -1.18036333e+03  1.06569049e+02  7.28959803e-01  7.39449641e+00
    47   END
    48   GHOST.MODEL.HSC       METADATA
     45END
     46GHOST.MODEL.HSC METADATA
    4947    FILTER      STR     y
    5048    @C_TERMS    F32     -2.04774887e-03  -4.50571358e+02  3.73884700e+02  -6.38727141e+03  4.28067607e+04  -1.47306815e+05  2.42465240e+05  -1.56137979e+05  # a comment
    5149    @R_TERMS    F32     2.04967838e+00   -8.92675213e+00  6.03954493e+02  -7.97354793e+03  5.32635002e+04  -1.79071587e+05  2.94475198e+05  -1.88924528e+05  # a comment
    52     LIMIT       F32     11.0
    5350    SCALE       F32     3.49794238e-06
    5451# WRONG ORDER
    5552#    @C_TERMS   F32     -1.56137979e+05  2.42465240e+05  -1.47306815e+05  4.28067607e+04  -6.38727141e+03  3.73884700e+02  -4.50571358e+02  -2.04774887e-03
    5653#    @R_TERMS   F32     -1.88924528e+05  2.94475198e+05  -1.79071587e+05  5.32635002e+04  -7.97354793e+03  6.03954493e+02  -8.92675213e+00  2.04967838e+00
    57   END
    58   GHOST.MODEL.HSC       METADATA
     54END
     55GHOST.MODEL.HSC METADATA
    5956    FILTER      STR     NB816
    6057    @C_TERMS    F32     -3.52735759e-03  -4.54174618e+02  5.11013724e+02  -8.05597593e+03  5.11417991e+04  -1.67422366e+05  2.65225596e+05  -1.65501517e+05  # a comment
    6158    @R_TERMS    F32     2.17954931e+00   -1.39611991e+01  7.88077371e+02  -1.01750660e+04  6.49121728e+04  -2.10323885e+05  3.36261570e+05  -2.11111649e+05  # a comment
    62     LIMIT       F32     11.0
    6359    SCALE       F32     3.49794238e-06
    6460# WRONG ORDER
    6561#    @C_TERMS   F32     -1.65501517e+05  2.65225596e+05  -1.67422366e+05  5.11417991e+04  -8.05597593e+03  5.11013724e+02  -4.54174618e+02  -3.52735759e-03
    6662#    @R_TERMS   F32     -2.11111649e+05  3.36261570e+05  -2.10323885e+05  6.49121728e+04  -1.01750660e+04  7.88077371e+02  -1.39611991e+01  2.17954931e+00
    67   END
    68   GHOST.MODEL.HSC       METADATA
     63END
     64GHOST.MODEL.HSC METADATA
    6965    FILTER      STR     NB921
    7066    @C_TERMS    F32     -2.99761113e-03  -4.52301392e+02  4.49346634e+02  -7.38661211e+03  4.83455130e+04  -1.62550708e+05  2.63017929e+05  -1.66995347e+05  # a comment
    7167    @R_TERMS    F32     2.11290612e+00   -1.15228777e+01  7.02729746e+02  -9.20923423e+03  6.01493518e+04  -1.98625679e+05  3.22255104e+05  -2.04640222e+05  # a comment
    72     LIMIT       F32     11.0
    7368    SCALE       F32     3.49794238e-06
    7469# WRONG ORDER
    7570#    @C_TERMS   F32     -1.66995347e+05  2.63017929e+05  -1.62550708e+05  4.83455130e+04  -7.38661211e+03  4.49346634e+02  -4.52301392e+02  -2.99761113e-03
    7671#    @R_TERMS   F32     -2.04640222e+05  3.22255104e+05  -1.98625679e+05  6.01493518e+04  -9.20923423e+03  7.02729746e+02  -1.15228777e+01  2.11290612e+00
    77   END
    7872END
     73
  • branches/czw_branch/20170908/ippconfig/hsc/psastro.config

    r40179 r40199  
    1313PHOTCODE.DATA METADATA
    1414  FILTER   STR g
    15   ZEROPT   F32 26.75
     15#  ZEROPT   F32 26.75
     16  ZEROPT   F32 26.70
    1617  PHOTCODE STR g
    17   GHOST_MAX_MAG                   F32 -16.5
     18  GHOST_MAX_MAG                   F32 -22.0
    1819END
    1920PHOTCODE.DATA METADATA
    2021  FILTER   STR r
    21   ZEROPT   F32 27.1
     22#  ZEROPT   F32 27.1
     23  ZEROPT   F32 27.05
    2224  PHOTCODE STR r
    23   GHOST_MAX_MAG                   F32 -20.0
     25  GHOST_MAX_MAG                   F32 -22.5
    2426END
    2527PHOTCODE.DATA METADATA
    2628  FILTER   STR i
    27   ZEROPT   F32 27.0
     29#  ZEROPT   F32 27.0
     30  ZEROPT   F32 26.8
    2831  PHOTCODE STR i
    29   GHOST_MAX_MAG                   F32 -25.0
     32  GHOST_MAX_MAG                   F32 -23.0
    3033END
    3134PHOTCODE.DATA METADATA
    3235  FILTER   STR z
    33   ZEROPT   F32 26.2
     36#  ZEROPT   F32 26.2
     37  ZEROPT   F32 26.0
    3438  PHOTCODE STR z
    35   GHOST_MAX_MAG                   F32 -25.0
     39  GHOST_MAX_MAG                   F32 -23.0
    3640END
    3741PHOTCODE.DATA METADATA
    3842  FILTER   STR y
    39   ZEROPT   F32 25.1
     43#  ZEROPT   F32 25.1
     44  ZEROPT   F32 25.55
    4045  PHOTCODE STR y
    41   GHOST_MAX_MAG                   F32 -25.0
     46  GHOST_MAX_MAG                   F32 -23.0
    4247END
    4348PHOTCODE.DATA METADATA
    4449  FILTER   STR NB816
    45   ZEROPT   F32 26.0
     50#  ZEROPT   F32 26.0
     51  ZEROPT   F32 23.75
    4652  PHOTCODE STR i
    47   GHOST_MAX_MAG                   F32 -25.0
     53  GHOST_MAX_MAG                   F32 -23.0
    4854END
    4955PHOTCODE.DATA METADATA
    5056  FILTER   STR NB921
    51   ZEROPT   F32 25.4
     57#  ZEROPT   F32 25.4
     58  ZEROPT   F32 23.95
    5259  PHOTCODE STR z
    53   GHOST_MAX_MAG                   F32 -25.0
     60  GHOST_MAX_MAG                   F32 -23.0
    5461END
    5562
     
    148155REFSTAR_MASK_BLEED_MAG_SLOPE_Y  F32   0.425
    149156
    150 REFSTAR_MASK_GLINTS             BOOL TRUE
     157REFSTAR_COUNT_GHOSTS            BOOL TRUE
     158#REFSTAR_MASK_GHOST              BOOL TRUE
     159REFSTAR_MASK_GHOST               BOOL FALSE
     160GHOST_MODEL                     STR  hsc/ghost.model.mdc
     161
     162
     163#REFSTAR_MASK_GLINTS            BOOL TRUE
     164REFSTAR_MASK_GLINTS             BOOL FALSE
    151165GLINT_MAX_MAG                   F32  -19
    152166GLINT_LENGTH_MAG_SLOPE          F32  0.0
  • branches/czw_branch/20170908/psastro/src/psastro.h

    r39926 r40199  
    6060psastroGhost     *psastroGhostAlloc (void);
    6161bool              psastroLoadGhosts (pmConfig *config);
     62bool              psastroLoadGhostsHSC (pmConfig *config);
    6263
    6364bool              psastroDataSave (pmConfig *config, psMetadata *stats);
  • branches/czw_branch/20170908/psastro/src/psastroLoadGhosts.c

    r40181 r40199  
    6161    psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
    6262
     63    if (1) {
     64      psWarning("Doing the hard coded switch to HSC ghosts still.");
     65      return (psastroLoadGhostsHSC(config));
     66    }
     67
    6368    // select the current recipe
    6469    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     
    7176    if (!REFSTAR_MASK_GHOST) return true;
    7277
     78   
    7379    char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
    7480    if (!strcasecmp(ghostFile, "NONE")) return true;
     
    264270bool psastroLoadGhostsHSC (pmConfig *config) {
    265271  bool status;
    266     pmChip *chip = NULL;
    267     pmCell *cell = NULL;
    268     pmReadout *readout = NULL;
    269     //    float zeropt, exptime, MAX_MAG;
    270     float MAX_MAG;
    271     psMetadata *ghostModel = NULL;
    272     psVector *C_terms;
    273     psVector *R_terms;
    274     float glintPixelScale;
     272  pmChip *chip = NULL;
     273  pmCell *cell = NULL;
     274  pmReadout *readout = NULL;
     275  float zeropt, exptime, MAX_MAG;
     276  psMetadata *ghostModel = NULL;
     277  psVector *C_terms;
     278  psVector *R_terms;
     279  float glintPixelScale;
     280 
     281  psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
     282 
     283  // select the current recipe
     284  psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     285  if (!recipe) {
     286    psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
     287    return false;
     288  }
     289 
     290  bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");
     291  if (!REFSTAR_MASK_GHOST) return true;
     292 
     293  // Load model from file
     294  char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
     295  if (!strcasecmp(ghostFile, "NONE")) return true;
     296  psLogMsg("psastro", PS_LOG_INFO, "ghost file %s",ghostFile);
     297  if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
     298    psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
     299    return false;
     300  }
     301 
     302  // Allocate FPA and refstars
     303  pmFPAview *view = pmFPAviewAlloc (0);
     304  // select the input astrometry data (also carries the refstars)
     305  pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     306  if (!astrom) {
     307    psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
     308    goto escape;
     309  }
     310  pmFPA *fpa = astrom->fpa;
     311 
     312  char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
     313  psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC");
     314  if (!item) {
     315    psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing");
     316    return false;
     317  }
     318  if (item->type != PS_DATA_METADATA_MULTI) {
     319    psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi");
     320    return false;
     321  }
     322 
     323  psListIterator *iter = psListIteratorAlloc(item->data.list,PS_LIST_HEAD, false);
     324  psMetadataItem *refItem = NULL;
     325  while ((refItem = psListGetAndIncrement(iter))) {
     326    if (refItem->type != PS_DATA_METADATA) {
     327      psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata");
     328      return false;
     329    }
     330    char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
     331    if (!status) {
     332      // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     333      continue;
     334    }
     335    if (strcmp(refFilter, filter)) continue;
    275336   
    276     psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
    277 
    278     // select the current recipe
    279     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
    280     if (!recipe) {
    281         psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
    282         return false;
    283     }
    284 
    285     bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");
    286     if (!REFSTAR_MASK_GHOST) return true;
    287 
    288     // Load model from file
    289     char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
    290     if (!strcasecmp(ghostFile, "NONE")) return true;
    291 
    292     if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
    293         psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
    294         return false;
    295     }
    296 
    297     // Allocate FPA and refstars
    298     pmFPAview *view = pmFPAviewAlloc (0);
    299     // select the input astrometry data (also carries the refstars)
    300     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
    301     if (!astrom) {
    302         psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
    303         goto escape;
    304     }
    305     pmFPA *fpa = astrom->fpa;
    306 
    307     char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
    308     psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC");
    309     if (!item) {
    310       psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing");
    311       return false;
    312     }
    313     if (item->type != PS_DATA_METADATA_MULTI) {
    314       psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi");
    315       return false;
    316     }
    317     psListIterator *iter = psListIteratorAlloc(item->data.list,PS_LIST_HEAD, false);
    318     psMetadataItem *refItem = NULL;
    319     while ((refItem = psListGetAndIncrement(iter))) {
    320       if (refItem->type != PS_DATA_METADATA) {
    321         psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata");
    322         return false;
     337    C_terms = psMetadataLookupPtr(&status, refItem->data.md, "C_TERMS");
     338    R_terms = psMetadataLookupPtr(&status, refItem->data.md, "R_TERMS");
     339    glintPixelScale = psMetadataLookupF32(&status, refItem->data.md, "SCALE");
     340  }
     341 
     342  // really error-out here?  or just skip?
     343  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
     344    psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
     345    goto escape;
     346  }
     347 
     348  // recipe values are given in instrumental magnitudes
     349  // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
     350  float MagOffset = zeropt + 2.5*log10(exptime);
     351  MAX_MAG += MagOffset;
     352 
     353  // this loop selects the matched stars for all chips
     354  while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
     355    psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     356    if (!chip->process || !chip->file_exists) { continue; }
     357    if (!chip->fromFPA) { continue; }
     358   
     359    while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
     360      psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     361      if (!cell->process || !cell->file_exists) { continue; }
     362     
     363      // process each of the readouts
     364      while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
     365        if (! readout->data_exists) { continue; }
     366       
     367        // select the raw objects for this readout (loaded in psastroChooseRefstars.c)
     368        // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c:
     369        // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only
     370        psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");
     371        if (refstars == NULL) { continue; }
     372       
     373        // identify the bright stars of interest
     374        for (int i = 0; i < refstars->n; i++) {
     375          pmAstromObj *ref = refstars->data[i];
     376          if (ref->Mag > MAX_MAG) continue;
     377         
     378          psastroGhost *ghost = psastroGhostAlloc ();
     379         
     380          double R_TPA  = sqrt(pow(ref->TP->y,2) + pow(ref->TP->x,2));
     381          double theta0 = atan2(ref->TP->y,ref->TP->x);
     382          double star_radius_deg = R_TPA * glintPixelScale;
     383         
     384          //      psTrace("psastro.ghost",5,
     385          psLogMsg("psastro",PS_LOG_INFO,
     386                  "Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g) TPA: (%f %f) R: %f %f %f",
     387                  i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI,ref->TP->x,ref->TP->y,
     388                  R_TPA,star_radius_deg,theta0);
     389         
     390          if (star_radius_deg > 0.5) { continue; }
     391         
     392          // Calculate expected position.
     393          double C = C_terms->data.F32[0] + C_terms->data.F32[1] * star_radius_deg + C_terms->data.F32[2] * pow(star_radius_deg,2) +
     394            C_terms->data.F32[3] * pow(star_radius_deg,3) + C_terms->data.F32[4] * pow(star_radius_deg,4) +
     395            C_terms->data.F32[5] * pow(star_radius_deg,5) + C_terms->data.F32[6] * pow(star_radius_deg,6) +
     396            C_terms->data.F32[7] * pow(star_radius_deg,7);
     397          double R = R_terms->data.F32[0] + R_terms->data.F32[1] * star_radius_deg + R_terms->data.F32[2] * pow(star_radius_deg,2) +
     398            R_terms->data.F32[3] * pow(star_radius_deg,3) + R_terms->data.F32[4] * pow(star_radius_deg,4) +
     399            R_terms->data.F32[5] * pow(star_radius_deg,5) + R_terms->data.F32[6] * pow(star_radius_deg,6) +
     400            R_terms->data.F32[7] * pow(star_radius_deg,7);
     401          R = R / 0.015;
     402         
     403          psPlane *fp = psPlaneAlloc();
     404          psPlane *tp = psPlaneAlloc();
     405         
     406          tp->x = 13.5 * (C * cos(theta0) / 0.015 + 12.78);
     407          tp->y = 13.5 * (C * sin(theta0) / 0.015 + 57.74);
     408          psPlaneTransformApply(fp,fpa->fromTPA, tp);
     409         
     410          ghost->srcFP->x = ref->FP->x;
     411          ghost->srcFP->y = ref->FP->y;
     412          ghost->FP->x    = fp->x;
     413          ghost->FP->y    = fp->y;
     414         
     415          ghost->inner.major = 0.0;
     416          ghost->inner.minor = 0.0;
     417          ghost->outer.major = R;
     418          ghost->outer.minor = R;
     419         
     420          pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
     421         
     422          if (ghostChip) {
     423            psLogMsg("psastro",PS_LOG_INFO,
     424                     //     psTrace("psastro.ghost",5,
     425                    "   in ghost: %d/%ld: ref: (%f,%f) or (%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)",
     426                    i,refstars->n,
     427                    ref->FP->x,ref->FP->y,
     428                    psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"),
     429                    ghost->FP->x,ghost->FP->y,
     430                    ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"),
     431                    C,
     432                    ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
     433                    ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
     434          }
     435          else {
     436            psTrace("psastro.ghost",5,"   in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)",
     437                    i,refstars->n,
     438                    ref->FP->x,ref->FP->y,
     439                    ghost->FP->x,ghost->FP->y,
     440                    ghost->chip->x,ghost->chip->y,"NONE",
     441                    ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
     442                    ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
     443          }                   
     444         
     445         
     446         
     447          if (!ghostChip) goto skip;
     448          if (!ghostChip->cells) goto skip;
     449          if (!ghostChip->cells->n) goto skip;
     450         
     451         
     452          pmCell *ghostCell = ghostChip->cells->data[0];
     453          if (!ghostCell) goto skip;
     454          if (!ghostCell->readouts) goto skip;
     455          if (!ghostCell->readouts->n) goto skip;
     456          pmReadout *ghostReadout = ghostCell->readouts->data[0];
     457          if (!ghostReadout) goto skip;
     458         
     459          psArray *ghosts = psMetadataLookupPtr (&status, ghostReadout->analysis, "PSASTRO.GHOSTS");
     460          if (ghosts == NULL) {
     461            ghosts = psArrayAllocEmpty (100);
     462            if (!psMetadataAdd (ghostReadout->analysis, PS_LIST_TAIL, "PSASTRO.GHOSTS", PS_DATA_ARRAY, "astrometry matches", ghosts)) {
     463              psError(PSASTRO_ERR_CONFIG, false, "failure to add ghosts to readout");
     464              goto escape;
     465            }
     466            psFree (ghosts);
     467          }
     468         
     469          psArrayAdd (ghosts, 100, ghost);
     470         
     471        skip:
     472         
     473          psFree (ghost);
     474        }
    323475      }
    324       char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
    325       if (!status) {
    326         // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    327         continue;
    328       }
    329       if (strcmp(refFilter, filter)) continue;
    330 
    331       C_terms = psMetadataLookupPtr(&status, refItem->data.md, "C_TERMS");
    332       R_terms = psMetadataLookupPtr(&status, refItem->data.md, "R_TERMS");
    333       MAX_MAG = psMetadataLookupF32(&status, refItem->data.md, "LIMIT");
    334       glintPixelScale = psMetadataLookupF32(&status, refItem->data.md, "SCALE");
    335     }
    336 
    337     // really error-out here?  or just skip?
    338     //    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
    339     //        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    340     //  goto escape;
    341     //    }
    342    
    343     // recipe values are given in instrumental magnitudes
    344     // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
    345     //    float MagOffset = zeropt + 2.5*log10(exptime);
    346     //    MAX_MAG += MagOffset;
    347 
    348     // this loop selects the matched stars for all chips
    349     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
    350         psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    351         if (!chip->process || !chip->file_exists) { continue; }
    352         if (!chip->fromFPA) { continue; }
    353 
    354         while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    355             psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    356             if (!cell->process || !cell->file_exists) { continue; }
    357 
    358             // process each of the readouts
    359             while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
    360                 if (! readout->data_exists) { continue; }
    361 
    362                 // select the raw objects for this readout (loaded in psastroChooseRefstars.c)
    363                 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c:
    364                 // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only
    365                 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");
    366                 if (refstars == NULL) { continue; }
    367 
    368                 // identify the bright stars of interest
    369                 for (int i = 0; i < refstars->n; i++) {
    370                     pmAstromObj *ref = refstars->data[i];
    371                     psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g) TPA: (%f %f)",
    372                             i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI,ref->TP->x,ref->TP->y);
    373                     if (ref->Mag > MAX_MAG) continue;
    374                    
    375                     psastroGhost *ghost = psastroGhostAlloc ();
    376 
    377                     double R_TPA  = sqrt(pow(ref->TP->y,2) + pow(ref->TP->x,2));
    378                     double theta0 = atan2(ref->TP->y,ref->TP->x);
    379                     double star_radius_deg = R_TPA * glintPixelScale;
    380                     if (star_radius_deg > 0.5) { continue; }
    381 
    382                     // Calculate expected position.
    383                     double C = C_terms->data.F32[0] + C_terms->data.F32[1] * star_radius_deg + C_terms->data.F32[2] * pow(star_radius_deg,2) +
    384                       C_terms->data.F32[3] * pow(star_radius_deg,3) + C_terms->data.F32[4] * pow(star_radius_deg,4) +
    385                       C_terms->data.F32[5] * pow(star_radius_deg,5) + C_terms->data.F32[6] * pow(star_radius_deg,6) +
    386                       C_terms->data.F32[7] * pow(star_radius_deg,7);
    387                     double R = R_terms->data.F32[0] + R_terms->data.F32[1] * star_radius_deg + R_terms->data.F32[2] * pow(star_radius_deg,2) +
    388                       R_terms->data.F32[3] * pow(star_radius_deg,3) + R_terms->data.F32[4] * pow(star_radius_deg,4) +
    389                       R_terms->data.F32[5] * pow(star_radius_deg,5) + R_terms->data.F32[6] * pow(star_radius_deg,6) +
    390                       R_terms->data.F32[7] * pow(star_radius_deg,7);
    391                     R = 13.5 * (R / 0.015); // Convert to TPA units.
    392 
    393                     psPlane *fp = psPlaneAlloc();
    394                     psPlane *tp = psPlaneAlloc();
    395 
    396                     tp->x = 13.5 * (C * cos(theta0) / 0.015 + 12.78);
    397                     tp->y = 13.5 * (C * sin(theta0) / 0.015 + 57.74);
    398                     psPlaneTransformApply(fp,fpa->fromTPA, tp);
    399                    
    400                     ghost->srcFP->x = ref->FP->x;
    401                     ghost->srcFP->y = ref->FP->y;
    402                     ghost->FP->x    = fp->x;
    403                     ghost->FP->y    = fp->y;
    404 
    405                     ghost->inner.major = 0.0;
    406                     ghost->inner.minor = 0.0;
    407                     ghost->outer.major = R;
    408                     ghost->outer.minor = R;
    409                    
    410                     pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
    411                    
    412 
    413                    
    414                     if (ghostChip) {
    415                       psTrace("psastro.ghost",5,"   in ghost: %d/%ld: ref: (%f,%f) or (%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)",
    416                               i,refstars->n,
    417                               ref->FP->x,ref->FP->y,
    418                               psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"),
    419                               ghost->FP->x,ghost->FP->y,
    420                               ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"),
    421                               C,
    422                               ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
    423                               ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
    424 /*                    psWarning("   GHOST_DATA: %d/%ld: ref: (%f,%f) or (%f,%f,%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", */
    425 /*                            i,refstars->n, */
    426 /*                            ref->FP->x,ref->FP->y, */
    427 /*                            ref_chip_x,ref_chip_y,psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), */
    428 /*                            ghost->FP->x,ghost->FP->y, */
    429 /*                            ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"), */
    430 /*                            rSrc, */
    431 /*                            ghost->inner.major,ghost->inner.minor,ghost->inner.theta, */
    432 /*                            ghost->outer.major,ghost->outer.minor,ghost->outer.theta); */
    433                     }
    434                     else {
    435                       psTrace("psastro.ghost",5,"   in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)",
    436                               i,refstars->n,
    437                               ref->FP->x,ref->FP->y,
    438                               ghost->FP->x,ghost->FP->y,
    439                               ghost->chip->x,ghost->chip->y,"NONE",
    440                               ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
    441                               ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
    442                     }                 
    443                      
    444 
    445                            
    446                     if (!ghostChip) goto skip;
    447                     if (!ghostChip->cells) goto skip;
    448                     if (!ghostChip->cells->n) goto skip;
    449 
    450                    
    451                     pmCell *ghostCell = ghostChip->cells->data[0];
    452                     if (!ghostCell) goto skip;
    453                     if (!ghostCell->readouts) goto skip;
    454                     if (!ghostCell->readouts->n) goto skip;
    455                     pmReadout *ghostReadout = ghostCell->readouts->data[0];
    456                     if (!ghostReadout) goto skip;
    457 
    458                     psArray *ghosts = psMetadataLookupPtr (&status, ghostReadout->analysis, "PSASTRO.GHOSTS");
    459                     if (ghosts == NULL) {
    460                         ghosts = psArrayAllocEmpty (100);
    461                         if (!psMetadataAdd (ghostReadout->analysis, PS_LIST_TAIL, "PSASTRO.GHOSTS", PS_DATA_ARRAY, "astrometry matches", ghosts)) {
    462                           psError(PSASTRO_ERR_CONFIG, false, "failure to add ghosts to readout");
    463                           goto escape;
    464                         }
    465                         psFree (ghosts);
    466                     }
    467 
    468                     psArrayAdd (ghosts, 100, ghost);
    469 
    470                 skip:
    471                    
    472                     psFree (ghost);
    473                 }
    474             }
    475         }
    476     }
    477 
    478     psastroExtractFreeChipBounds();
    479 
    480     psFree (C_terms);
    481     psFree (R_terms);
    482     psFree (ghostModel);
    483     psFree (view);
    484     return true;
    485 
    486 escape:
    487     psFree (C_terms);
    488     psFree (R_terms);
    489     psFree (ghostModel);
    490     psFree (view);
    491     return false;
     476    }
     477  }
     478 
     479  psastroExtractFreeChipBounds();
     480 
     481  psFree (C_terms);
     482  psFree (R_terms);
     483  //    psFree (ghostModel);
     484  psFree (view);
     485  return true;
     486 
     487 escape:
     488  psFree (C_terms);
     489  psFree (R_terms);
     490  //    psFree (ghostModel);
     491  psFree (view);
     492  return false;
    492493}
Note: See TracChangeset for help on using the changeset viewer.