IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41367 for trunk/psastro


Ignore:
Timestamp:
May 27, 2020, 2:21:31 PM (6 years ago)
Author:
tdeboer
Message:

gpc1 dynamic masks set up

Location:
trunk/psastro/src
Files:
11 edited

Legend:

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

    r41290 r41367  
    156156psVector         *psastroZeroPointReadoutAccum(psVector *dMag, pmReadout *readout, float exptime, float refminMag, float refmaxMag);
    157157bool              psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, psMetadata *recipe);
    158 bool              psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe);
     158bool              psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe);
    159159bool              psastroZeroPointRefMagLimitFromRecipe (float *refminMag, float *refmaxMag, pmFPA *fpa, psMetadata *recipe);
    160160
  • trunk/psastro/src/psastroChooseGlintStars.c

    r24645 r41367  
    3737
    3838    // really error-out here?  or just skip?
    39     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     39    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    4040        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    4141        return false;
  • trunk/psastro/src/psastroConvert.c

    r39926 r41367  
    6565
    6666      // really error-out here?  or just skip?
    67       if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     67      if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    6868        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    6969        zeropt = 0.0;
  • trunk/psastro/src/psastroExtractGhosts.c

    r24648 r41367  
    5353
    5454    // really error-out here?  or just skip?
    55     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     55    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    5656        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    5757        return false;
  • trunk/psastro/src/psastroExtractStars.c

    r24648 r41367  
    6565
    6666    // really error-out here?  or just skip?
    67     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     67    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    6868        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    6969        return false;
  • trunk/psastro/src/psastroLoadCrosstalk.c

    r36837 r41367  
    9494
    9595  // really error-out here?  or just skip?
    96   if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
     96  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
    9797    psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    9898    goto escape;
  • trunk/psastro/src/psastroLoadGhosts.c

    r41348 r41367  
    113113    pmFPAview *view = pmFPAviewAlloc (0);
    114114
    115     GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
     115    //We need to check whether we are dealing with an old style ghost_model, or a new style model. Check if the mirror_rad polynomial exists
     116    float mirCheck = 0;
     117    md = psMetadataLookupMetadata (&status, ghostModel, "GHOST.MIRROR.RAD");
     118    if (!md) { psLogMsg ("psastro", PS_LOG_INFO, "No ghost mirror_rad polynomial found. Assuming old-style ghost masking"); }
     119    if (md) {
     120        GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
     121        mirCheck = 1;
     122    }
     123
    116124    GET_2D_POLY ("GHOST.CENTER.X", centerX);
    117125    GET_2D_POLY ("GHOST.CENTER.Y", centerY);
     
    131139
    132140    // raise an error if the config is broken
    133     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
     141    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
    134142        psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
    135143        goto escape;
     
    179187                    ghost->srcFP->y = ref->FP->y;
    180188
    181                     //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
    182189                    double rSrc = hypot (ref->FP->x, ref->FP->y);
    183190                    double theta0 = atan2(ref->FP->y,ref->FP->x);
    184191
    185                     double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
    186                     double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
    187                     double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
    188 
    189                     // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords
    190                     ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
    191                     ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
     192                    if(mirCheck) {
     193                         //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
     194                        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
     195                        double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
     196                        double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
     197
     198                        // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords
     199                        ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
     200                        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
     201                    } 
     202                    if(!mirCheck) {
     203                        //Use the old-style ghost position determination
     204                        ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
     205                        ghost->FP->y = -ref->FP->y + psPolynomial2DEval(centerY, -ref->FP->x, -ref->FP->y);
     206                    }
    192207
    193208                    ghost->inner.major = psPolynomial1DEval (innerMajor, rSrc);
     
    210225                    ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
    211226                    // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
     227
    212228
    213229                    if (ghostChip) {
     
    356372 
    357373  // if a filter is defined, but the recipe elements are missing, the config is broken.
    358   if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
     374  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
    359375        psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
    360376        goto escape;
  • trunk/psastro/src/psastroLoadGlints.c

    r41348 r41367  
    2626    bool status;
    2727    float zeropt, exptime;
     28    psVector *x_glint = psVectorAlloc(2,PS_TYPE_F32);
     29    psVector *y_glint = psVectorAlloc(2,PS_TYPE_F32);
    2830
    2931    psLogMsg ("psastro", PS_LOG_INFO, "determine glint positions");
     
    3941    if (!REFSTAR_MASK_GLINTS) return true;
    4042
    41     // select the limiting magnitude
     43    // select relevant keywords
    4244    double GLINT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "GLINT_MAX_MAG");
    4345    double GLINT_LENGTH_MAG_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_SLOPE");
    4446    double GLINT_LENGTH_MAG_ZERO = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_ZERO");
     47    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
     48    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
     49
     50    //we will use one of the new keywords to differentiate between an old and new style glint treatment
     51    float glintCheck = 0;
    4552    double GLINT_LENGTH_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_SLOPE");
     53    if (!status) {
     54        psLogMsg ("psastro", PS_LOG_INFO, "Assuming old-style glint masking, given the recipe keywords");
     55        glintCheck = 1;
     56    }
    4657    double GLINT_LENGTH_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_REF");
     58    double GLINT_LENGTH_POS_CUT = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_CUT");
     59    double GLINT_LENGTH_MIN_FPA = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MIN_FPA");
     60    if (!status) GLINT_LENGTH_MIN_FPA=1000.;
    4761    double GLINT_ANGLE_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_SLOPE");
    4862    double GLINT_ANGLE_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_REF");
    49     double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
    50     double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
     63
    5164
    5265    // select the set of glint regions (GLINT.REGION is a MULTI of METADATA items)
     
    7083
    7184    // really error-out here?  or just skip?
    72     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     85    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, &GLINT_MAX_MAG, fpa, recipe)) {
    7386        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    7487        return false;
     
    7992    float MagOffset = zeropt + 2.5*log10(exptime);
    8093    GLINT_MAX_MAG += MagOffset;
    81     GLINT_LENGTH_MAG_ZERO += MagOffset;
     94    //GLINT_LENGTH_MAG_ZERO += MagOffset;
    8295
    8396    // select the raw objects for this readout (loaded in psastroExtract.c)
     
    91104    psastroChipBounds (fpa);
    92105
    93 
    94106    // find the possible glint stars, and convert the position to FPA coordinates.
    95107    // search for stars within the glint regions
     
    97109
    98110        pmAstromObj *star = glintStars->data[i];
    99         if (star->Mag > GLINT_MAX_MAG) continue; // XXX should not be needed...
     111        if (star->Mag > GLINT_MAX_MAG) continue;
    100112
    101113        // project glint star to the focal-plane
    102114        psProject (star->TP, star->sky, fpa->toSky);
    103115        psPlaneTransformApply (star->FP, fpa->fromTPA, star->TP);
    104         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);
     116        //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);
    105117
    106118        // find the GLINT.REGION this star lands in (if any)
     
    132144            }
    133145
    134             double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
     146            //double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
     147            //glint length should depend on the brightness on image, i.e. in instrumental mag. The same instrumental mag in different filters should likely give the same glint length.
     148            double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - (star->Mag-MagOffset));
    135149            double glintAngle = 0;
    136150
    137             //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than 30k pixels     
    138             if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < 30000 ){
    139               glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
    140 
    141             }
    142             if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < 30000 ) {
    143               glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
    144             }
    145             //also compute the angle of the glint, which depends on position parallel to the FPX
    146             if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){
    147               glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
    148 
    149             }
    150             if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
    151               glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
     151            //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than about 30k pixels
     152            if(glintCheck) {
     153                if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < GLINT_LENGTH_POS_CUT ){
     154                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
     155                }
     156                if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < GLINT_LENGTH_POS_CUT ) {
     157                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
     158                }
     159                //also compute the angle of the glint, which depends on position parallel to the FPX
     160                if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){
     161                  glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
     162                }
     163                if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
     164                  glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
     165                }
    152166            }
    153167
     
    157171            if (!strcasecmp(glintType, "LEFT")   && ((star->FP->x + glintLength) < -20000.))  continue;
    158172            if (!strcasecmp(glintType, "RIGHT")  && ((star->FP->x - glintLength) > 20000.))  continue;
    159 
    160             psVector *x_glint = psVectorAlloc(2,PS_TYPE_F32);
    161             psVector *y_glint = psVectorAlloc(2,PS_TYPE_F32);
    162173
    163174            if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) {
     
    220231                    yFPA1 = yFPA0 + glintLength*cos(glintAngle);
    221232                }
     233
     234                if(glintLength < GLINT_LENGTH_MIN_FPA) continue;
    222235
    223236                x_glint->data.F32[0] = xFPA0;
     
    294307                          psFree (glints);
    295308                        }
    296                        
    297                         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);
    298                         psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
     309                                                psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
    299310                        glint->data.F32[0] = xChip0;
    300311                        glint->data.F32[1] = yChip0;
     
    369380                    yFPA1 = yFPA0 + glintLength*sin(glintAngle*-1.);
    370381                }
     382
     383                if(glintLength < GLINT_LENGTH_MIN_FPA) continue;
    371384
    372385                x_glint->data.F32[0] = xFPA0;
     
    441454                        }
    442455                       
    443                         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);
    444 
    445456                        psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
    446457                        glint->data.F32[0] = xChip0;
  • trunk/psastro/src/psastroMaskUpdates.Mosaic.c

    r21183 r41367  
    5656
    5757    // really error-out here?  or just skip?
    58     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     58    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    5959        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    6060        return false;
  • trunk/psastro/src/psastroMaskUpdates.c

    r41348 r41367  
    184184
    185185    // really error-out here?  or just skip?
    186     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &GHOST_MAX_MAG, fpa, recipe)) {
     186    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &GHOST_MAX_MAG, NULL, fpa, recipe)) {
    187187        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    188188        return false;
     
    443443                        //psLogMsg ("psastro", 3, "glint: %f %f %f %f\n", glint->x0, glint->y0, glint->x1, glint->y1);
    444444                        //psastroMaskRectangle (readoutMask->mask, glintMaskValue, glint->x0, glint->y0, glint->x1, glint->y1);
    445 
    446                         psLogMsg ("psastro", 3, "glint: %d %f %f %f %f %f\n",i, glint->data.F32[0], glint->data.F32[1],glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
    447445                        psastroMaskBox (readoutMask->mask, glintMaskValue, glint->data.F32[0], glint->data.F32[1],
    448446                                    glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
  • trunk/psastro/src/psastroZeroPoint.c

    r37552 r41367  
    5555
    5656    // really error-out here?  or just skip?
    57     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
     57    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
    5858        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    5959        return false;
     
    480480  return false; }
    481481
    482 bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe) {
     482bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe) {
    483483
    484484    bool status;
     
    527527            //MEH null is a pain.. so only log if set
    528528            psLogMsg ("psastro", PS_LOG_INFO, "found GHOST_MAX_MAG %f",*ghostMaxMag);
     529        }
     530        if (glintMaxMag) {
     531            float MaxMag = psMetadataLookupF32 (&status, refItem->data.md, "GLINT_MAX_MAG");
     532            if (status) {
     533                *glintMaxMag = MaxMag ;
     534                //MEH null is a pain.. so only log if set
     535                psLogMsg ("psastro", PS_LOG_INFO, "found GLINT_MAX_MAG %f",*glintMaxMag);
     536            }
    529537        }
    530538        //MEH what zpt is set to
Note: See TracChangeset for help on using the changeset viewer.