RTModel 2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- RTModel/RTModel.py +293 -0
- RTModel/__init__.py +5 -0
- RTModel/bin/Finalizer.exe +0 -0
- RTModel/bin/InitCond.exe +0 -0
- RTModel/bin/LevMar.exe +0 -0
- RTModel/bin/ModelSelector.exe +0 -0
- RTModel/bin/Reader.exe +0 -0
- RTModel/data/ESPL.tbl +0 -0
- RTModel/data/TemplateLibrary.txt +114 -0
- RTModel/include/LevMarFit.h +81 -0
- RTModel/include/VBBinaryLensingLibrary.h +312 -0
- RTModel/include/bumper.h +32 -0
- RTModel/lib/Finalizer.cpp +412 -0
- RTModel/lib/InitCond.cpp +1398 -0
- RTModel/lib/LevMar.cpp +12 -0
- RTModel/lib/LevMarFit.cpp +1277 -0
- RTModel/lib/ModelSelector.cpp +913 -0
- RTModel/lib/Reader.cpp +670 -0
- RTModel/lib/VBBinaryLensingLibrary.cpp +4986 -0
- RTModel/lib/bumper.cpp +168 -0
- RTModel/plotmodel/__init__.py +5 -0
- RTModel/plotmodel/plotmodel.py +452 -0
- RTModel-2.0.dist-info/LICENSE +165 -0
- RTModel-2.0.dist-info/METADATA +61 -0
- RTModel-2.0.dist-info/RECORD +27 -0
- RTModel-2.0.dist-info/WHEEL +5 -0
- RTModel-2.0.dist-info/top_level.txt +1 -0
RTModel/lib/Reader.cpp
ADDED
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
// Reader.cpp : main project file.
|
|
2
|
+
// This program formats data for a specific event for following work.
|
|
3
|
+
// for following work.
|
|
4
|
+
|
|
5
|
+
#define _CRT_SECURE_NO_WARNINGS
|
|
6
|
+
#define _USE_MATH_DEFINES
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <math.h>
|
|
10
|
+
#include <malloc.h>
|
|
11
|
+
#include <regex>
|
|
12
|
+
#include <filesystem>
|
|
13
|
+
|
|
14
|
+
using namespace std;
|
|
15
|
+
using namespace std::filesystem;
|
|
16
|
+
|
|
17
|
+
#ifdef _WIN32
|
|
18
|
+
char systemslash = '\\';
|
|
19
|
+
#else
|
|
20
|
+
char systemslash = '/';
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
double tau=0.1; // conventional correlation time for consecutive points
|
|
24
|
+
int npmax=4000; // maximum number of points left after re-binning
|
|
25
|
+
int otherseasons = 1; // How to use other seasons
|
|
26
|
+
int renormalize = 1; // Re-normalize error bars
|
|
27
|
+
double thresholdoutliers = 10; // Threshold for removing outliers
|
|
28
|
+
|
|
29
|
+
struct datapoint{
|
|
30
|
+
datapoint *prev,*next;
|
|
31
|
+
double t,y,err,sig,basesig;
|
|
32
|
+
int dn;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct dataset{
|
|
36
|
+
dataset *prev,*next;
|
|
37
|
+
datapoint *first,*last;
|
|
38
|
+
int length;
|
|
39
|
+
char label[100];
|
|
40
|
+
|
|
41
|
+
dataset();
|
|
42
|
+
~dataset();
|
|
43
|
+
void addpoint(double,double,double);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
#define _computesig\
|
|
47
|
+
p->sig=(p->y-p->prev->y);\
|
|
48
|
+
pc=(p->t-p->prev->t)/tau;\
|
|
49
|
+
p->sig*=p->sig/(p->err*p->err + p->prev->err*p->prev->err);\
|
|
50
|
+
p->sig+=pc*pc;\
|
|
51
|
+
p->sig *= p->basesig;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
int main(int argc, char *argv[])
|
|
56
|
+
{
|
|
57
|
+
char exedir[256]="";
|
|
58
|
+
char eventname[512] = "";
|
|
59
|
+
char filename[256] = "";
|
|
60
|
+
char titstring[256]="",nostr[2],*undersc;
|
|
61
|
+
char command[256],buffer[256];
|
|
62
|
+
double value;
|
|
63
|
+
double t,y,err,yr,errr,w1,w2;
|
|
64
|
+
FILE *f;
|
|
65
|
+
int ifile,flag,nps,normalized=0,satellite;
|
|
66
|
+
double pc,residual,residual1,residual2,outlier,crosscheck,weight,minfac,maxlength;
|
|
67
|
+
dataset *datalist=0,*curdataset,*pmaxdataset;
|
|
68
|
+
datapoint *p,*pmax,*p1,*p2;
|
|
69
|
+
|
|
70
|
+
// Directory preliminaries. Reads event name from arguments.
|
|
71
|
+
|
|
72
|
+
printf("******************************************\n");
|
|
73
|
+
printf("************* Reader **********\n");
|
|
74
|
+
printf("******************************************\n\n");
|
|
75
|
+
printf("*** This program formats data for a specific event\n\n");
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if(argc>1){
|
|
79
|
+
strcpy(eventname,argv[1]);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
printf("\n\nEvent name? ");
|
|
83
|
+
scanf("%s", eventname);
|
|
84
|
+
//sprintf(eventname, "WDC10193");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
printf("\n\n- Event: %s\n",eventname);
|
|
88
|
+
|
|
89
|
+
current_path(eventname);
|
|
90
|
+
|
|
91
|
+
if (exists("LCToFit.txt")) {
|
|
92
|
+
printf("\n\n- Data already processed");
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Reading Reader.ini and set parameters accordingly
|
|
97
|
+
|
|
98
|
+
if (exists("ini")) {
|
|
99
|
+
current_path("ini");
|
|
100
|
+
f = fopen("Reader.ini", "r");
|
|
101
|
+
if (f != 0) {
|
|
102
|
+
printf("\n\n- Reading options in Reader.ini");
|
|
103
|
+
while (!feof(f)) {
|
|
104
|
+
int red = fscanf(f, "%s %s %lf", command, buffer, &value);
|
|
105
|
+
if (red != 3) {
|
|
106
|
+
command[0] = 0;
|
|
107
|
+
//if (red != 0) {
|
|
108
|
+
// printf("\n\n!!! Bad command in Reader.ini");
|
|
109
|
+
// return -1;
|
|
110
|
+
//};
|
|
111
|
+
}
|
|
112
|
+
if (strcmp(command, "binning") == 0) {
|
|
113
|
+
npmax = (int) value;
|
|
114
|
+
}
|
|
115
|
+
if (strcmp(command, "tau") == 0) {
|
|
116
|
+
tau = value;
|
|
117
|
+
}
|
|
118
|
+
if (strcmp(command, "otherseasons") == 0) {
|
|
119
|
+
otherseasons = (int) value;
|
|
120
|
+
}
|
|
121
|
+
if (strcmp(command, "renormalize") == 0) {
|
|
122
|
+
renormalize = (int) value;
|
|
123
|
+
}
|
|
124
|
+
if (strcmp(command, "thresholdoutliers") == 0) {
|
|
125
|
+
thresholdoutliers = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
fclose(f);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
printf("\n\n- Default options:");
|
|
132
|
+
}
|
|
133
|
+
current_path(eventname);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
printf("\nUse of other seasons %d", otherseasons);
|
|
139
|
+
printf("\nBinning down to %d", npmax);
|
|
140
|
+
printf("\nThreshold for outliers removal: %lf", thresholdoutliers);
|
|
141
|
+
printf("\nTimescale for scatter evaluation %lf", tau);
|
|
142
|
+
printf("\nRenormalize error bars: %s", (renormalize>0)? "yes" : "no");
|
|
143
|
+
if (renormalize == 0) normalized = 1;
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// Read data from files and create structured lists
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
printf("\n\n- Reading data from files\n");
|
|
151
|
+
|
|
152
|
+
curdataset = datalist = 0;
|
|
153
|
+
current_path("Data");
|
|
154
|
+
auto searchstring = regex(".*\\.dat");
|
|
155
|
+
for (auto const& itr : directory_iterator(".")) {
|
|
156
|
+
string curfile = itr.path().filename().string();
|
|
157
|
+
if (regex_match(curfile, searchstring)) {
|
|
158
|
+
strcpy(filename, curfile.c_str());
|
|
159
|
+
if (!datalist) {
|
|
160
|
+
curdataset = datalist = new dataset;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
curdataset->next = new dataset;
|
|
164
|
+
curdataset->next->prev = curdataset;
|
|
165
|
+
curdataset = curdataset->next;
|
|
166
|
+
}
|
|
167
|
+
printf("\n%s", filename);
|
|
168
|
+
strcpy(curdataset->label, filename);
|
|
169
|
+
f = fopen(filename, "r");
|
|
170
|
+
fscanf(f, "%[^\n]", titstring);
|
|
171
|
+
fscanf(f, "%[\n]", nostr);
|
|
172
|
+
while (fscanf(f, "%[^\n]", titstring) == 1) {
|
|
173
|
+
fscanf(f, "%[\n]", nostr);
|
|
174
|
+
sscanf(titstring, "%lf %lf %lf", &y, &err, &t);
|
|
175
|
+
// Sanity checks on individual point
|
|
176
|
+
if (y < 90 && err >0) {
|
|
177
|
+
curdataset->addpoint(t, y, err);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
fclose(f);
|
|
181
|
+
printf("\npoints: %d", curdataset->length);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//auto itr = directory_iterator(".");
|
|
185
|
+
//while (!itr._At_end()) {
|
|
186
|
+
// string curfile = (*itr).path().filename().string();
|
|
187
|
+
// if (regex_match(curfile, searchstring)) {
|
|
188
|
+
// strcpy(filename, curfile.c_str());
|
|
189
|
+
// if (!datalist) {
|
|
190
|
+
// curdataset = datalist = new dataset;
|
|
191
|
+
// }
|
|
192
|
+
// else {
|
|
193
|
+
// curdataset->next = new dataset;
|
|
194
|
+
// curdataset->next->prev = curdataset;
|
|
195
|
+
// curdataset = curdataset->next;
|
|
196
|
+
// }
|
|
197
|
+
// printf("\n%s", filename);
|
|
198
|
+
// strcpy(curdataset->label,filename);
|
|
199
|
+
// f = fopen(filename, "r");
|
|
200
|
+
// fscanf(f, "%[^\n]", titstring);
|
|
201
|
+
// fscanf(f, "%[\n]", nostr);
|
|
202
|
+
// while (fscanf(f, "%[^\n]", titstring) == 1) {
|
|
203
|
+
// fscanf(f, "%[\n]", nostr);
|
|
204
|
+
// sscanf(titstring, "%lf %lf %lf", &y, &err, &t);
|
|
205
|
+
// // Sanity checks on individual point
|
|
206
|
+
// if (y < 90 && err >0) {
|
|
207
|
+
// curdataset->addpoint(t, y, err);
|
|
208
|
+
// }
|
|
209
|
+
// }
|
|
210
|
+
// fclose(f);
|
|
211
|
+
// printf("\npoints: %d", curdataset->length);
|
|
212
|
+
// fclose(f);
|
|
213
|
+
// }
|
|
214
|
+
// itr++;
|
|
215
|
+
//}
|
|
216
|
+
current_path(eventname);
|
|
217
|
+
|
|
218
|
+
// Sort lists
|
|
219
|
+
|
|
220
|
+
printf("\n\n- Time ordering of data\n");
|
|
221
|
+
|
|
222
|
+
curdataset = datalist;
|
|
223
|
+
while(curdataset){
|
|
224
|
+
printf("\n%s", curdataset->label);
|
|
225
|
+
p = curdataset->first;
|
|
226
|
+
while (p) {
|
|
227
|
+
pmax = p;
|
|
228
|
+
p1 = pmax->next;
|
|
229
|
+
while (p1) {
|
|
230
|
+
if (p1->t == pmax->t) {
|
|
231
|
+
p2 = p1->prev;
|
|
232
|
+
if (p1->prev) p1->prev->next = p1->next;
|
|
233
|
+
if (p1->next) p1->next->prev = p1->prev;
|
|
234
|
+
delete p1;
|
|
235
|
+
curdataset->length--;
|
|
236
|
+
p1 = p2;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (p1->t < pmax->t) {
|
|
240
|
+
pmax = p1;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
p1 = p1->next;
|
|
244
|
+
}
|
|
245
|
+
if (p != pmax) {
|
|
246
|
+
pc = pmax->t;
|
|
247
|
+
pmax->t = p->t;
|
|
248
|
+
p->t = pc;
|
|
249
|
+
pc = pmax->y;
|
|
250
|
+
pmax->y = p->y;
|
|
251
|
+
p->y = pc;
|
|
252
|
+
pc = pmax->err;
|
|
253
|
+
pmax->err = p->err;
|
|
254
|
+
p->err = pc;
|
|
255
|
+
}
|
|
256
|
+
p = p->next;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
curdataset = curdataset->next;
|
|
260
|
+
//if (curdataset->length <= 3) {
|
|
261
|
+
// printf(" discarded!");
|
|
262
|
+
// if (curdataset->prev) {
|
|
263
|
+
// dataset* predataset = curdataset->prev;
|
|
264
|
+
// curdataset = curdataset->next;
|
|
265
|
+
// delete predataset->next;
|
|
266
|
+
// predataset->next = curdataset;
|
|
267
|
+
// if (curdataset) curdataset->prev = predataset;
|
|
268
|
+
// }
|
|
269
|
+
// else {
|
|
270
|
+
// datalist = curdataset->next;
|
|
271
|
+
// if (datalist) datalist->prev = 0;
|
|
272
|
+
// delete curdataset;
|
|
273
|
+
// curdataset = datalist;
|
|
274
|
+
// }
|
|
275
|
+
//}
|
|
276
|
+
//else {
|
|
277
|
+
// curdataset = curdataset->next;
|
|
278
|
+
//}
|
|
279
|
+
//pmax=curdataset->first->next;
|
|
280
|
+
//while(pmax){
|
|
281
|
+
// flag=0;
|
|
282
|
+
// p=curdataset->first;
|
|
283
|
+
// while(p->t<=pmax->t && p!=pmax) p=p->next;
|
|
284
|
+
// if(p!=pmax){
|
|
285
|
+
// if(p->t!=pmax->t){
|
|
286
|
+
// pc=pmax->t;
|
|
287
|
+
// pmax->t=p->t;
|
|
288
|
+
// p->t=pc;
|
|
289
|
+
// pc=pmax->y;
|
|
290
|
+
// pmax->y=p->y;
|
|
291
|
+
// p->y=pc;
|
|
292
|
+
// pc=pmax->err;
|
|
293
|
+
// pmax->err=p->err;
|
|
294
|
+
// p->err=pc;
|
|
295
|
+
// }else{
|
|
296
|
+
// if(p->prev) p->prev->next=p->next;
|
|
297
|
+
// if(p->next) p->next->prev=p->prev;
|
|
298
|
+
// delete p;
|
|
299
|
+
// curdataset->length--;
|
|
300
|
+
// }
|
|
301
|
+
// flag=1;
|
|
302
|
+
// }
|
|
303
|
+
// if(!flag) pmax=pmax->next;
|
|
304
|
+
//}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
// Estimating error bars for each dataset
|
|
309
|
+
|
|
310
|
+
double ft1, ft2;
|
|
311
|
+
printf("\n\n- Assessing error bars\n");
|
|
312
|
+
|
|
313
|
+
minfac=1.e100;
|
|
314
|
+
maxlength=-minfac;
|
|
315
|
+
for(curdataset=datalist;curdataset;curdataset=curdataset->next){
|
|
316
|
+
residual=weight=0;
|
|
317
|
+
for(p=curdataset->first->next;p;p=p->next){
|
|
318
|
+
residual1=residual2 = 0;
|
|
319
|
+
if(p->next){
|
|
320
|
+
p1=p->next;
|
|
321
|
+
if(p1->next){
|
|
322
|
+
p2=p1->next;
|
|
323
|
+
ft2 = (p->t - p1->t) / (p2->t - p1->t);
|
|
324
|
+
ft1 = 1 - ft2;
|
|
325
|
+
y=p1->y+((p2->t==p1->t)? 0 : (p2->y-p1->y)*ft2);
|
|
326
|
+
pc=(p2->t-p->t)/tau;
|
|
327
|
+
err=(p1->err*p1->err*ft1*ft1+p2->err*p2->err*ft2*ft2 +p->err*p->err)*exp(pc/tau);
|
|
328
|
+
w1=1/exp(pc/tau);
|
|
329
|
+
pc=(p->y-y);
|
|
330
|
+
residual1= pc /sqrt(err);
|
|
331
|
+
yr = y;
|
|
332
|
+
errr = err;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if(p->prev){
|
|
336
|
+
p1=p->prev;
|
|
337
|
+
if(p1->prev){
|
|
338
|
+
p2=p1->prev;
|
|
339
|
+
ft2 = (p->t - p1->t) / (p2->t - p1->t);
|
|
340
|
+
ft1 = 1 - ft2;
|
|
341
|
+
y=p1->y+((p2->t==p1->t)? 0 : (p2->y-p1->y)/(p2->t-p1->t)*(p->t-p1->t));
|
|
342
|
+
pc=(p2->t-p->t)/tau;
|
|
343
|
+
err=(p1->err*p1->err*ft1*ft1+p2->err*p2->err*ft2*ft2+p->err*p->err)*exp(-pc/tau);
|
|
344
|
+
w2=1/exp(-pc/tau);
|
|
345
|
+
pc=(p->y-y);
|
|
346
|
+
residual2 = pc / sqrt(err);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
outlier = residual1 * residual1 + residual2 * residual2;
|
|
350
|
+
crosscheck = (y - yr);
|
|
351
|
+
crosscheck *= crosscheck;
|
|
352
|
+
crosscheck /= (err + errr);
|
|
353
|
+
if (residual1!=0 && residual2!=0 && crosscheck <9 && sqrt(outlier) >thresholdoutliers) {
|
|
354
|
+
printf("\nOutlier found: %lf %lf %lf", p->t, p->y, sqrt(outlier));
|
|
355
|
+
p1 = p ->prev;
|
|
356
|
+
p2 = p->next;
|
|
357
|
+
p1->next = p2;
|
|
358
|
+
p2->prev = p1;
|
|
359
|
+
delete p;
|
|
360
|
+
curdataset->length--;
|
|
361
|
+
p = p1;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
residual += outlier;
|
|
365
|
+
weight += w1 + w2;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// residual*=0.5*curdataset->length/weight;
|
|
369
|
+
residual=(residual+1.)/(weight+1.);
|
|
370
|
+
pc=sqrt(residual);
|
|
371
|
+
printf("\n%s", curdataset->label);
|
|
372
|
+
printf("\nResidual: %le Length: %d Weight: %le Normalization factor: %le",residual,curdataset->length,weight,pc);
|
|
373
|
+
curdataset->first->sig=pc;
|
|
374
|
+
if(curdataset->length>maxlength){
|
|
375
|
+
minfac=pc;
|
|
376
|
+
maxlength=curdataset->length;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Re-normalizing error bars for each dataset
|
|
381
|
+
|
|
382
|
+
if (normalized < 0.5) {
|
|
383
|
+
printf("\n\n- Re-normalizing error bars");
|
|
384
|
+
for (curdataset = datalist; curdataset; curdataset = curdataset->next) {
|
|
385
|
+
pc = curdataset->first->sig;// / minfac;
|
|
386
|
+
for (p = curdataset->first->next; p; p = p->next) {
|
|
387
|
+
p->err *= pc;
|
|
388
|
+
}
|
|
389
|
+
curdataset->first->sig = 0;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
// Eliminating short datasets
|
|
395
|
+
|
|
396
|
+
printf("\n\n- Removing short datasets\n");
|
|
397
|
+
|
|
398
|
+
pmaxdataset = datalist;
|
|
399
|
+
nps = 0;
|
|
400
|
+
while (pmaxdataset) {
|
|
401
|
+
curdataset = pmaxdataset->next;
|
|
402
|
+
if (pmaxdataset->length < 4) {
|
|
403
|
+
printf("\n- Discarding: %s", pmaxdataset->label);
|
|
404
|
+
if (pmaxdataset->prev) {
|
|
405
|
+
pmaxdataset->prev->next = pmaxdataset->next;
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
datalist = pmaxdataset->next;
|
|
409
|
+
}
|
|
410
|
+
if (pmaxdataset->next) pmaxdataset->next->prev = pmaxdataset->prev;
|
|
411
|
+
pmaxdataset->next = 0;
|
|
412
|
+
delete pmaxdataset;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
nps += pmaxdataset->length;
|
|
416
|
+
}
|
|
417
|
+
pmaxdataset = curdataset;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Calculate peak season
|
|
421
|
+
|
|
422
|
+
if (otherseasons > 0) {
|
|
423
|
+
|
|
424
|
+
printf("\n\n- Calculate peak season\n");
|
|
425
|
+
|
|
426
|
+
for (curdataset = datalist; curdataset; curdataset = curdataset->next) {
|
|
427
|
+
datapoint** chunkfirst, ** chunklast;
|
|
428
|
+
int nchunks, ns, imaxdev;
|
|
429
|
+
double* devs;
|
|
430
|
+
double sy, sy2, ss, maxdev;
|
|
431
|
+
printf("\n%s", curdataset->label);
|
|
432
|
+
// Divide dataset in chunks separated by gaps longer than 30 days
|
|
433
|
+
chunkfirst = (datapoint**)malloc(sizeof(chunkfirst));
|
|
434
|
+
chunklast = (datapoint**)malloc(sizeof(chunkfirst));
|
|
435
|
+
chunkfirst[0] = curdataset->first;
|
|
436
|
+
nchunks = 0;
|
|
437
|
+
do {
|
|
438
|
+
p = chunkfirst[nchunks];
|
|
439
|
+
while (p && p->next && p->next->t - p->t < 30) p = p->next;
|
|
440
|
+
chunklast[nchunks] = p;
|
|
441
|
+
if (p->next) {
|
|
442
|
+
nchunks++;
|
|
443
|
+
chunkfirst = (datapoint**)realloc(chunkfirst, sizeof(chunkfirst) * (nchunks + 1));
|
|
444
|
+
chunklast = (datapoint**)realloc(chunklast, sizeof(chunkfirst) * (nchunks + 1));
|
|
445
|
+
chunkfirst[nchunks] = p->next;
|
|
446
|
+
}
|
|
447
|
+
} while (p->next);
|
|
448
|
+
nchunks++;
|
|
449
|
+
|
|
450
|
+
// Calculate standard deviation from flat light curve for each chunk
|
|
451
|
+
devs = (double*)malloc(sizeof(double) * nchunks);
|
|
452
|
+
imaxdev = 0;
|
|
453
|
+
maxdev = -1;
|
|
454
|
+
for (int ichunk = 0; ichunk < nchunks; ichunk++) {
|
|
455
|
+
sy = ss = sy2 = 0;
|
|
456
|
+
ns = 0;
|
|
457
|
+
for (p = chunkfirst[ichunk]; p != chunklast[ichunk]->next; p = p->next) {
|
|
458
|
+
sy += p->y / (p->err * p->err);
|
|
459
|
+
sy2 += p->y * p->y / (p->err * p->err);
|
|
460
|
+
ss += 1 / (p->err * p->err);
|
|
461
|
+
ns++;
|
|
462
|
+
}
|
|
463
|
+
devs[ichunk] = sqrt((sy2 - sy * sy / ss) / ns);
|
|
464
|
+
// Note chunk with maximal deviation (should be peak season)
|
|
465
|
+
if (devs[ichunk] > maxdev) {
|
|
466
|
+
maxdev = devs[ichunk];
|
|
467
|
+
imaxdev = ichunk;
|
|
468
|
+
}
|
|
469
|
+
printf("\n%lf --- %lf : dev: %lf", chunkfirst[ichunk]->t, chunklast[ichunk]->t, devs[ichunk]);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (otherseasons == 1) { // Diminish significance of seasons other than peak season
|
|
473
|
+
printf("\nSeasons other than peak season considered less significant in re-binning");
|
|
474
|
+
for (int ichunk = 0; ichunk < nchunks; ichunk++) {
|
|
475
|
+
if (ichunk != imaxdev) {
|
|
476
|
+
double fac = devs[ichunk] / maxdev;
|
|
477
|
+
fac *= fac;
|
|
478
|
+
for (p = chunkfirst[ichunk]; p != chunklast[ichunk]->next; p = p->next) {
|
|
479
|
+
p->basesig = fac;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
else { // Otherwise remove seasons other than peak season
|
|
485
|
+
printf("\nSeasons other than peak season are removed");
|
|
486
|
+
for (p = curdataset->first; p != chunkfirst[imaxdev]; p = p1) {
|
|
487
|
+
p1 = p->next;
|
|
488
|
+
delete p;
|
|
489
|
+
curdataset->length--;
|
|
490
|
+
}
|
|
491
|
+
curdataset->first = chunkfirst[imaxdev];
|
|
492
|
+
curdataset->first->prev = 0;
|
|
493
|
+
for (p = chunklast[imaxdev]->next; p; p = p1) {
|
|
494
|
+
p1 = p->next;
|
|
495
|
+
delete p;
|
|
496
|
+
curdataset->length--;
|
|
497
|
+
}
|
|
498
|
+
curdataset->last = chunklast[imaxdev];
|
|
499
|
+
curdataset->last->next = 0;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
free(devs);
|
|
503
|
+
free(chunkfirst);
|
|
504
|
+
free(chunklast);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
// Calculate significance of each point with respect to the previous one
|
|
511
|
+
|
|
512
|
+
printf("\n- Calculate significance of each data point\n");
|
|
513
|
+
|
|
514
|
+
for(curdataset=datalist;curdataset;curdataset=curdataset->next){
|
|
515
|
+
for(p=curdataset->first->next;p;p=p->next){
|
|
516
|
+
_computesig
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
// Rebin useless points, reducing the number of points to npmax
|
|
522
|
+
|
|
523
|
+
printf("\n- Rebinning data down to %d\n",npmax);
|
|
524
|
+
while(nps>npmax){
|
|
525
|
+
pmax=datalist->first->next;
|
|
526
|
+
pmaxdataset=datalist;
|
|
527
|
+
ifile=flag=0;
|
|
528
|
+
for(curdataset=datalist;curdataset;curdataset=curdataset->next){
|
|
529
|
+
for(p=curdataset->first->next;p;p=p->next){
|
|
530
|
+
if(p->sig<pmax->sig){
|
|
531
|
+
pmax=p;
|
|
532
|
+
pmaxdataset=curdataset;
|
|
533
|
+
flag=ifile;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
ifile++;
|
|
537
|
+
}
|
|
538
|
+
p=pmax->prev;
|
|
539
|
+
// printf("\n%d %d %lf\n%lf %le %le\n%lf %le %le",nps,flag,pmax->sig,p->t,p->y,p->err,pmax->t,pmax->y,pmax->err);
|
|
540
|
+
w1=1/(p->err*p->err);
|
|
541
|
+
w2=1/(pmax->err*pmax->err);
|
|
542
|
+
p->t=(p->t*w1+pmax->t*w2)/(w1+w2);
|
|
543
|
+
p->y=(p->y*w1+pmax->y*w2)/(w1+w2);
|
|
544
|
+
p->err=1/sqrt(w1+w2);
|
|
545
|
+
p->next=pmax->next;
|
|
546
|
+
// printf("\n%lf %le %le",p->t,p->y,p->err);
|
|
547
|
+
|
|
548
|
+
if(pmax->next){
|
|
549
|
+
pmax->next->prev=p;
|
|
550
|
+
}else{
|
|
551
|
+
pmaxdataset->last=p;
|
|
552
|
+
}
|
|
553
|
+
pmaxdataset->length--;
|
|
554
|
+
delete pmax;
|
|
555
|
+
nps--;
|
|
556
|
+
|
|
557
|
+
if(p->t>-1.e99 && p->y>-1.e99){
|
|
558
|
+
}else{
|
|
559
|
+
if(p->prev){
|
|
560
|
+
p->prev->next=p->next;
|
|
561
|
+
}else{
|
|
562
|
+
datalist->first=p->next;
|
|
563
|
+
}
|
|
564
|
+
if(p->next){
|
|
565
|
+
p->next->prev=p->prev;
|
|
566
|
+
}else{
|
|
567
|
+
datalist->last=p->prev;
|
|
568
|
+
}
|
|
569
|
+
delete p;
|
|
570
|
+
pmaxdataset->length--;
|
|
571
|
+
nps --;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
if(pmaxdataset->length<4){
|
|
576
|
+
if(pmaxdataset->prev){
|
|
577
|
+
pmaxdataset->prev->next=pmaxdataset->next;
|
|
578
|
+
}else{
|
|
579
|
+
datalist=pmaxdataset->next;
|
|
580
|
+
}
|
|
581
|
+
if(pmaxdataset->next) pmaxdataset->next->prev=pmaxdataset->prev;
|
|
582
|
+
nps-=pmaxdataset->length;
|
|
583
|
+
pmaxdataset->next=0;
|
|
584
|
+
delete pmaxdataset;
|
|
585
|
+
}else{
|
|
586
|
+
if(p->prev){
|
|
587
|
+
_computesig
|
|
588
|
+
}
|
|
589
|
+
p=p->next;
|
|
590
|
+
if(p){
|
|
591
|
+
_computesig
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Write rebinned datasets to file
|
|
597
|
+
|
|
598
|
+
printf("\n- Writing final data to LCToFit.txt\n");
|
|
599
|
+
|
|
600
|
+
remove("LCToFit.bkp");
|
|
601
|
+
rename("LCToFit.txt","LCToFit.bkp");
|
|
602
|
+
|
|
603
|
+
f=fopen("LCToFit.txt","w");
|
|
604
|
+
ifile=0;
|
|
605
|
+
fprintf(f,"%d\n",nps);
|
|
606
|
+
for(curdataset=datalist;curdataset;curdataset=curdataset->next){
|
|
607
|
+
printf("\n%d",curdataset->length);
|
|
608
|
+
undersc=curdataset->label-5+strlen(curdataset->label);
|
|
609
|
+
satellite=(*undersc<'A')? (*undersc)-'0' : 0; // satellite data should have names like ZOB1501241.dat where 1.dat distinguishes satellites data
|
|
610
|
+
for(p=curdataset->first;p;p=p->next){
|
|
611
|
+
y=pow(10.,-0.4*p->y);
|
|
612
|
+
err=p->err*y*0.9210340371976184;
|
|
613
|
+
fprintf(f,"%d %.10le %.10le %.10le %d\n",ifile,p->t,y,err,satellite);
|
|
614
|
+
}
|
|
615
|
+
ifile++;
|
|
616
|
+
}
|
|
617
|
+
fclose(f);
|
|
618
|
+
|
|
619
|
+
f=fopen("FilterToData.txt","w");
|
|
620
|
+
for(curdataset=datalist;curdataset;curdataset=curdataset->next){
|
|
621
|
+
fprintf(f,"%s\n",curdataset->label);
|
|
622
|
+
}
|
|
623
|
+
fclose(f);
|
|
624
|
+
|
|
625
|
+
// Exiting
|
|
626
|
+
|
|
627
|
+
delete datalist;
|
|
628
|
+
|
|
629
|
+
//printf("\nHello!");
|
|
630
|
+
// getchar();
|
|
631
|
+
|
|
632
|
+
return 0;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
dataset::dataset(){
|
|
637
|
+
length=0;
|
|
638
|
+
prev=next=0;
|
|
639
|
+
first=last=0;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
dataset::~dataset(){
|
|
643
|
+
datapoint *p,*q;
|
|
644
|
+
|
|
645
|
+
delete next;
|
|
646
|
+
for(p=first;p;p=q){
|
|
647
|
+
q=p->next;
|
|
648
|
+
delete p;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
void dataset::addpoint(double t, double y, double err){
|
|
653
|
+
datapoint *p;
|
|
654
|
+
p=new datapoint;
|
|
655
|
+
p->t=t;
|
|
656
|
+
p->y=y;
|
|
657
|
+
p->err=err;
|
|
658
|
+
if(length){
|
|
659
|
+
p->prev=last;
|
|
660
|
+
last->next=p;
|
|
661
|
+
last=p;
|
|
662
|
+
}else{
|
|
663
|
+
first=last=p;
|
|
664
|
+
p->prev=0;
|
|
665
|
+
}
|
|
666
|
+
p->next=0;
|
|
667
|
+
p->sig=0;
|
|
668
|
+
p->basesig = 1;
|
|
669
|
+
length++;
|
|
670
|
+
}
|