IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40490


Ignore:
Timestamp:
Jun 27, 2018, 4:11:05 PM (8 years ago)
Author:
eugene
Message:

add options and elements for HSC ghosts and glints

Location:
trunk/psastro
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro

  • trunk/psastro/src/psastro.h

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

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

    r24645 r40490  
    4444    double GLINT_LENGTH_MAG_ZERO = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_ZERO");
    4545    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
     46    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
     47   
    4648
    4749    // select the set of glint regions (GLINT.REGION is a MULTI of METADATA items)
     
    9597        psProject (star->TP, star->sky, fpa->toSky);
    9698        psPlaneTransformApply (star->FP, fpa->fromTPA, star->TP);
    97         fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f\n", star->Mag, star->FP->x, star->FP->y);
     99        fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f (%f %f) %8.1f %8.1f\n", star->Mag, star->FP->x, star->FP->y, star->sky->r * PS_DEG_RAD, star->sky->d * PS_DEG_RAD, star->TP->x,star->TP->y);
    98100
    99101        // find the GLINT.REGION this star lands in (if any)
     
    298300                }
    299301            }
     302            if (!strcasecmp(glintType, "HSC")) {
     303              // It's inefficient to keep looking these up.
     304              double GLINT_RADIUS_INNER = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.RADIUS.INNER");
     305              double GLINT_RADIUS_OUTER = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.RADIUS.OUTER");
     306             
     307              // double R_FPA = sqrt(pow(star->FP->y,2) + pow(star->FP->x,2));
     308              double R_FPA =  sqrt(pow(star->TP->y,2) + pow(star->TP->x,2));
     309              //              R_FPA *= 1.30;
     310              if (R_FPA < GLINT_RADIUS_INNER) { continue; }
     311              if (R_FPA > GLINT_RADIUS_OUTER) { continue; }
     312              psTrace("psastro.masks",4,"HSC_GLINT_STARS: %f %f %f\n",
     313                      //                      star->FP->x,star->FP->y,star->Mag);
     314                      star->TP->x,star->TP->y,star->Mag);
     315              psVector *C_terms;
     316              psVector *R_terms;
     317              double scale_factor = 1.0;
     318             
     319              char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
     320              psMetadataItem *item = psMetadataLookup(glintItem->data.md, "GLINT.FILTER.TERM");
     321              if (!item) {
     322                psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM data missing");
     323                return false;
     324              }
     325              if (item->type != PS_DATA_METADATA_MULTI) {
     326                psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM not multi");
     327                return false;
     328              }
     329              psListIterator *iter = psListIteratorAlloc(item->data.list,PS_LIST_HEAD, false);
     330              psMetadataItem *refItem = NULL;
     331              while ((refItem = psListGetAndIncrement(iter))) {
     332                if (refItem->type != PS_DATA_METADATA) {
     333                  psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM entry not metadata");
     334                  return false;
     335                }
     336                char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
     337                if (!status) {
     338                  // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     339                  continue;
     340                }
     341                if (strcmp(refFilter, filter)) continue;
     342
     343                C_terms = psMetadataLookupPtr(&status, refItem->data.md, "C_TERMS");
     344                R_terms = psMetadataLookupPtr(&status, refItem->data.md, "R_TERMS");
     345                scale_factor = psMetadataLookupF32(&status, refItem->data.md, "FACTOR");
     346                double limit = psMetadataLookupF32(&status, refItem->data.md, "LIMIT");
     347                limit += MagOffset;
     348                if (star->Mag > limit) { continue; }
     349              }
     350              // check
     351              double glintPixelScale = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.PIXEL.SCALE");
     352              //              psMetadata *GLINT_PARAMETER_SET = psMetadataLookupPtr(&status, glintItem->data.md, "GLINT.FILTER.TERM");
     353              //              psMetadata *GLINT_PARAMETERS    = psMetadataLookupPtr(&status, GLINT_PARAMETER_SET, filter);
     354             
     355
     356              //              double theta0 = atan2(star->FP->y,star->FP->x);
     357              double theta0 = atan2(star->TP->y,star->TP->x);
     358              double star_radius_deg = R_FPA * glintPixelScale;
     359
     360              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);
     361              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);
     362
     363              double inner_edge_angle, outer_edge_angle;
     364              if (star_radius_deg < 0.8831) {
     365                outer_edge_angle = 0.0;
     366              }
     367              else if (star_radius_deg < 0.9368) {
     368                outer_edge_angle = 46.2985 * sqrt(star_radius_deg - 0.8831);
     369              }
     370              else {
     371                outer_edge_angle = -2.67 + 14.3 * star_radius_deg;
     372              }
     373              if (star_radius_deg < 0.964) {
     374                inner_edge_angle = -243.866 * pow(star_radius_deg - 0.932,2) + 2.4636;
     375              }
     376              else {
     377                inner_edge_angle = 66.2061 * sqrt(star_radius_deg - 0.9635);
     378              }
     379
     380              inner_edge_angle = inner_edge_angle * PS_RAD_DEG;
     381              outer_edge_angle = outer_edge_angle * PS_RAD_DEG;
     382             
     383              // These define the ends of a single arc in arc-centric coordinates
     384              double x1 = C - R * cos(inner_edge_angle);
     385              double y1 = R * sin(inner_edge_angle);
     386              double x2 = C - R * cos(outer_edge_angle);
     387              double y2 = R * sin(outer_edge_angle);
     388
     389              // Create the endpoints for the pair of arcs in device coordinates (in millimeters)
     390              double theta1 = theta0 + M_PI / 2.0;
     391              double x1s = (x1 * cos(theta1) - y1 * sin(theta1)) * scale_factor;
     392              double y1s = (y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor;
     393              double x1e = (x2 * cos(theta1) - y2 * sin(theta1)) * scale_factor;
     394              double y1e = (y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor;
     395             
     396              double x2s = (x1 * cos(theta1) + y1 * sin(theta1)) * scale_factor;
     397              double y2s = (-1.0 * y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor;
     398              double x2e = (x2 * cos(theta1) + y2 * sin(theta1)) * scale_factor;
     399              double y2e = (-1.0 * y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor;
     400
     401              psVector *x_start = psVectorAlloc(4,PS_TYPE_F32);
     402              psVector *y_start = psVectorAlloc(4,PS_TYPE_F32);
     403              psVector *x_end   = psVectorAlloc(4,PS_TYPE_F32);
     404              psVector *y_end   = psVectorAlloc(4,PS_TYPE_F32);
     405                     
     406              // CZW: I know this looks like a typo, but trust me, it's not a typo.
     407              psPlane *fp = psPlaneAlloc();
     408              psPlane *tp = psPlaneAlloc();
     409
     410              fprintf(stderr,"HSC GLINT %f: x1x2(%f %f) (%f %f) x1sx1e (%f %f %f %f) x2sx2e (%f %f %f %f)\n",
     411                      star->Mag,
     412                      x1,y1,x2,y2,
     413                      x1s,y1s,x1e,y1e,
     414                      x2s,y2s,x2e,y2e);
     415                     
     416             
     417              tp->x = 13.5 * (y1s / 0.015 + 12.78);
     418              tp->y = 13.5 * (x1s / -0.015 + 57.74);
     419              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     420              x_start->data.F32[0] = fp->x;
     421              y_start->data.F32[0] = fp->y;
     422              //              x_start->data.F32[0] = tp->x;
     423              //              y_start->data.F32[0] = tp->y;
     424
     425              tp->x = 13.5 * (y1e / 0.015 + 12.78);
     426              tp->y = 13.5 * (x1e / -0.015 + 57.74);
     427              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     428              x_end->data.F32[0]   = fp->x;
     429              y_end->data.F32[0]   = fp->y;
     430              //              x_end->data.F32[0]   = tp->x;
     431              //              y_end->data.F32[0]   = tp->y;
     432
     433              x_start->data.F32[1] = x_end->data.F32[0]; 
     434              y_start->data.F32[1] = y_end->data.F32[0]; 
     435              x_end->data.F32[1]   = x_start->data.F32[0];
     436              y_end->data.F32[1]   = y_start->data.F32[0];
     437
     438              tp->x = 13.5 * (y2s / 0.015 + 12.78);
     439              tp->y = 13.5 * (x2s / -0.015 + 57.74);
     440              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     441              x_start->data.F32[2] = fp->x;
     442              y_start->data.F32[2] = fp->y;
     443              //              x_start->data.F32[2] = tp->x;
     444              //              y_start->data.F32[2] = tp->y;
     445
     446              tp->x = 13.5 * (y2e / 0.015 + 12.78);
     447              tp->y = 13.5 * (x2e / -0.015 + 57.74);
     448              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     449              x_end->data.F32[2]   = fp->x;
     450              y_end->data.F32[2]   = fp->y;
     451              //              x_end->data.F32[2]   = tp->x;
     452              //              y_end->data.F32[2]   = tp->y;
     453             
     454              x_start->data.F32[3] = x_end->data.F32[2]; 
     455              y_start->data.F32[3] = y_end->data.F32[2]; 
     456              x_end->data.F32[3]   = x_start->data.F32[2];
     457              y_end->data.F32[3]   = y_start->data.F32[2];
     458
     459              psFree(fp);
     460              psFree(tp);
     461             
     462              for (int glint_point = 0; glint_point < 4; glint_point++) {
     463                for (int nChip = 0; nChip < fpa->chips->n; nChip++) {
     464                  pmChip *chip = fpa->chips->data[nChip];
     465                  if (!chip) continue;
     466                 
     467                  if (!psastroFindChipInYrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) {
     468                    continue;
     469                  }
     470                  if (!psastroFindChipInXrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) {
     471                    continue;
     472                  }
     473
     474                  double xChip0, yChip0, xChip1, yChip1, chip_angle, glint_length;
     475                  psastroFPAtoChip (&xChip0, &yChip0, fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point]);
     476                  psastroFPAtoChip (&xChip1, &yChip1, fpa, nChip, x_end->data.F32[glint_point], y_end->data.F32[glint_point]);
     477
     478                  chip_angle = atan2(yChip1 - yChip0, xChip1 - xChip0);
     479                  glint_length = sqrt(pow(yChip1 - yChip0,2) + pow(xChip1 - xChip0,2));
     480
     481                  // select the 0th readout of the 0th cell for this chip
     482                  if (!chip->cells) continue;
     483                  if (!chip->cells->n) continue;
     484                  pmCell *glintCell = chip->cells->data[0];
     485                  if (!glintCell) continue;
     486                  if (!glintCell->readouts) continue;
     487                  if (!glintCell->readouts->n) continue;
     488                  pmReadout *glintReadout = glintCell->readouts->data[0];
     489                  if (!glintReadout) continue;
     490                 
     491                  // save the glints on the readout->analysis metadata, creating if needed
     492                  psArray *glints = psMetadataLookupPtr (&status, glintReadout->analysis, "PSASTRO.GLINTS.HSC");
     493                  if (glints == NULL) {
     494                    glints = psArrayAllocEmpty (100);
     495                    if (!psMetadataAdd (glintReadout->analysis, PS_LIST_TAIL, "PSASTRO.GLINTS.HSC", PS_DATA_ARRAY, "astrometry matches", glints)) {
     496                      psWarning("failure to add glints to readout");
     497                      psFree (glints);
     498                      continue;
     499                  }
     500                    psFree (glints);
     501                  }
     502                 
     503                  fprintf (stderr, "glint %s : %d %f,%f to %f,%f (%f %f %f)\n", glintType, nChip, xChip0, yChip0, xChip1, yChip1, glint_length, glintWidth, chip_angle);
     504                  psTrace("psastro.masks",4,"HSC_GLINT: Star: %f %f Glint CR %f %f Parameters: %f %f %f Ends: %f %f -> %f %f Chip: %f %f -> %f %f @ %s %f\n",
     505                          star->FP->x,star->FP->y,
     506                          C,R,
     507                          inner_edge_angle,outer_edge_angle,theta0,
     508                          x_start->data.F32[glint_point],y_start->data.F32[glint_point],x_end->data.F32[glint_point],y_end->data.F32[glint_point],
     509                          xChip0,yChip0,xChip1,yChip1,
     510                          psMetadataLookupStr(&status,glintReadout->parent->parent->concepts,"CHIP.NAME"),chip_angle);
     511                  psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
     512                  glint->data.F32[0] = xChip0;
     513                  glint->data.F32[1] = yChip0;
     514                  glint->data.F32[2] = glint_length * pixelScale / pixelScale;
     515                  glint->data.F32[3] = glintWidth;
     516                  glint->data.F32[4] = chip_angle;
     517
     518                  psArrayAdd (glints, 100, glint);
     519
     520                  psFree (glint);
     521                } // End loop over chips
     522              } // End loop over glint endpoints
     523
     524              psFree(x_start);
     525              psFree(x_end);
     526              psFree(y_start);
     527              psFree(y_end);
     528            } // End HSC glint block
     529           
    300530        }
    301531    }
  • trunk/psastro/src/psastroMaskUpdates.c

    r33851 r40490  
    129129   
    130130    bool REFSTAR_MASK_BLEED                = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED");
    131 
     131    bool REFSTAR_MASK_BLEED_ORIENTATION_X  = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED_ORIENTATION_X");
     132    bool REFSTAR_MASK_BLEED_ORIENTATION_Y  = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED_ORIENTATION_Y");
     133
     134   
    132135    double REFSTAR_MASK_MAX_MAG            = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_MAX_MAG");
    133136    double REFSTAR_MASK_SATSTAR_MAG_SLOPE  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_SATSTAR_MAG_SLOPE");
     
    143146    double REFSTAR_MASK_BLEED_MAG_SLOPE    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE");
    144147
     148    double REFSTAR_MASK_BLEED_MAG_MAX_X    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX_X");
     149    double REFSTAR_MASK_BLEED_MAG_SLOPE_X  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE_X");
     150    double REFSTAR_MASK_BLEED_MAG_MAX_Y    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX_Y");
     151    double REFSTAR_MASK_BLEED_MAG_SLOPE_Y  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE_Y");
     152
    145153    double REFSTAR_MASK_CROSSTALK_MAG_MAX  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_MAX");
    146154    double REFSTAR_MASK_CROSSTALK_MAG_SLOPE= psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_SLOPE");
     
    180188    }
    181189
     190    psTrace("psastro.masks",2,"Configuration loaded for masking.");
     191   
    182192    // recipe values are given in instrumental magnitudes
    183193    // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
     
    187197    REFSTAR_MASK_SATSPIKE_MAG_MAX += MagOffset;
    188198    REFSTAR_MASK_BLEED_MAG_MAX += MagOffset;
     199    REFSTAR_MASK_BLEED_MAG_MAX_X += MagOffset;
     200    REFSTAR_MASK_BLEED_MAG_MAX_Y += MagOffset;
     201   
    189202    GHOST_MAX_MAG += MagOffset;
    190203
     204    psTrace("psastro.masks",2,"Magnitudes: max_mag: %f satstar: %f satspike: %f bleed: %f ghost %f\n",
     205            REFSTAR_MASK_MAX_MAG,REFSTAR_MASK_SATSTAR_MAG_MAX,REFSTAR_MASK_SATSPIKE_MAG_MAX,REFSTAR_MASK_BLEED_MAG_MAX,GHOST_MAX_MAG);
     206   
    191207    // select the output mask image :: we mosaic to chip mosaic format
    192208    pmFPAfile *outMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUTPUT.MASK");
     
    287303                if (!refstars) continue;
    288304
     305                psTrace("psastro.masks",2,"In Readout loop.");
    289306                // we need to generate the following masks regions:
    290307                // 1) circle around the saturated stars (scaled by magnitude)
     
    301318                        }
    302319                    }
    303 
     320                    psTrace("psastro.masks",4,"In refstar loop: %d/%ld %f %f\n",
     321                            i,refstars->n,ref->Mag,REFSTAR_MASK_MAX_MAG);
    304322                    if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;
    305323
     
    334352
    335353                        // The length should also be a function of the image background level
    336 
     354                        psTrace("psastro.masks",4,"Masking: Radius: %f Theta: %f Length: %f Width: %f\n",
     355                                radius,Theta,spikeLength,spikeWidth);
     356                        psTrace("psastro.masks",4,"Also: %f %f %f %f\n",ref->chip->x,ref->chip->y,ROTANGLE,REFSTAR_MASK_SATSTAR_POS_ZERO);
    337357                        psastroMaskBox (readoutMask->mask, spikeMaskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta);
    338358                    }
     
    349369                            float xCell = 0.0;
    350370                            float yCell = 0.0;
    351                             float xEnd = 0.0;
    352                             float yEnd = 0.0;
     371                            float xStart = 0.0;
     372                            float xEnd   = 0.0;
     373                            float yStart = 0.0;
     374                            float yEnd   = 0.0;
     375                            //                            float xEnd = 0.0;
     376                            //                            float yEnd = 0.0;
     377                            float width = 0.0;
     378                            float length = 0.0;
    353379                            // find coordinate of star on cell
    354380                            pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y);
    355381                            // find coordinate of end-point on chip
    356382
    357                             int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE");
    358                             pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize);
    359 
    360                             float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
    361                             psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd);
     383                            if (REFSTAR_MASK_BLEED_ORIENTATION_X) {
     384                              length = pow(10,REFSTAR_MASK_BLEED_MAG_SLOPE_X*(REFSTAR_MASK_BLEED_MAG_MAX_X - ref->Mag));
     385                              width  = REFSTAR_MASK_BLEED_MAG_SLOPE  *(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
     386
     387                              pmChipCoordsForCell (&xStart, &yStart, refCell, xCell - length, yCell - 0.5 * width);
     388                              pmChipCoordsForCell (&xEnd, &yEnd,     refCell, xCell + length, yCell + 0.5 * width);
     389                              psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) xStart, (int) yStart, (int) xEnd, (int) yEnd + 1);
     390                            }
     391                            if (REFSTAR_MASK_BLEED_ORIENTATION_Y) {
     392                              length = pow(10,REFSTAR_MASK_BLEED_MAG_SLOPE_Y*(REFSTAR_MASK_BLEED_MAG_MAX_Y - ref->Mag));
     393                              width  = REFSTAR_MASK_BLEED_MAG_SLOPE  *(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
     394
     395                              pmChipCoordsForCell (&xStart, &yStart, refCell, xCell - 0.5 * width, yCell - length);
     396                              pmChipCoordsForCell (&xEnd, &yEnd,     refCell, xCell + 0.5 * width, yCell + length);
     397                              psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) xStart, (int) yStart, (int) xEnd + 1, (int) yEnd);
     398                            }
     399                           
    362400                        }
    363401                    }
     
    392430                    }
    393431                }
    394 
     432                // Because it's very GPC1-specific, handle alternate glint types here
     433                psArray *hsc_glints = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GLINTS.HSC");
     434                if (hsc_glints) {
     435                  for (int i = 0; i < hsc_glints->n; i++) {
     436                    // Contains (start_x, start_y, length, width, theta)
     437                    psVector *glint = hsc_glints->data[i];
     438
     439                    psTrace("psastro.masks", 4, "Masking glint %d on chip %s with params (%f,%f,%f,%f,%f)\n",
     440                            i, psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"),
     441                            glint->data.F32[0], glint->data.F32[1],
     442                            glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
     443
     444                    psastroMaskBox (readoutMask->mask, glintMaskValue, glint->data.F32[0], glint->data.F32[1],
     445                                    glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
     446                  }
     447                }
     448               
    395449                // Select the crosstalk artifact regions for this readout, and mask a circular region
    396450                // corresponding to the source star
Note: See TracChangeset for help on using the changeset viewer.