IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25027 for branches/pap/psastro


Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
21 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/psastro

    • Property svn:mergeinfo deleted
  • branches/pap/psastro/src/Makefile.am

    r23810 r25027  
    8989        psastroMaskUpdates.c        \
    9090        psastroMaskUtils.c          \
     91        psastroChooseGlintStars.c   \
     92        psastroLoadGlints.c   \
    9193        psastroLoadGhosts.c         \
    9294        psastroGhostUtils.c         \
  • branches/pap/psastro/src/psastro.h

    r23810 r25027  
    7373bool              psastroMaskUpdates (pmConfig *config);
    7474
     75bool              psastroLoadGlints (pmConfig *config);
     76bool              psastroChooseGlintStars (pmConfig *config, psArray *refs, const char *source);
     77
    7578psArray          *psastroLoadRefstars (pmConfig *config, const char *source);
    7679bool              psastroChipAstrom (pmConfig *config);
     
    144147bool              psastroZeroPoint (pmConfig *config);
    145148bool              psastroZeroPointReadout(pmReadout *readout, float zeropt, float exptime);
    146 bool              psastroZeroPointFromRecipe (float *zeropt, float *exptime, pmFPA *fpa, psMetadata *recipe);
     149bool              psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe);
    147150
    148151// masking functions
     
    162165pmChip           *psastroFindChip (double *xChip, double *yChip, pmFPA *fpa, double xFPA, double yFPA);
    163166bool              psastroChipBounds (pmFPA *fpa);
     167bool              psastroFindChipInXrange (pmFPA *fpa, int nChip, double xFPA, double yFPA);
     168bool              psastroFindChipInYrange (pmFPA *fpa, int nChip, double xFPA, double yFPA);
     169bool              psastroFindChipYedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip);
     170bool              psastroFindChipXedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip);
     171bool              psastroFPAtoChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA);
     172
    164173
    165174// psastroExtract functions
  • branches/pap/psastro/src/psastroAnalysis.c

    r23688 r25027  
    8686        return false;
    8787    }
     88
     89    if (!psastroChooseGlintStars (config, refs, "PSASTRO.INPUT")) {
     90        psError (PSASTRO_ERR_UNKNOWN, false, "failed to select glint stars from reference star list\n");
     91        psFree(refs);
     92        return false;
     93    }
    8894    psFree (refs);  // refs of interest are saved on readout->analysis
    8995
  • branches/pap/psastro/src/psastroAstromGuess.c

    r21422 r25027  
    382382    psStats *statsQ = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    383383
    384     psVectorStats (statsP, cornerPd, NULL, cornerMK, 1);
    385     psVectorStats (statsQ, cornerQd, NULL, cornerMK, 1);
     384    if (!psVectorStats (statsP, cornerPd, NULL, cornerMK, 1)) {
     385        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     386        return false;
     387    }
     388    if (!psVectorStats (statsQ, cornerQd, NULL, cornerMK, 1)) {
     389        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     390        return false;
     391    }
    386392
    387393    float angle = atan2 (map->y->coeff[1][0], map->x->coeff[1][0]);
  • branches/pap/psastro/src/psastroChipAstrom.c

    r21409 r25027  
    130130    }
    131131
     132    if (numGoodChips == 0) {
     133        psError(PSASTRO_ERR_UNKNOWN, false, "Failed to fit any chips");
     134        return false;
     135    }
     136
    132137    if (!psastroFixChips (config, recipe)) {
    133138        psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");
  • branches/pap/psastro/src/psastroChooseRefstars.c

    r23412 r25027  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     8 *  @version $Revision: 1.21 $
    99 *  @date $Date: 2009-02-07 02:03:34 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
     
    4949    pmFPAview *view = pmFPAviewAlloc (0);
    5050    pmFPA *fpa = input->fpa;
     51
     52    // XXX kind of a hack -- think this through a bit more clearly:
     53    if (psMetadataLookupPtr (&status, fpa->analysis, "MATCHED_REFS")) {
     54        // we loaded a set of matched references from an earlier astrometry
     55        // analysis.  however, we are re-doing the astrometry here, so remove
     56        // that prior set of matched references
     57        psMetadataRemoveKey (fpa->analysis, "MATCHED_REFS");
     58    }
    5159
    5260    // sort by mag
     
    114122                psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);
    115123
     124# if (0)
     125                // XXX test
     126                FILE *outfile = fopen ("refstars.dat", "w");
     127                assert (outfile);
     128                for (int nn = 0; nn < refstars->n; nn++) {
     129                          pmAstromObj *ref = refstars->data[nn];
     130                          fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
     131                }
     132                fclose (outfile);
     133# endif
     134
    116135                psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
    117136                psFree (refstars);
  • branches/pap/psastro/src/psastroExtractGhosts.c

    r23810 r25027  
    5353
    5454    // really error-out here?  or just skip?
    55     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     55    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
    5656        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    5757        return false;
  • branches/pap/psastro/src/psastroExtractStars.c

    r23666 r25027  
    6565
    6666    // really error-out here?  or just skip?
    67     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     67    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
    6868        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    6969        return false;
  • branches/pap/psastro/src/psastroFindChip.c

    • Property svn:mergeinfo deleted
    r23810 r25027  
    110110}
    111111
     112// identify chips which land on this column (FP coords)
     113bool psastroFindChipInXrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
     114
     115    if (!chipXmin || !chipXmax) {
     116        psAbort ("chip bounds not set");
     117    }
     118
     119    if (xFPA <  chipXmin->data.F32[nChip]) return false;
     120    if (xFPA >= chipXmax->data.F32[nChip]) return false;
     121    return true;
     122}
     123
     124// identify chips which land on this row (FP coords)
     125bool psastroFindChipInYrange (pmFPA *fpa, int nChip, double xFPA, double yFPA) {
     126
     127    if (!chipYmin || !chipYmax) {
     128        psAbort ("chip bounds not set");
     129    }
     130
     131    if (yFPA <  chipYmin->data.F32[nChip]) return false;
     132    if (yFPA >= chipYmax->data.F32[nChip]) return false;
     133    return true;
     134}
     135
     136// return the FPA coordinates of the Y edges of the chip
     137bool psastroFindChipYedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
     138
     139    *yFPAs = chipYmin->data.F32[nChip];
     140    *yFPAe = chipYmax->data.F32[nChip];
     141    return true;
     142}
     143
     144// return the FPA coordinates of the X edges of the chip
     145bool psastroFindChipXedges (double *yFPAs, double *yFPAe, pmFPA *fpa, int nChip) {
     146
     147    *yFPAs = chipXmin->data.F32[nChip];
     148    *yFPAe = chipXmax->data.F32[nChip];
     149    return true;
     150}
     151
     152// convert FPA to Chip coordinates
     153bool psastroFPAtoChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA) {
     154
     155    pmChip *chip = fpa->chips->data[nChip];
     156
     157    psPlane ptCH, ptFP;
     158    ptFP.x = xFPA;
     159    ptFP.y = yFPA;
     160    psPlaneTransformApply (&ptCH, chip->fromFPA, &ptFP);
     161
     162    *xChip = ptCH.x;
     163    *yChip = ptCH.y;
     164    return true;
     165}
     166
    112167bool psastroExtractFreeChipBounds () {
    113168 
  • branches/pap/psastro/src/psastroFixChipsTest.c

    r21409 r25027  
    140140    psStats *stats;
    141141    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    142     psVectorStats (stats, dX, NULL, NULL, 0);
     142    if (!psVectorStats (stats, dX, NULL, NULL, 0)) {
     143        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     144        return false;
     145    }
    143146    Xo = stats->robustMedian;
    144147    fprintf (stderr, "offset x: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
     
    146149
    147150    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    148     psVectorStats (stats, dY, NULL, NULL, 0);
     151    if (!psVectorStats (stats, dY, NULL, NULL, 0)) {
     152        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     153        return false;
     154    }
    149155    Yo = stats->robustMedian;
    150156    fprintf (stderr, "offset y: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
     
    168174    }
    169175    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    170     psVectorStats (stats, dT, NULL, NULL, 0);
     176    if (!psVectorStats (stats, dT, NULL, NULL, 0)) {
     177        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     178        return false;
     179    }
    171180    float To = stats->robustMedian;
    172181    fprintf (stderr, "offset t: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
  • branches/pap/psastro/src/psastroLoadGhosts.c

    r23810 r25027  
    4646    pmCell *cell = NULL;
    4747    pmReadout *readout = NULL;
    48     float zeropt, exptime;
     48    float zeropt, exptime, MAX_MAG;
    4949    psMetadata *md = NULL;
    5050    psPolynomial2D *centerX = NULL;
     
    7171    if (!strcasecmp(ghostFile, "NONE")) return true;
    7272
    73     double MAX_MAG = psMetadataLookupF32 (&status, recipe, "GHOST_MAX_MAG");
    74 
    7573    if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) {
    7674        psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model");
     
    9795
    9896    // really error-out here?  or just skip?
    99     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     97    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
    10098        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    10199        goto escape;
     
    162160                    // which encompass the full size of the ghost
    163161                    pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, -ghost->srcFP->x, -ghost->srcFP->y);
    164                     fprintf (stderr, "raw chip position: %f, %f ", ghost->chip->x, ghost->chip->y);
     162                    // fprintf (stderr, "raw chip position: %f, %f ", ghost->chip->x, ghost->chip->y);
    165163
    166164                    ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
    167                     fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
     165                    // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
    168166
    169167                    if (!ghostChip) goto skip;
  • branches/pap/psastro/src/psastroLoadRefstars.c

    r23412 r25027  
    128128    if (!strcmp (outformat, "PS1_DEV_0")) {
    129129      refstars = psastroReadGetstar_PS1_DEV_0 (fits);
     130
     131      // XXX test
     132      // FILE *outfile = fopen ("refstars.dat", "w");
     133      // assert (outfile);
     134      // for (int nn = 0; nn < refstars->n; nn++) {
     135      //          pmAstromObj *ref = refstars->data[nn];
     136      //          fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
     137      // }
     138      // fclose (outfile);
    130139    }
    131140    if (refstars == NULL) {
     
    181190            ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
    182191            ref->Mag      = 0.001*psMetadataLookupS32 (&status, row, "MAG");  // ELIXIR uses millimags
     192            ref->Color    = 0.0;
    183193        } else {
    184194            ref->sky->r   = RAD_DEG*psMetadataLookupF64 (&status, row, "RA");
    185195            ref->sky->d   = RAD_DEG*psMetadataLookupF64 (&status, row, "DEC");
    186196            ref->Mag      = psMetadataLookupF32 (&status, row, "MAG"); // PANSTARRS uses mags
     197            ref->Color    = 0.0;
    187198        }
    188199
     
    216227        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
    217228
    218         ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
    219         ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
     229        ref->sky->r   = RAD_DEG*psMetadataLookupF64 (&status, row, "RA");
     230        ref->sky->d   = RAD_DEG*psMetadataLookupF64 (&status, row, "DEC");
    220231        ref->Mag      = psMetadataLookupF32 (&status, row, "MAG");
     232        float MagC1   = psMetadataLookupF32 (&status, row, "MAG_C1");
     233        float MagC2   = psMetadataLookupF32 (&status, row, "MAG_C2");
     234        if (!isnan(MagC1) && !isnan(MagC2)) {
     235            ref->Color = MagC1 - MagC2;
     236        } else {
     237            // XXX save the color and the slope in the table header?
     238            ref->Color = 0.0;
     239        }
    221240
    222241        // XXX VERY temporary hack to avoid M31 bulge
  • branches/pap/psastro/src/psastroMaskUpdates.c

    r23844 r25027  
    2828    pmCell *cell = NULL;
    2929    pmReadout *readout = NULL;
    30     float zeropt, exptime;
     30    float zeropt, exptime, GHOST_MAX_MAG;
    3131
    3232    psImageMaskType ghostMaskValue = pmConfigMaskGet("GHOST", config); // Mask value for ghost pixels
     33    psImageMaskType glintMaskValue = pmConfigMaskGet("GHOST", config); // Mask value for glint pixels (overload ghost)
    3334    psImageMaskType spikeMaskValue = pmConfigMaskGet("SPIKE", config); // Mask value for ghost pixels
    3435    psImageMaskType starMaskValue  = pmConfigMaskGet("STARCORE", config); // Mask value for ghost pixels
     
    5354    }
    5455    bool COUNT_GHOSTS = psMetadataLookupF32 (&status, recipe, "REFSTAR_COUNT_GHOSTS");
    55     double GHOST_MAX_MAG = psMetadataLookupF32 (&status, recipe, "GHOST_MAX_MAG");
    5656    int nGhosts = 0;
     57
     58    // convert star positions to glint positions and add to the fpa->analysis data
     59    if (!psastroLoadGlints (config)) {
     60        psError(PSASTRO_ERR_CONFIG, false, "Error loading glints");
     61        return false;
     62    }
    5763
    5864    psLogMsg ("psastro", PS_LOG_INFO, "generating a bright-star mask");
     
    7985
    8086    // really error-out here?  or just skip?
    81     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     87    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &GHOST_MAX_MAG, fpa, recipe)) {
    8288        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    8389        return false;
     
    221227                    }
    222228
     229                    // This masking option was needed for persistent charge trails in GPC1; it
     230                    // has since been replaced with 'burntool', which is applied upon readout
     231                    // by the camera software, and therefore is aware of the image sequence.
    223232                    if (REFSTAR_MASK_BLEED) {
    224 
    225233                        // convert x,y chip coordinates to cells in maskChip
    226234                        pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y);
     
    245253                }
    246254
    247                 // select the raw objects for this readout (loaded in psastroExtract.c)
     255                // select the ghost object for this readout (loaded in psastroExtractGhosts.c).
     256                // These differ from the reference stars since the star position is not
     257                // contained by the readout; instead, the ghost position is predicted based on
     258                // the ghost model, and the ghost positions associated with a given readout are
     259                // supplied here.
    248260                psArray *ghosts = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GHOSTS");
    249                 if (ghosts == NULL) { continue; }
    250 
    251                 // identify the bright stars of interest
    252                 for (int i = 0; i < ghosts->n; i++) {
    253                     psastroGhost *ghost = ghosts->data[i];
    254                     // XXX bright vs faint ghost bits? (OR with SUSPECT)
    255                     psastroMaskEllipticalAnnulus (readoutMask->mask, ghostMaskValue, ghost->chip->x, ghost->chip->y, ghost->inner, ghost->outer);
    256                 }
    257 
    258                 // select the raw objects for this readout, flag is they fall in a mask
    259                 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS");
    260                 if (rawstars == NULL) return false;
     261                if (ghosts) {
     262                    // mask the ghosts on this readout
     263                    for (int i = 0; i < ghosts->n; i++) {
     264                        psastroGhost *ghost = ghosts->data[i];
     265                        // XXX bright vs faint ghost bits? (OR with SUSPECT)
     266                        psastroMaskEllipticalAnnulus (readoutMask->mask, ghostMaskValue, ghost->chip->x, ghost->chip->y, ghost->inner, ghost->outer);
     267                    }
     268                }
     269
     270                // Select the glint mask regions for this readout (loaded in
     271                // psastroExtractGlints.c).  These glint regions are defined as rectangular
     272                // boxes and are generated for each chip based on the position of the bright
     273                // stars beyond the edge of the focal plane.  This masking is currently very
     274                // GPC1-specific
     275                psArray *glints = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GLINTS");
     276                if (glints) {
     277                    // mask the glints on this readout
     278                    for (int i = 0; i < glints->n; i++) {
     279                        psRegion *glint = glints->data[i];
     280                        psastroMaskRectangle (readoutMask->mask, glintMaskValue, glint->x0, glint->y0, glint->x1, glint->y1);
     281                    }
     282                }
     283
     284                // this probably should move into a function of its own:
     285                {
     286                    // select the raw objects for this readout, flag is they fall in a mask
     287                    psArray *inSources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
     288                    if (inSources == NULL) continue;
    261289               
    262                 // XXX finish this:
    263                 for (int i = 0; i < rawstars->n; i++) {
    264                     pmAstromObj *raw = rawstars->data[i];
    265                     psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[(int)(raw->chip->x)][(int)(raw->chip->y)];
    266                     if (value) continue;
     290                    // create a replacement output array:
     291                    // psArray *outSources = psAllocArrayEmpty(100);
     292
     293                    // XXX finish this: raise a bit for stars that land on certain types of masks;
     294                    // others (eg, bright star core) should be ignored.
     295                    for (int i = 0; i < inSources->n; i++) {
     296                        pmSource *source = inSources->data[i];
     297
     298                        int xChip = source->peak->x;
     299                        int yChip = source->peak->y;
     300
     301                        bool onChip = true;
     302                        onChip &= (xChip >= 0);
     303                        onChip &= (xChip < readoutMask->mask->numCols);
     304                        onChip &= (yChip >= 0);
     305                        onChip &= (yChip < readoutMask->mask->numRows);
     306                        if (!onChip) {
     307                            // if the source is off the edge of the chip, raise a different bit?
     308                            source->mode |= PM_SOURCE_MODE_OFF_CHIP;
     309                            continue;
     310                        }
     311
     312                        psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip];
     313                        if (value & ghostMaskValue) {
     314                            source->mode |= PM_SOURCE_MODE_ON_GHOST;
     315                        }
     316                        // XXX note that for now, glint and ghost are identical
     317                        pmSourceMode PM_SOURCE_MODE_ON_GLINT = PM_SOURCE_MODE_ON_GHOST;
     318                        if (value & glintMaskValue) {
     319                            source->mode |= PM_SOURCE_MODE_ON_GLINT;
     320                        }
     321                        if (value & spikeMaskValue) {
     322                            source->mode |= PM_SOURCE_MODE_ON_SPIKE;
     323                        }
     324                    }
    267325                }
    268326            }
  • branches/pap/psastro/src/psastroMaskUtils.c

    r23810 r25027  
    181181bool psastroMaskEllipticalAnnulus (psImage *mask, psImageMaskType value, float x0, float y0, psEllipseAxes eInner, psEllipseAxes eOuter) {
    182182
     183    // skip the masking if the outer ellipse is nonsensical
     184    psEllipseShape sOuter = psEllipseAxesToShape (eOuter);
     185    if (isnan(sOuter.sx) || isnan(sOuter.sy) || isnan(sOuter.sxy)) return false;
     186
    183187    psEllipseShape sInner = psEllipseAxesToShape (eInner);
    184     psEllipseShape sOuter = psEllipseAxesToShape (eOuter);
     188    if (isnan(sInner.sx) || isnan(sInner.sy) || isnan(sInner.sxy)) {
     189        // use a solid ellipse if the inner ellipse is nonsensical
     190        sInner.sx = 0.1;
     191        sInner.sy = 0.1;
     192        sInner.sxy = 0.0;
     193    }
    185194
    186195    // phi is the coordinate along the elliptical path
  • branches/pap/psastro/src/psastroModelAnalysis.c

    r21409 r25027  
    153153
    154154    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    155     psVectorStats (stats, posZero, NULL, NULL, 0);
     155    if (!psVectorStats (stats, posZero, NULL, NULL, 0)) {
     156        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     157        return false;
     158    }
    156159
    157160    fprintf (outfile, "# pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
  • branches/pap/psastro/src/psastroModelFitBoresite.c

    r21409 r25027  
    6262
    6363    // center (Xo) = mean(Xo), RX = range / 2
    64     psVectorStats (stats, Xo, NULL, NULL, 0);
     64    if (!psVectorStats (stats, Xo, NULL, NULL, 0)) {
     65        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     66        return NULL;
     67    }
    6568    params->data.F32[PAR_X0] = stats->sampleMean;
    6669    params->data.F32[PAR_RX] = (stats->max - stats->min) / 2.0;
    6770
    6871    // center (Yo) = mean(Yo), RY = range / 2
    69     psVectorStats (stats, Yo, NULL, NULL, 0);
     72    if (!psVectorStats (stats, Yo, NULL, NULL, 0)) {
     73        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     74        return NULL;
     75    }
    7076    params->data.F32[PAR_Y0] = stats->sampleMean;
    7177    params->data.F32[PAR_RY] = (stats->max - stats->min) / 2.0;
  • branches/pap/psastro/src/psastroMosaicOneChip.c

    r21422 r25027  
    5858
    5959    // modify the order to correspond to the actual number of matched stars:
    60     if ((match->n < 17) && (order >= 3)) order = 2;
    61     if ((match->n < 13) && (order >= 2)) order = 1;
    62     if ((match->n <  9) && (order >= 1)) order = 0;
    63     if ((match->n <  3) || (order < 0) || (order > 3)) {
     60    int Ndof_min = 3;
     61    int order_max = 0.5*(sqrt(4*match->n - 4*Ndof_min + 1) - 3);
     62    order = PS_MIN (order, order_max);
     63
     64    // if ((match->n < 17) && (order >= 3)) order = 2;
     65    // if ((match->n < 13) && (order >= 2)) order = 1;
     66    // if ((match->n <  9) && (order >= 1)) order = 0;
     67
     68    if (order < 0) {
    6469        psLogMsg ("psastro", 3, "insufficient stars (%ld) or invalid order (%d)", match->n, order);
    6570        return false;
  • branches/pap/psastro/src/psastroOneChipFit.c

    r21422 r25027  
    6464        // modify the order to correspond to the actual number of matched stars:
    6565        int Ndof_min = 3;
    66         int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));
     66        int order_max = 0.5*(sqrt(4*match->n - 4*Ndof_min + 1) - 3);
    6767        order = PS_MIN (order, order_max);
     68
     69        // order 0 : Ro -> nterms = 1 * 2;
     70        // order 1 : Ro, Rx, Ry -> nterms = 3 * 2;
     71        // order 2 : Ro, Rx, Ry, Rxx, Rxy, Ryy -> nterms = 6 * 2;
     72        // order 3 : Ro, Rx, Ry, Rxx, Rxy, Ryy, Rxxx, Rxxy, Rxyy, Ryyy -> nterms = 10 * 2
     73        // 2*(N+1)*(N+2)/2 = (N+1)*(N+2) = nterms;
     74        // (order+1)(order+2) + ndof = nvalues
     75        // order^2 + 3*order + 2 + ndof = nvalue;
     76        // order^2 + 3*order + 2 + ndof - nvalue = 0;
     77        // 2*order = -3 +/- sqrt (9 - 4*(2 - nvalue + ndof));
     78        // 2*order = -3 +/- sqrt (9 - 8 + 4*nvalue - 4*ndof);
     79        // 2*order = (sqrt (1 + 4*nvalue - 4*ndof) - 3);
    6880
    6981        // if ((match->n < 11) && (order >= 3)) order = 2;
  • branches/pap/psastro/src/psastroZeroPoint.c

    r21409 r25027  
    5050
    5151    // really error-out here?  or just skip?
    52     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
     52    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
    5353        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
    5454        return false;
     
    126126    // this analysis has too few data points to use the robust median method
    127127    psStats *stats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    128     psVectorStats (stats, dMag, NULL, NULL, 0);
     128    if (!psVectorStats (stats, dMag, NULL, NULL, 0)) {
     129        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     130        return false;
     131    }
    129132    fprintf (stderr, "zero point %f +/- %f using %d stars; transparency %f\n", stats->clippedMean, stats->clippedStdev, Npts, zeropt - stats->clippedMean);
    130133
     
    145148  return false; }
    146149
    147 bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, pmFPA *fpa, psMetadata *recipe) {
     150bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe) {
    148151
    149152    bool status;
     
    170173        char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");
    171174        if (!status) {
    172             psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     175            // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
    173176            continue;
    174177        }
     
    181184        *zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT");
    182185        if (!status) {
    183             psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");
     186            psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing ZEROPT");
    184187            continue;
     188        }
     189        if (ghostMaxMag) {
     190            *ghostMaxMag = psMetadataLookupF32 (&status, refItem->data.md, "GHOST_MAX_MAG");
     191            if (!status) {
     192                psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing GHOST_MAX_MAG");
     193                continue;
     194            }
    185195        }
    186196        psFree (iter);
Note: See TracChangeset for help on using the changeset viewer.