IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20036


Ignore:
Timestamp:
Oct 9, 2008, 3:07:38 PM (18 years ago)
Author:
Paul Price
Message:

Merging from Chris Beaumont branch (cns_branch_20081009) to get luminosity function plots.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryObjects.c

    r17437 r20036  
    88*  @author EAM, IfA
    99*
    10 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2008-04-11 07:42:05 $
     10*  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2008-10-10 01:07:38 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <config.h>
    1818#endif
     19
    1920
    2021/******************************************************************************/
     
    2829#include <unistd.h>   // for unlink
    2930#include <pslib.h>
     31#include <kapa.h> // cnb: do I need an IFDEF?
    3032
    3133#include "pmHDU.h"
    3234#include "pmFPA.h"
    3335#include "pmAstrometryObjects.h"
     36#include "pmKapaPlots.h"
    3437
    3538#define PM_ASTROMETRYOBJECTS_DEBUG 1
     39
    3640/******************************************************************************
    3741pmAstromObjSortByMag(**a, **b): sort by mag (descending)
     
    243247    // need to use the stats lookups functions to get the width and center
    244248    for (int i = 0; i < nIter; i++) {
    245         if (!psVectorClipFitPolynomial2D (map->x, results->xStats, mask, 0xff, x, wt, X, Y)) {
     249        if (!psVectorClipFitPolynomial2D (map->x, results->xStats, mask, 0xff, x, wt, X, Y)) {
    246250            psError(PS_ERR_UNKNOWN, false, "failure in clip-fitting for x\n");
    247             psFree (x);
    248             psFree (y);
    249             psFree (X);
    250             psFree (Y);
    251             psFree (wt);
    252             psFree (mask);
    253 
    254             return results;
    255         }
     251            psFree (x);
     252            psFree (y);
     253            psFree (X);
     254            psFree (Y);
     255            psFree (wt);
     256            psFree (mask);
     257
     258            return results;
     259        }
    256260        psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", results->xStats->clippedMean, results->xStats->clippedStdev, results->xStats->clippedNvalues, x->n);
    257261
    258262        if (!psVectorClipFitPolynomial2D (map->y, results->yStats, mask, 0xff, y, wt, X, Y)) {
    259263            psError(PS_ERR_UNKNOWN, false, "failure in clip-fitting for y\n");
    260             psFree (x);
    261             psFree (y);
    262             psFree (X);
    263             psFree (Y);
    264             psFree (wt);
    265             psFree (mask);
    266 
    267             return results;
    268         }
     264            psFree (x);
     265            psFree (y);
     266            psFree (X);
     267            psFree (Y);
     268            psFree (wt);
     269            psFree (mask);
     270
     271            return results;
     272        }
    269273        psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", results->yStats->clippedMean, results->yStats->clippedStdev, results->yStats->clippedNvalues, y->n);
    270274    }
     
    514518    const psMetadata *config)
    515519{
     520
    516521    PS_ASSERT_PTR_NON_NULL(raw, NULL);
    517522    PS_ASSERT_PTR_NON_NULL(ref, NULL);
     
    559564    psF32 **D2 = gridD2->data.F32;
    560565
     566    // vectors to hold dX and dY
     567    int nplot = raw->n * ref->n;
     568    float dXplot[nplot];
     569    float dYplot[nplot];
     570
    561571    // accumulate grids for focal plane (L,M) matches
    562572    for (int i = 0; i < raw->n; i++) {
     
    567577            dY = ob1->FP->y - ob2->FP->y;
    568578
     579            dXplot[(i * ref->n) + j] = dX;
     580            dYplot[(i * ref->n) + j] = dY;
    569581            // fprintf (f, "dX,dY: %8.2f %8.2f : %8.2f %8.2f : %8.2f %8.2f\n", dX, dY, ob1->FP->x, ob2->FP->x, ob1->FP->y, ob2->FP->y);
    570582            // find bin coordinates for this delta-delta
     
    673685    // fprintf (stderr, "sigma: nMatch: %d, nTest: %d, nTen: %d\n", stats->nMatch, stats->nTest, sort->data.U32[sort->n - 10]);
    674686
    675     psFree (sort);
     687    /*** plot DXs and DYs ***/
     688    KapaSection section = {"s1", 0.00, 0.00, 1.0, 1.0};
     689    //KapaSection left = {"s2", 0.05, 0.05, 0.35, 0.8};
     690    //KapaSection right = {"s3", 0.55, 0.05, 0.35, 0.8};
     691    //KapaSection yprof = {"s4", 0.45, 0.05, 0.10, 0.9};
     692    //KapaSection xprof = {"s5", .05, .90, .35, .1};
     693
     694    Graphdata graphdata;
     695    int kapa = pmKapaOpen(true);
     696    KapaClearPlots(kapa);
     697    KapaInitGraph(&graphdata);
     698    KapaSetSection(kapa, &section);
     699    graphdata.xmin = stats->offset.x - 1.5 * maxOffpix;
     700    graphdata.xmax = stats->offset.x + 1.5 * maxOffpix;
     701    graphdata.ymin = stats->offset.y - 1.5 * maxOffpix;
     702    graphdata.ymax = stats->offset.y + 1.5 * maxOffpix;
     703
     704    KapaSetLimits(kapa, &graphdata);
     705    KapaSetFont(kapa, "helvetica", 14);
     706    KapaBox(kapa, &graphdata);
     707    KapaSendLabel (kapa, "X offset", KAPA_LABEL_XM);
     708    KapaSendLabel (kapa, "Y offset", KAPA_LABEL_YM);
     709    KapaSendLabel (kapa, "pmAstromGridAngle residuals. Big Box: Serach Region. Small Box: Correlation Peak.",
     710                   KAPA_LABEL_XP);
     711    graphdata.style = 2;
     712    graphdata.ptype = 0;
     713    graphdata.size = 0.4;
     714    graphdata.color = KapaColorByName ("black");
     715    KapaPrepPlot(kapa, nplot, &graphdata);
     716    KapaPlotVector (kapa, nplot, dXplot, "x");
     717    KapaPlotVector (kapa, nplot, dYplot, "y");
     718
     719    //Overplot bounding box, peak of distribution
     720    float xbound[5] = { -maxOffpix, maxOffpix, maxOffpix, -maxOffpix, -maxOffpix};
     721    float ybound[5] = { -maxOffpix, -maxOffpix, maxOffpix, maxOffpix, -maxOffpix};
     722    float xbin[5] = {stats->offset.x - 0.5 * Scale, stats->offset.x + 0.5 * Scale, stats->offset.x + 0.5 * Scale,
     723                     stats->offset.x - 0.5 * Scale, stats->offset.x - 0.5 * Scale};
     724    float ybin[5] = {stats->offset.y - 0.5 * Scale, stats->offset.y - 0.5 * Scale, stats->offset.y + 0.5 * Scale,
     725                     stats->offset.y + 0.5 * Scale, stats->offset.y - 0.5 * Scale};
     726    graphdata.color = KapaColorByName("red");
     727    graphdata.style = 0;
     728    graphdata.size = 1.0;
     729    KapaPrepPlot(kapa, 5, &graphdata);
     730    KapaPlotVector (kapa, 5, xbound, "x");
     731    KapaPlotVector (kapa, 5, ybound, "y");
     732    KapaPrepPlot(kapa, 5, &graphdata);
     733    KapaPlotVector (kapa, 5, xbin, "x");
     734    KapaPlotVector (kapa, 5, ybin, "y");
     735
     736    KapaPNG(kapa, "dXdY.png");
     737    char c;
     738    fscanf(stdin, "%c", &c);
     739    /*** end ***/
     740
     741  psFree (sort);
    676742    psFree (listNP);
    677743    psFree (gridNP);
     
    730796    minStat->minMetric = 1e10;
    731797    for (double scale = minScale; scale <= maxScale; scale += delScale) {
    732         for (double angle = minAngle; angle <= maxAngle; angle += delAngle) {
    733             rot = pmAstromRotateObj (raw, center, angle, scale);
     798        for (double angle = minAngle; angle <= maxAngle; angle += delAngle) {
     799            rot = pmAstromRotateObj (raw, center, angle, scale);
    734800
    735801# if 0
    736             FILE *f1 = fopen ("raw.dat", "w");
    737             for (int i = 0; i < rot->n; i++) {
    738                 pmAstromObj *obj = rot->data[i];
    739                 fprintf (f1, "%8.2f %8.2f   %6.2f\n", obj->FP->x, obj->FP->y, obj->Mag);
    740             }
    741             fclose (f1);
    742             FILE *f2 = fopen ("ref.dat", "w");
    743             for (int i = 0; i < ref->n; i++) {
    744                 pmAstromObj *obj = ref->data[i];
    745                 fprintf (f2, "%8.2f %8.2f   %6.2f\n", obj->FP->x, obj->FP->y, obj->Mag);
    746             }
    747             fclose (f2);
    748             fprintf (stderr, "type return");
    749             char c;
    750             fscanf (stdin, "%c", &c);
     802            FILE *f1 = fopen ("raw.dat", "w");
     803            for (int i = 0; i < rot->n; i++) {
     804                pmAstromObj *obj = rot->data[i];
     805                fprintf (f1, "%8.2f %8.2f   %6.2f\n", obj->FP->x, obj->FP->y, obj->Mag);
     806            }
     807            fclose (f1);
     808            FILE *f2 = fopen ("ref.dat", "w");
     809            for (int i = 0; i < ref->n; i++) {
     810                pmAstromObj *obj = ref->data[i];
     811                fprintf (f2, "%8.2f %8.2f   %6.2f\n", obj->FP->x, obj->FP->y, obj->Mag);
     812            }
     813            fclose (f2);
     814            fprintf (stderr, "type return");
     815            char c;
     816            fscanf (stdin, "%c", &c);
    751817# endif
    752 
    753             newStat = pmAstromGridAngle (rot, ref, config);
    754             newStat->angle  = angle;
    755             newStat->scale  = scale;
    756             newStat->center = center;
    757 
    758             if (isfinite(newStat->minMetric) && (newStat->minMetric > 0.0) && (newStat->minMetric < minStat->minMetric)) {
    759                 *minStat = *newStat;
    760                 psLogMsg ("psModule.astrom", 4, "grid test - offset: %7.2f,%7.2f @ %6.1f deg x %7.3f (%4d pts, %5.1f sig, %5.1f var, %6.3f log metric) *",
    761                           minStat->offset.x, minStat->offset.y, PS_DEG_RAD*minStat->angle, minStat->scale, minStat->nMatch, minStat->nSigma, minStat->minVar, log10(minStat->minMetric));
    762             } else {
    763                 psLogMsg ("psModule.astrom", 4, "grid test - offset: %7.2f,%7.2f @ %6.1f deg x %7.3f (%4d pts, %5.1f sig, %5.1f var, %6.3f log metric)",
    764                           newStat->offset.x, newStat->offset.y, PS_DEG_RAD*newStat->angle, newStat->scale, newStat->nMatch, newStat->nSigma, newStat->minVar, log10(newStat->minMetric));
    765 
    766             }
    767             psFree (newStat);
    768             psFree (rot);
    769         }
     818            newStat = pmAstromGridAngle (rot, ref, config);
     819            newStat->angle  = angle;
     820            newStat->scale  = scale;
     821            newStat->center = center;
     822
     823            if (isfinite(newStat->minMetric) && (newStat->minMetric > 0.0) && (newStat->minMetric < minStat->minMetric)) {
     824                *minStat = *newStat;
     825                psLogMsg ("psModule.astrom", 4, "grid test - offset: %7.2f,%7.2f @ %6.1f deg x %7.3f (%4d pts, %5.1f sig, %5.1f var, %6.3f log metric) *",
     826                          minStat->offset.x, minStat->offset.y, PS_DEG_RAD*minStat->angle, minStat->scale, minStat->nMatch, minStat->nSigma, minStat->minVar, log10(minStat->minMetric));
     827            } else {
     828                psLogMsg ("psModule.astrom", 4, "grid test - offset: %7.2f,%7.2f @ %6.1f deg x %7.3f (%4d pts, %5.1f sig, %5.1f var, %6.3f log metric)",
     829                          newStat->offset.x, newStat->offset.y, PS_DEG_RAD*newStat->angle, newStat->scale, newStat->nMatch, newStat->nSigma, newStat->minVar, log10(newStat->minMetric));
     830
     831            }
     832            psFree (newStat);
     833            psFree (rot);
     834        }
    770835    }
    771836    psLogMsg ("psModule.astrom.grid.match", 4, "grid best - offset: %7.2f,%7.2f @ %6.1f deg x %7.3f (%4d pts, %5.1f sig, %5.1f var, %6.3f log metric)",
  • trunk/psastro/src/psastro.h

    r19512 r20036  
    1717// logN = offset + slope * logS
    1818typedef struct {
    19     double mMin;                        // minimum magnitude bin with data
    20     double mMax;                        // maximum magnitude bin with data
    21     double offset;                      // fitted line offset
    22     double slope;                       // fitted line slope
    23     double mPeak;                       // mag of peak bin
    24     int nPeak;                          // # of stars in peak bin
    25     int sPeak;                          // sum of stars to peak bin
     19    double mMin;                        // minimum magnitude bin with data
     20    double mMax;                        // maximum magnitude bin with data
     21    double offset;                      // fitted line offset
     22    double slope;                       // fitted line slope
     23    double mPeak;                       // mag of peak bin
     24    int nPeak;                          // # of stars in peak bin
     25    int sPeak;                          // sum of stars to peak bin
    2626} pmLumFunc;
    2727
     
    4747bool              psastroChooseRefstars (pmConfig *config, psArray *refs);
    4848bool              psastroRefstarSubset (pmReadout *readout);
    49 pmLumFunc        *psastroLuminosityFunction (psArray *stars);
     49pmLumFunc        *psastroLuminosityFunction (psArray *stars, pmLumFunc *rawFunc);
     50bool              psastroLuminosityFunctionPlot(psVector *lnMag, psVector *Mag, pmLumFunc *lumFunc, pmLumFunc *rawFunc);
    5051psArray          *psastroRemoveClumps (psArray *input, int scale);
    5152
     
    5657
    5758// mosaic fitting functions
    58 bool              psastroMosaicDistortion (pmFPA *fpa, psMetadata *recipe, int pass);
     59bool              psastroMosaicDistortion (pmFPA *fpa, psMetadata *recipe, int pass);
    5960psPlaneTransform *psastroMosaicFitRotAndScale (pmFPA *fpa);
    6061bool              psastroMosaicApplyRotAndScale (pmFPA *fpa, psPlaneTransform *TPtoFP);
    61 bool              psastroMosaicDistortionFromGradients (pmFPA *fpa, psMetadata *recipe);
     62bool              psastroMosaicDistortionFromGradients (pmFPA *fpa, psMetadata *recipe);
    6263bool              psastroMosaicCorrectDistortion (pmFPA *fpa, psPlaneTransform *TPtoFP);
    63 bool              psastroMosaicCommonScale (pmFPA *fpa, psMetadata *recipe);
    64 bool              psastroMosaicAstrom (pmConfig *config);
    65 bool              psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration);
    66 bool              psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration);
    67 bool              psastroMosaicSetAstrom (pmFPA *fpa);
    68 bool              psastroMosaicHeaders (pmConfig *config);
    69 bool              psastroMosaicRescaleChips (pmFPA *fpa);
    70 bool              psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration);
     64bool              psastroMosaicCommonScale (pmFPA *fpa, psMetadata *recipe);
     65bool              psastroMosaicAstrom (pmConfig *config);
     66bool              psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration);
     67bool              psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration);
     68bool              psastroMosaicSetAstrom (pmFPA *fpa);
     69bool              psastroMosaicHeaders (pmConfig *config);
     70bool              psastroMosaicRescaleChips (pmFPA *fpa);
     71bool              psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration);
    7172
    7273// Return version strings.
    73 psString          psastroVersion(void);
    74 psString          psastroVersionLong(void);
     74psString          psastroVersion(void);
     75psString          psastroVersionLong(void);
    7576
    7677// demo plots
    77 bool              psastroPlotRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe);
    78 bool              psastroPlotRefstars (psArray *refstars, psMetadata *recipe);
    79 bool              psastroPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
     78bool              psastroPlotRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe);
     79bool              psastroPlotRefstars (psArray *refstars, psMetadata *recipe);
     80bool              psastroPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
    8081
    81 bool              psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip);
    82 bool              psastroDumpRefstars (psArray *refstars, char *filename);
    83 bool              psastroDumpMatches (pmFPA *fpa, char *filename);
    84 bool              psastroDumpStars (psArray *stars, char *filename);
     82bool              psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip);
     83bool              psastroDumpRefstars (psArray *refstars, char *filename);
     84bool              psastroDumpMatches (pmFPA *fpa, char *filename);
     85bool              psastroDumpStars (psArray *stars, char *filename);
    8586bool              psastroDumpMatchedStars (char *filename, psArray *rawstars, psArray *refstars, psArray *match);
    8687bool              psastroDumpGradients (psArray *gradients, char *filename);
    8788
    88 bool              psastroMosaicSetAstrom_tmp (pmFPA *fpa);
    89 int               psastroSortByMag (const void *a, const void *b);
     89bool              psastroMosaicSetAstrom_tmp (pmFPA *fpa);
     90int               psastroSortByMag (const void *a, const void *b);
    9091
    9192bool              psastroFixChips (pmConfig *config, psMetadata *recipe);
  • trunk/psastro/src/psastroLuminosityFunction.c

    r17677 r20036  
    2727}
    2828
    29 pmLumFunc *psastroLuminosityFunction (psArray *stars) {
     29pmLumFunc *psastroLuminosityFunction (psArray *stars, pmLumFunc *rawFunc) {
    3030
    3131    if (stars->n == 0) return NULL;
     
    3636    double mMax = star->Mag;
    3737    for (int i = 0; i < stars->n; i++) {
    38         star = stars->data[i];
    39         mMin = PS_MIN (star->Mag, mMin);
    40         mMax = PS_MAX (star->Mag, mMax);
     38        star = stars->data[i];
     39        mMin = PS_MIN (star->Mag, mMin);
     40        mMax = PS_MAX (star->Mag, mMax);
    4141    }
    4242
    4343    int nBin = 1 + (mMax - mMin) / dMag;
    4444    if (nBin <= 1) {
    45         psLogMsg ("psastro", 4, "insufficient valid stars for this readout\n");
    46         return NULL;
     45        psLogMsg ("psastro", 4, "insufficient valid stars for this readout\n");
     46        return NULL;
    4747    }
    4848
     
    5454
    5555    for (int i = 0; i < stars->n; i++) {
    56         star = stars->data[i];
    57         if (!isfinite(star->Mag)) continue;
    58         int bin = (star->Mag - mMin) / dMag;
    59         if (bin < 0) psAbort("bin cannot be negative!");
    60         if (bin >= nBin) psAbort("bin cannot be > %d!", nBin);
    61         nMags->data.F32[bin] += 1.0;
     56        star = stars->data[i];
     57        if (!isfinite(star->Mag)) continue;
     58        int bin = (star->Mag - mMin) / dMag;
     59        if (bin < 0) psAbort("bin cannot be negative!");
     60        if (bin >= nBin) psAbort("bin cannot be > %d!", nBin);
     61        nMags->data.F32[bin] += 1.0;
    6262    }
    6363
     
    6767    int sPeak = 0;
    6868    for (int i = 0; i < nMags->n; i++) {
    69         if (nMags->data.F32[i] < nPeak) continue;
    70         iPeak = i;
    71         nPeak = nMags->data.F32[i];
    72         sPeak += nPeak;
     69        if (nMags->data.F32[i] < nPeak) continue;
     70        iPeak = i;
     71        nPeak = nMags->data.F32[i];
     72        sPeak += nPeak;
    7373    }
    7474
     
    8181    int n = 0;
    8282    for (int i = 0; i < nMags->n; i++) {
    83         if (nMags->data.F32[i] < 1) continue;
    84         if ((i > iPeak) && (nMags->data.F32[i] < 0.8*nPeak)) continue;
    85         lnMag->data.F32[n] = log10 (nMags->data.F32[i]);
    86         Mag->data.F32[n] = mMin + (i + 0.5)*dMag;
    87         n++;
     83        if (nMags->data.F32[i] < 1) continue;
     84        if ((i > iPeak) && (nMags->data.F32[i] < 0.8*nPeak)) continue;
     85        lnMag->data.F32[n] = log10 (nMags->data.F32[i]);
     86        Mag->data.F32[n] = mMin + (i + 0.5)*dMag;
     87        n++;
    8888    }
    8989    lnMag->n = n;
     
    100100
    101101    if (!psVectorClipFitPolynomial1D(line, stats, mask, 0xff, lnMag, NULL, Mag)) {
    102         psLogMsg ("psastro", 4, "Failed to fit the luminosity function\n");
    103         return(NULL);
     102        psLogMsg ("psastro", 4, "Failed to fit the luminosity function\n");
     103        return(NULL);
    104104    }
    105105
     
    108108    double mMaxValid = NAN;
    109109    for (int i = 0; i < Mag->n; i++) {
    110         if (mask->data.U8[i]) continue;
    111         if (isnan(mMinValid) || (Mag->data.F32[i] < mMinValid)) {
    112             mMinValid = Mag->data.F32[i];
    113         }
    114         if (isnan(mMaxValid) || (Mag->data.F32[i] > mMaxValid)) {
    115             mMaxValid = Mag->data.F32[i];
    116         }
     110        if (mask->data.U8[i]) continue;
     111        if (isnan(mMinValid) || (Mag->data.F32[i] < mMinValid)) {
     112            mMinValid = Mag->data.F32[i];
     113        }
     114        if (isnan(mMaxValid) || (Mag->data.F32[i] > mMaxValid)) {
     115            mMaxValid = Mag->data.F32[i];
     116        }
    117117    }
    118118
     
    129129    lumFunc->sPeak = sPeak;
    130130
     131    psastroLuminosityFunctionPlot(lnMag, Mag, lumFunc, rawFunc);
     132
    131133    psFree (lnMag);
    132134    psFree (nMags);
Note: See TracChangeset for help on using the changeset viewer.