IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2017, 4:20:46 PM (9 years ago)
Author:
watersc1
Message:

HSC changes that haven't been committed yet. Includes a number of configuration changes, improved glint masking, unfinished ghost masking, and the PSF model that I forgot to include previously.

Location:
branches/czw_branch/20170908/psastro/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20170908/psastro/src/psastroLoadGhosts.c

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

    r24645 r40179  
    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                if (star->Mag > limit) { continue; }
     348              }
     349              // check
     350              double glintPixelScale = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.PIXEL.SCALE");
     351              //              psMetadata *GLINT_PARAMETER_SET = psMetadataLookupPtr(&status, glintItem->data.md, "GLINT.FILTER.TERM");
     352              //              psMetadata *GLINT_PARAMETERS    = psMetadataLookupPtr(&status, GLINT_PARAMETER_SET, filter);
     353             
     354
     355              //              double theta0 = atan2(star->FP->y,star->FP->x);
     356              double theta0 = atan2(star->TP->y,star->TP->x);
     357              double star_radius_deg = R_FPA * glintPixelScale;
     358
     359              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);
     360              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);
     361
     362              double inner_edge_angle, outer_edge_angle;
     363              if (star_radius_deg < 0.8831) {
     364                outer_edge_angle = 0.0;
     365              }
     366              else if (star_radius_deg < 0.9368) {
     367                outer_edge_angle = 46.2985 * sqrt(star_radius_deg - 0.8831);
     368              }
     369              else {
     370                outer_edge_angle = -2.67 + 14.3 * star_radius_deg;
     371              }
     372              if (star_radius_deg < 0.964) {
     373                inner_edge_angle = -243.866 * pow(star_radius_deg - 0.932,2) + 2.4636;
     374              }
     375              else {
     376                inner_edge_angle = 66.2061 * sqrt(star_radius_deg - 0.9635);
     377              }
     378
     379              inner_edge_angle = inner_edge_angle * PS_RAD_DEG;
     380              outer_edge_angle = outer_edge_angle * PS_RAD_DEG;
     381             
     382              // These define the ends of a single arc in arc-centric coordinates
     383              double x1 = C - R * cos(inner_edge_angle);
     384              double y1 = R * sin(inner_edge_angle);
     385              double x2 = C - R * cos(outer_edge_angle);
     386              double y2 = R * sin(outer_edge_angle);
     387
     388              // Create the endpoints for the pair of arcs in device coordinates (in millimeters)
     389              double theta1 = theta0 + M_PI / 2.0;
     390              double x1s = (x1 * cos(theta1) - y1 * sin(theta1)) * scale_factor;
     391              double y1s = (y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor;
     392              double x1e = (x2 * cos(theta1) - y2 * sin(theta1)) * scale_factor;
     393              double y1e = (y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor;
     394             
     395              double x2s = (x1 * cos(theta1) + y1 * sin(theta1)) * scale_factor;
     396              double y2s = (-1.0 * y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor;
     397              double x2e = (x2 * cos(theta1) + y2 * sin(theta1)) * scale_factor;
     398              double y2e = (-1.0 * y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor;
     399
     400              psVector *x_start = psVectorAlloc(4,PS_TYPE_F32);
     401              psVector *y_start = psVectorAlloc(4,PS_TYPE_F32);
     402              psVector *x_end   = psVectorAlloc(4,PS_TYPE_F32);
     403              psVector *y_end   = psVectorAlloc(4,PS_TYPE_F32);
     404                     
     405              // CZW: I know this looks like a typo, but trust me, it's not a typo.
     406              psPlane *fp = psPlaneAlloc();
     407              psPlane *tp = psPlaneAlloc();
     408
     409              fprintf(stderr,"HSC GLINT: x1x2(%f %f) (%f %f) x1sx1e (%f %f %f %f) x2sx2e (%f %f %f %f)\n",
     410                      x1,y1,x2,y2,
     411                      x1s,y1s,x1e,y1e,
     412                      x2s,y2s,x2e,y2e);
     413                     
     414             
     415              tp->x = 13.5 * (y1s / 0.015 + 12.78);
     416              tp->y = 13.5 * (x1s / -0.015 + 57.74);
     417              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     418              x_start->data.F32[0] = fp->x;
     419              y_start->data.F32[0] = fp->y;
     420              x_start->data.F32[0] = tp->x;
     421              y_start->data.F32[0] = tp->y;
     422
     423              tp->x = 13.5 * (y1e / 0.015 + 12.78);
     424              tp->y = 13.5 * (x1e / -0.015 + 57.74);
     425              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     426              x_end->data.F32[0]   = fp->x;
     427              y_end->data.F32[0]   = fp->y;
     428              x_end->data.F32[0]   = tp->x;
     429              y_end->data.F32[0]   = tp->y;
     430
     431              x_start->data.F32[1] = x_end->data.F32[0]; 
     432              y_start->data.F32[1] = y_end->data.F32[0]; 
     433              x_end->data.F32[1]   = x_start->data.F32[0];
     434              y_end->data.F32[1]   = y_start->data.F32[0];
     435
     436              tp->x = 13.5 * (y2s / 0.015 + 12.78);
     437              tp->y = 13.5 * (x2s / -0.015 + 57.74);
     438              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     439              x_start->data.F32[2] = fp->x;
     440              y_start->data.F32[2] = fp->y;
     441              x_start->data.F32[2] = tp->x;
     442              y_start->data.F32[2] = tp->y;
     443
     444              tp->x = 13.5 * (y2e / 0.015 + 12.78);
     445              tp->y = 13.5 * (x2e / -0.015 + 57.74);
     446              psPlaneTransformApply(fp,fpa->fromTPA, tp);
     447              x_end->data.F32[2]   = fp->x;
     448              y_end->data.F32[2]   = fp->y;
     449              x_end->data.F32[2]   = tp->x;
     450              y_end->data.F32[2]   = tp->y;
     451             
     452              x_start->data.F32[3] = x_end->data.F32[2]; 
     453              y_start->data.F32[3] = y_end->data.F32[2]; 
     454              x_end->data.F32[3]   = x_start->data.F32[2];
     455              y_end->data.F32[3]   = y_start->data.F32[2];
     456
     457              psFree(fp);
     458              psFree(tp);
     459             
     460              for (int glint_point = 0; glint_point < 4; glint_point++) {
     461                for (int nChip = 0; nChip < fpa->chips->n; nChip++) {
     462                  pmChip *chip = fpa->chips->data[nChip];
     463                  if (!chip) continue;
     464                 
     465                  if (!psastroFindChipInYrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) {
     466                    continue;
     467                  }
     468                  if (!psastroFindChipInXrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) {
     469                    continue;
     470                  }
     471
     472                  double xChip0, yChip0, xChip1, yChip1, chip_angle, glint_length;
     473                  psastroFPAtoChip (&xChip0, &yChip0, fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point]);
     474                  psastroFPAtoChip (&xChip1, &yChip1, fpa, nChip, x_end->data.F32[glint_point], y_end->data.F32[glint_point]);
     475
     476                  chip_angle = atan2(yChip1 - yChip0, xChip1 - xChip0);
     477                  glint_length = sqrt(pow(yChip1 - yChip0,2) + pow(xChip1 - xChip0,2));
     478
     479                  // select the 0th readout of the 0th cell for this chip
     480                  if (!chip->cells) continue;
     481                  if (!chip->cells->n) continue;
     482                  pmCell *glintCell = chip->cells->data[0];
     483                  if (!glintCell) continue;
     484                  if (!glintCell->readouts) continue;
     485                  if (!glintCell->readouts->n) continue;
     486                  pmReadout *glintReadout = glintCell->readouts->data[0];
     487                  if (!glintReadout) continue;
     488                 
     489                  // save the glints on the readout->analysis metadata, creating if needed
     490                  psArray *glints = psMetadataLookupPtr (&status, glintReadout->analysis, "PSASTRO.GLINTS.HSC");
     491                  if (glints == NULL) {
     492                    glints = psArrayAllocEmpty (100);
     493                    if (!psMetadataAdd (glintReadout->analysis, PS_LIST_TAIL, "PSASTRO.GLINTS.HSC", PS_DATA_ARRAY, "astrometry matches", glints)) {
     494                      psWarning("failure to add glints to readout");
     495                      psFree (glints);
     496                      continue;
     497                  }
     498                    psFree (glints);
     499                  }
     500                 
     501                  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);
     502                  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",
     503                          star->FP->x,star->FP->y,
     504                          C,R,
     505                          inner_edge_angle,outer_edge_angle,theta0,
     506                          x_start->data.F32[glint_point],y_start->data.F32[glint_point],x_end->data.F32[glint_point],y_end->data.F32[glint_point],
     507                          xChip0,yChip0,xChip1,yChip1,
     508                          psMetadataLookupStr(&status,glintReadout->parent->parent->concepts,"CHIP.NAME"),chip_angle);
     509                  psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
     510                  glint->data.F32[0] = xChip0;
     511                  glint->data.F32[1] = yChip0;
     512                  glint->data.F32[2] = glint_length * pixelScale / pixelScale;
     513                  glint->data.F32[3] = glintWidth;
     514                  glint->data.F32[4] = chip_angle;
     515
     516                  psArrayAdd (glints, 100, glint);
     517
     518                  psFree (glint);
     519                } // End loop over chips
     520              } // End loop over glint endpoints
     521
     522              psFree(x_start);
     523              psFree(x_end);
     524              psFree(y_start);
     525              psFree(y_end);
     526            } // End HSC glint block
     527           
    300528        }
    301529    }
  • branches/czw_branch/20170908/psastro/src/psastroMaskUpdates.c

    r33851 r40179  
    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.