IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21156


Ignore:
Timestamp:
Jan 23, 2009, 3:05:43 PM (17 years ago)
Author:
bills
Message:

Fixes to destreaking of raw images

Location:
trunk/magic/remove/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src

    • Property svn:ignore
      •  

        old new  
        22streaksreplace
        33streakscompare
         4streaksrelease
  • trunk/magic/remove/src/.cvsignore

    r20816 r21156  
    22streaksreplace
    33streakscompare
     4streaksrelease
  • trunk/magic/remove/src/Line.c

    r20664 r21156  
    321321                if (DistanceSquared (line, x, y) <= halfWidth2)
    322322                {
    323                     pixel = psAlloc (sizeof(PixelPos));
    324                     pixel->x = (int) x;
    325                     pixel->y = (int) y;
    326                     psArrayAdd (pixels, 1024, pixel);
    327                     psFree (pixel);
     323                    if (x >=0 && y >= 0) {
     324                        pixel = psAlloc (sizeof(PixelPos));
     325                        pixel->x = (unsigned int) x;
     326                        pixel->y = (unsigned int) y;
     327                        psArrayAdd (pixels, 1024, pixel);
     328                        psFree (pixel);
     329                    }
    328330                }
    329331            }
     
    368370                if (DistanceSquared (line, x, y) <= halfWidth2)
    369371                {
    370                     pixel = psAlloc (sizeof(PixelPos));
    371                     pixel->x = (int) x;
    372                     pixel->y = (int) y;
    373                     psArrayAdd (pixels, 1024, pixel);
    374                     psFree (pixel);
     372                    if (x >=0 && y >= 0) {
     373                        pixel = psAlloc (sizeof(PixelPos));
     374                        pixel->x = (unsigned int) x;
     375                        pixel->y = (unsigned int) y;
     376                        psArrayAdd (pixels, 1024, pixel);
     377                        psFree (pixel);
     378                    }
    375379                }
    376380            }
  • trunk/magic/remove/src/Makefile.simple

    r21085 r21156  
    66COMMON_OBJECTS = \
    77        streaksio.o \
    8         streaksutil.o
     8        streaksutil.o \
     9        streaksastrom.o
    910
    1011REMOVE_OBJECTS=    \
    1112    ${COMMON_OBJECTS} \
    1213    streaksremove.o \
    13     streaksastrom.o \
    1414    streaksextern.o \
    1515    warpedpixels.o \
     
    3030STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1
    3131OPTFLAGS= -g
    32 #CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}
    33 CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS}
     32CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}
     33#CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS}
    3434LDFLAGS=`psmodules-config --libs`
    3535
  • trunk/magic/remove/src/streaksastrom.c

    r20842 r21156  
    1717
    1818    if (fromCell) {
    19         // The metadata is the cell concepts
     19        // XXX: I think that this is not needed
     20        // We are only asked to get the concepts from the cell when we're reading from a pmfile (skycell)
     21        // In that case we (x0,y0) = (0,0) and the parirties are positive
     22        // If the x0, y0 are not zero they are probably in the FITS unity based array format
     23        // We should probably assert that these are zero
    2024        cell_x0 =  psMetadataLookupS32(&mdok, md, "CELL.X0");
    2125        if (!mdok) {
     
    2832            return NULL;
    2933        }
    30 
    3134        xParityCell = psMetadataLookupS32(&mdok, md, "CELL.XPARITY");
    3235        if (!mdok || (xParityCell != 1 && xParityCell != -1)) {
     
    6568            return false;
    6669        }
    67 
    6870    } else {
    6971        // no metadata regular cell
     72        // used by warpedpixels
    7073        cell_x0 = 0;
    7174        cell_y0 = 0;
     
    8992}
    9093
     94void
     95chipToCell(double *xCell, double *yCell, strkAstrom *astrom, double xChip, double yChip)
     96{
     97    // convert from chip to cell
     98    if (astrom->xParity > 0) {
     99        *xCell = xChip - astrom->cell_x0;
     100    } else {
     101        *xCell = astrom->cell_x0 - 1 - xChip;
     102    }
     103    if (astrom->yParity > 0) {
     104        *yCell = yChip - astrom->cell_y0;
     105    } else {
     106        *yCell = astrom->cell_y0 - 1 - yChip;
     107    }
     108}
     109
     110void
     111cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell)
     112{
     113    if (astrom->xParity > 0) {
     114        *xChip = xCell + astrom->cell_x0;
     115    } else {
     116        *xChip = astrom->cell_x0 - 1 - xCell;
     117    }
     118    if (astrom->yParity > 0) {
     119        *yChip = yCell + astrom->cell_y0;
     120    } else {
     121        *yChip =  astrom->cell_y0 - 1 - yCell;
     122    }
     123}
     124
     125void
     126cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell)
     127{
     128    if (astrom->xParity > 0) {
     129        *xChip = xCell + astrom->cell_x0;
     130    } else {
     131        *xChip = astrom->cell_x0 - 1 - xCell;
     132    }
     133    if (astrom->yParity > 0) {
     134        *yChip = yCell + astrom->cell_y0;
     135    } else {
     136        *yChip =  astrom->cell_y0 - 1 - yCell;
     137    }
     138}
     139 
    91140bool
    92141skyToCell(strkPt *outPt, strkAstrom *astrom, double ra, double dec)
     
    107156    psPlaneTransformApply(pt->chip, chip->fromFPA, pt->FP);
    108157
    109     // convert from chip to cell
    110     outPt->x = (pt->chip->x - astrom->cell_x0) * astrom->xParity;
    111     outPt->y = (pt->chip->y - astrom->cell_y0) * astrom->yParity;
     158    chipToCell(&outPt->x, &outPt->y, astrom, pt->chip->x, pt->chip->y);
    112159
    113160//    printf("cell: %f %f chip: %f %f\n", outPt->x, outPt->y, pt->chip->x, pt->chip->y);
     
    115162    return true;
    116163}
    117  
     164
    118165bool
    119166cellToSky(strkPt *outPt, strkAstrom *astrom, double x, double y)
     
    123170    pmAstromObj *pt = (pmAstromObj *) astrom->pt;
    124171   
    125     // XXX: TODO: confirm that this cell to chip transformation is correct
    126     pt->chip->x = (x * astrom->xParity) + astrom->cell_x0;
    127     pt->chip->y = (y * astrom->yParity) + astrom->cell_y0;
     172    cellToChip(&pt->chip->x, &pt->chip->y, astrom, x, y);
    128173
    129174    pt->chip->xErr = 0;  // Is setting these errors to zero the right thing to do?
     
    142187}
    143188
    144 void
    145 cellToChip(PixelPos *chip, strkAstrom *astrom, PixelPos *cell)
    146 {
    147     // TODO: do I need to worry about going from int to float and back again here?
    148     chip->x = (cell->x * astrom->xParity) + astrom->cell_x0;
    149     chip->y = (cell->y * astrom->yParity) + astrom->cell_y0;
    150 }
    151189 
    152190static bool
     
    166204    PS_ASSERT_PTR_NON_NULL(hdu->header, 1)
    167205    if (sf->bilevelAstrometry) {
    168         // Do we get here for GPC1 ? I don't necessarily have an fpa for the input image
    169206        if (!pmAstromReadBilevelMosaic(sf->inAstrom->fpa, phu->header)) {
    170207            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");
     
    232269    }
    233270}
     271
     272void
     273linearizeTransforms(strkAstrom *astrom)
     274{
     275    if (!pmAstromLinearizeTransforms((pmFPA *) astrom->fpa, (pmChip *) astrom->chip)) {
     276        streaksExit("linear fit to astrometry failed\n", PS_EXIT_UNKNOWN_ERROR);
     277    }
     278}
  • trunk/magic/remove/src/streakscompare.c

    r20843 r21156  
    3939            streaksExit("failed to advance to next extesion\n", PS_EXIT_DATA_ERROR);
    4040        }
    41         readImage(file1, 0, stage);
    42         readImage(file2, 0, stage);
     41        readImage(file1, 0, stage, false);
     42        readImage(file2, 0, stage, false);
    4343
    4444        psImage *image1 = file1->image;
  • trunk/magic/remove/src/streaksio.c

    r21085 r21156  
    4141
    4242    sf->inMask = sFileOpen(config, stage, "INPUT.MASK", NULL, false);
    43     if (sf->inMask) {
     43    if (sf->inMask && (sf->stage != IPP_STAGE_RAW)) {
    4444        inputBasename = basename(sf->inMask->name);
    4545        sf->outMask = sFileOpen(config, stage, "OUTPUT", inputBasename, true);
     
    295295streakFilesNextExtension(streakFiles *sf)
    296296{
    297     // unless stage is raw or chip when we get here we're done
     297    // unless stage is raw when we get here we're done
    298298    if (sf->stage != IPP_STAGE_RAW) {
    299299        if (sf->view) {
     
    315315    if (sf->extnum < sf->nHDU) {
    316316        moveExt(sf->inImage, sf->extnum);
    317         if (sf->inMask) {
    318             moveExt(sf->inMask, sf->extnum);
    319         }
    320         if (sf->inWeight) {
    321             moveExt(sf->inWeight, sf->extnum);
    322         }
     317        // No mask and weight images for raw stage
    323318        return true;
    324319    } else {
     320        // we're all done
    325321        return false;
    326322    }
     
    354350
    355351    sFile *inMask = sfiles->inMask;
    356     if (inMask) {
     352    if (inMask && sfiles->outMask) {
    357353        psMetadata *maskHeader = psFitsReadHeader(NULL, inMask->fits);
    358354        if (!maskHeader) {
     
    469465}
    470466
    471 void
    472 setDataExtent(ippStage stage, sFile *in)
    473 {
    474     if (stage == IPP_STAGE_RAW) {
     467static void
     468setDataExtent(ippStage stage, sFile *in, bool rawImage)
     469{
     470    if (rawImage) {
    475471        psString datasec = psMetadataLookupStr(NULL, in->header, "DATASEC");
    476472        if (!datasec) {
     
    480476        int xmin, xmax, ymin, ymax;
    481477        sscanf(datasec, "[%d:%d,%d:%d]", &xmin, &xmax, &ymin, &ymax);
     478
     479        // I've inadvertantly introduced an implicit assumption that cell coordinates
     480        // are the same as image coordinates. This is true for GPC1
     481        // Test for this condition not being true
     482        if (xmin != 1) {
     483            psError(PS_ERR_IO, true, "can't handle datasec with minimum x != 1: %s", datasec);
     484            streaksExit("", PS_EXIT_PROG_ERROR);
     485        }
     486        if (ymin != 1) {
     487            psError(PS_ERR_IO, true, "can't handle datasec with minimum y != 1: %s", datasec);
     488            streaksExit("", PS_EXIT_PROG_ERROR);
     489        }
     490
     491        // These values are different than the size of the actual image which includes
     492        // the bias area.
    482493        in->numCols = xmax - xmin + 1;
    483494        in->numRows = ymax - ymin + 1;
     
    489500
    490501void
    491 readImage(sFile *in, int extnum, ippStage stage)
     502readImage(sFile *in, int extnum, ippStage stage, bool isMask)
    492503{
    493504    psRegion region = {0, 0, 0, 0};
     
    526537            streaksExit("", PS_EXIT_DATA_ERROR);
    527538        }
     539        if (in->image->type.type == PS_TYPE_U16) {
     540            in->exciseValue = 65535;
     541            psMetadataAddU16(in->header, PS_LIST_TAIL, "BLANK", 0, "", 65535);
     542            psMetadataAddU16(in->header, PS_LIST_TAIL, "ZBLANK", 0, "", 65535);
     543        } else {
     544            in->exciseValue = NAN;
     545        }
    528546    }  else {
    529547        if (stage != IPP_STAGE_RAW) {
     
    539557        psImage *image = (psImage *) (in->imagecube->data[0]);
    540558    }
    541     setDataExtent(stage, in);
     559    setDataExtent(stage, in, (stage == IPP_STAGE_RAW) && !isMask);
    542560}
    543561
     
    676694writeImageCube(sFile *sfile, psArray *imagecube, psString extname, int extnum)
    677695{
    678     if (!imagecube) {
     696    if (!sfile || !imagecube) {
    679697        return;
    680698    }
     
    687705    sfile->header = NULL;
    688706}
    689 
    690 #ifdef notdef
    691 void
    692 writeImages(streakFiles *sf, bool exciseImageCube)
    693 {
    694     psString extname = NULL;
    695     if (sf->nHDU > 1) {
    696         bool mdok;
    697         extname = psMetadataLookupStr(&mdok, sf->inImage->header, "EXTNAME");
    698     }
    699     if (sf->inImage->numZPlanes == 0)  {
    700         // note exciseing complete images is handled in readAndCopyToOutput
    701         writeImage(sf->outImage, extname, sf->extnum);
    702         writeImage(sf->recImage, extname, sf->extnum);
    703     } else {
    704         // we have an image cube
    705         double initValue;
    706         if (exciseImageCube) {
    707             // copy the entire input image to the recovery image
    708             writeImageCube(sf->recImage, sf->inImage->imagecube, extname, sf->extnum);
    709             initValue = NAN;
    710         } else {
    711             // otherwise write it to the output
    712             writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum);
    713             initValue = 0;
    714         }
    715 
    716         // borrow one of the images from the imagecube and set it to init value
    717         psImage *image = psArrayGet (sf->inImage->imagecube, 0);
    718         psMemIncrRefCounter(image);
    719         psImageInit(image, initValue);
    720         if (exciseImageCube) {
    721             sf->outImage->image = image;
    722             writeImage(sf->outImage, extname, sf->extnum);
    723         } else {
    724             // write zero valued image to reccovery
    725             if (sf->recImage) {
    726                 sf->recImage->image = image;
    727                 writeImage(sf->recImage, extname, sf->extnum);
    728             }
    729         }
    730         // Assumption: there are no mask and weight images for video cells
    731         return;
    732     }
    733     if (sf->outMask) {
    734         writeImage(sf->outMask, extname, sf->extnum);
    735         writeImage(sf->recMask, extname, sf->extnum);
    736     }
    737     if (sf->outWeight) {
    738         writeImage(sf->outWeight, extname, sf->extnum);
    739         writeImage(sf->recWeight, extname, sf->extnum);
    740     }
    741 }
    742 #endif
    743707
    744708void
     
    952916}
    953917
     918bool
     919isExciseValue(double value, double exciseValue)
     920{
     921    if (isnan(exciseValue)) {
     922        return isnan(value);
     923    } else {
     924        return value == exciseValue;
     925    }
     926}
     927
     928void
     929setMaskedToNAN(streakFiles *sfiles, psU8 maskMask, bool printCounts)
     930{
     931        int maskedPixels = 0;
     932        int nandPixels = 0;
     933        int nandWeights = 0;
     934
     935        psImage *image = sfiles->outImage->image;
     936        psImage *mask = sfiles->inMask->image;
     937        psImage *weight = NULL;
     938        if (sfiles->outWeight) {
     939            weight = sfiles->outWeight->image;
     940        }
     941        double exciseValue = sfiles->inImage->exciseValue;
     942
     943        if (printCounts) {
     944            psTimerStart("NAN_MASKED");
     945        }
     946
     947        for (int y=0; y < sfiles->inImage->numRows; y++) {
     948            for (int x=0; x < sfiles->inImage->numCols; x++) {
     949                // these gets are not necessary, we could just set the pixels to nan
     950                // but I want to get the counts
     951                double imageVal  = psImageGet(image, x, y);
     952                psU8 maskVal;
     953                if (sfiles->stage == IPP_STAGE_RAW) {
     954                    int xChip, yChip;
     955                    cellToChipInt(&xChip, &yChip, sfiles->astrom, x, y);
     956                    maskVal = psImageGet(mask, xChip, yChip);
     957                } else {
     958                    maskVal = psImageGet(mask, x, y);
     959                }
     960                if (maskVal & maskMask) {
     961                    ++maskedPixels;
     962                    if (!isExciseValue(imageVal, sfiles->inImage->exciseValue)) {
     963                        ++nandPixels;
     964                        psImageSet(image, x, y, exciseValue);
     965                    }
     966                    if (weight) {
     967                        double weightVal = weight ? psImageGet(weight, x, y) : 0;
     968                        if (!isnan(weightVal)) {
     969                            ++nandWeights;
     970                            psImageSet(weight, x, y, NAN);
     971                        }
     972                    }
     973                }
     974            }
     975        }
     976        if (printCounts) {
     977            printf("time to NAN mask pixels: %f\n", psTimerClear("NAN_MASKED"));
     978            int totalPixels = image->numRows * image->numCols;
     979            printf("pixels:        %10ld\n", totalPixels);
     980            printf("masked pixels: %10ld %4.2f%%\n", maskedPixels, 100. * maskedPixels / totalPixels);
     981            printf("nand pixels:   %10ld %4.2f%%\n", nandPixels, 100. * nandPixels / totalPixels);
     982            if (weight) {
     983                printf("nand weights:  %10ld %4.2f%%\n", nandWeights, 100. * nandWeights / totalPixels);
     984            }
     985        }
     986}
  • trunk/magic/remove/src/streaksio.h

    r20816 r21156  
    1212void closeImage(sFile *sfile);
    1313
    14 void readImage(sFile *sfile, int extnum, ippStage stage);
     14void readImage(sFile *sfile, int extnum, ippStage stage, bool isMask);
    1515void copyPHU(streakFiles *sfiles, bool remove);
    1616void copyTable(sFile *out, sFile *in, int extnum);
     
    2525bool streakFilesNextExtension(streakFiles *sf);
    2626
     27bool isExciseValue(double, double);
     28void setMaskedToNAN(streakFiles *sfiles, psU8 maskMask, bool printCounts);
    2729#endif // STREAKS_IO_H
  • trunk/magic/remove/src/streaksrelease.c

    r21085 r21156  
    5151    }
    5252
    53     int totalPixels = 0;
    54     int totalMaskedPixels = 0;
    55     int totalNANdPixels = 0;
    56     int totalNANdWeights = 0;
    57 
    5853    // Iterate through each component of the input (there is only one except for raw images)
    5954    do {
     
    7065        }
    7166
    72         int maskedPixels = 0;
    73         int nandPixels = 0;
    74         int nandWeights = 0;
    75 
    76         psImage *image = sfiles->outImage->image;
    77         psImage *mask = sfiles->outMask->image;
    78         psImage *weight= sfiles->outWeight->image;
    79 
    80         for (int y=0; y < image->numRows; y++) {
    81             for (int x=0; x < image->numCols; x++) {
    82                 // these gets are not necessary, we could just set the pixels to nan
    83                 // but I want to get the counts
    84                 double imageVal  = psImageGet(image, x, y);
    85                 double weightVal = psImageGet(weight, x, y);
    86                 psU8 maskVal   = psImageGet(mask, x, y);
    87                 if (maskVal & maskMask) {
    88                     ++maskedPixels;
    89                     if (!isnan(imageVal)) {
    90                         ++nandPixels;
    91                         psImageSet(image, x, y, NAN);
    92                     }
    93                     if (!isnan(weightVal)) {
    94                         ++nandWeights;
    95                         psImageSet(weight, x, y, NAN);
    96                     }
    97                 }
    98             }
    99         }
    100         totalPixels += sfiles->inImage->numRows * sfiles->inImage->numCols;
    101         totalMaskedPixels += maskedPixels;
    102         totalNANdPixels += nandPixels;
    103         totalNANdWeights += nandWeights;
     67        setMaskedToNAN(sfiles, maskMask, true);
    10468
    10569        // write out the destreaked temporary images and the recovery images
     
    10872        printf("time to process component %d: %f\n", sfiles->extnum, psTimerClear("PROCESS_COMPONENT"));
    10973    } while (streakFilesNextExtension(sfiles));
    110 
    111     printf("pixels:        %10ld\n", totalPixels);
    112     printf("masked pixels: %10ld %4.2f%%\n", totalMaskedPixels, 100. * totalMaskedPixels / totalPixels);
    113     printf("nand pixels:   %10ld %4.2f%%\n", totalNANdPixels, 100. * totalNANdPixels / totalPixels);
    114     printf("nand weights:  %10ld %4.2f%%\n", totalNANdWeights, 100. * totalNANdWeights / totalPixels);
    11574
    11675    psTimerStart("CLOSE_IMAGES");
     
    292251    } else {
    293252        // image data directly from psFits
    294         readImage(sf->inImage, sf->extnum, sf->stage);
     253        readImage(sf->inImage, sf->extnum, sf->stage, false);
    295254    }
    296255    sf->outImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header);
     
    325284
    326285    if (sf->inMask) {
    327         readImage(sf->inMask, sf->extnum, sf->stage);
     286        readImage(sf->inMask, sf->extnum, sf->stage, true);
    328287        sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
    329288        if (sf->recMask) {
     
    358317
    359318    if (sf->inWeight) {
    360         readImage(sf->inWeight, sf->extnum, sf->stage);
     319        readImage(sf->inWeight, sf->extnum, sf->stage, false);
    361320        sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
    362321        if (sf->recWeight) {
  • trunk/magic/remove/src/streaksremove.c

    r21085 r21156  
    99static void writeImages(streakFiles *sf, bool exciseImageCube);
    1010static bool replicateOutputs(streakFiles *sfiles);
     11static void updateAstrometry(streakFiles *sfiles);
    1112
    1213int
     
    2122    if (!config) {
    2223        psError(PS_ERR_UNKNOWN, false, "failed to parse arguments\n");
    23         return PS_EXIT_CONFIG_ERROR;
     24        streaksExit("", PS_EXIT_CONFIG_ERROR);
    2425    }
    2526
     
    2728    if (!status) {
    2829        psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n");
    29         return PS_EXIT_CONFIG_ERROR;
     30        streaksExit("", PS_EXIT_CONFIG_ERROR);
    3031    }
    3132    double maskStreak = (double) psMetadataLookupU8(&status, masks, "STREAK");
    3233    if (!status) {
    3334        psError(PM_ERR_CONFIG, false, "failed to lookup mask value for STREAK in recipes\n");
    34         return PS_EXIT_CONFIG_ERROR;
    35     }
     35        streaksExit("", PS_EXIT_CONFIG_ERROR);
     36    }
     37
     38    // optionally setting pixels with any mask bits execpt POOR.WARP to NAN
     39    psU8 poorWarp = (double) psMetadataLookupU8(&status, masks, "POOR.WARP");
     40    if (!status) {
     41        psError(PM_ERR_CONFIG, false, "failed to lookup mask value for POOR.WARP in recipes\n");
     42        streaksExit("", PS_EXIT_CONFIG_ERROR);
     43    }
     44    psU8 maskMask = ~poorWarp;
    3645
    3746    psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS");
     
    4049    if (!streaks) {
    4150        psErrorStackPrint(stderr, "failed to read streaks file: %s", streaksFileName);
    42         exit (PS_EXIT_PROG_ERROR);
     51        streaksExit("", PS_EXIT_PROG_ERROR);
    4352    }
    4453
    4554    streakFiles *sfiles = openFiles(config, true);
    4655    setupAstrometry(sfiles);
     56
     57    bool nanForRelease = psMetadataLookupBool(&status, config->arguments, "NAN_FOR_RELEASE");
     58    if (nanForRelease && (sfiles->inMask == NULL)) {
     59        psError(PS_ERR_UNKNOWN, true, "mask image must be supplied with -release.");
     60        streaksExit("", PS_EXIT_PROG_ERROR);
     61    }
    4762
    4863    bool exciseAll = false;
     
    113128            printf("time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS"));
    114129
    115             if (checkNonWarpedPixels) {
    116                 psTimerStart("EXCISE_NON_WARPED");
    117 
    118                 exciseNonWarpedPixels(sfiles, maskStreak);
    119 
    120                 printf("time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED"));
    121             }
    122130           
    123131            if (sfiles->inImage->image) {
     132                if (checkNonWarpedPixels) {
     133                    psTimerStart("EXCISE_NON_WARPED");
     134
     135                    exciseNonWarpedPixels(sfiles, maskStreak);
     136
     137                    printf("time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED"));
     138                }
    124139                totalStreakPixels +=  psArrayLength(pixels);
    125140                psTimerStart("REMOVE_STREAKS");
     
    137152                }
    138153                printf("time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS"));
     154
     155                if (nanForRelease) {
     156                    setMaskedToNAN(sfiles, maskMask, true);
     157                }
     158
    139159            } else {
    140160                // this component contains an image cube, excise it completely
     
    142162            }
    143163            psArrayElementsFree (pixels);
     164        }
     165
     166        if (sfiles->stage == IPP_STAGE_CHIP) {
     167        // if (CHIP_LEVEL_INPUT(sfiles->stage)) {
     168            updateAstrometry(sfiles);
    144169        }
    145170
     
    302327            true);
    303328    }
     329
     330    if ((argnum = psArgumentGet(argc, argv, "-release"))) {
     331        psArgumentRemove(argnum, &argc, argv);
     332        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "NAN_FOR_RELEASE", 0, "set masked pixels to NAN",
     333            true);
     334    }
    304335   
    305336    if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) {
     
    424455
    425456    return config;
     457}
     458
     459static void
     460updateAstrometry(streakFiles *sf)
     461{
     462    if (sf->bilevelAstrometry) {
     463        linearizeTransforms(sf->astrom);
     464        // XXX: pmAstrometry.c should set the correct CTYPE values
     465        if (!pmAstromWriteWCS(sf->outImage->header, sf->inAstrom->fpa, sf->chip, 0.001)) {
     466            psError(PS_ERR_UNKNOWN, false, "failed to update astrometry for extension %d", sf->extnum);
     467            streaksExit("", PS_EXIT_UNKNOWN_ERROR);
     468        }
     469        if (sf->outMask) {
     470            pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
     471        }
     472        if (sf->outWeight) {
     473            pmAstromWriteWCS(sf->outWeight->header, sf->inAstrom->fpa, sf->chip, 0.001);
     474        }
     475    }
    426476}
    427477
     
    438488    } else {
    439489        // image data directly from psFits
    440         readImage(sf->inImage, sf->extnum, sf->stage);
     490        readImage(sf->inImage, sf->extnum, sf->stage, false);
    441491        if (SFILE_IS_IMAGE(sf->inImage)) {
    442492            sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false,
     
    493543
    494544    if (sf->inMask) {
    495         readImage(sf->inMask, sf->extnum, sf->stage);
    496         sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
    497         if (sf->recMask) {
    498             sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
    499         }
    500         if (updateAstrometry) {
    501             pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
    502         }
    503         setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll);
    504         if (sf->outChMask) {
    505             sf->outChMask->header = (psMetadata *) psMemIncrRefCounter(sf->outMask->header);
    506             sf->outChMask->image = (psImage *) psMemIncrRefCounter(sf->outMask->image);
    507             if (sf->recChMask) {
    508                 sf->recChMask->header = (psMetadata *) psMemIncrRefCounter(sf->recMask->header);
    509                 sf->recChMask->image = (psImage *) psMemIncrRefCounter(sf->recMask->image);
    510             }
    511         }
     545        readImage(sf->inMask, sf->extnum, sf->stage, true);
     546        if (sf->outMask) {
     547            sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
     548            if (sf->recMask) {
     549                sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
     550            }
     551            if (updateAstrometry) {
     552                pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001);
     553            }
     554            setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll);
     555            if (sf->outChMask) {
     556                sf->outChMask->header = (psMetadata *) psMemIncrRefCounter(sf->outMask->header);
     557                sf->outChMask->image = (psImage *) psMemIncrRefCounter(sf->outMask->image);
     558                if (sf->recChMask) {
     559                    sf->recChMask->header = (psMetadata *) psMemIncrRefCounter(sf->recMask->header);
     560                    sf->recChMask->image = (psImage *) psMemIncrRefCounter(sf->recMask->image);
     561                }
     562            }
    512563
    513564#ifdef STREAKS_COMPRESS_OUTPUT
    514         // XXX: see note above
    515         copyFitsOptions(sf->outMask, sf->recMask, sf->inMask);
    516         psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
    517         if (sf->recMask) {
    518             psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
    519         }
    520         if (sf->outChMask) {
    521             copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask);
    522             psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
    523             if (sf->recChMask) {
    524                 psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
    525             }
    526         }
     565            // XXX: see note above
     566            copyFitsOptions(sf->outMask, sf->recMask, sf->inMask);
     567            psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
     568            if (sf->recMask) {
     569                psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
     570            }
     571            if (sf->outChMask) {
     572                copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask);
     573                psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
     574                if (sf->recChMask) {
     575                    psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);
     576                }
     577            }
    527578#endif
     579        }
    528580    }
    529581
    530582    if (sf->inWeight) {
    531         readImage(sf->inWeight, sf->extnum, sf->stage);
     583        readImage(sf->inWeight, sf->extnum, sf->stage, false);
    532584        sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
    533585        if (sf->recWeight) {
     
    661713excisePixel(streakFiles *sfiles, unsigned int x, unsigned int y, bool streak, double newMaskValue)
    662714{
     715    double exciseValue = sfiles->inImage->exciseValue;
     716
    663717    // we clip so that the streak calculation code doesn't have to
    664718    if ((x < 0) || (x >= sfiles->inImage->numCols) || (y < 0) || (y >= sfiles->inImage->numRows)) {
     
    667721
    668722    double imageValue  = psImageGet (sfiles->inImage->image,  x, y);
    669     if (sfiles->recImage && !isnan(imageValue) ) {
     723    if (sfiles->recImage && !isExciseValue(imageValue, sfiles->inImage->exciseValue) ) {
    670724        psImageSet (sfiles->recImage->image,  x, y, imageValue);
    671725    }
    672726
    673727    if (sfiles->transparentStreaks == 0) {
    674         psImageSet (sfiles->outImage->image,  x, y, NAN);
     728        psImageSet (sfiles->outImage->image,  x, y, exciseValue);
    675729    } else {
    676730        if (streak) {
     
    678732            psImageSet (sfiles->outImage->image,  x, y, imageValue + sfiles->transparentStreaks);
    679733        } else {
    680             psImageSet (sfiles->outImage->image,  x, y, NAN);
    681         }
    682     }
    683 
    684     if (sfiles->inWeight) {
     734            psImageSet (sfiles->outImage->image,  x, y, exciseValue);
     735        }
     736    }
     737
     738    if (sfiles->outWeight) {
    685739        if (sfiles->recWeight) {
    686740            double weightValue = psImageGet (sfiles->inWeight->image, x, y);
    687741            psImageSet (sfiles->recWeight->image, x, y, weightValue);
    688742        }
     743        // Assume that weight images are always a floating point type
    689744        psImageSet (sfiles->outWeight->image, x, y, NAN);
    690745    }
    691     if (sfiles->inMask) {
     746    if (sfiles->outMask) {
    692747        if (sfiles->recMask) {
    693748            double maskValue   = psImageGet (sfiles->inMask->image,   x, y);
     
    705760    int xParity = sfiles->astrom->xParity;
    706761    int yParity = sfiles->astrom->yParity;
    707     int numCols = sfiles->inImage->numCols;
    708     int numRows = sfiles->inImage->numRows;
     762    int numCols = sfiles->inImage->numCols; // for raw images this was calculated from the width of datasec
     763    int numRows = sfiles->inImage->numRows; // for raw images this was calculated from the height of datasec
    709764
    710765//    printf("%2d x0: %4d y0: %4d xpar: %d ypar: %d\n", sfiles->extnum, cell_x0, cell_y0, xParity, yParity);
    711766
     767    // XXX: in the case of raw images we are making an implicit assumption here
     768    // that the DATASEC begins at (x, y) = (0, 0) in the array for this image
     769    // While this is true for GPC1 it isn't necessarily true
    712770    for (int yCell = 0; yCell < numRows; yCell++) {
    713771        int yChip;
     
    751809
    752810    // we clip so that the streak calculation code doesn't have to
     811    // clipping here insures that we don't touch the overscan regions
    753812    if ((cellCoord->x < 0) || (cellCoord->x >= sfiles->inImage->numCols) ||
    754813        (cellCoord->y < 0) || (cellCoord->y >= sfiles->inImage->numRows)) {
     
    756815    }
    757816
    758     cellToChip(&chipCoord, sfiles->astrom, cellCoord);
    759 
    760 #ifdef notdef
    761     // Shouldn't need this but for raw images I'm getting
    762     // x = warpedPixels->numCols for cell xy70 when cell.x = 0
    763     // Perhaps cell_x0 should be IMNPIX-1 since IMNPIX is in the 1 based system of the fits
    764     // headers
     817    cellToChipInt(&chipCoord.x, &chipCoord.y, sfiles->astrom, cellCoord->x, cellCoord->y);
     818
    765819    if (chipCoord.x < 0 || chipCoord.x >= sfiles->warpedPixels->numCols) {
    766820        return false;
     
    769823        return false;
    770824    }
    771 #endif
    772825
    773826    return psImageGet(sfiles->warpedPixels, chipCoord.x, chipCoord.y) ? true : false;
  • trunk/magic/remove/src/streaksremove.h

    r21085 r21156  
    2626    psArray     *imagecube;
    2727    pmFPAfile   *pmfile;
    28     int         numCols;
    29     int         numRows;
     28    int         col0;
     29    int         numCols;    // number of columns in data section of image (doesn't include bias section)
     30    int         xParity;
     31    int         row0;
     32    int         numRows;    // number of rows in data section of image (does not include bias section)
     33    int         yParity;
     34    double      exciseValue;
    3035} sFile;
    3136
     
    7580    int numCols, int numRows);
    7681// can't declare this in streaksastrom due to header file ordering
    77 extern void cellToChip(PixelPos *chip, strkAstrom *astrom, PixelPos *cell);
     82extern void cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell);
     83extern void cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell);
    7884
    7985extern bool computeWarpedPixels(streakFiles *sf);
  • trunk/magic/remove/src/streaksreplace.c

    r20816 r21156  
    327327    } else {
    328328        // image data directly from psFits
    329         readImage(sf->inImage, sf->extnum, sf->stage);
     329        readImage(sf->inImage, sf->extnum, sf->stage, false);
    330330    }
    331331    // read the recovery pixels
    332     readImage(sf->recImage, sf->extnum, sf->stage);
     332    readImage(sf->recImage, sf->extnum, sf->stage, false);
    333333
    334334    sf->outImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header);
     
    359359#endif
    360360    if (sf->inMask) {
    361         readImage(sf->inMask, sf->extnum, sf->stage);
    362         readImage(sf->recMask, sf->extnum, sf->stage);
     361        readImage(sf->inMask, sf->extnum, sf->stage, true);
     362        readImage(sf->recMask, sf->extnum, sf->stage, true);
    363363        sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header);
    364364
     
    372372
    373373    if (sf->inWeight) {
    374         readImage(sf->inWeight, sf->extnum, sf->stage);
    375         readImage(sf->recWeight, sf->extnum, sf->stage);
     374        readImage(sf->inWeight, sf->extnum, sf->stage, false);
     375        readImage(sf->recWeight, sf->extnum, sf->stage, false);
    376376
    377377        sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header);
  • trunk/magic/remove/src/warpedpixels.c

    r20816 r21156  
    4141        // write out the warped pixels
    4242        psMetadata * header = psMetadataAlloc();
    43         pmAstromWriteWCS(header, sf->inAstrom->fpa, sf->chip, 0.001);
     43        if (sf->inAstrom->fpa->toSky->type != PS_PROJ_DIS) {
     44            pmAstromWriteWCS(header, sf->inAstrom->fpa, sf->chip, 0.001);
     45        }
    4446        psFits *fits = psFitsOpen("warpedpixels.fits", "w");
    4547
     
    7678    sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, NULL,
    7779        sf->warpedPixels->numCols, sf->warpedPixels->numRows);
    78    
    7980
    8081    // convert corners of skycell to sky coordinates
Note: See TracChangeset for help on using the changeset viewer.