Changeset 26259
- Timestamp:
- Nov 22, 2009, 2:57:41 PM (16 years ago)
- Location:
- trunk/psastro
- Files:
-
- 24 edited
- 1 copied
-
doc/outline.txt (copied) (copied from branches/eam_branches/20091113/psastro/doc/outline.txt )
-
src/psastro.h (modified) (2 diffs)
-
src/psastroAnalysis.c (modified) (2 diffs)
-
src/psastroArguments.c (modified) (1 diff)
-
src/psastroChipAstrom.c (modified) (2 diffs)
-
src/psastroChooseRefstars.c (modified) (1 diff)
-
src/psastroConvert.c (modified) (2 diffs)
-
src/psastroDemoDump.c (modified) (1 diff)
-
src/psastroFixChips.c (modified) (3 diffs)
-
src/psastroFixChipsTest.c (modified) (1 diff)
-
src/psastroLoadGhosts.c (modified) (1 diff)
-
src/psastroLoadRefstars.c (modified) (2 diffs)
-
src/psastroMaskUpdates.c (modified) (1 diff)
-
src/psastroMosaicAstrom.c (modified) (2 diffs)
-
src/psastroMosaicFPtoTP.c (modified) (2 diffs)
-
src/psastroMosaicGetGrads.c (modified) (1 diff)
-
src/psastroMosaicGradients.c (modified) (1 diff)
-
src/psastroMosaicOneChip.c (modified) (3 diffs)
-
src/psastroMosaicSetMatch.c (modified) (3 diffs)
-
src/psastroOneChipFit.c (modified) (7 diffs)
-
src/psastroOneChipGrid.c (modified) (3 diffs)
-
src/psastroRefstarSubset.c (modified) (3 diffs)
-
src/psastroRemoveClumps.c (modified) (1 diff)
-
src/psastroUtils.c (modified) (2 diffs)
-
src/psastroZeroPoint.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastro.h
r26173 r26259 88 88 bool psastroLuminosityFunctionPlot(psVector *lnMag, psVector *Mag, pmLumFunc *lumFunc, pmLumFunc *rawFunc); 89 89 psArray *psastroRemoveClumps (psArray *input, int scale); 90 psArray *psastroRemoveClumpsIterate (psArray *input, int scale, int nIter); 91 bool psastroRemoveClumpsRawstars (pmConfig *config); 90 92 91 93 92 94 // utility functions: 93 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip , psArray *rawstars, psArray *refstars);95 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip); 94 96 bool psastroWriteStars (char *filename, psArray *sources); 95 97 bool psastroWriteTransform (psPlaneTransform *map); … … 149 151 bool psastroZeroPoint (pmConfig *config); 150 152 psVector *psastroZeroPointReadoutAccum(psVector *dMag, pmReadout *readout, float exptime); 151 bool psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, float edgeFraction, bool useMean);153 bool psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, psMetadata *recipe); 152 154 bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe); 153 155 154 psStats *psastroStatsPercentile (psVector *myVector, float flimit); 156 psStats *psastroStatsPercentile (psVector *myVector, psMetadata *recipe); 157 float psastroStatsPercentileValue (psHistogram *histogram, psHistogram *cumulative, psVector *myVector, float flimit); 155 158 156 159 // masking functions -
trunk/psastro/src/psastroAnalysis.c
r24647 r26259 69 69 } 70 70 71 if (!psastroRemoveClumpsRawstars(config)) { 72 psError (PSASTRO_ERR_UNKNOWN, false, "failed to remove RAWSTAR clumps\n"); 73 return false; 74 } 75 71 76 // load the reference stars overlapping the data stars 72 77 psArray *refs = psastroLoadRefstars(config, "PSASTRO.INPUT"); … … 127 132 psastroMaskUpdates (config); 128 133 129 // XXX how do we specify stack astrometry?130 // psastroStackAstrom (config, refs);131 132 134 return true; 133 135 } -
trunk/psastro/src/psastroArguments.c
r23242 r26259 62 62 // define the reference astrometry file 63 63 status = pmConfigFileSetsMD (config->arguments, &argc, argv, "ASTROM.MODEL", "-astrommodel", "-astrommodellist"); 64 if (status) {65 // if supplied, assume -fixchips is desired66 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.FIX.CHIPS", PS_META_REPLACE, "", true);67 }68 64 69 65 // define the reference astrometry file -
trunk/psastro/src/psastroChipAstrom.c
r25299 r26259 56 56 57 57 // select the raw objects for this readout 58 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS ");58 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 59 59 if (rawstars == NULL) { continue; } 60 60 61 61 // select the raw objects for this readout 62 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS ");62 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 63 63 if (refstars == NULL) { continue; } 64 64 … … 66 66 if ((rawstars->n < 4) || (refstars->n < 4)) { 67 67 readout->data_exists = false; 68 psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", 69 rawstars->n, refstars->n); 68 psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", rawstars->n, refstars->n); 70 69 continue; 71 70 } -
trunk/psastro/src/psastroChooseRefstars.c
r24806 r26259 134 134 135 135 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars); 136 137 // generate a reduced subset excluding the clumps 138 // XXX do we need both REFSTARS and SUBSET? 139 psArray *subset = psastroRemoveClumpsIterate(refstars, 150, 3); 140 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS.SUBSET", PS_DATA_ARRAY, "astrometry objects", subset); 141 136 142 psFree (refstars); 143 psFree (subset); 137 144 psFree (extent); 138 145 139 146 if (matchLumFunc) { 140 // in this case, no PSASTRO.REFSTARS is added to readout->analysis 147 // limit the total magnitude range of PSASTRO.REFSTARS.SUBSET based on 148 // overlapping luminosity functions 141 149 if (!psastroRefstarSubset (readout)) { 142 150 psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n"); -
trunk/psastro/src/psastroConvert.c
r23303 r26259 127 127 128 128 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.RAWSTARS", PS_DATA_ARRAY, "astrometry objects", rawStars); 129 129 130 psLogMsg ("psastro", 4, "loaded %ld sources, using %ld of %ld good sources (inst mag: %f to %f)\n", sources->n, rawStars->n, inStars->n, mMin, mMax); 130 131 psLogMsg ("psastro", 4, "skip reasons: mode: %d, faint: %d, bright: %d, inf: %d\n", nModeSkip, nFaintSkip, nBrightSkip, nInfSkip); … … 153 154 154 155 psF32 *PAR = model->params->data.F32; 156 psF32 *dPAR = model->dparams->data.F32; 155 157 156 158 pmAstromObj *obj = pmAstromObjAlloc (); 157 159 158 160 // is the source magnitude calibrated in any sense? 159 obj->pix->x = PAR[PM_PAR_XPOS]; 160 obj->pix->y = PAR[PM_PAR_YPOS]; 161 obj->pix->x = PAR[PM_PAR_XPOS]; 162 obj->pix->y = PAR[PM_PAR_YPOS]; 163 obj->pix->xErr = dPAR[PM_PAR_XPOS]; 164 obj->pix->yErr = dPAR[PM_PAR_YPOS]; 161 165 obj->Mag = source->psfMag; 166 obj->dMag = source->errMag; 162 167 163 168 // XXX do we have the information giving the readout and cell offset? -
trunk/psastro/src/psastroDemoDump.c
r21409 r26259 160 160 161 161 // select the raw objects for this readout 162 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");162 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 163 163 if (rawstars == NULL) continue; 164 164 165 165 // select the raw objects for this readout 166 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");166 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 167 167 if (refstars == NULL) continue; 168 168 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); -
trunk/psastro/src/psastroFixChips.c
r21422 r26259 248 248 badAstrom |= fabs(obsAngle - refAngle) > angleTol; 249 249 250 fprintf (stderr, "chip %d, angle: %f, pixel: %f,%f\n", view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y); 250 fprintf (stderr, "chip %d, angle: %f, pixel: %f,%f : ", view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y); 251 if (badAstrom) { 252 fprintf (stderr, "BAD ASTROM\n"); 253 } else { 254 fprintf (stderr, "GOOD ASTROM\n"); 255 } 251 256 252 257 // XXX for now, just use first readout … … 265 270 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DY", PS_META_REPLACE, "chip y offset wrt model", obsCoord.y - refCoord.y); 266 271 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DT", PS_META_REPLACE, "chip rot offset wrt model", obsAngle - refAngle); 272 273 continue; 267 274 268 275 // for successful chips, save the measured offsets in the header … … 319 326 } 320 327 321 psastroUpdateChipToFPA (input->fpa, obsChip , rawstars, refstars);328 psastroUpdateChipToFPA (input->fpa, obsChip); 322 329 323 330 // XXX update the header with info to reflect the failure -
trunk/psastro/src/psastroFixChipsTest.c
r23989 r26259 246 246 } 247 247 248 psastroUpdateChipToFPA (fpa, chip , rawstars, refstars);248 psastroUpdateChipToFPA (fpa, chip); 249 249 250 250 // XXX skip the re-fit step for a test -
trunk/psastro/src/psastroLoadGhosts.c
r24650 r26259 119 119 if (! readout->data_exists) { continue; } 120 120 121 // select the raw objects for this readout (loaded in psastroExtract.c) 121 // select the raw objects for this readout (loaded in psastroChooseRefstars.c) 122 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c: 123 // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only 122 124 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 123 125 if (refstars == NULL) { continue; } -
trunk/psastro/src/psastroLoadRefstars.c
r24805 r26259 50 50 return false; 51 51 } 52 53 // the name in the recipe may be one of: 54 // (A) the actual directory name 55 // (B) a reference to the name in the PSASTRO.CATDIRS folder in site.config 56 // (C) a reference to a folder in the PSASTRO.CATDIRS folder in site.config, containing multiple copy locations 52 57 char *catdir_virtual = psMetadataLookupStr(&status, catdirs, catdir_recipe); 58 59 psMetadata *catdir_folder = psMetadataLookupMetadata(&status, catdirs, catdir_recipe); 60 if (catdir_folder) { 61 // randomly choose one of the entries 62 psLogMsg ("psastro", 3, "choosing catdir_folder\n"); 63 int nEntry = catdir_folder->list->n; 64 65 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 66 double frnd = psRandomUniform(rng); 67 int entry = PS_MIN(nEntry - 1, PS_MAX(0, nEntry * frnd)); 68 psFree(rng); 69 70 psMetadataItem *item = psListGet(catdir_folder->list, entry); 71 if (item->type != PS_DATA_STRING) { 72 psError(PSASTRO_ERR_CONFIG, true, "Invalid entry in PSASTRO.CATDIR folder: %s\n", item->name); 73 return false; 74 } 75 catdir_virtual = item->data.str; 76 } 77 53 78 char *catdir = (catdir_virtual == NULL) ? catdir_recipe : catdir_virtual; 54 79 … … 56 81 psString CATDIR = pmConfigConvertFilename(catdir, config, false, false); // Resolved filename 57 82 PS_ASSERT (CATDIR, NULL); 83 84 psLogMsg ("psastro", 3, "looking up reference objects in %s\n", CATDIR); 58 85 59 86 char *getstarCommand = psStringCopy(psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR")); -
trunk/psastro/src/psastroMaskUpdates.c
r26173 r26259 193 193 194 194 // select the raw objects for this readout 195 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c: 196 // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only 197 // applied to the SUBSETs 195 198 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 196 199 if (!refstars) continue; -
trunk/psastro/src/psastroMosaicAstrom.c
r21409 r26259 20 20 21 21 bool status; 22 char filename[256];23 22 24 23 // select the current recipe … … 38 37 pmFPA *fpa = input->fpa; 39 38 40 // before we do object matches, we need to (optionally) fix failed chips. We compare chips with41 // the supplied mosaic model. Adjust significant outliers to match model.42 # if (0)43 if (!psastroFixChips (config, recipe)) {44 psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");45 return false;46 }47 if (!psastroFixChipsTest (config, recipe)) {48 psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");49 return false;50 }51 # endif52 53 39 char *outroot = psMetadataLookupStr (&status, config->arguments, "OUTPUT"); 54 40 if (!status || !outroot) psAbort ("Can't find outroot on config->arguments"); 55 41 56 if (!psastroMosaicFit (fpa, recipe, outroot, 0)) return false; 57 if (!psastroMosaicFit (fpa, recipe, outroot, 1)) return false; 58 if (!psastroMosaicFit (fpa, recipe, outroot, 2)) return false; 59 if (!psastroMosaicFit (fpa, recipe, outroot, 3)) return false; 42 int nIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NITER"); 43 if (!status) psAbort ("missing config value"); 44 45 // this should be in a loop with nIter = 46 for (int iter = 0; iter < nIter; iter++) { 47 if (!psastroMosaicFit (fpa, recipe, outroot, iter)) return false; 48 } 60 49 61 50 // now fit the chips under the common distortion with higher-order terms 62 51 // first, re-perform the match with a slightly tighter circle 63 if (!psastroMosaicSetMatch (fpa, recipe, 4)) {52 if (!psastroMosaicSetMatch (fpa, recipe, nIter)) { 64 53 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (4th pass)"); 65 54 return false; 66 55 } 67 if (!psastroMosaicChipAstrom (fpa, recipe, 4)) {56 if (!psastroMosaicChipAstrom (fpa, recipe, nIter)) { 68 57 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (4th pass)"); 69 58 return false; 70 59 } 60 71 61 if (psTraceGetLevel("psastro.dump") > 0) { 72 snprintf (filename, 256, "%s.10.dat", outroot); 62 // the last filename (see filenames in psastroMosaicFit) 63 char filename[256]; 64 snprintf (filename, 256, "%s.%d.dat", outroot, 2*nIter + 2); 73 65 psastroDumpMatches (fpa, filename); 74 66 } -
trunk/psastro/src/psastroMosaicFPtoTP.c
r21409 r26259 45 45 46 46 // select the raw objects for this readout 47 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");47 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 48 48 if (rawstars == NULL) { continue; } 49 49 50 50 // select the raw objects for this readout 51 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");51 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 52 52 if (refstars == NULL) { continue; } 53 53 … … 126 126 } 127 127 128 // apply the rotation and scale to all stars in PSASTRO.REFSTARS (also adjusts 129 // PSASTRO.REFSTARS.SUBSET since they are the same pointers) 128 130 bool psastroMosaicApplyRotAndScale (pmFPA *fpa, psPlaneTransform *TPtoFP) { 129 131 -
trunk/psastro/src/psastroMosaicGetGrads.c
r15671 r26259 27 27 28 28 // select the raw objects for this readout 29 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");29 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 30 30 if (rawstars == NULL) { continue; } 31 31 32 32 // select the raw objects for this readout 33 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");33 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 34 34 if (refstars == NULL) { continue; } 35 35 -
trunk/psastro/src/psastroMosaicGradients.c
r21409 r26259 48 48 49 49 // select the raw objects for this readout 50 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");50 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 51 51 if (rawstars == NULL) { continue; } 52 52 53 53 // select the raw objects for this readout 54 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");54 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 55 55 if (refstars == NULL) { continue; } 56 56 -
trunk/psastro/src/psastroMosaicOneChip.c
r24037 r26259 31 31 32 32 // select the raw objects for this readout 33 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");33 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 34 34 if (rawstars == NULL) return false; 35 35 36 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");36 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 37 37 if (refstars == NULL) return false; 38 38 … … 124 124 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 125 125 126 float rawXstdev = psStatsGetValue (results->xStats, psStatsStdevOption(results->xStats->options)); 127 float rawYstdev = psStatsGetValue (results->yStats, psStatsStdevOption(results->yStats->options)); 128 126 129 // pixError is the average 1D scatter in pixels ('results' are in FPA units = microns) 127 float pixError = 0.5*(r esults->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale;130 float pixError = 0.5*(rawXstdev + rawYstdev) / pixelScale; 128 131 129 132 // astError is the average 1D scatter in arcsec ('results' are in FPA units = microns) 130 float astError = 0.5*(r esults->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;133 float astError = 0.5*(rawXstdev + rawYstdev) * plateScale; 131 134 int astNstar = results->yStats->clippedNvalues; 132 135 … … 161 164 psMetadataAddF32 (updates, PS_LIST_TAIL, "EQUINOX", PS_META_REPLACE, "", 2000.0); // XXX this is bogus: should be defined based on equinox of refstars 162 165 166 // additional error measurements: 167 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MDX", PS_META_REPLACE, "mosaic astrometry X stdev (arcsec)", rawXstdev * plateScale); 168 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MSX", PS_META_REPLACE, "mosaic astrometry X systematic err (arcsec)", results->dXsys * plateScale); 169 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MRX", PS_META_REPLACE, "mosaic astrometry X 10-90 percentile (arcsec)", results->dXrange * plateScale); 170 171 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MDY", PS_META_REPLACE, "mosaic astrometry Y stdev (arcsec)", rawYstdev * plateScale); 172 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MSY", PS_META_REPLACE, "mosaic astrometry Y systematic err (arcsec)", results->dYsys * plateScale); 173 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_MRY", PS_META_REPLACE, "mosaic astrometry Y 10-90 percentile (arcsec)", results->dYrange * plateScale); 174 163 175 // determine fromFPA transformation and apply new transformation to raw & ref stars 164 psastroUpdateChipToFPA (fpa, chip , rawstars, refstars);176 psastroUpdateChipToFPA (fpa, chip); 165 177 166 178 //plot results -
trunk/psastro/src/psastroMosaicSetMatch.c
r21422 r26259 26 26 double RADIUS = psMetadataLookupF32 (&status, recipe, radiusWord); 27 27 if (!status) { 28 psError(PS_ERR_IO, false, "Failed to lookup matching radius: %s", radiusWord); 29 psFree (view); 30 return false; 28 psAbort("Failed to lookup matching radius: %s", radiusWord); 29 } 30 31 int uniqIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.UNIQ.ITER"); 32 if (!status) { 33 psAbort("Failed to lookup matching PSASTRO.MOSAIC.UNIQ.ITER"); 31 34 } 32 35 … … 58 61 59 62 // select the raw objects for this readout 60 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");63 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 61 64 if (rawstars == NULL) { continue; } 62 65 63 66 // select the raw objects for this readout 64 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");67 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 65 68 if (refstars == NULL) { continue; } 66 69 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); … … 68 71 psArray *matches = pmAstromRadiusMatchChip (rawstars, refstars, RADIUS); 69 72 psTrace ("psastro", 4, "Matched %ld refstars\n", matches->n); 73 74 if (iteration >= uniqIter) { 75 psArray *unique = pmAstromRadiusMatchUniq (rawstars, refstars, matches); 76 if (!unique) { 77 psLogMsg ("psastro", 3, "failed to generate a uniq set of matched sources\n"); 78 return false; 79 } 80 psFree (matches); 81 matches = unique; 82 } 70 83 71 84 pmAstromVisualPlotMosaicMatches(rawstars, refstars, matches, iteration, recipe); -
trunk/psastro/src/psastroOneChipFit.c
r24035 r26259 28 28 REQUIRED_RECIPE_VALUE (int nIter, "PSASTRO.MATCH.FIT.NITER", S32); 29 29 30 // for iterations >= uniqIter, require a single match per reference 31 REQUIRED_RECIPE_VALUE (int uniqIter, "PSASTRO.MATCH.UNIQ.ITER", S32); 32 30 33 // correct radius to FP units (physical pixel scale in microns per pixel) 31 34 REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32); … … 61 64 return false; 62 65 } 66 67 if (iter >= uniqIter) { 68 psArray *unique = pmAstromRadiusMatchUniq (rawstars, refstars, match); 69 if (!unique) { 70 psLogMsg ("psastro", 3, "failed to generate a uniq set of matched sources\n"); 71 return false; 72 } 73 psFree (match); 74 match = unique; 75 } 63 76 64 77 // modify the order to correspond to the actual number of matched stars: … … 101 114 } 102 115 103 // XXX allow stati tic to be set by the user116 // XXX allow statistic to be set by the user 104 117 // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 105 118 fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); … … 117 130 118 131 // determine fromFPA transformation and apply new transformation to raw & ref stars 119 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 132 // this applies the transformation to all stars (including subset) 133 psastroUpdateChipToFPA (fpa, chip); // updates PSASTRO.RAWSTARS and PSASTRO.REFSTARS 120 134 121 135 // toSky converts from FPA & TPA units (microns) to sky units (radians) 122 136 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 123 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 124 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 137 138 float rawXstdev = psStatsGetValue (results->xStats, psStatsStdevOption(results->xStats->options)); 139 float rawYstdev = psStatsGetValue (results->yStats, psStatsStdevOption(results->yStats->options)); 140 141 float astError = 0.5*(rawXstdev + rawYstdev) * plateScale; 125 142 int astNstar = results->yStats->clippedNvalues; 126 143 psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar); … … 136 153 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 137 154 155 float rawXstdev = psStatsGetValue (results->xStats, psStatsStdevOption(results->xStats->options)); 156 float rawYstdev = psStatsGetValue (results->yStats, psStatsStdevOption(results->yStats->options)); 157 138 158 // pixError is the average 1D scatter in pixels ('results' are in FPA units = microns) 139 // float pixError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale; 140 float pixError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) / pixelScale; 159 float pixError = 0.5*(rawXstdev + rawYstdev) / pixelScale; 141 160 142 161 // astError is the average 1D scatter in arcsec ('results' are in FPA units = microns) 143 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 144 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 162 float astError = 0.5*(rawXstdev + rawYstdev) * plateScale; 163 164 // x and y are forced to use the same subset of values: 145 165 int astNstar = results->yStats->clippedNvalues; 146 166 … … 170 190 psMetadataAddF32 (updates, PS_LIST_TAIL, "EQUINOX", PS_META_REPLACE, "equinox of ref catalog", 2000.0); // XXX this is bogus: should be defined based on equinox of refstars 171 191 172 // XXX drop from here : determine fromFPA transformation and apply new transformation to raw & ref stars 173 // psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 192 // additional error measurements: 193 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CDX", PS_META_REPLACE, "chip astrometry X stdev (arcsec)", rawXstdev * plateScale); 194 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CSX", PS_META_REPLACE, "chip astrometry X systematic err (arcsec)", results->dXsys * plateScale); 195 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CRX", PS_META_REPLACE, "chip astrometry X 10-90 percentile (arcsec)", results->dXrange * plateScale); 196 197 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CDY", PS_META_REPLACE, "chip astrometry Y stdev (arcsec)", rawYstdev * plateScale); 198 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CSY", PS_META_REPLACE, "chip astrometry Y systematic err (arcsec)", results->dYsys * plateScale); 199 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_CRY", PS_META_REPLACE, "chip astrometry Y 10-90 percentile (arcsec)", results->dYrange * plateScale); 174 200 175 201 // XXX check if we correctly applied the new transformation: … … 189 215 psFree (results); 190 216 psFree (fitStats); 217 191 218 return validSolution; 192 219 } -
trunk/psastro/src/psastroOneChipGrid.c
r21409 r26259 31 31 32 32 // generate the bright subset of maxNstar entries (note: rawstars is sorted by S/N) 33 psArray * subset= psArrayAlloc (PS_MIN (maxNstar, rawstars->n));33 psArray *gridStars = psArrayAlloc (PS_MIN (maxNstar, rawstars->n)); 34 34 for (int i = 0; (i < maxNstar) && (i < rawstars->n); i++) { 35 subset->data[i] = psMemIncrRefCounter (rawstars->data[i]);35 gridStars->data[i] = psMemIncrRefCounter (rawstars->data[i]); 36 36 } 37 37 38 // XXX set clump scale from recipe 39 psArray *gridStars = psastroRemoveClumps (subset, 150); 40 psFree (subset); 41 42 psArray *refSubset = psastroRemoveClumps (refstars, 150); 43 44 psLogMsg ("psastro", 3, "grid search using %ld raw vs %ld ref stars\n", gridStars->n, refSubset->n); 38 psLogMsg ("psastro", 3, "grid search using %ld raw vs %ld ref stars\n", gridStars->n, refstars->n); 45 39 46 40 // find initial offset / rotation / scale 47 pmAstromStats *gridStats = pmAstromGridMatch (gridStars, ref Subset, recipe);41 pmAstromStats *gridStats = pmAstromGridMatch (gridStars, refstars, recipe); 48 42 if (gridStats == NULL) { 49 43 psLogMsg ("psastro", 3, "failed to find a grid match solution\n"); 50 44 psFree (gridStars); 51 psFree (refSubset);52 45 return false; 53 46 } … … 55 48 56 49 // tweak the position by finding peak of matches stars 57 stats = pmAstromGridTweak (gridStars, ref Subset, recipe, gridStats);50 stats = pmAstromGridTweak (gridStars, refstars, recipe, gridStats); 58 51 if (stats == NULL) { 59 52 psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n"); 60 53 psFree (gridStats); 61 54 psFree (gridStars); 62 psFree (refSubset);63 55 return false; 64 56 } … … 67 59 // adjust the chip.toFPA terms only 68 60 pmAstromGridApply (chip->toFPA, stats); 69 psastroUpdateChipToFPA (fpa, chip , rawstars, refstars);61 psastroUpdateChipToFPA (fpa, chip); // updates PSASTRO.RAWSTARS and PSASTRO.REFSTARS 70 62 psFree (gridStats); 71 63 psFree (gridStars); 72 psFree (refSubset);73 64 psFree (stats); 74 65 -
trunk/psastro/src/psastroRefstarSubset.c
r21409 r26259 16 16 17 17 // select the raw objects for this readout 18 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS ");18 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 19 19 if (rawstars == NULL) { 20 20 psError(PSASTRO_ERR_DATA, false, "missing rawstars in psastroRefstarSubset\n"); … … 23 23 24 24 // select the raw objects for this readout 25 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS ");25 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 26 26 if (refstars == NULL) { 27 27 psError(PSASTRO_ERR_DATA, false, "missing refstars in psastroRefstarSubset\n"); … … 74 74 psLogMsg ("psastro", 4, "keeping %ld of %ld reference stars\n", subset->n, refstars->n); 75 75 76 psMetadataRemoveKey (readout->analysis, "PSASTRO.REFSTARS ");77 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS ", PS_DATA_ARRAY, "astrometry matches", subset);76 psMetadataRemoveKey (readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 77 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS.SUBSET", PS_DATA_ARRAY, "astrometry matches", subset); 78 78 79 79 if (psTraceGetLevel("psastro.dump") > 0) { -
trunk/psastro/src/psastroRemoveClumps.c
r21422 r26259 12 12 13 13 # include "psastroInternal.h" 14 15 bool psastroRemoveClumpsRawstars (pmConfig *config) { 16 17 bool status; 18 19 pmChip *chip = NULL; 20 pmCell *cell = NULL; 21 pmReadout *readout = NULL; 22 23 // select the current recipe 24 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE); 25 if (!recipe) { 26 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe"); 27 return false; 28 } 29 30 // select the input data sources 31 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSASTRO.INPUT"); 32 if (!input) { 33 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 34 return false; 35 } 36 37 pmFPAview *view = pmFPAviewAlloc (0); 38 pmFPA *fpa = input->fpa; 39 40 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 41 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 42 if (!chip->process || !chip->file_exists) { continue; } 43 44 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 45 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 46 if (!cell->process || !cell->file_exists) { continue; } 47 if (!chip->fromFPA) { continue; } 48 49 // process each of the readouts 50 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 51 if (! readout->data_exists) { continue; } 52 53 // select the raw objects for this readout 54 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS"); 55 if (rawstars == NULL) { continue; } 56 57 // generate a reduced subset excluding the clumps 58 // XXX do we need both RAWSTARS and SUBSET? 59 // XXX put these parameters in the recipe, please 60 psArray *subset = psastroRemoveClumpsIterate(rawstars, 150, 3); 61 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.RAWSTARS.SUBSET", PS_DATA_ARRAY, "astrometry objects", subset); 62 psFree (subset); 63 } 64 } 65 } 66 psFree (view); 67 return true; 68 } 69 70 psArray *psastroRemoveClumpsIterate (psArray *input, int scale, int nIter) { 71 72 psArray *newset = psMemIncrRefCounter (input); 73 for (int i = 0; i < nIter; i++) { 74 psArray *subset = psastroRemoveClumps (newset, 150); 75 psFree (newset); 76 newset = subset; 77 } 78 return newset; 79 } 14 80 15 81 /** -
trunk/psastro/src/psastroUtils.c
r21422 r26259 106 106 } 107 107 108 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip , psArray *rawstars, psArray *refstars) {108 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip) { 109 109 110 110 psRegion *region = pmChipPixels (chip); … … 114 114 psFree (region); 115 115 116 for (int i = 0; i < rawstars->n; i++) { 117 pmAstromObj *raw = rawstars->data[i]; 118 119 psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip); 120 psPlaneTransformApply (raw->TP, fpa->toTPA, raw->FP); 121 psDeproject (raw->sky, raw->TP, fpa->toSky); 122 } 123 124 for (int i = 0; i < refstars->n; i++) { 125 pmAstromObj *ref = refstars->data[i]; 126 psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP); 116 // loop over cells in this chip 117 for (int nCell = 0; nCell < chip->cells->n; nCell++) { 118 pmCell *cell = chip->cells->data[nCell]; 119 if (!cell->process || !cell->file_exists) { continue; } 120 121 // loop over readouts in this cell 122 for (int nRead = 0; nRead < cell->readouts->n; nRead++) { 123 pmReadout *readout = cell->readouts->data[nRead]; 124 if (! readout->data_exists) { continue; } 125 126 // select the raw objects for this readout 127 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 128 if (rawstars) { 129 for (int i = 0; i < rawstars->n; i++) { 130 pmAstromObj *raw = rawstars->data[i]; 131 psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip); 132 psPlaneTransformApply (raw->TP, fpa->toTPA, raw->FP); 133 psDeproject (raw->sky, raw->TP, fpa->toSky); 134 } 135 } 136 137 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 138 if (refstars) { 139 for (int i = 0; i < refstars->n; i++) { 140 pmAstromObj *ref = refstars->data[i]; 141 psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP); 142 } 143 } 144 } 127 145 } 128 146 -
trunk/psastro/src/psastroZeroPoint.c
r25906 r26259 30 30 // recipe options 31 31 bool byExposure = psMetadataLookupBool (&status, recipe, "ZERO.POINT.BY.EXPOSURE"); 32 bool useMean = psMetadataLookupBool (&status, recipe, "ZERO.POINT.USE.MEAN");33 float edgeFraction = psMetadataLookupF32 (&status, recipe, "ZERO.POINT.EDGE.FRACTION");34 32 35 33 // select the input data sources … … 86 84 // calculate dMag for the matched stars just for this readout (well, chip) 87 85 psMetadata *header = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER"); 88 psastroZeroPointAnalysis (header, dMag, zeropt, edgeFraction, useMean);86 psastroZeroPointAnalysis (header, dMag, zeropt, recipe); 89 87 psFree (dMag); 90 88 dMag = NULL; … … 96 94 if (byExposure) { 97 95 psMetadata *header = psMetadataLookupMetadata (&status, fpa->analysis, "PSASTRO.HEADER"); 98 psastroZeroPointAnalysis (header, dMag, zeropt, edgeFraction, useMean); 96 if (!header) { 97 header = psMetadataAlloc (); 98 psMetadataAddMetadata (fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", header); 99 psFree (header); 100 } 101 psastroZeroPointAnalysis (header, dMag, zeropt, recipe); 99 102 psFree (dMag); 100 103 dMag = NULL; … … 113 116 114 117 // select the raw objects for this readout 115 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS ");118 psArray *rawstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.RAWSTARS.SUBSET"); 116 119 if (rawstars == NULL) return dMag; 117 120 118 121 // select the raw objects for this readout 119 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS ");122 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 120 123 if (refstars == NULL) return dMag; 121 124 … … 141 144 } 142 145 143 bool psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, float edgeFraction, bool useMean) {146 bool psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, psMetadata *recipe) { 144 147 145 148 // XXX make this depend on the mode? … … 148 151 return false; 149 152 } 153 154 bool status; 155 bool useMean = psMetadataLookupBool (&status, recipe, "ZERO.POINT.USE.MEAN"); 150 156 151 157 // the zero point analysis depends on the type of desired statistic. For comparisons … … 166 172 } 167 173 } else { 168 stats = psastroStatsPercentile (dMag, edgeFraction);174 stats = psastroStatsPercentile (dMag, recipe); 169 175 if (!stats) { 170 176 psError(PS_ERR_UNKNOWN, false, "failure to measure zero point by edge"); … … 183 189 } 184 190 185 #define MAG_RESOLUTION 0.00 1191 #define MAG_RESOLUTION 0.0002 186 192 187 193 // set the bin closest to the corresponding value. if USE_END is +/- 1, … … 233 239 // return results in stats->sampleMean, sampleStdev 234 240 // XXX this is a misuse of psStats -- make our own structure? 235 psStats *psastroStatsPercentile (psVector *myVector, float flimit) {241 psStats *psastroStatsPercentile (psVector *myVector, psMetadata *recipe) { 236 242 237 243 // search for the 'blue' edge of the dMag distribution: 238 244 // the distribution is not a normal population, but instead has a broad range with fairly hard edges. 239 245 // construct a histogram and look for the 246 247 bool status; 248 float edgeFraction = psMetadataLookupF32 (&status, recipe, "ZERO.POINT.EDGE.FRACTION"); 249 int edgeSample = psMetadataLookupS32 (&status, recipe, "ZERO.POINT.EDGE.SAMPLE"); 250 float edgeSampleFraction = psMetadataLookupF32 (&status, recipe, "ZERO.POINT.EDGE.SAMPLE.FRACTION"); 240 251 241 252 // stats is first used to find the data range … … 245 256 float min = NAN, max = NAN; // Mimimum and maximum values 246 257 258 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 259 247 260 // Get the minimum and maximum values 248 261 if (!psVectorStats(stats, myVector, NULL, NULL, 0)) goto escape; … … 250 263 max = stats->max; 251 264 if (isnan(min) || isnan(max)) goto escape; 252 psTrace("psastro", 6, "Data min/max is (%.2f, %.2f)\n", min, max);265 psTrace("psastro", 5, "Data min/max is (%.2f, %.2f)\n", min, max); 253 266 254 267 // If all data points have the same value, then we set the appropriate members of stats and return. … … 264 277 float binSize = MAG_RESOLUTION; 265 278 long numBins = (max - min) / binSize; // Number of bins 266 psTrace("psastro", 6, "Numbins is %ld\n", numBins);267 psTrace("psastro", 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max);268 269 // Generate the histogram279 psTrace("psastro", 5, "Numbins is %ld\n", numBins); 280 psTrace("psastro", 5, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max); 281 282 // allocate the histogram containers 270 283 histogram = psHistogramAlloc(min, max, numBins); 271 if (!psVectorHistogram(histogram, myVector, NULL, NULL, 0)) {272 // if psVectorHistogram returns false, we have a programming error273 psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for psastroZeroPointAnalysis\n");274 psFree(histogram);275 psFree(stats);276 return NULL;277 }278 if (psTraceGetLevel("psastro") >= 8) {279 PS_VECTOR_PRINT_F32(histogram->bounds);280 PS_VECTOR_PRINT_F32(histogram->nums);281 }282 283 // Convert the specific histogram to a cumulative histogram284 // The cumulative histogram data points correspond to the UPPER bound value (N < Bin[i+1])285 284 cumulative = psHistogramAlloc(min, max, numBins); 286 cumulative->nums->data.F32[0] = histogram->nums->data.F32[0]; 287 for (long i = 1; i < histogram->nums->n; i++) { 288 cumulative->nums->data.F32[i] = cumulative->nums->data.F32[i-1] + histogram->nums->data.F32[i]; 289 cumulative->bounds->data.F32[i-1] = histogram->bounds->data.F32[i]; 290 } 291 if (psTraceGetLevel("psastro") >= 8) { 292 PS_VECTOR_PRINT_F32(cumulative->bounds); 293 PS_VECTOR_PRINT_F32(cumulative->nums); 294 } 295 296 // Find the bin which contains the first data point above the limit 297 long totalDataPoints = cumulative->nums->data.F32[numBins - 1]; 298 psTrace("psastro", 6, "Total data points is %ld\n", totalDataPoints); 299 300 // find bin which is the lower bound of the limit value (value[bin] < f < value[bin+1] 301 long bin; 302 PS_BIN_FOR_VALUE(bin, cumulative->nums, flimit * totalDataPoints, 0); 303 psTrace("psastro", 6, "The bin is %ld (%.2f to %.2f)\n", bin, cumulative->bounds->data.F32[bin], cumulative->bounds->data.F32[bin+1]); 304 305 // Linear interpolation to the limit value in bin units 306 float value; 307 PS_BIN_INTERPOLATE (value, cumulative->nums, cumulative->bounds, bin, totalDataPoints * flimit); 308 psTrace("psastro", 6, "limit value is %f\n", value); 309 310 stats->clippedMean = value; 311 stats->clippedStdev = 0.0; // XXX derive correct error value 285 286 // find the mean value: 287 stats->clippedMean = psastroStatsPercentileValue (histogram, cumulative, myVector, edgeFraction); 288 289 int nSubset = myVector->n * edgeSampleFraction; 290 psVector *subset = psVectorAlloc (nSubset, PS_TYPE_F32); 291 292 float Sum = 0.0; 293 float S2 = 0.0; 294 for (int i = 0; i < edgeSample; i++) { 295 296 // generate the subset vector 297 for (long i = 0; i < nSubset; i++) { 298 double frnd = psRandomUniform(rng); 299 int entry = PS_MIN(myVector->n - 1, PS_MAX(0, myVector->n * frnd)); 300 301 subset->data.F32[i] = myVector->data.F32[entry]; 302 } 303 304 float value = psastroStatsPercentileValue (histogram, cumulative, subset, edgeFraction); 305 306 Sum += value; 307 S2 += value*value; 308 } 309 psTrace("psastro", 6, "subset stats: Sum: %f, S2: %f, Npts: %d\n", Sum, S2, edgeSample); 310 311 stats->clippedStdev = PS_MAX (sqrt(S2 / edgeSample - PS_SQR(Sum/edgeSample)), MAG_RESOLUTION); 312 psTrace("psastro", 5, "percentile stats %f +/- %f\n", stats->clippedMean, stats->clippedStdev); 313 312 314 stats->results |= PS_STAT_CLIPPED_MEAN; 313 315 stats->results |= PS_STAT_CLIPPED_STDEV; … … 317 319 psFree(histogram); 318 320 psFree(cumulative); 321 psFree(subset); 322 psFree(rng); 319 323 return stats; 320 324 … … 332 336 } 333 337 338 339 // measure the edge of the sample at flimit 340 // return results in stats->sampleMean, sampleStdev 341 // XXX this is a misuse of psStats -- make our own structure? 342 float psastroStatsPercentileValue (psHistogram *histogram, psHistogram *cumulative, psVector *myVector, float flimit) { 343 344 // need to initialize the histogram on each pass 345 psVectorInit (histogram->nums, 0); 346 if (!psVectorHistogram(histogram, myVector, NULL, NULL, 0)) { 347 // if psVectorHistogram returns false, we have a programming error 348 psAbort ("Unable to generate histogram for psastroZeroPointAnalysis"); 349 } 350 if (psTraceGetLevel("psastro") >= 8) { 351 PS_VECTOR_PRINT_F32(histogram->bounds); 352 PS_VECTOR_PRINT_F32(histogram->nums); 353 } 354 355 // Convert the specific histogram to a cumulative histogram 356 // The cumulative histogram data points correspond to the UPPER bound value (N < Bin[i+1]) 357 cumulative->nums->data.F32[0] = histogram->nums->data.F32[0]; 358 for (long i = 1; i < histogram->nums->n; i++) { 359 cumulative->nums->data.F32[i] = cumulative->nums->data.F32[i-1] + histogram->nums->data.F32[i]; 360 cumulative->bounds->data.F32[i-1] = histogram->bounds->data.F32[i]; 361 } 362 if (psTraceGetLevel("psastro") >= 8) { 363 PS_VECTOR_PRINT_F32(cumulative->bounds); 364 PS_VECTOR_PRINT_F32(cumulative->nums); 365 } 366 367 // Find the bin which contains the first data point above the limit 368 long numBins = cumulative->nums->n; 369 long totalDataPoints = cumulative->nums->data.F32[numBins - 1]; 370 psTrace("psastro", 6, "Total data points is %ld\n", totalDataPoints); 371 372 // find bin which is the lower bound of the limit value (value[bin] < f < value[bin+1] 373 long bin; 374 PS_BIN_FOR_VALUE(bin, cumulative->nums, flimit * totalDataPoints, 0); 375 psTrace("psastro", 6, "The bin is %ld (%.4f to %.4f)\n", bin, cumulative->bounds->data.F32[bin], cumulative->bounds->data.F32[bin+1]); 376 377 // Linear interpolation to the limit value in bin units 378 float value; 379 PS_BIN_INTERPOLATE (value, cumulative->nums, cumulative->bounds, bin, totalDataPoints * flimit); 380 psTrace("psastro", 6, "limit value is %f\n", value); 381 382 return value; 383 } 334 384 335 385 # define ESCAPE(MSG) { \
Note:
See TracChangeset
for help on using the changeset viewer.
