Changeset 39648
- Timestamp:
- Aug 5, 2016, 1:08:51 PM (10 years ago)
- Location:
- trunk/Ohana/src/relphot
- Files:
-
- 4 edited
-
include/relphot.h (modified) (2 diffs)
-
src/StatDataSetOps.c (modified) (2 diffs)
-
src/liststats.c (modified) (8 diffs)
-
src/select_images.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relphot/include/relphot.h
r39643 r39648 10 10 11 11 # define ID_SECF_STACK_PRIMARY 0x00004000 12 13 # define NBOOTSTRAP 100 12 14 13 15 # ifndef MAX_INT … … 121 123 int *msklist; // mask modifications 122 124 int Nlist; 125 126 double *values; 127 double *wtvals; 128 double *wtlist; 129 double *ykeep; 130 double *dykeep; 131 double *wtkeep; 132 double *ysample; 133 double *dysample; 134 double *wtsample; 135 double *bvalue; 136 123 137 } StatDataSet; 124 138 -
trunk/Ohana/src/relphot/src/StatDataSetOps.c
r39636 r39648 14 14 ALLOCATE (dataset[i].measSeq, int, Nmax); 15 15 ALLOCATE (dataset[i].msklist, int, Nmax); 16 17 ALLOCATE (dataset[i].values, double, Nmax); 18 ALLOCATE (dataset[i].wtvals, double, Nmax); 19 ALLOCATE (dataset[i].wtlist, double, Nmax); 20 ALLOCATE (dataset[i].ykeep, double, Nmax); 21 ALLOCATE (dataset[i].dykeep, double, Nmax); 22 ALLOCATE (dataset[i].wtkeep, double, Nmax); 23 ALLOCATE (dataset[i].ysample, double, Nmax); 24 ALLOCATE (dataset[i].dysample, double, Nmax); 25 ALLOCATE (dataset[i].wtsample, double, Nmax); 26 ALLOCATE (dataset[i].bvalue, double, NBOOTSTRAP); 16 27 } 28 17 29 return dataset; 18 30 } … … 29 41 FREE (dataset[i].measSeq); 30 42 FREE (dataset[i].msklist); 43 44 FREE (dataset[i].values); 45 FREE (dataset[i].wtvals); 46 FREE (dataset[i].wtlist); 47 FREE (dataset[i].ykeep); 48 FREE (dataset[i].dykeep); 49 FREE (dataset[i].wtkeep); 50 FREE (dataset[i].ysample); 51 FREE (dataset[i].dysample); 52 FREE (dataset[i].wtsample); 53 FREE (dataset[i].bvalue); 31 54 } 32 55 FREE (dataset); -
trunk/Ohana/src/relphot/src/liststats.c
r39641 r39648 193 193 # define FLT_TOLERANCE 1e-6 194 194 # define WEIGHT_THRESHOLD 0.3 195 # define NBOOTSTRAP 100196 195 197 196 int fit_least_squares (double *fit, double *y, double *dy, double *wgt, double *wt, int Npts); … … 202 201 int liststats_irls (StatDataSet *dataset, int Npoints, StatType *stats) { 203 202 204 double value;205 206 203 liststats_init (stats); 207 204 208 // OLS 209 if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, NULL, Npoints)) return FALSE; 205 if (Npoints == 0) { 206 double value = NAN; 207 stats->mean = value; 208 stats->min = value; 209 stats->max = value; 210 stats->Nmeas = Npoints; 211 stats->chisq = NAN; 212 stats->sigma = NAN; 213 stats->error = NAN; 214 return TRUE; 215 } 216 217 if (Npoints == 1) { 218 double value = dataset->flxlist[0]; 219 stats->mean = value; 220 stats->min = value; 221 stats->max = value; 222 stats->Nmeas = Npoints; 223 stats->chisq = NAN; 224 stats->sigma = NAN; 225 stats->error = dataset->errlist[0]; 226 return TRUE; 227 } 228 229 int midpt = 0.5 * Npoints; 230 231 // make the initial guess based on the median (not weighted mean) 232 // ALLOCATE_PTR (values, double, Npoints); 233 for (int i = 0; i < Npoints; i++) { 234 dataset->values[i] = dataset->flxlist[i]; 235 } 236 dsort (dataset->values, Npoints); 237 double value = (Npoints % 2) ? dataset->values[midpt] : 0.5*(dataset->values[midpt] + dataset->values[midpt-1]); 238 239 // OLS (replace by median above) 240 // if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, NULL, Npoints)) return FALSE; 210 241 211 242 // XXX add to dataset elements? 212 ALLOCATE_PTR (wtvals, double, Npoints);213 ALLOCATE_PTR (wtlist, double, Npoints);243 // ALLOCATE_PTR (wtvals, double, Npoints); 244 // ALLOCATE_PTR (wtlist, double, Npoints); 214 245 215 246 int converged = FALSE; … … 218 249 for (int i = 0; i < Npoints; i++) { 219 250 // we are only including the formal error, not the weight in the definition of wt[] 220 wtvals[i] = weight_cauchy ((dataset->flxlist[i] - value) / dataset->errlist[i]);251 dataset->wtvals[i] = weight_cauchy ((dataset->flxlist[i] - value) / dataset->errlist[i]); 221 252 } 222 253 223 254 double oldValue = value; 224 if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, wtvals, Npoints)) {255 if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, dataset->wtvals, Npoints)) { 225 256 value = oldValue; 226 257 break; … … 238 269 // double Sum_W = 0.0; 239 270 for (int i = 0; i < Npoints; i++) { 240 wtvals[i] = weight_cauchy ((dataset->flxlist[i] - value) / dataset->errlist[i]); 241 wtlist[i] = wtvals[i]; 242 // Sum_W += wtvals[i]; 243 } 244 dsort (wtlist, Npoints); 245 int midpt = 0.5 * Npoints; 246 double WtMedian = (Npoints % 2) ? wtlist[midpt] : 0.5*(wtlist[midpt] + wtlist[midpt-1]); 271 dataset->wtvals[i] = weight_cauchy ((dataset->flxlist[i] - value) / dataset->errlist[i]); 272 dataset->wtlist[i] = dataset->wtvals[i]; 273 // Sum_W += dataset->wtvals[i]; 274 } 275 dsort (dataset->wtlist, Npoints); 276 double WtMedian = (Npoints % 2) ? dataset->wtlist[midpt] : 0.5*(dataset->wtlist[midpt] + dataset->wtlist[midpt-1]); 247 277 // double WtThreshold = WEIGHT_THRESHOLD * Sum_W / (1.0 * Npoints); 248 278 double WtThreshold = WEIGHT_THRESHOLD * WtMedian; … … 250 280 // generate the unmasked subset 251 281 // XXX add these to the dataset elements? 252 ALLOCATE_PTR ( ykeep, double, Npoints);253 ALLOCATE_PTR (dykeep, double, Npoints);254 ALLOCATE_PTR (wtkeep, double, Npoints);282 // ALLOCATE_PTR ( ykeep, double, Npoints); 283 // ALLOCATE_PTR (dykeep, double, Npoints); 284 // ALLOCATE_PTR (wtkeep, double, Npoints); 255 285 256 286 // save unmasked points … … 261 291 double dSig = 0.0; 262 292 for (int i = 0; i < Npoints; i++) { 263 if (( wtvals[i] < WtThreshold) || !isfinite(dataset->flxlist[i])) {293 if ((dataset->wtvals[i] < WtThreshold) || !isfinite(dataset->flxlist[i])) { 264 294 dataset->msklist[i] = TRUE; // mark the masked points 265 295 continue; 266 296 } 267 ykeep[Nkeep] = dataset->flxlist[i];268 d ykeep[Nkeep] = dataset->errlist[i];269 wtkeep[Nkeep] = dataset->wgtlist[i]; // externally-supplied weight297 dataset->ykeep[Nkeep] = dataset->flxlist[i]; 298 dataset->dykeep[Nkeep] = dataset->errlist[i]; 299 dataset->wtkeep[Nkeep] = dataset->wgtlist[i]; // externally-supplied weight 270 300 Nkeep ++; 271 301 … … 283 313 // bootstrap resampling to generate the errorbars 284 314 // XXX add these to the dataset elements? 285 ALLOCATE_PTR (ysample, double, Nkeep);286 ALLOCATE_PTR (dysample, double, Nkeep);287 ALLOCATE_PTR (wtsample, double, Nkeep);288 ALLOCATE_PTR (bvalue, double, NBOOTSTRAP); // vector to save the bootstrap values315 // ALLOCATE_PTR (ysample, double, Nkeep); 316 // ALLOCATE_PTR (dysample, double, Nkeep); 317 // ALLOCATE_PTR (wtsample, double, Nkeep); 318 // ALLOCATE_PTR (bvalue, double, NBOOTSTRAP); // vector to save the bootstrap values 289 319 290 320 int Nboot = 0; … … 295 325 // I need to draw Npoints random entries from 'points' with replacement: 296 326 int N = Nkeep * drand48(); 297 ysample[i] =ykeep[N];298 d ysample[i] =dykeep[N];299 wtsample[i] =wtkeep[N];300 } 301 302 if (!fit_least_squares (&value, ysample, dysample,wtsample, NULL, Nkeep)) continue;303 304 bvalue[Nboot] = value;327 dataset->ysample[i] = dataset->ykeep[N]; 328 dataset->dysample[i] = dataset->dykeep[N]; 329 dataset->wtsample[i] = dataset->wtkeep[N]; 330 } 331 332 if (!fit_least_squares (&value, dataset->ysample, dataset->dysample, dataset->wtsample, NULL, Nkeep)) continue; 333 334 dataset->bvalue[Nboot] = value; 305 335 Nboot ++; 306 336 } 307 337 308 dsort ( bvalue, Nboot);338 dsort (dataset->bvalue, Nboot); 309 339 310 double Slo = VectorFractionInterpolate ( bvalue, 0.158655, Nboot);311 double Shi = VectorFractionInterpolate ( bvalue, 0.841345, Nboot);340 double Slo = VectorFractionInterpolate (dataset->bvalue, 0.158655, Nboot); 341 double Shi = VectorFractionInterpolate (dataset->bvalue, 0.841345, Nboot); 312 342 stats->error = (Shi - Slo) / 2.0; 313 314 free (bvalue);315 free ( ysample);316 free (dysample);317 free (wtsample);318 free ( ykeep);319 free (dykeep);320 free (wtkeep);321 free (wtvals);322 free (wtlist);323 343 324 344 return TRUE; -
trunk/Ohana/src/relphot/src/select_images.c
r39643 r39648 46 46 double DmaxSkyRegion = region[0].Dmax; 47 47 48 double dD = CALIBRATE_STACKS_AND_WARPS ? 0. 5: 5.0;48 double dD = CALIBRATE_STACKS_AND_WARPS ? 0.0 : 5.0; 49 49 double dR = dD / cos(RAD_DEG*DminSkyRegion); 50 50 RminSkyRegion -= dR;
Note:
See TracChangeset
for help on using the changeset viewer.
