IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 25, 2010, 1:17:19 PM (16 years ago)
Author:
watersc1
Message:

Hopefully final edits for maskstats code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroMaskUpdates.c

    r28043 r28089  
    3030int colEnd(psU16 corner_list,int i,int x_0,int y_0,int R,int max) {
    3131  if ((corner_list == 0x04)||(corner_list == 0x05)) {
    32     return((int) fabs(x_0 - sqrt(pow(R,2) - pow(y_0 - i,2))));
     32    int v = (int) fabs(x_0 - sqrt(pow(R,2) - pow(y_0 - i,2)));
     33    if (v > max) {
     34      return(max);
     35    }
     36    else {
     37      return(v);
     38    }
    3339  }
    3440  else {
     
    5460           (corner_list == 0x03)||(corner_list == 0x0b)||
    5561           (corner_list == 0x07)) {
    56     return((int) fabs(y_0 - sqrt(pow(R,2) - pow(x_0 - j,2))));
     62    int v = (int) fabs(y_0 - sqrt(pow(R,2) - pow(x_0 - j,2)));
     63    if (v > max) {
     64      return(max);
     65    }
     66    else {
     67      return(v);
     68    }
    5769  }
    5870  else {
     
    6274}
    6375
    64 /**
     76/* #define MASK_DEBUG 1 */
     77
     78/*
    6579 * create a mask or mask regions based on the collection of reference stars that * are in the vicinity of each chip
    6680 */
     
    112126        return false;
    113127    }
    114 
    115128    psLogMsg ("psastro", PS_LOG_INFO, "generating a bright-star mask");
    116 
     129   
    117130    bool REFSTAR_MASK_BLEED                = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED");
    118131
     
    137150    psU16 advisoryMaskVal = psMetadataLookupU32(&status, recipe, "MASKSTAT.ADVISORY");
    138151
    139     psS32 Npix_valid = 0;
    140     psS32 Npix_static = 0;
    141     psS32 Npix_magic = 0;
    142     psS32 Npix_dynamic = 0;
    143     psS32 Npix_advisory = 0;
     152    psS32 Npix_ref_valid = 0;
     153    psS32 Npix_ref_static = 0;
     154    psS32 Npix_ref_magic = 0;
     155    psS32 Npix_ref_dynamic = 0;
     156    psS32 Npix_ref_advisory = 0;
     157
     158    psS32 Npix_max_valid = 0;
     159    psS32 Npix_max_static = 0;
     160    psS32 Npix_max_magic = 0;
     161    psS32 Npix_max_dynamic = 0;
     162    psS32 Npix_max_advisory = 0;
    144163   
    145164    psU16 corner_list = 0x00;
     
    177196
    178197    // Get camera specific mask stat options
    179     psF32 FOV = psMetadataLookupF32(&status, fpaMask->camera, "FOV"); // Almost certainly doesn't exist. Placeholder for now.
    180     psS32 CONSTANT_BLANK = psMetadataLookupS32(&status, fpaMask->camera, "NPIX_INTERCHIP"); // Need to add this as well.
    181    
    182     Npix_valid += CONSTANT_BLANK;
    183     Npix_static += CONSTANT_BLANK;
    184 
     198    psF32 FOV_REF = psMetadataLookupF32(&status, fpaMask->camera, "FOV_REF");
     199    psF32 FOV_MAX = psMetadataLookupF32(&status, fpaMask->camera, "FOV_MAX");
     200    psS32 NPIX_REF = psMetadataLookupS32(&status, fpaMask->camera, "NPIX_REF");
     201    psS32 NPIX_MAX = psMetadataLookupS32(&status, fpaMask->camera, "NPIX_MAX");
    185202   
    186203    // select the reference mask fpa :: we use this to determine cell boundaries
     
    209226    // open/load files as needed
    210227    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
    211 
     228#ifdef MASK_DEBUG
     229    psImage *masktest = psImageAlloc(10500,10500,PS_TYPE_U16);
     230    psImageMaskType **maskIData = masktest->data.PS_TYPE_IMAGE_MASK_DATA;
     231#endif
    212232    // this loop selects the matched stars for all chips
    213233    while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
     
    435455          while ((cell = pmFPAviewNextCell(view, fpa, 1)) != NULL) {
    436456            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
    437             psWarning("In CELL: FOV: %f CONSTANT: %d Mask bits: %d %d %d %d\n",
    438                       FOV,CONSTANT_BLANK,staticMaskVal,magicMaskVal,dynamicMaskVal,advisoryMaskVal);
    439            
    440457            if (!cell->process || !cell->file_exists) {continue; }
    441458            while ((readout = pmFPAviewNextReadout(view, fpa, 1)) != NULL) {
    442459              pmReadout *readoutMask = pmFPAviewThisReadout (view, outMask->fpa);
    443460              if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;
    444               psWarning("In READOUT: FOV: %f CONSTANT: %d Mask bits: %d %d %d %d\n",
    445                         FOV,CONSTANT_BLANK,staticMaskVal,magicMaskVal,dynamicMaskVal,advisoryMaskVal);
    446              
    447461              if (!readoutMask->data_exists) {continue; }
     462
    448463              psPlane coordFPA;
    449464              psPlane coordCell;
     
    453468              psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
    454469              // Dance coordinates around
    455               // Calculate which corners fall within the field of view.
     470              // Calculate which corners fall within the field of view.  If this chip is fully contained, we can
     471              // do a simple scan instead of checking it falls within the FOV.
    456472              // 0x04   0x08
    457473              // 0x01   0x02
     474              corner_list = 0;
    458475             
    459               coordFPA.x = 0.0;
    460               coordFPA.y = 0.0;
    461               psPlaneTransformApply(&coordCell,chip->fromFPA,&coordFPA);
    462               if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV,2)) {
     476              coordCell.x = 0.0;
     477              coordCell.y = 0.0;
     478              psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     479              if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_REF,2)) {
    463480                corner_list = corner_list | 0x01;
    464481              }
    465              
    466               coordCell.x = mask->numCols - 1;
    467               psPlaneTransformApply(&coordCell,chip->fromFPA,&coordFPA);
    468               if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV,2)) {
     482              coordCell.x = (1.0 * mask->numCols - 1.0);
     483              psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     484              if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_REF,2)) {
    469485                corner_list = corner_list | 0x02;
    470486              }
    471              
    472               coordCell.y = mask->numRows - 1;
    473               psPlaneTransformApply(&coordCell,chip->fromFPA,&coordFPA);
    474               if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV,2)) {
     487              coordCell.y = 1.0 * (mask->numRows - 1);
     488              psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     489              if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_REF,2)) {
    475490                corner_list = corner_list | 0x08;
    476491              }
    477              
    478               coordCell.x = 0;
    479               psPlaneTransformApply(&coordCell,chip->fromFPA,&coordFPA);
    480               if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV,2)) {
     492              coordCell.x = 0.0;
     493              psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     494              if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_REF,2)) {
    481495                corner_list = corner_list | 0x04;
    482496              }
    483              
    484               int x_0 = coordFPA.x;
    485               int y_0 = coordFPA.y;
    486              
    487              
     497
    488498              // Scan over the valid regions of the image and count masked pixels
    489               if ((corner_list == 0x04)||(corner_list == 0x08)||
    490                   (corner_list == 0x05)||(corner_list == 0x0a)) {
    491                 for (int i = 0; i < mask->numRows - 1; i++) {
    492                   for (int j = colStart(corner_list,i,x_0,y_0,FOV,mask->numCols - 1);
    493                        j < colEnd(corner_list,i,x_0,y_0,FOV,mask->numCols - 1); j++) {
    494                     Npix_valid++;
    495                     if (maskData[i][j] & staticMaskVal) {
    496                       Npix_static++;
    497                       continue;
    498                     }
    499                     if (maskData[i][j] & dynamicMaskVal) {
    500                       Npix_dynamic++;
    501                       continue;
    502                     }
    503                     if (maskData[i][j] & magicMaskVal) {
    504                       Npix_magic++;
    505                       continue;
    506                     }
    507                     if (maskData[i][j] & advisoryMaskVal) {
    508                       Npix_advisory++;
    509                       continue;
    510                     }
     499              for (int i = 0; i < mask->numRows - 1; i++) {
     500                for (int j = 0; j < mask->numCols - 1; j++) {
     501                  coordCell.x = j;
     502                  coordCell.y = i;
     503                  coordFPA.x = 0.0;
     504                  coordFPA.y = 0.0;
     505                  int region = 0;
     506
     507                  if (corner_list == 0x0f) {
     508                    Npix_ref_valid++;
     509                    Npix_max_valid++;
     510                    region = 1;
     511/* #ifdef MASK_DEBUG */
     512/*                  psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell); */
     513/*                  maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] = */
     514/*                    maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] + 0x01; */
     515/* #endif */
    511516                  }
    512                 }
    513               }
    514               else {
    515                 for (int j = 0; j < mask->numCols - 1; j++) {
    516                   for (int i = rowStart(corner_list,j,x_0,y_0,FOV,mask->numRows - 1);
    517                        i < rowEnd(corner_list,j,x_0,y_0,FOV,mask->numRows - 1); i++) {
    518                     Npix_valid++;
    519                     if (maskData[i][j] & staticMaskVal) {
    520                       Npix_static++;
    521                       continue;
    522                     }
    523                     if (maskData[i][j] & dynamicMaskVal) {
    524                       Npix_dynamic++;
    525                       continue;
    526                     }
    527                     if (maskData[i][j] & magicMaskVal) {
    528                       Npix_magic++;
    529                       continue;
    530                     }
    531                     if (maskData[i][j] & advisoryMaskVal) {
    532                       Npix_advisory++;
    533                       continue;
    534                     }
     517                  if (!region) {
     518                    psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     519                    if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_REF,2)) {
     520                      Npix_ref_valid++;
     521                      Npix_max_valid++;
     522                      region = 1;
     523/* #ifdef MASK_DEBUG */
     524/*                    maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] = */
     525/*                      maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] +  0x01; */
     526/* #endif */
     527                    }
     528                    else if (pow(coordFPA.x,2) + pow(coordFPA.y,2) <= pow(FOV_MAX,2)) {
     529                      Npix_max_valid++;
     530                      region = 2;
     531/* #ifdef MASK_DEBUG  */
     532/*                    maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] = */
     533/*                      maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] + 0x01; */
     534/* #endif */
     535                    }
     536                  }
     537                  if (!region) {
     538                    continue;
     539                  }
     540                 
     541                  if (maskData[i][j] & staticMaskVal) {
     542#ifdef MASK_DEBUG
     543                    psPlaneTransformApply(&coordFPA,chip->toFPA,&coordCell);
     544                    maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] =
     545                      maskIData[(int) (coordFPA.y/4 + 5250)][(int) (coordFPA.x/4 + 5250)] + 1;
     546#endif
     547                    if (region == 1) {
     548                      Npix_ref_static++;
     549                      Npix_max_static++;
     550                    }
     551                    if (region == 2) {
     552                      Npix_max_static++;
     553                    }
     554                    continue;
     555                  }
     556                  if (maskData[i][j] & dynamicMaskVal) {
     557                    if (region == 1) {
     558                      Npix_ref_dynamic++;
     559                      Npix_max_dynamic++;
     560                    }
     561                    if (region == 2) {
     562                      Npix_max_dynamic++;
     563                    }
     564                    continue;
     565                  }
     566                  if (maskData[i][j] & magicMaskVal) {
     567                    if (region == 1) {
     568                      Npix_ref_magic++;
     569                      Npix_max_magic++;
     570                    }
     571                    if (region == 2) {
     572                      Npix_max_magic++;
     573                    }
     574                    continue;
     575                  }
     576                  if (maskData[i][j] & advisoryMaskVal) {
     577                    if (region == 1) {
     578                      Npix_ref_advisory++;
     579                      Npix_max_advisory++;
     580                    }
     581                    if (region == 2) {
     582                      Npix_max_advisory++;
     583                    }
     584                    continue;
    535585                  }
    536586                }
     
    555605    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    556606
     607#ifdef MASK_DEBUG
     608    psFits *maskFits = psFitsOpen("/data/ipp007.0/watersc1/mask.test.fits","w");
     609    psFitsWriteImage(maskFits,NULL,masktest,1,"mask");
     610
     611    psFree(maskFits);
     612    psFree(masktest);
     613#endif
    557614    if (COUNT_GHOSTS) {
    558615        // save nGhosts to update header.
     
    566623    }
    567624
    568     psMetadataAddS32(stats,PS_LIST_TAIL, "MASKFRAC_NPIX", 0,
    569                      "Number of valid pixels", Npix_valid);
    570     psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_STATIC", 0,
    571                      "Fraction of pixels statically masked", (float) Npix_static / Npix_valid);
    572     psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_DYNAMIC", 0,
    573                      "Fraction of pixels dynamically masked", (float) Npix_dynamic / Npix_valid);
    574     psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_MAGIC", 0,
    575                      "Fraction of pixels magically masked", (float) Npix_magic / Npix_valid);
    576     psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_ADVISORY", 0,
    577                      "Fraction of pixels masked as an advisory", (float) Npix_advisory / Npix_valid);
     625    Npix_ref_static += (NPIX_REF - Npix_ref_valid);
     626    Npix_max_static += (NPIX_MAX - Npix_max_valid);
     627    psMetadataAddS32(stats,PS_LIST_TAIL, "MASKFRAC_REF_NPIX", 0,
     628                     "Number of valid pixels", Npix_ref_valid);
     629    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_REF_STATIC", 0,
     630                     "Fraction of pixels statically masked", (float) Npix_ref_static / NPIX_REF);
     631    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_REF_DYNAMIC", 0,
     632                     "Fraction of pixels dynamically masked", (float) Npix_ref_dynamic / NPIX_REF);
     633    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_REF_MAGIC", 0,
     634                     "Fraction of pixels magically masked", (float) Npix_ref_magic / NPIX_REF);
     635    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_REF_ADVISORY", 0,
     636                     "Fraction of pixels masked as an advisory", (float) Npix_ref_advisory / NPIX_REF);
     637
     638    psMetadataAddS32(stats,PS_LIST_TAIL, "MASKFRAC_MAX_NPIX", 0,
     639                     "Number of valid pixels", Npix_max_valid);
     640    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_MAX_STATIC", 0,
     641                     "Fraction of pixels statically masked", (float) Npix_max_static / NPIX_MAX);
     642    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_MAX_DYNAMIC", 0,
     643                     "Fraction of pixels dynamically masked", (float) Npix_max_dynamic / NPIX_MAX);
     644    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_MAX_MAGIC", 0,
     645                     "Fraction of pixels magically masked", (float) Npix_max_magic / NPIX_MAX);
     646    psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_MAX_ADVISORY", 0,
     647                     "Fraction of pixels masked as an advisory", (float) Npix_max_advisory / NPIX_MAX);
    578648   
    579649    // deactivate all files
Note: See TracChangeset for help on using the changeset viewer.