Changeset 40408
- Timestamp:
- Apr 26, 2018, 12:37:03 PM (8 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 1 added
- 6 edited
-
dvo/Makefile (modified) (2 diffs)
-
dvo/avperiodogram.c (modified) (11 diffs)
-
dvo/avperiodomatch.c (added)
-
dvo/dvo_host_utils.c (modified) (3 diffs)
-
dvo/init.c (modified) (2 diffs)
-
dvo/region_list.c (modified) (2 diffs)
-
include/dvoshell.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/Makefile
r40398 r40408 27 27 $(SRC)/mySequence.$(ARCH).o \ 28 28 $(SRC)/photcode_ops.$(ARCH).o \ 29 $(SRC)/PeriodogramOps.$(ARCH).o \ 29 30 $(SRC)/find_matches.$(ARCH).o 30 31 … … 46 47 $(SRC)/avmatch.$(ARCH).o \ 47 48 $(SRC)/avperiodogram.$(ARCH).o \ 49 $(SRC)/avperiodomatch.$(ARCH).o \ 48 50 $(SRC)/badimages.$(ARCH).o \ 49 51 $(SRC)/catdir.$(ARCH).o \ -
trunk/Ohana/src/opihi/dvo/avperiodogram.c
r40402 r40408 1 1 # include "dvoshell.h" 2 # define MIN_VAR 1e-83 # define NPERIODS 504 5 /* basic outline of the code:6 7 * parse optional arguments8 * -parallel : launch parallel jobs [below is called for non-parallel or for dvo_client9 10 * parse optional -where-measure clause11 *12 13 */14 15 typedef struct {16 int Nperiods;17 opihi_flt *period;18 opihi_flt *power;19 } PeriodogramResult;20 21 void PeriodogramResultFree (PeriodogramResult *result);22 void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average);23 PeriodogramResult *periodogram_fm_raw (opihi_flt *time, opihi_flt *flux, opihi_flt *dflux, int Npts);24 25 float minP = 0.2;26 float maxP = 200.0;27 2 28 3 int avperiodogram (int argc, char **argv) { … … 57 32 PARALLEL = TRUE; 58 33 } 34 35 /* load photcode information (this needs to come before the SelectRegions command below to define the catdir */ 36 if (!InitPhotcodes ()) goto escape; 37 int Nsecfilt = GetPhotcodeNsecfilt (); 59 38 60 39 // parse skyregion options. NOTE: this is stripped off in parallel operation and always … … 70 49 71 50 // **** launch parallel / remote jobs **** 72 // th is does all the work of re-packaging the command, calling it on the remote machines, then loading in the results51 // the result files are left behind for the user to access (no automatic re-merge) 73 52 if (PARALLEL && !HOST_ID) { 74 int status = HostTableParallelOps (skylist, argc, argv, NULL, TRUE, 0, VERBOSE);53 int status = HostTableParallelOps (skylist, argc, argv, NULL, FALSE, 0, VERBOSE); 75 54 SkyListFree (skylist); 76 55 FreeSkyRegionSelection (selection); … … 82 61 if ((N = get_argument (argc, argv, "-min-period"))) { 83 62 remove_argument (N, &argc, argv); 84 minP = atof (argv[N]);63 PeriodogramSetOptions (atof (argv[N]), NAN); 85 64 remove_argument (N, &argc, argv); 86 65 } … … 88 67 if ((N = get_argument (argc, argv, "-max-period"))) { 89 68 remove_argument (N, &argc, argv); 90 maxP = atof (argv[N]);69 PeriodogramSetOptions (NAN, atof (argv[N])); 91 70 remove_argument (N, &argc, argv); 92 71 } … … 179 158 dvo_catalog_init (&catalog, TRUE); 180 159 181 /* load photcode information */182 if (!InitPhotcodes ()) goto escape;183 int Nsecfilt = GetPhotcodeNsecfilt ();184 185 160 // init locally static variables (time refs) 186 161 dbExtractAveragesInit (); 162 dbExtractMeasuresInit(HOST_ID); 187 163 188 164 // examine line for 'where' or 'match to'. 'match to' is forbidden … … 207 183 208 184 // parse stack elements into fields and scalars as needed 185 Nfields = 0; 186 ALLOCATE (fields, dbField, 1); 209 187 if (!dbCheckStack (stack, Nstack, DVO_TABLE_AVERAGE, &fields, &Nfields)) goto escape; 210 188 … … 288 266 // The first 3 values[] / fields[] will be time, mag, dmag 289 267 for (off_t n = 0; n < Nmfields; n++) { 290 mvalues[n] = dbExtractMeasures (average, secfilt, measure, NULL, NULL, &mfields[n]);268 mvalues[n] = dbExtractMeasures (average, secfilt, &measure[k], NULL, NULL, &mfields[n]); 291 269 } 292 270 if (!dbBooleanCond (mstack, Nmstack, mvalues)) continue; 271 272 // do not allow any NAN or Inf values to polute the result 273 if (!isfinite(mvalues[0].Flt)) continue; 274 if (!isfinite(mvalues[1].Flt)) continue; 275 if (!isfinite(mvalues[2].Flt)) continue; 293 276 294 277 time[Npts] = mvalues[0].Flt; … … 299 282 } 300 283 301 PeriodogramResult *result = periodogram_fm_raw (time, mag, dmag, Npts); 284 PeriodogramResult *result = PeriodogramRawFloatingMean (time, mag, dmag, Npts); 285 free (time); 286 free (mag); 287 free (dmag); 288 289 if (!result) continue; 290 291 if (VERBOSE2) gprint (GP_ERR, "periodogram for %d, %d\n", (int) average->catID, (int) average->objID); 302 292 303 293 // XXX if we have 1e6 objects, we will have output files with sizes of ~80GB … … 308 298 Nobject ++; 309 299 } 310 311 fclose (foutput);312 fflush (foutput);313 314 300 dvo_catalog_free (&catalog); 315 301 } 316 302 ClearInterrupt (old_sigaction); 317 303 318 if (values) free (values); 304 fclose (foutput); 305 fflush (foutput); 306 307 // free measure stack stuff 308 FREE (mvalues); 309 dbFreeFields(mfields, Nmfields); 310 dbFreeStack(mstack, Nmstack); 311 FREE (mstack); 312 313 FREE (values); 319 314 dbFreeFields (fields, Nfields); 320 315 dbFreeStack (stack, Nstack); 321 if (stack) free (stack); 316 FREE (stack); 317 322 318 SkyListFree (skylist); 323 319 FreeSkyRegionSelection (selection); 320 321 free (output); 324 322 return (TRUE); 325 323 … … 341 339 return (FALSE); 342 340 } 343 344 // low-level periodogram-fm function345 PeriodogramResult *periodogram_fm_raw (opihi_flt *time, opihi_flt *flux, opihi_flt *dflux, int Npts) {346 347 /* find the max baseline, sum the inverse variances */348 double minT = time[0];349 double maxT = time[0];350 opihi_flt Weight = 0;351 352 opihi_flt *tv = time;353 opihi_flt *df = dflux;354 opihi_flt *fv = flux;355 356 for (int i = 0; i < Npts; i++, tv++, df++) {357 minT = MIN (minT, *tv);358 maxT = MAX (maxT, *tv);359 // skip points with 0.0 error? or add minimum variance?360 Weight += 1.0 / (SQ(*df) + MIN_VAR); // MIN_VAR : added in quadrature to avoid Inf (XXX make this a user parameter?)361 }362 363 double WeightInv = 1.0 / Weight;364 double dTime = maxT - minT;365 if (dTime == 0) {366 gprint (GP_ERR, "ERROR: time range is zero\n");367 return NULL;368 }369 370 int Np = 0;371 int NP = NPERIODS;372 ALLOCATE_PTR (period, double, NP);373 ALLOCATE_PTR (power, double, NP);374 375 // for testing, we are going to write out the terms explicitly376 // for optimization, some of the trig functions can be calculated more efficiently377 // by storing cos,sin(w t) and using some recurrence rules378 379 // maxP = minP * dP^n [n = 0 -- Nperiods-1]380 // log(maxP) = log(minP) + (Nperiods - 1) * log (dP)381 // log(dP) = (log(maxP) - log(minP)) / (Nperiods - 1)382 // double dP = LINEAR ? (maxP - minP)/(NPERIODS - 1) : pow(10.0, ((log10(maxP) - log10(minP))/(NPERIODS - 1)));383 384 double P = minP;385 for (Np = 0; (Np < NPERIODS) && (P <= maxP); Np++) {386 double w = 2*M_PI/P;387 388 /* find the period offset tau */389 tv = time;390 df = dflux;391 392 double cs = 0.0, sn = 0.0, sn2 = 0.0, cs2 = 0.0;393 394 for (int i = 0; i < Npts; i++, tv++, df++) {395 opihi_flt wt = WeightInv / (SQ(*df) + MIN_VAR);396 cs += wt*cos (*tv*w);397 sn += wt*sin (*tv*w);398 cs2 += wt*cos (*tv*w*2);399 sn2 += wt*sin (*tv*w*2);400 }401 double ytan = sn2 - 2*cs*sn;402 double xtan = cs2 - (SQ(cs) - SQ(sn));403 double tau = 0.5*atan2 (ytan, xtan) / w;404 405 /* find the power at this period */406 tv = time;407 df = dflux;408 fv = flux;409 410 // YY = YY_s - Y_s*Y_s411 // CC = CC_s - C_s*C_s412 // SS = SS_s - S_s*S_s413 // YC = YC_s - Y_s*C_s414 // YS = YS_s - Y_s*S_s415 416 double YY_s = 0.0, CC_s = 0.0, SS_s = 0.0, YC_s = 0.0, YS_s = 0.0;417 double Y_s = 0.0, C_s = 0.0, S_s = 0.0;418 for (int i = 0; i < Npts; i++, tv++, fv++, df++) {419 opihi_flt wt = WeightInv / (SQ(*df) + MIN_VAR);420 cs = cos (w*(*tv-tau));421 sn = sin (w*(*tv-tau));422 423 double wtf = *fv*wt;424 Y_s += wtf;425 C_s += wt*cs;426 S_s += wt*sn;427 428 YY_s += wtf*(*fv);429 YC_s += wtf*cs;430 YS_s += wtf*sn;431 432 CC_s += wt*cs*cs;433 SS_s += wt*sn*sn;434 }435 double YY = YY_s - SQ(Y_s);436 double YC = YC_s - Y_s*C_s;437 double YS = YS_s - Y_s*S_s;438 double CC = CC_s - SQ(C_s);439 double SS = SS_s - SQ(S_s);440 441 double Pa = SQ(YC) / CC;442 double Pb = SQ(YS) / SS;443 double Po = (Pa + Pb) / YY;444 445 power[Np] = Po;446 period[Np] = P;447 if (Np >= NP) {448 NP += 100;449 REALLOCATE (power, opihi_flt, NP);450 REALLOCATE (period, opihi_flt, NP);451 }452 453 float dP = 0.4 * SQ(P) / dTime;454 P += dP;455 }456 457 ALLOCATE_PTR (result, PeriodogramResult, 1);458 result->Nperiods = Np;459 result->period = period;460 result->power = power;461 462 return result;463 }464 465 void PeriodogramResultFree (PeriodogramResult *result) {466 if (!result) return;467 468 FREE (result->period);469 FREE (result->power);470 free (result);471 return;472 }473 474 // write the period and power vectors to an extension in this output file475 void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average) {476 477 // generate a binary table478 Header outheader;479 FTable outtable;480 gfits_init_header (&outheader);481 gfits_init_table (&outtable);482 outtable.header = &outheader;483 484 gfits_create_table_header (&outheader, "BINTABLE", extname);485 486 // add some metadata derived from average:487 gfits_modify (&outheader, "RA_OBJ", "%lf", 1, average->R);488 gfits_modify (&outheader, "DEC_OBJ", "%lf", 1, average->D);489 gfits_modify (&outheader, "OBJ_ID", "%d", 1, average->objID);490 gfits_modify (&outheader, "CAT_ID", "%d", 1, average->catID);491 492 gfits_define_bintable_column (&outheader, "D", "PERIOD", NULL, NULL, 1.0, 0.0);493 gfits_define_bintable_column (&outheader, "D", "POWER", NULL, NULL, 1.0, 0.0);494 495 gfits_create_table (&outheader, &outtable);496 497 gfits_set_bintable_column (&outheader, &outtable, "PERIOD", result->period, result->Nperiods);498 gfits_set_bintable_column (&outheader, &outtable, "POWER", result->power, result->Nperiods);499 500 // write the actual table data501 gfits_fwrite_Theader (foutput, &outheader);502 gfits_fwrite_table (foutput, &outtable);503 504 gfits_free_header (&outheader);505 gfits_free_table (&outtable);506 } -
trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
r40291 r40408 212 212 continue; 213 213 } 214 free (table->hosts[i].results);215 table->hosts[i].results = NULL;214 // free (table->hosts[i].results); 215 // table->hosts[i].results = NULL; 216 216 set_int_variable (name, 1); // result file has been read 217 217 … … 225 225 FreeVectorArray (invec, Ninvec); 226 226 } 227 } else { 228 // free (table->hosts[i].results); 229 // table->hosts[i].results = NULL; 227 230 } 228 231 } … … 242 245 free (vec); 243 246 244 free (table);247 FreeHostTable (table); 245 248 return TRUE; 246 249 } -
trunk/Ohana/src/opihi/dvo/init.c
r40398 r40408 4 4 int avmatch PROTO((int, char **)); 5 5 int avperiodogram PROTO((int, char **)); 6 int avperiodomatch PROTO((int, char **)); 6 7 int badimages PROTO((int, char **)); 7 8 int calextract PROTO((int, char **)); … … 68 69 {1, "avextract", avextract, "extract average data values"}, 69 70 {1, "avmatch", avmatch, "extract average data values matched to RA,DEC points"}, 70 {1, "avperiodogram", avperiodogram, "perform periodogram on objects based on restrictions"}, 71 {1, "avperiodogram", avperiodogram, "perform periodogram on objects based on restrictions"}, 72 {1, "avperiodomatch", avperiodomatch, "perform periodogram on objects based on ra,dec list"}, 71 73 {1, "badimages", badimages, "look for images with anomalous astrometry"}, 72 74 // {1, "calextract", calextract, "extract photometry calibration"}, -
trunk/Ohana/src/opihi/dvo/region_list.c
r33662 r40408 181 181 SkyList *skylist; 182 182 183 // the list of regions comes directly from a file 184 if (selection->list != NULL) { 185 skylist = SkyListLoadFile (selection->list); 186 return (skylist); 187 } 188 189 // all other options require sky to be set 190 if (!sky) { 191 gprint (GP_ERR, "CATDIR not set\n"); 192 return NULL; 193 } 194 183 195 /* determine region-file names */ 184 196 if (selection->name != NULL) { … … 186 198 return (skylist); 187 199 } 188 189 if (selection->list != NULL) {190 skylist = SkyListLoadFile (selection->list);191 return (skylist);192 }193 200 194 201 if (selection->useDisplay) { -
trunk/Ohana/src/opihi/include/dvoshell.h
r39569 r40408 41 41 char *HOSTDIR; 42 42 char *RESULT_FILE; 43 44 typedef struct { 45 int Nmeasure; 46 int Nperiods; 47 opihi_flt *period; 48 opihi_flt *power; 49 double P50; 50 double R50; 51 double R90; 52 } PeriodogramResult; 53 54 /*** Periodogram functions (avperiodogram and avperiodomatch) ***/ 55 void PeriodogramResultFree (PeriodogramResult *result); 56 void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average); 57 void PeriodogramSetOptions (float minimumPeriod, float maximumPeriod); 58 PeriodogramResult *PeriodogramRawFloatingMean (opihi_flt *time, opihi_flt *flux, opihi_flt *dflux, int Npts); 43 59 44 60 /*** dvo prototypes ***/
Note:
See TracChangeset
for help on using the changeset viewer.
