IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41290


Ignore:
Timestamp:
Feb 25, 2020, 9:55:36 AM (6 years ago)
Author:
eugene
Message:

handle HSC vs GPC style ghost models. Allow both in ghost model file (code loads GPC and/or HSC ghost models if file contains corresponding elements)

Location:
trunk/psastro/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastro.h

    r40490 r41290  
    6060psastroGhost     *psastroGhostAlloc (void);
    6161bool              psastroLoadGhosts (pmConfig *config);
    62 bool              psastroLoadGhostsHSC (pmConfig *config);
    6362
    6463bool              psastroDataSave (pmConfig *config, psMetadata *stats);
  • trunk/psastro/src/psastroLoadGhosts.c

    r40552 r41290  
    1313# include "psastroInternal.h"
    1414
     15// These are only used locally:
     16bool psastroLoadGhostsGPC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile);
     17bool psastroLoadGhostsHSC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile);
     18
    1519# define GET_2D_POLY(NAME,OUT) \
    1620    md = psMetadataLookupMetadata (&status, ghostModel, NAME); \
     
    4145 */
    4246
    43                    
    44 
    4547bool psastroLoadGhosts (pmConfig *config) {
     48
     49    bool status;
     50
     51    psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
     52
     53    // select the current recipe
     54    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     55    if (!recipe) {
     56        psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
     57        return false;
     58    }
     59
     60    // do we want to mask ghosts?
     61    bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");
     62    if (!REFSTAR_MASK_GHOST) return true;
     63
     64    // choose ghost model file
     65    char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
     66    if (!strcasecmp(ghostFile, "NONE")) return true;
     67
     68    // load ghost model metadata structure
     69    psMetadata *ghostModel = NULL;
     70    if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
     71        psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
     72        return false;
     73    }
     74
     75    // test for items which are used by either the GPC or HSC ghost models:
     76    psMetadataItem *item = NULL;
     77
     78    // test for required HSC ghost model elements
     79    item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC");
     80    if (item) {
     81        status = psastroLoadGhostsHSC (config, recipe, ghostModel, ghostFile);
     82        if (!status) goto escape;
     83    }
     84   
     85    // test for required GPC ghost model elements
     86    item = psMetadataLookup(ghostModel, "GHOST.CENTER.X");
     87    if (item) {
     88        status = psastroLoadGhostsGPC (config, recipe, ghostModel, ghostFile);
     89        if (!status) goto escape;
     90    }
     91   
     92escape:
     93    psFree (ghostModel);
     94    return status;
     95}
     96 
     97bool psastroLoadGhostsGPC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile) {
    4698
    4799    bool status;
     
    57109    psPolynomial1D *innerMajor = NULL;
    58110    psPolynomial1D *innerMinor = NULL;
    59     psMetadata *ghostModel = NULL;
    60 
    61     psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
    62 
    63     // XXX this needs to be camera-dependent
    64     if (0) {
    65       psWarning("Doing the hard coded switch to HSC ghosts still.");
    66       return (psastroLoadGhostsHSC(config));
    67     }
    68 
    69     psWarning("hard coded switch to GPC ghosts.");
    70 
    71     // select the current recipe
    72     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
    73     if (!recipe) {
    74         psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
    75         return false;
    76     }
    77 
    78     bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");
    79     if (!REFSTAR_MASK_GHOST) return true;
    80 
    81    
    82     char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
    83     if (!strcasecmp(ghostFile, "NONE")) return true;
    84 
    85     if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
    86         psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
    87         return false;
    88     }
    89111
    90112    pmFPAview *view = pmFPAviewAlloc (0);
    91 
    92     GET_2D_POLY ("GHOST.CENTER.X", centerX);
    93     GET_2D_POLY ("GHOST.CENTER.Y", centerY);
    94 
    95     GET_1D_POLY ("GHOST.OUTER.MAJOR", outerMajor);
    96     GET_1D_POLY ("GHOST.OUTER.MINOR", outerMinor);
    97     GET_1D_POLY ("GHOST.INNER.MAJOR", innerMajor);
    98     GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor);
    99113
    100114    // select the input astrometry data (also carries the refstars)
     
    106120    pmFPA *fpa = astrom->fpa;
    107121
    108     // really error-out here?  or just skip?
     122    GET_2D_POLY ("GHOST.CENTER.X", centerX);
     123    GET_2D_POLY ("GHOST.CENTER.Y", centerY);
     124
     125    GET_1D_POLY ("GHOST.OUTER.MAJOR", outerMajor);
     126    GET_1D_POLY ("GHOST.OUTER.MINOR", outerMinor);
     127    GET_1D_POLY ("GHOST.INNER.MAJOR", innerMajor);
     128    GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor);
     129
     130    // raise an error if the config is broken
    109131    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
    110         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
     132        psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
    111133        goto escape;
    112134    }
     
    253275    psFree (outerMajor);
    254276    psFree (outerMinor);
    255     psFree (ghostModel);
    256277    psFree (view);
    257278    return true;
     
    264285    psFree (outerMajor);
    265286    psFree (outerMinor);
    266     psFree (ghostModel);
    267287    psFree (view);
    268288    return false;
    269289}
    270 
    271 
    272290 
    273 bool psastroLoadGhostsHSC (pmConfig *config) {
     291// This function adds the ghost mask elements to the ghostReadout->analysis structures.
     292// We return false and raise an error on a config problem.
     293bool psastroLoadGhostsHSC (pmConfig *config, psMetadata *recipe, psMetadata *ghostModel, char *ghostFile) {
     294
    274295  bool status;
    275296  pmChip *chip = NULL;
     
    277298  pmReadout *readout = NULL;
    278299  float zeropt, exptime, MAX_MAG;
    279   psMetadata *ghostModel = NULL;
    280300  psVector *C_terms = NULL;
    281301  psVector *R_terms = NULL;
    282302  float glintPixelScale = 0.0;
    283303 
    284   psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions");
    285  
    286   // select the current recipe
    287   psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
    288   if (!recipe) {
    289     psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
    290     return false;
    291   }
    292  
    293   bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST");
    294   if (!REFSTAR_MASK_GHOST) return true;
    295  
    296   // Load model from file
    297   char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL");
    298   if (!strcasecmp(ghostFile, "NONE")) return true;
    299   psLogMsg("psastro", PS_LOG_INFO, "ghost file %s",ghostFile);
    300   if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
    301     psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
    302     return false;
    303   }
    304  
    305304  // Allocate FPA and refstars
    306305  pmFPAview *view = pmFPAviewAlloc (0);
     306
    307307  // select the input astrometry data (also carries the refstars)
    308308  pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     
    314314 
    315315  char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
     316
    316317  psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC");
    317318  if (!item) {
    318     psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing");
    319     return false;
     319      psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC data missing");
     320      goto escape;
    320321  }
    321322  if (item->type != PS_DATA_METADATA_MULTI) {
    322     psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi");
    323     return false;
     323      psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC not multi");
     324      goto escape;
    324325  }
    325326 
     
    328329  while ((refItem = psListGetAndIncrement(iter))) {
    329330    if (refItem->type != PS_DATA_METADATA) {
    330       psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata");
    331       return false;
     331        psError(PSASTRO_ERR_CONFIG, true, "GHOST.MODEL.HSC entry not metadata");
     332        goto escape;
    332333    }
    333334    char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
    334335    if (!status) {
    335       // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    336336      continue;
    337337    }
     
    343343  }
    344344
    345   // really error-out here?  or just skip?
     345  // if a ghost model is not defined for a filter, skip HSC ghost model for that filter (no error)
    346346  if (!R_terms) {
    347347    psLogMsg ("psastro", PS_LOG_INFO, "failed to find HSC ghost model for filter %s", filter);
    348     goto escape;
    349   }
    350  
    351   // really error-out here?  or just skip?
     348    goto giveup;
     349  }
     350 
     351  // if a filter is defined, but the recipe elements are missing, the config is broken.
    352352  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
    353     psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    354     goto escape;
     353        psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
     354        goto escape;
    355355  }
    356356 
     
    430430         
    431431          if (ghostChip) {
    432             psLogMsg("psastro",PS_LOG_INFO,
    433                      //     psTrace("psastro.ghost",5,
     432            psLogMsg("psastro", PS_LOG_INFO,
    434433                    "   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)",
    435434                    i,refstars->n,
     
    441440                    ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
    442441                    ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
    443           }
    444           else {
    445             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)",
     442          } else {
     443            psTrace("psastro.ghost", 5,
     444                    "   in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)",
    446445                    i,refstars->n,
    447446                    ref->FP->x,ref->FP->y,
     
    451450                    ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
    452451          }                   
    453          
    454          
    455452         
    456453          if (!ghostChip) goto skip;
     
    475472            psFree (ghosts);
    476473          }
    477          
    478474          psArrayAdd (ghosts, 100, ghost);
    479475         
    480476        skip:
    481          
    482477          psFree (ghost);
    483478        }
     
    488483  psastroExtractFreeChipBounds();
    489484 
     485giveup:
    490486  psFree (C_terms);
    491487  psFree (R_terms);
    492   //    psFree (ghostModel);
    493488  psFree (view);
    494489  return true;
     
    497492  psFree (C_terms);
    498493  psFree (R_terms);
    499   //    psFree (ghostModel);
    500494  psFree (view);
    501495  return false;
  • trunk/psastro/src/psastroLoadGlints.c

    r40552 r41290  
    364364              if (star_radius_deg < 0.8831) {
    365365                outer_edge_angle = 0.0;
    366               }
    367               else if (star_radius_deg < 0.9368) {
     366              } else if (star_radius_deg < 0.9368) {
    368367                outer_edge_angle = 46.2985 * sqrt(star_radius_deg - 0.8831);
    369               }
    370               else {
     368              } else {
    371369                outer_edge_angle = -2.67 + 14.3 * star_radius_deg;
    372370              }
    373371              if (star_radius_deg < 0.964) {
    374372                inner_edge_angle = -243.866 * pow(star_radius_deg - 0.932,2) + 2.4636;
    375               }
    376               else {
     373              } else {
    377374                inner_edge_angle = 66.2061 * sqrt(star_radius_deg - 0.9635);
    378375              }
     
    383380              // These define the ends of a single arc in arc-centric coordinates
    384381              double x1 = C - R * cos(inner_edge_angle);
    385               double y1 = R * sin(inner_edge_angle);
     382              double y1 =     R * sin(inner_edge_angle);
    386383              double x2 = C - R * cos(outer_edge_angle);
    387               double y2 = R * sin(outer_edge_angle);
     384              double y2 =     R * sin(outer_edge_angle);
    388385
    389386              // Create the endpoints for the pair of arcs in device coordinates (in millimeters)
     
    414411                      x2s,y2s,x2e,y2e);
    415412                     
    416              
     413              // NOTE: the calculations below appear to expect (x1s, y1s) in millimeters, as mentioned above.
     414              // They are then scaled to camera pixel units using 0.015 millimeters / pixel, and then to
     415              // TPA units using 13.5 pixels / pixel.  I do not know where the (12.78, 57.75) mm offsets
     416              // come from (displacement of reference chip?)
     417               
    417418              tp->x = 13.5 * (y1s / 0.015 + 12.78);
    418419              tp->y = 13.5 * (x1s / -0.015 + 57.74);
     
    420421              x_start->data.F32[0] = fp->x;
    421422              y_start->data.F32[0] = fp->y;
    422               //              x_start->data.F32[0] = tp->x;
    423               //              y_start->data.F32[0] = tp->y;
    424423
    425424              tp->x = 13.5 * (y1e / 0.015 + 12.78);
     
    428427              x_end->data.F32[0]   = fp->x;
    429428              y_end->data.F32[0]   = fp->y;
    430               //              x_end->data.F32[0]   = tp->x;
    431               //              y_end->data.F32[0]   = tp->y;
    432429
    433430              x_start->data.F32[1] = x_end->data.F32[0]; 
     
    441438              x_start->data.F32[2] = fp->x;
    442439              y_start->data.F32[2] = fp->y;
    443               //              x_start->data.F32[2] = tp->x;
    444               //              y_start->data.F32[2] = tp->y;
    445440
    446441              tp->x = 13.5 * (y2e / 0.015 + 12.78);
     
    449444              x_end->data.F32[2]   = fp->x;
    450445              y_end->data.F32[2]   = fp->y;
    451               //              x_end->data.F32[2]   = tp->x;
    452               //              y_end->data.F32[2]   = tp->y;
    453446             
    454447              x_start->data.F32[3] = x_end->data.F32[2]; 
Note: See TracChangeset for help on using the changeset viewer.