IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30165


Ignore:
Timestamp:
Dec 24, 2010, 3:16:41 PM (15 years ago)
Author:
eugene
Message:

add psphotVisualShowObjectRegions; add option to psphotVisualShowResidualImage to redisplay variance and mask

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/psphot/src/psphotVisual.c

    r30140 r30165  
    9393    strcpy (coords.ctype, "RA---TAN");
    9494
    95     psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    96     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    97     if (!psImageBackground(stats, NULL, inImage, NULL, 0, rng)) {
    98         fprintf (stderr, "failed to get background values\n");
    99         return false;
    100     }
    101 
    10295    image.Nx = inImage->numCols;
    10396    image.Ny = inImage->numRows;
     
    125118    free (image.data2d);
    126119
     120    return true;
     121}
     122
     123bool psphotVisualShowObjectRegions (pmReadout *readout, psMetadata *recipe, psArray *sources) {
     124
     125    KiiImage image;
     126    KapaImageData data;
     127    Coords coords;
     128
     129    bool status = false;
     130
     131    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     132    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     133    assert (maskVal);
     134
     135    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels
     136    assert (maskVal);
     137
     138    maskVal |= markVal;
     139
     140    if (!pmVisualTestLevel("psphot.image.objects", 2)) return true;
     141
     142    int kapa = psphotKapaChannel (1);
     143    if (kapa == -1) return false;
     144
     145    strcpy (coords.ctype, "RA---TAN");
     146
     147    psImage *inImage = readout->image;
     148    psImage *inMask = readout->mask;
     149    image.Nx = inImage->numCols;
     150    image.Ny = inImage->numRows;
     151   
     152    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     153    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
     154    if (!psImageBackground(stats, NULL, inImage, inMask, 0xffff, rng)) {
     155        fprintf (stderr, "failed to get background values\n");
     156        return false;
     157    }
     158
     159    ALLOCATE (image.data2d, float *, image.Ny);
     160    for (int iy = 0; iy < image.Ny; iy++) {
     161        ALLOCATE (image.data2d[iy], float, image.Nx);
     162        for (int ix = 0; ix < image.Nx; ix++) {
     163            image.data2d[iy][ix] = 0;
     164        }
     165    }
     166
     167    // loop over sources and set unmasked pixels to 0
     168    for (int i = 0; i < sources->n; i++) {
     169
     170        pmSource *source = sources->data[i];
     171        if (source == NULL) continue;
     172
     173        psImage *mask = source->maskObj;
     174        if (mask == NULL) continue;
     175
     176        for (int iy = 0; iy < mask->numRows; iy++) {
     177            int jy = iy + mask->row0;
     178            if (jy < 0) continue;
     179            if (jy >= inImage->numRows) continue;
     180            for (int ix = 0; ix < mask->numCols; ix++) {
     181                int jx = ix + mask->col0;
     182                if (jx < 0) continue;
     183                if (jx >= inImage->numCols) continue;
     184
     185                if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue;
     186                image.data2d[jy][jx] = 1;
     187            }
     188        }
     189    }
     190
     191    for (int iy = 0; iy < image.Ny; iy++) {
     192        for (int ix = 0; ix < image.Nx; ix++) {
     193            image.data2d[iy][ix] = (image.data2d[iy][ix] == 0.0) ? NAN : inImage->data.F32[iy][ix];
     194        }
     195    }
     196
     197    strcpy (data.name, "maskObj");
     198    strcpy (data.file, "maskObj");
     199    // data.zero = 0.0;
     200    // data.range = 1.0;
     201    data.zero = stats->robustMedian - stats->robustStdev;
     202    data.range = 5*stats->robustStdev;
     203    data.logflux = 0;
     204
     205    KiiSetChannel (kapa, 2);
     206    KiiNewPicture2D (kapa, &image, &data, &coords);
     207
     208    for (int iy = 0; iy < image.Ny; iy++) {
     209        free (image.data2d[iy]);
     210    }
     211    free (image.data2d);
     212
    127213    psFree (stats);
    128214    psFree (rng);
    129 
     215   
     216    pmVisualAskUser(NULL);
    130217    return true;
    131218}
     
    24012488}
    24022489
    2403 bool psphotVisualShowResidualImage (pmReadout *readout) {
     2490// option to redo variance since in some cases we may have displayed a different image in the meanwhile
     2491bool psphotVisualShowResidualImage (pmReadout *readout, bool reshow) {
    24042492
    24052493    if (!pmVisualTestLevel("psphot.image.resid", 2)) return true;
     
    24082496    if (myKapa == -1) return false;
    24092497
    2410     psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1);
     2498    if (reshow) {
     2499        psphotVisualShowMask (myKapa, readout->mask, "mask", 2);
     2500        psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1);
     2501    }
    24112502    psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", 0);
    24122503
Note: See TracChangeset for help on using the changeset viewer.