IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23344


Ignore:
Timestamp:
Mar 17, 2009, 11:03:01 AM (17 years ago)
Author:
beaumont
Message:

minor updates to relastroVisual

Location:
branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/include/relastro.h

    r22724 r23344  
    8787
    8888double SIGMA_LIM;
    89 int MIN_SRC_FIT;
     89int SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored
    9090double MIN_ERROR;
    9191
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ConfigInit.c

    r22724 r23344  
    2020
    2121  GetConfig (config, "RELASTRO_SIGMA_LIM",     "%lf", 0, &SIGMA_LIM);
    22   GetConfig (config, "RELASTRO_MIN_SRC_FIT",   "%d",  0, &MIN_SRC_FIT);
     22  GetConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW);
    2323
    2424  // XXX these are used in relphot to identify poor stars / images -- define
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/FitChip.c

    r22724 r23344  
    66# define FIT_CHIP_NITER     3
    77# define FIT_CHIP_NSIGMA    3.0
     8
    89
    910// XXX we should test if the fit is sufficiently constrained across the chip, or if the
     
    2829    for (i = Nscatter = 0; i < Nmatch; i++) {
    2930      if (raw[i].mask) continue;
    30       if (raw[i].dMag > FIT_CHIP_MAX_ERROR) continue;
     31      if (isnan(raw[i].dMag) || raw[i].dMag > FIT_CHIP_MAX_ERROR) continue;
    3132
    3233      dL = raw[i].L - ref[i].L;
     
    4142    dsort (values, Nscatter);
    4243    dRmax = FIT_CHIP_NSIGMA*values[(int)(0.40*Nscatter)];
     44    relastroVisualPlotScatter(values, dRmax, Nscatter);
    4345    relastroVisualPlotRawRef(raw, ref, dRmax, Nmatch);
    4446
     
    5254    for (i = 0; i < Nmatch; i++) {
    5355      if (raw[i].mask) continue;
     56      if (isnan(raw[i].dMag) || raw[i].dMag > FIT_CHIP_MAX_ERROR) continue;
    5457
    5558      // only keep objects within dRmax
     
    9699      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, coords);
    97100    }
    98 
    99     relastroVisualPlotRawRef(fit, coords, dRmax, Nmatch);
    100101
    101102  }
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/ImageOps.c

    r22724 r23344  
    293293    // an object with only one detection provides no information about the image calibration
    294294    raw[i].mask = FALSE;
    295     if (catalog[c].average[n].Nmeasure < MIN_SRC_FIT) {
    296       raw[i].mask = TRUE;
    297     }
     295    int mask = FALSE;
     296    if (catalog[c].average[n].Nmeasure <= SRC_MEAS_TOOFEW) {
     297      mask = TRUE;
     298    }
     299    raw[i].mask = mask;
     300
    298301
    299302    switch (mode) {
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/bcatalog.c

    r21508 r23344  
    22
    33int bcatalog (Catalog *subcatalog, Catalog *catalog) {
    4  
     4
    55  int i, j, k, offset, found;
    66  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
     
    2323  /* exclude stars not in range or with too few measurements */
    2424  for (i = 0; i < catalog[0].Naverage; i++) {
    25     if (catalog[0].average[i].Nmeasure < 2) continue;
     25    if (catalog[0].average[i].Nmeasure <= SRC_MEAS_TOOFEW) continue;
    2626
    2727    /* start with all stars good */
     
    4747      /* select measurements by photcode, or equiv photcode, if specified */
    4848      if (NphotcodesKeep > 0) {
    49         found = FALSE;
    50         for (k = 0; (k < NphotcodesKeep) && !found; k++) {
    51           if (photcodesKeep[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
    52           if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
    53         }
    54         if (!found) continue;
     49        found = FALSE;
     50        for (k = 0; (k < NphotcodesKeep) && !found; k++) {
     51          if (photcodesKeep[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     52          if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     53        }
     54        if (!found) continue;
    5555      }
    5656      if (NphotcodesSkip > 0) {
    57         found = FALSE;
    58         for (k = 0; (k < NphotcodesSkip) && !found; k++) {
    59           if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
    60           if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
    61         }
    62         if (found) continue;
     57        found = FALSE;
     58        for (k = 0; (k < NphotcodesSkip) && !found; k++) {
     59          if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
     60          if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE;
     61        }
     62        if (found) continue;
    6363      }
    6464
    6565      /* select measurements by time */
    6666      if (TimeSelect) {
    67         if (catalog[0].measure[offset].t < TSTART) continue;
    68         if (catalog[0].measure[offset].t > TSTOP) continue;
     67        if (catalog[0].measure[offset].t < TSTART) continue;
     68        if (catalog[0].measure[offset].t > TSTOP) continue;
    6969      }
    7070
     
    7575      /* select measurements by quality */
    7676      if (PhotFlagSelect) {
    77         if (PhotFlagBad) {
    78           mask = PhotFlagBad;
    79         } else {
    80           code = GetPhotcodebyCode (catalog[0].measure[offset].photcode);
    81           mask = code[0].astromBadMask;
    82         }
    83         if (mask & catalog[0].measure[offset].photFlags) continue;
     77        if (PhotFlagBad) {
     78          mask = PhotFlagBad;
     79        } else {
     80          code = GetPhotcodebyCode (catalog[0].measure[offset].photcode);
     81          mask = code[0].astromBadMask;
     82        }
     83        if (mask & catalog[0].measure[offset].photFlags) continue;
    8484      }
    8585
     
    8989      /* select measurements by mag limit */
    9090      if (ImagSelect) {
    91         mag = PhotInst (&catalog[0].measure[offset]);
    92         if (mag < ImagMin) continue;
    93         if (mag > ImagMax) continue;
     91        mag = PhotInst (&catalog[0].measure[offset]);
     92        if (mag < ImagMin) continue;
     93        if (mag > ImagMax) continue;
    9494      }
    9595
     
    110110      subcatalog[0].measure[Nmeasure]          = catalog[0].measure[offset];
    111111      subcatalog[0].measure[Nmeasure].averef   = Naverage;
    112       if (RESET) { 
    113         subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    114         subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     112      if (RESET) {
     113        subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     114        subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
    115115      }
    116116      Nmeasure ++;
    117117      Nm ++;
    118118      if (Nmeasure == NMEASURE) {
    119         NMEASURE += 1000;
    120         REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
     119        NMEASURE += 1000;
     120        REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
    121121      }
    122122    }
     
    139139
    140140  if (VERBOSE) {
    141     fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i, 
    142              subcatalog[0].Naverage, subcatalog[0].Nmeasure);
     141    fprintf (stderr, "%d: using %d stars (%d measures) for catalog\n", i,
     142             subcatalog[0].Naverage, subcatalog[0].Nmeasure);
    143143   }
    144144  return (TRUE);
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/relastroVisual.c

    r22726 r23344  
    66#include "relastro.h"
    77
     8#define TESTING
     9
    810#define KAPAX 700
    911#define KAPAY 700
     
    1113static int kapa = -1;
    1214static int kapa2 = -1;
    13 
    14 static int isVisual = 1;
    15 static int plotRawRef = 1;
     15static int kapa3 = -1;
     16
     17static int isVisual = FALSE;
     18static int plotRawRef = TRUE;
     19static int plotScatter = TRUE;
     20static int plotResid = TRUE;
     21static int plotVector = TRUE;
    1622
    1723/** Spawn a kapa window */
     
    2430      return 0;
    2531    }
    26     KapaResize (*kapid, KAPAX, KAPAY);
     32    //    KapaResize (*kapid, KAPAX, KAPAY);
    2733  }
    2834  return 1;
     
    4652
    4753/** Size graphdata to encompass all points */
    48 static void scaleGraphdata(float x[], float y[], Graphdata *graphdata, int n) {
    49   float xlo = 9999999, xhi = -9999999, ylo = 9999999, yhi = -9999999;
    50   int i;
    51   for(i = 0; i < n; i++) {
    52     if(x[i] < xlo) xlo = x[i];
    53     if(x[i] > xhi) xhi = x[i];
    54     if(y[i] < ylo) ylo = y[i];
    55     if(y[i] > yhi) yhi = y[i];
    56   }
    57   graphdata->xmin = xlo;
    58   graphdata->ymin = ylo;
    59   graphdata->xmax = xhi;
    60   graphdata->ymax = yhi;
    61 }
     54static int scaleGraphdata(float x[], float y[], Graphdata *graphdata, int n) {
     55    float xlo = FLT_MAX, xhi = -FLT_MAX, ylo = FLT_MAX, yhi = -FLT_MAX;
     56    int i;
     57    int goodData = 0;
     58    for(i = 0; i < n; i++) {
     59        goodData++;
     60        if(!finite(x[i]) || !finite(y[i])) continue;
     61        if(x[i] < xlo) xlo = x[i];
     62        if(x[i] > xhi) xhi = x[i];
     63        if(y[i] < ylo) ylo = y[i];
     64        if(y[i] > yhi) yhi = y[i];
     65    }
     66    if (goodData < 2) return 0;
     67    graphdata->xmin = xlo;
     68    graphdata->ymin = ylo;
     69    graphdata->xmax = xhi;
     70    graphdata->ymax = yhi;
     71    return 1;
     72}
     73
     74static int residPlot(float x[], float y[],
     75                     float xVec[], float yVec[],
     76                     int npts, int *kapaID) {
     77    if (!plotResid) return 1;
     78    Graphdata graphdata;
     79    KapaSection section;
     80
     81    if (!initWindow(kapaID)) return 0;
     82
     83    KapaInitGraph(&graphdata);
     84    KapaClearPlots(*kapaID);
     85    KapaSetFont(*kapaID, "helvetica", 14);
     86
     87    section.name = "0";
     88    section.x = 0.0; section.y = 0.0;
     89    section.dx = .45, section.dy = .45;
     90    graphdata.ptype = 7;
     91    graphdata.style = 2;
     92
     93    KapaSetSection(*kapaID, &section);
     94    if(!scaleGraphdata(x, xVec, &graphdata, npts)) return 0;
     95    KapaSetLimits(*kapaID, &graphdata);
     96    KapaBox(*kapaID, &graphdata);
     97    KapaSendLabel(*kapaID, "x", KAPA_LABEL_XM);
     98    KapaSendLabel(*kapaID, "dx", KAPA_LABEL_YM);
     99    KapaPrepPlot(*kapaID, npts, &graphdata);
     100    KapaPlotVector(*kapaID, npts, x, "x");
     101    KapaPlotVector(*kapaID, npts, xVec, "y");
     102
     103    section.x = .5; section.y = 0; section.name="1";
     104    KapaSetSection(*kapaID, &section);
     105    if(!scaleGraphdata(x, yVec, &graphdata, npts)) return 0;
     106    KapaSetLimits(*kapaID, &graphdata);
     107    KapaBox(*kapaID, &graphdata);
     108    KapaSendLabel(*kapaID, "x", KAPA_LABEL_XM);
     109    KapaSendLabel(*kapaID, "dy", KAPA_LABEL_YP);
     110    KapaPrepPlot(*kapaID, npts, &graphdata);
     111    KapaPlotVector(*kapaID, npts, x, "x");
     112    KapaPlotVector(*kapaID, npts, yVec, "y");
     113
     114    section.x = .0; section.y = .5; section.name="2";
     115    KapaSetSection(*kapaID, &section);
     116    if(!scaleGraphdata(y, xVec, &graphdata, npts)) return 0;;
     117    KapaSetLimits(*kapaID, &graphdata);
     118    KapaBox(*kapaID, &graphdata);
     119    KapaSendLabel(*kapaID, "y", KAPA_LABEL_XM);
     120    KapaSendLabel(*kapaID, "dx", KAPA_LABEL_YM);
     121    KapaPrepPlot(*kapaID, npts, &graphdata);
     122    KapaPlotVector(*kapaID, npts, y, "x");
     123    KapaPlotVector(*kapaID, npts, xVec, "y");
     124
     125    section.x = .5; section.y = .5; section.name="3";
     126    KapaSetSection(*kapaID, &section);
     127    if(!scaleGraphdata(y, yVec, &graphdata, npts)) return 0;
     128    KapaSetLimits(*kapaID, &graphdata);
     129    KapaBox(*kapaID, &graphdata);
     130    KapaSendLabel(*kapaID, "y", KAPA_LABEL_XM);
     131    KapaSendLabel(*kapaID, "dy", KAPA_LABEL_YP);
     132    KapaPrepPlot(*kapaID, npts, &graphdata);
     133    KapaPlotVector(*kapaID, npts, y, "x");
     134    KapaPlotVector(*kapaID, npts, yVec, "y");
     135
     136    return 1;
     137}
     138
    62139
    63140/**Plot a vector field*/
    64141static int plotVectorField(float x[], float y[],
    65142                           float xVec[], float yVec[],
    66                            int npts, int *kapaID) {
    67 
    68   Graphdata graphdata; 
    69   float singleX[2], singleY[2];
    70   float maxVecLength, vecScaleFactor;
    71   float graphSize;
    72   int i;
     143                           int npts, int *kapaID, double maxVecLength) {
     144
     145    if(!plotVector) return 1;
     146
     147    Graphdata graphdata;
     148    float singleX[2], singleY[2];
     149    float vecScaleFactor;
     150    float graphSize;
     151    int i;
     152    char plotTitle[50];
     153    sprintf(plotTitle, "Maximum Vector Size = %5.1e", maxVecLength);
    73154
    74155    if (!initWindow(kapaID)) return 0;
     
    76157    KapaInitGraph(&graphdata);
    77158    KapaClearPlots(*kapaID);
    78     scaleGraphdata(x, y, &graphdata, npts);
    79 
    80     //scale the raw xvec, yvecs down to fit into the window
    81     maxVecLength = 0;
    82     for(i = 0; i < npts; i++) {
    83         if (fabs(xVec[i]) > maxVecLength) {
    84             maxVecLength = fabs(xVec[i]);
    85         }
    86         if (fabs(yVec[i]) > maxVecLength) {
    87             maxVecLength = fabs(yVec[i]);
    88         }
    89     }
     159    if(!scaleGraphdata(x, y, &graphdata, npts)) return 0;
     160
    90161    graphSize = graphdata.xmax - graphdata.xmin;
    91162    if ((graphdata.ymax - graphdata.ymin) > graphSize) {
    92163        graphSize = graphdata.ymax - graphdata.ymin;
    93164    }
    94     vecScaleFactor = graphSize * 0.1 / maxVecLength;
     165
     166    vecScaleFactor = graphSize * 0.02 / (float)maxVecLength;
     167#ifdef TESTING
     168    fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n",
     169            graphSize, maxVecLength, vecScaleFactor);
     170#endif
     171
    95172
    96173    KapaSetFont (*kapaID, "helvetica", 14);
    97174    KapaSetLimits(*kapaID, &graphdata);
    98175    KapaBox(*kapaID, &graphdata);
    99    
     176    KapaSendLabel(*kapaID, plotTitle, KAPA_LABEL_XP);
     177
    100178    graphdata.ptype = 7;
    101179    graphdata.style = 2;
     
    107185    graphdata.ptype = 0;
    108186    graphdata.style = 0;
     187    graphdata.color = KapaColorByName("blue");
    109188    for(i = 0; i < npts; i++) {
    110189        singleX[0] = x[i];
    111190        singleY[0] = y[i];
    112         singleX[1] = xVec[i] * vecScaleFactor;
    113         singleY[1] = yVec[i] * vecScaleFactor;
    114 
     191        singleX[1] = x[i] + xVec[i] * vecScaleFactor;
     192        singleY[1] = y[i] + yVec[i] * vecScaleFactor;
    115193        KapaPrepPlot(*kapaID, 2, &graphdata);
    116194        KapaPlotVector(*kapaID, 2, singleX, "x");
     
    119197    return 1;
    120198}
     199
     200int relastroVisualPlotScatter(double values[], double thresh, int npts) {
     201    float *x, *data;
     202    int i;
     203    float xline[2], yline[2];
     204    if (!isVisual || !plotScatter) return 1;
     205    if (!initWindow(&kapa2)) return 0;
     206
     207    ALLOCATE(x, float, npts);
     208    ALLOCATE(data, float, npts);
     209
     210    for(i = 0; i < npts; i++) {
     211        x[i] = i;
     212        data[i] = (float) values[i];
     213    }
     214
     215    Graphdata graphdata;
     216    KapaSection section;
     217    section.x = 0; section.y = 0; section.dx = 1; section.dy = 1;
     218    section.name = "junk";
     219
     220    KapaInitGraph(&graphdata);
     221    KapaClearPlots(kapa2);
     222    KapaSetSection(kapa2, &section);
     223
     224    graphdata.ptype = 0;
     225    graphdata.style = 0;
     226    graphdata.xmin = 0;
     227    graphdata.xmax = npts;
     228    graphdata.ymin = 0;
     229    graphdata.ymax = data[npts-1];
     230
     231    KapaSetFont(kapa2, "helvetica", 14);
     232    KapaSetLimits(kapa2, &graphdata);
     233    KapaBox(kapa2, &graphdata);
     234    KapaSendLabel( kapa2, "Object", KAPA_LABEL_XM);
     235    KapaSendLabel( kapa2, "Offset(pixels)", KAPA_LABEL_YM);
     236    KapaSendLabel( kapa2, "Astrometric Offset with fit cutoff",
     237                   KAPA_LABEL_XP);
     238    KapaPrepPlot(kapa2, npts, &graphdata);
     239    KapaPlotVector(kapa2, npts, x, "x");
     240    KapaPlotVector(kapa2, npts, data, "y");
     241
     242    graphdata.color = KapaColorByName("red");
     243    KapaPrepPlot(kapa2, 2, &graphdata);
     244    yline[0] = (float) thresh;
     245    yline[1] = (float) thresh;
     246    xline[0] = graphdata.xmin;
     247    xline[1] = graphdata.xmax;
     248    KapaPlotVector(kapa2, 2, xline, "x");
     249    KapaPlotVector(kapa2, 2, yline, "y");
     250
     251    askUser(&plotScatter);
     252    return 1;
     253}
     254
    121255
    122256
     
    173307  }
    174308
    175   ALLOCATE(xVec, float, numFit);
    176   ALLOCATE(yVec, float, numFit);
     309  if (numFit == 0) return 0;
    177310
    178311  Graphdata graphdata;
     
    184317  graphdata.style = 2;
    185318
    186   scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit);
    187   //  scaleGraphdata(refXfit, refYfit, &graphdata, numFit);
    188 
    189   //plot the fitted objects as vectors
    190   for(i = 0; i < numFit; i++) {
    191       xVec[i] = rawXfit[i] - refXfit[i];
    192       yVec[i] = rawYfit[i] - refYfit[i];
    193   }
    194 
    195   plotVectorField(refX, refY, xVec, yVec, numFit, &kapa2);
     319  if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) {
     320      fprintf(stderr, "Not enough finite points for plotting");
     321      return 0;
     322  }
    196323
    197324  KapaSetFont(kapa, "helvetica", 14);
     
    227354  KapaPlotVector(kapa, numFit, refYfit, "y");
    228355
     356  ALLOCATE(xVec, float, numFit);
     357  ALLOCATE(yVec, float, numFit);
     358
     359  //plot the fitted objects as vectors
     360  for(i = 0; i < numFit; i++) {
     361      xVec[i] = rawXfit[i] - refXfit[i];
     362      yVec[i] = rawYfit[i] - refYfit[i];
     363  }
     364
     365  plotVectorField(rawXfit, rawYfit, xVec, yVec, numFit, &kapa3, dRmax);
     366  if(!residPlot(rawXfit, rawYfit, xVec, yVec, numFit, &kapa2)) {
     367      fprintf(stderr, "Unable to plot residuals");
     368      return 0;
     369  }
     370
     371  FREE(xVec);
     372  FREE(yVec);
    229373
    230374  askUser(&plotRawRef);
  • branches/cnb_branches/cnb_branch_20090301/Ohana/src/relastro/src/relastroVisual.h

    r22725 r23344  
    33
    44int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj);
     5int relastroVisualPlotScatter(double values[], double thresh, int npts);
    56
    67#endif
Note: See TracChangeset for help on using the changeset viewer.