IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23839


Ignore:
Timestamp:
Apr 13, 2009, 4:05:58 PM (17 years ago)
Author:
Paul Price
Message:

Generate ds9 region files for stamps at interesting places.

Location:
trunk/psModules/src/imcombine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r23740 r23839  
    850850    psTrace("psModules.imcombine", 1, "Deviation limit: %f\n", limit);
    851851
     852
     853    psString ds9name = NULL;            // Filename for ds9 region file
     854    static int ds9num = 0;              // File number for ds9 region file
     855    psStringAppend(&ds9name, "stamps_reject_%d.ds9", ds9num);
     856    FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "rejected stamps");
     857    psFree(ds9name);
     858    ds9num++;
     859
    852860    int numRejected = 0;                // Number of stamps rejected
    853861    int numGood = 0;                    // Number of good stamps
     
    872880                    }
    873881                }
     882                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red");
    874883
    875884                // Set stamp for replacement
     
    897906                numGood++;
    898907                newMean += deviations->data.F32[i];
     908                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green");
    899909            }
    900910        }
    901911    }
    902912    newMean /= numGood;
     913
     914    if (ds9) {
     915        fclose(ds9);
     916    }
    903917
    904918    if (numRejected > 0) {
  • trunk/psModules/src/imcombine/pmSubtractionEquation.c

    r21422 r23839  
    749749    }
    750750
     751    psString ds9name = NULL;            // Filename for ds9 region file
     752    static int ds9num = 0;              // File number for ds9 region file
     753    psStringAppend(&ds9name, "stamps_solution_%d.ds9", ds9num);
     754    FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "solution stamps");
     755    psFree(ds9name);
     756    ds9num++;
     757
    751758    if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) {
    752759        // Accumulate the least-squares matricies and vectors
     
    761768                (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix1);
    762769                (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector1);
     770                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green");
    763771                numStamps++;
     772            } else if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED) {
     773                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red");
    764774            }
    765775        }
     
    830840                (void)psBinaryOp(sumVector1, sumVector1, "+", stamp->vector1);
    831841                (void)psBinaryOp(sumVector2, sumVector2, "+", stamp->vector2);
     842                pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green");
    832843                numStamps++;
    833844            }
     
    9901001        // XXXXX Free temporary matrices and vectors
    9911002
     1003    }
     1004
     1005    if (ds9) {
     1006        fclose(ds9);
    9921007    }
    9931008
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r23837 r23839  
    149149    return clean;
    150150}
     151
     152//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     153// Functions for generating ds9 region files
     154//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     155
     156static bool ds9regions = false;         // Save ds9 region files?
     157
     158void pmSubtractionRegions(bool state)
     159{
     160    ds9regions = state;
     161}
     162
     163FILE *pmSubtractionStampsFile(const pmSubtractionStampList *stamps, const char *filename,
     164                              const char *description)
     165{
     166    if (!ds9regions || !stamps || !filename) {
     167        return NULL;
     168    }
     169
     170    psLogMsg("psModules.imcombine", PS_LOG_INFO, "Writing %s to ds9 region file: %s",
     171             description, filename);
     172
     173    FILE *file = fopen(filename, "w");
     174
     175    // Outline the stamps
     176    for (int i = 0; i < stamps->num; i++) {
     177        psRegion *region = stamps->regions->data[i]; // Region of interest
     178        float xCentre = 0.5 * (region->x0 + region->x1), yCentre = 0.5 * (region->y0 + region->y1);
     179        fprintf(file, "image;box(%f,%f,%f,%f,0) # color=blue\nimage;text(%f,%f,{%d}) # color=blue\n",
     180                xCentre, yCentre, region->x1 - region->x0, region->y1 - region->y0,
     181                xCentre, yCentre, i);
     182    }
     183
     184    return file;
     185}
     186
     187void pmSubtractionStampPrint(FILE *ds9, float x, float y, float size, const char *color)
     188{
     189    if (!ds9regions || !ds9) {
     190        return;
     191    }
     192    fprintf(ds9, "image;circle(%f,%f,%f)", x, y, size);
     193    if (color && strlen(color) > 0) {
     194        fprintf(ds9, " # color=%s", color);
     195    }
     196    fprintf(ds9, "\n");
     197    return;
     198}
     199
    151200
    152201//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    366415}
    367416
    368 bool pmSubtractionStampsRegions(pmSubtractionStampList *stamps, const char *filename)
    369 {
    370     PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
    371     PS_ASSERT_STRING_NON_EMPTY(filename, false);
    372 
    373     FILE *outFile = fopen(filename, "w"); // File to write
    374     if (!outFile) {
    375         psError(PS_ERR_IO, false, "Unable to open %s for writing", filename);
    376         return false;
    377     }
    378 
    379     for (int i = 0; i < stamps->num; i++) {
    380         // Outline the stamp
    381         psRegion *region = stamps->regions->data[i]; // Region of interest
    382         fprintf(outFile, "image;box(%f,%f,%f,%f,0)\n",
    383                 0.5 * (region->x0 + region->x1), 0.5 * (region->y0 + region->y1),
    384                 region->x1 - region->x0, region->y1 - region->y0);
    385 
    386         psVector *xList = stamps->x->data[i], *yList = stamps->y->data[i]; // Coordinate lists
    387 
    388         for (int j = 0; j < xList->n; j++) {
    389             fprintf(outFile, "image;circle(%f,%f,%d)\n",
    390                     xList->data.F32[j], yList->data.F32[j], stamps->footprint);
    391         }
    392     }
    393 
    394     fclose(outFile);
    395 
    396     return true;
    397 }
     417
    398418
    399419pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, const psVector *y,
     
    424444    int numStamps = stamps->num;        // Number of stamps
    425445
     446    psString ds9name = NULL;            // Filename for ds9 region file
     447    static int ds9num = 0;              // File number for ds9 region file
     448    psStringAppend(&ds9name, "stamps_all_%d.ds9", ds9num);
     449    FILE *ds9 = pmSubtractionStampsFile(stamps, ds9name, "all stamps"); // ds9 region file
     450    ds9num++;
     451
    426452    // Initialise the lists
    427453    stamps->x = psArrayAlloc(numStamps);
     
    442468            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because outside region",
    443469                    xPix, yPix);
     470            pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "magenta");
    444471            continue;
    445472        }
     
    448475            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because bad mask",
    449476                    xPix, yPix);
     477            pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "red");
    450478            continue;
    451479        }
     
    471499                psTrace("psModules.imcombine", 9, "Putting input stamp (%d,%d) into subregion %d",
    472500                        xPix, yPix, j);
     501                pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "green");
    473502            }
    474503        }
     
    477506            psTrace("psModules.imcombine", 9, "Unable to find subregion for stamp (%d,%d)",
    478507                    xPix, yPix);
    479         }
     508            pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "yellow");
     509        }
     510    }
     511
     512    if (ds9) {
     513        fclose(ds9);
    480514    }
    481515
     
    508542    }
    509543
    510     if (psTraceGetLevel("psModules.imcombine") >= 9) {
    511         pmSubtractionStampsRegions(stamps, "stamps_all.ds9");
    512     }
    513 
    514544    return stamps;
    515545}
     
    581611}
    582612
    583 #if 0
    584 bool pmSubtractionStampsGenerate(pmSubtractionStampList *stamps, float fwhm, int kernelSize)
    585 {
    586     PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
    587     PS_ASSERT_FLOAT_LARGER_THAN(fwhm, 0.0, false);
    588     PS_ASSERT_INT_NONNEGATIVE(kernelSize, false);
    589 
    590     int size = kernelSize + stamps->footprint; // Size of postage stamps
    591     int num = stamps->num;              // Number of stamps
    592     float sigma = fwhm / (2.0 * sqrtf(2.0 * log(2.0))); // Gaussian sigma
    593 
    594     for (int i = 0; i < num; i++) {
    595         pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
    596         if (!(stamp->status & PM_SUBTRACTION_STAMP_CALCULATE)) {
    597             continue;
    598         }
    599 
    600         float x = stamp->x, y = stamp->y; // Coordinates of stamp
    601         float flux = stamp->flux; // Flux of star
    602         if (!isfinite(flux)) {
    603             psWarning("Unable to generate PSF for stamp %d --- bad flux.", i);
    604             stamp->status = PM_SUBTRACTION_STAMP_REJECTED;
    605             continue;
    606         }
    607 
    608         float xStamp = x - (int)(x + 0.5); // x coordinate of star in stamp frame
    609         float yStamp = y - (int)(y + 0.5); // y coordinate of star in stamp frame
    610 
    611         psFree(stamp->image2);
    612         stamp->image2 = psKernelAlloc(-size, size, -size, size);
    613         psKernel *target = stamp->image2; // Target stamp
    614 
    615         // Put in a Waussian, just for fun!
    616         for (int v = -size; v <= size; v++) {
    617             for (int u = -size; u <= size; u++) {
    618                 float z = (PS_SQR(u + xStamp) + PS_SQR(v + yStamp)) / (2.0 * PS_SQR(sigma));
    619                 target->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 / (1.0 + z + PS_SQR(z));
    620             }
    621         }
    622 
    623     }
    624 
    625     return true;
    626 }
    627 #endif
    628 
    629613pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *image,
    630614                                                          const psImage *subMask, const psRegion *region,
  • trunk/psModules/src/imcombine/pmSubtractionStamps.h

    r23789 r23839  
    125125
    126126
    127 /// Write a ds9 region file with stamp positions
     127/// Turn on/off generation of ds9 region files
    128128///
    129129/// Intended for debugging
    130 bool pmSubtractionStampsRegions(pmSubtractionStampList *stamps, ///< Stamps
    131                                 const char *filename ///< Filename to which to write regions
     130void pmSubtractionRegions(bool state    ///< Generate ds9 region files?
    132131    );
    133132
     133/// Open a file for ds9 regions
     134///
     135/// Intended for debugging
     136FILE *pmSubtractionStampsFile(const pmSubtractionStampList *stamps, ///< List of stamps, for outlines
     137                              const char *filename, ///< Filename to write
     138                              const char *description ///< Description of file
     139    );
     140
     141/// Print a stamp position to ds9 region file
     142///
     143/// Intended for debugging
     144void pmSubtractionStampPrint(FILE *ds9, ///< ds9 region file
     145                             float x, float y, ///< Position of stamp
     146                             float size,///< Size of circle
     147                             const char *color ///< Colour
     148    );
    134149
    135150#endif
Note: See TracChangeset for help on using the changeset viewer.