RTModel 2.3__tar.gz → 2.4__tar.gz

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.
Files changed (63) hide show
  1. {rtmodel-2.3 → rtmodel-2.4}/.github/workflows/build_wheels.yml +12 -4
  2. {rtmodel-2.3 → rtmodel-2.4}/CMakeLists.txt +16 -3
  3. {rtmodel-2.3 → rtmodel-2.4}/PKG-INFO +3 -2
  4. {rtmodel-2.3 → rtmodel-2.4}/RTModel/RTModel.py +54 -28
  5. {rtmodel-2.3 → rtmodel-2.4}/RTModel/__init__.py +1 -1
  6. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/Finalizer.cpp +1 -0
  7. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/InitCond.cpp +16 -4
  8. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/LevMar.cpp +4 -4
  9. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/LevMarFit.cpp +38 -32
  10. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/LevMarFit.h +5 -5
  11. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/ModelSelector.cpp +1 -0
  12. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/Reader.cpp +1 -0
  13. {rtmodel-2.3 → rtmodel-2.4}/RTModel/plotmodel/__init__.py +1 -1
  14. {rtmodel-2.3 → rtmodel-2.4}/RTModel/plotmodel/plotmodel.py +133 -23
  15. {rtmodel-2.3 → rtmodel-2.4}/changelog.md +1 -0
  16. {rtmodel-2.3 → rtmodel-2.4}/docs/Fitting.md +2 -1
  17. {rtmodel-2.3 → rtmodel-2.4}/docs/ModelCategories.md +6 -2
  18. {rtmodel-2.3 → rtmodel-2.4}/docs/ModelingRun.md +2 -0
  19. {rtmodel-2.3 → rtmodel-2.4}/docs/PlotModel.md +34 -0
  20. {rtmodel-2.3 → rtmodel-2.4}/docs/README.md +6 -6
  21. rtmodel-2.4/docs/plotmodel_fig1.png +0 -0
  22. rtmodel-2.4/fVBM.py +16 -0
  23. {rtmodel-2.3 → rtmodel-2.4}/pyproject.toml +4 -3
  24. rtmodel-2.3/RTModel/include/VBMicrolensingLibrary.h +0 -483
  25. rtmodel-2.3/RTModel/lib/VBMicrolensingLibrary.cpp +0 -8007
  26. rtmodel-2.3/docs/plotmodel_fig1.png +0 -0
  27. {rtmodel-2.3 → rtmodel-2.4}/.github/workflows/run_tests.yml +0 -0
  28. {rtmodel-2.3 → rtmodel-2.4}/.gitignore +0 -0
  29. {rtmodel-2.3 → rtmodel-2.4}/LICENSE +0 -0
  30. {rtmodel-2.3 → rtmodel-2.4}/MANIFEST.in +0 -0
  31. {rtmodel-2.3 → rtmodel-2.4}/README.md +0 -0
  32. {rtmodel-2.3 → rtmodel-2.4}/RTModel/data/ESPL.tbl +0 -0
  33. {rtmodel-2.3 → rtmodel-2.4}/RTModel/data/TemplateLibrary.txt +0 -0
  34. {rtmodel-2.3 → rtmodel-2.4}/RTModel/include/LevMarFit.h +0 -0
  35. {rtmodel-2.3 → rtmodel-2.4}/RTModel/include/bumper.h +0 -0
  36. {rtmodel-2.3 → rtmodel-2.4}/RTModel/lib/bumper.cpp +0 -0
  37. {rtmodel-2.3 → rtmodel-2.4}/RTModel/templates/__init__.py +0 -0
  38. {rtmodel-2.3 → rtmodel-2.4}/RTModel/templates/templates.py +0 -0
  39. {rtmodel-2.3 → rtmodel-2.4}/docs/Animation.md +0 -0
  40. {rtmodel-2.3 → rtmodel-2.4}/docs/Archive.md +0 -0
  41. {rtmodel-2.3 → rtmodel-2.4}/docs/Constraints.md +0 -0
  42. {rtmodel-2.3 → rtmodel-2.4}/docs/DataPreparation.md +0 -0
  43. {rtmodel-2.3 → rtmodel-2.4}/docs/DataPreprocessing.md +0 -0
  44. {rtmodel-2.3 → rtmodel-2.4}/docs/FinalAssessment.md +0 -0
  45. {rtmodel-2.3 → rtmodel-2.4}/docs/InitCond.md +0 -0
  46. {rtmodel-2.3 → rtmodel-2.4}/docs/LimbDarkening.md +0 -0
  47. {rtmodel-2.3 → rtmodel-2.4}/docs/ModelSelection.md +0 -0
  48. {rtmodel-2.3 → rtmodel-2.4}/docs/Satellite.md +0 -0
  49. {rtmodel-2.3 → rtmodel-2.4}/docs/Template.png +0 -0
  50. {rtmodel-2.3 → rtmodel-2.4}/docs/TemplateLibraries.md +0 -0
  51. {rtmodel-2.3 → rtmodel-2.4}/docs/ani.gif +0 -0
  52. {rtmodel-2.3 → rtmodel-2.4}/docs/plotchain.png +0 -0
  53. {rtmodel-2.3 → rtmodel-2.4}/docs/plotmodel_fig2.png +0 -0
  54. {rtmodel-2.3 → rtmodel-2.4}/events/OB190033.zip +0 -0
  55. {rtmodel-2.3 → rtmodel-2.4}/events/event001.zip +0 -0
  56. {rtmodel-2.3 → rtmodel-2.4}/events/event001done.zip +0 -0
  57. {rtmodel-2.3 → rtmodel-2.4}/events/event002.zip +0 -0
  58. {rtmodel-2.3 → rtmodel-2.4}/events/readme.md +0 -0
  59. {rtmodel-2.3 → rtmodel-2.4}/events/satellite1.txt +0 -0
  60. {rtmodel-2.3 → rtmodel-2.4}/jupyter/Model_event001.ipynb +0 -0
  61. {rtmodel-2.3 → rtmodel-2.4}/tests/build_tests/test_built_executables_exist.py +0 -0
  62. {rtmodel-2.3 → rtmodel-2.4}/tests/end_to_end_tests/test_ps_run.py +0 -0
  63. {rtmodel-2.3 → rtmodel-2.4}/tests/end_to_end_tests/test_ps_run_resources/example_event.zip +0 -0
@@ -1,6 +1,13 @@
1
1
  name: Build
2
2
 
3
- on: [push]
3
+ on:
4
+ push:
5
+ paths:
6
+ - '**.cpp'
7
+ - '**.h'
8
+ - '**.py'
9
+ - '**.toml'
10
+ - '**.yml'
4
11
 
5
12
  jobs:
6
13
  build_wheels:
@@ -8,15 +15,16 @@ jobs:
8
15
  runs-on: ${{ matrix.os }}
9
16
  strategy:
10
17
  matrix:
11
- # macos-13 is an intel runner, macos-14 is apple silicon
12
- os: [ubuntu-latest, windows-latest, macos-latest]
18
+ os: [ubuntu-latest, windows-latest, macos-13,macos-14] # was macos-latest
13
19
 
14
20
  steps:
15
21
  - uses: actions/checkout@v4
16
22
 
17
23
  - name: Build wheels
18
24
  uses: pypa/cibuildwheel@v2.22.0
19
- # env:
25
+ env: #
26
+ MACOSX_DEPLOYMENT_TARGET: "10.15" #
27
+ CIBW_SKIP: pp*
20
28
  # CIBW_SOME_OPTION: value
21
29
  # ...
22
30
  #with:
@@ -11,6 +11,20 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
11
11
  endif()
12
12
  endif()
13
13
 
14
+ # Find directory of VBMicrolensing
15
+
16
+ find_package(Python3 COMPONENTS Interpreter Development)
17
+ set(Python3_EXECUTABLE "./python")
18
+
19
+ execute_process(
20
+ COMMAND ${PYTHON_EXECUTABLE} fVBM.py
21
+ #-c "import sys, os, inspect; sys.path.extend(os.environ['PYTHONPATH'].split(os.pathsep)); mod = __import__('VBMicrolensing'); dir1=os.path.dirname(inspect.getfile(mod)); print(dir1.replace(\"\\\",\"/\"))"
22
+ OUTPUT_VARIABLE VBMICROLENSING_DIR
23
+ OUTPUT_STRIP_TRAILING_WHITESPACE
24
+ )
25
+ message(STATUS "Installation directory of VBMicrolensing: ${VBMICROLENSING_DIR}")
26
+
27
+
14
28
  # Build executables
15
29
  # =================
16
30
 
@@ -20,9 +34,8 @@ target_include_directories(Reader PRIVATE RTModel/include)
20
34
  add_executable(InitCond RTModel/lib/InitCond.cpp)
21
35
  target_include_directories(InitCond PRIVATE RTModel/include)
22
36
 
23
- add_executable(LevMar RTModel/lib/bumper.cpp RTModel/lib/LevMar.cpp RTModel/lib/LevMarFit.cpp
24
- RTModel/lib/VBMicrolensingLibrary.cpp)
25
- target_include_directories(LevMar PRIVATE RTModel/include)
37
+ add_executable(LevMar RTModel/lib/bumper.cpp RTModel/lib/LevMar.cpp RTModel/lib/LevMarFit.cpp ${VBMICROLENSING_DIR}/lib/VBMicrolensingLibrary.cpp)
38
+ target_include_directories(LevMar PRIVATE RTModel/include ${VBMICROLENSING_DIR}/lib)
26
39
 
27
40
  add_executable(ModelSelector RTModel/lib/bumper.cpp RTModel/lib/ModelSelector.cpp)
28
41
  target_include_directories(ModelSelector PRIVATE RTModel/include)
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RTModel
3
- Version: 2.3
3
+ Version: 2.4
4
4
  Summary: RTModel is a tool for microlensing event interpretation.
5
5
  Keywords: Microlensing analysis and fitting
6
6
  Author-Email: Valerio Bozza <valboz@sa.infn.it>
7
7
  License: GPL-3.0
8
8
  Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Intended Audience :: Science/Research
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Project-URL: Homepage, https://github.com/valboz/RTModel
13
13
  Requires-Python: <4,>=3.7
@@ -15,6 +15,7 @@ Requires-Dist: numpy
15
15
  Requires-Dist: pytest
16
16
  Requires-Dist: matplotlib
17
17
  Requires-Dist: tqdm
18
+ Requires-Dist: tabulate
18
19
  Requires-Dist: VBMicrolensing>=4.1.0
19
20
  Description-Content-Type: text/markdown
20
21
 
@@ -80,13 +80,16 @@ class RTModel:
80
80
  f.write('thresholdoutliers = ' + str(self.Reader_thresholdoutliers) + '\n')
81
81
  print('- Launching: Reader')
82
82
  print(' Pre-processing data...')
83
- completedprocess = subprocess.run([self.bindir+self.readerexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
84
- if(completedprocess.returncode != 0):
85
- print('! Error in pre-processing. Please check your data!')
86
- self.done = True
87
- else:
83
+ try:
84
+ completedprocess=subprocess.run([self.bindir+self.readerexe,self.eventname], cwd = self.bindir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text = True)
88
85
  print(' OK')
89
-
86
+ except subprocess.CalledProcessError as e:
87
+ print('\033[30;41m! Error in pre-processing. Please check your data!\033[m')
88
+ print('\033[30;43m'+e.stdout+'\033[m')
89
+ print('\033[30;43m'+e.stderr+'\033[m')
90
+ print('\033[30;41m! Program stopped here!\033[m')
91
+ self.done = True
92
+
90
93
  def config_InitCond(self, npeaks = 2, peakthreshold = 10.0, oldmodels = 4, override = None, nostatic = False, onlyorbital = False, usesatellite = 0
91
94
  , templatelibrary = None, modelcategories = ['PS','PX','BS','BO','LS','LX','LO'], onlyupdate =False):
92
95
  self.InitCond_npeaks = npeaks # Number of peaks in the observed light curve to be considered for setting initial conditions.
@@ -124,11 +127,8 @@ class RTModel:
124
127
  f.write('onlyupdate = 1\n')
125
128
  print('- Launching: InitCond')
126
129
  print(' Setting initial conditions...')
127
- completedprocess = subprocess.run([self.bindir+self.initcondexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
128
- if(completedprocess.returncode != 0):
129
- print('! Error in setting initial conditions!')
130
- self.done = True
131
- else:
130
+ try:
131
+ completedprocess=subprocess.run([self.bindir+self.initcondexe,self.eventname], cwd = self.bindir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text = True)
132
132
  peaksearch = True
133
133
  i=0
134
134
  while(peaksearch):
@@ -141,6 +141,12 @@ class RTModel:
141
141
  for i in range(0,npeaks):
142
142
  print(f'{float(f.readline().split()[0]):.4f}',end = ' ')
143
143
  print('\n OK')
144
+ except subprocess.CalledProcessError as e:
145
+ print('\033[30;41m! Error in setting initial conditions!\033[m')
146
+ print('\033[30;43m'+e.stdout+'\033[m')
147
+ print('\033[30;43m'+e.stderr+'\033[m')
148
+ print('\033[30;41m! Program stopped here!\033[m')
149
+ self.done = True
144
150
 
145
151
  def config_LevMar(self, nfits = 6, offsetdegeneracy = 3, timelimit = 600.0, maxsteps = 50, bumperpower = 2.0):
146
152
  self.LevMar_nfits = nfits # Number of models to be calculated from the same initial condition using the bumper method
@@ -169,12 +175,15 @@ class RTModel:
169
175
  f.write('parametersfile = ' + parameters_file)
170
176
  print('- Launching: LevMar')
171
177
  print(' Fitting ' + strmodel + ' ...')
172
- completedprocess = subprocess.run([self.bindir+self.levmarexe,self.eventname, strmodel,self.satellitedir], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
173
- if(completedprocess.returncode != 0):
174
- print('! Error in fit!')
175
- self.done = True
176
- else:
178
+ try:
179
+ completedprocess=subprocess.run([self.bindir+self.levmarexe,self.eventname, strmodel,self.satellitedir], cwd = self.bindir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text = True)
177
180
  print(' OK')
181
+ except subprocess.CalledProcessError as e:
182
+ print('\033[30;41m! Error in fit!\033[m')
183
+ print('\033[30;43m'+e.stdout+'\033[m')
184
+ print('\033[30;43m'+e.stderr+'\033[m')
185
+ print('\033[30;41m! Program stopped here!\033[m')
186
+ self.done = True
178
187
 
179
188
  def launch_fits(self,modelcode):
180
189
  if(not os.path.exists(self.eventname + '/' + self.inidir)):
@@ -207,18 +216,24 @@ class RTModel:
207
216
  procepochs = []
208
217
  iinitcond = 0
209
218
  finitcond = 0
210
- finitcondold = -1
219
+ finitcondold = -1
220
+ timeouts = 0
221
+ crashes = 0
211
222
  pbar = tqdm(total = ninitconds,desc = 'Fits completed',file=sys.stdout, colour='GREEN', smoothing = 0)
212
223
  while(finitcond < ninitconds):
213
224
  i=0
214
225
  while i < len(processes):
215
226
  if(time.time() - procepochs[i] > self.LevMar_timelimit):
216
227
  processes[i].kill()
228
+ timeouts += 1
229
+ crashes -= 1
217
230
  premodfiles = glob.glob(self.eventname +'/PreModels/*.txt')
218
231
  strmodel = modelcode + '{:0>4}'.format(str(procnumbers[i]))
219
232
  with open(self.eventname +'/PreModels/' + strmodel + '/t' + strmodel + '.dat','w') as f:
220
233
  f.write(f'{len(premodfiles)} {self.LevMar_nfits}')
221
234
  if(processes[i].poll() != None):
235
+ if(processes[i].returncode!=0):
236
+ crashes +=1
222
237
  processes.pop(i)
223
238
  procnumbers.pop(i)
224
239
  procepochs.pop(i)
@@ -240,6 +255,11 @@ class RTModel:
240
255
  finitcondold =finitcond
241
256
  time.sleep(0.1)
242
257
  pbar.close()
258
+ if(crashes>0):
259
+ print('crashed fits: ' + str(crashes))
260
+ if(timeouts>0):
261
+ print('timed out fits: ' + str(timeouts))
262
+ print(' OK')
243
263
  else:
244
264
  print('- No initial conditions for this category')
245
265
 
@@ -266,25 +286,31 @@ class RTModel:
266
286
  'TS' : '- Selecting models for Triple-lens-Single-source fits',
267
287
  'TX' : '- Selecting models for Triple-lens-Single-source fits with parallax'}
268
288
  print(stringmodels[modelcode])
269
- completedprocess = subprocess.run([self.bindir+self.modelselectorexe,self.eventname, modelcode], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
270
- if(completedprocess.returncode != 0):
271
- print('! Error in model selection!')
272
- self.done = True
273
- else:
289
+ try:
290
+ completedprocess=subprocess.run([self.bindir+self.modelselectorexe,self.eventname, modelcode], cwd = self.bindir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text = True)
274
291
  print(' OK')
292
+ except subprocess.CalledProcessError as e:
293
+ print('\033[30;41m! Error in model selection!\033[m')
294
+ print('\033[30;43m'+e.stdout+'\033[m')
295
+ print('\033[30;43m'+e.stderr+'\033[m')
296
+ print('\033[30;41m! Program stopped here!\033[m')
297
+ self.done = True
275
298
 
276
299
  def Finalizer(self):
277
300
  print('- Launching: Finalizer')
278
301
  print(' Making final assessment for this event')
279
- completedprocess = subprocess.run([self.bindir+self.finalizerexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
280
- if(completedprocess.returncode != 0):
281
- print('! Error in finalization. Maybe there are problems with models')
282
- self.done = True
283
- else:
302
+ try:
303
+ completedprocess=subprocess.run([self.bindir+self.finalizerexe,self.eventname], cwd = self.bindir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text = True)
284
304
  with open(self.eventname + '/Nature.txt') as f:
285
305
  for line in f.readlines():
286
306
  print(" " + line,end='')
287
307
  print(" OK")
308
+ except subprocess.CalledProcessError as e:
309
+ print('\033[30;41m! Error in finalization!\033[m')
310
+ print('\033[30;43m'+e.stdout+'\033[m')
311
+ print('\033[30;43m'+e.stderr+'\033[m')
312
+ print('\033[30;41m! Program stopped here!\033[m')
313
+ self.done = True
288
314
 
289
315
  def run(self, event = None, cleanup = False):
290
316
  phase =0
@@ -320,7 +346,7 @@ class RTModel:
320
346
  elif phase > self.endphase:
321
347
  if(cleanup):
322
348
  print('- Cleaning up preliminary models')
323
- cleanup_preliminary_models()
349
+ self.cleanup_preliminary_models()
324
350
  print("- Analysis of " + self.eventname + " successfully completed!")
325
351
  print("o " + time.asctime())
326
352
  self.done = True
@@ -1,4 +1,4 @@
1
- __version__ = "2.2"
1
+ __version__ = "2.4"
2
2
  __author__ = 'Valerio Bozza'
3
3
  __credits__ = 'University of Salerno, Italy'
4
4
 
@@ -44,6 +44,7 @@ int main(int argc, char* argv[]) {
44
44
  bumper* bumperlist = 0, * scanbumper, * scanbumper2;
45
45
 
46
46
 
47
+ setbuf(stdout, nullptr);
47
48
  printf("******************************************\n");
48
49
  printf("********** Finalizer *********\n");
49
50
  printf("******************************************\n\n\n");
@@ -21,7 +21,7 @@ char systemslash = '/';
21
21
 
22
22
  // Main global parameters
23
23
  int nobspeaks = 2; // Number of peaks in the observed light curve to be considered for setting initial conditions.
24
- double sigmathr = 5.; // Number of sigmas for spline approximation
24
+ double sigmathr = 5.; // Number of sigmas for spline approximation currently set to 0.5 peakthr
25
25
  double peakthr = 10.; // Number of sigmnas necessary for a deviation to be identified as a maximum or a minimum.
26
26
  int maxoldmodels = 4; // Maximum number of old models to include in new run as initial conditions
27
27
  bool override = false; // Override peak identification and manually set peak times
@@ -72,6 +72,7 @@ int main(int argc, char* argv[])
72
72
  dataset** peaklist, * cpeaks, * newpeaks;
73
73
  datapoint* p, * pm, * pmm, * pl, * pr, * pasy = 0, * highestpeak, * minimum, * startsection, * endsection, * sectionpeak;
74
74
 
75
+ setbuf(stdout, nullptr);
75
76
 
76
77
  // Directory preliminaries. Reads event name from arguments.
77
78
 
@@ -93,6 +94,9 @@ int main(int argc, char* argv[])
93
94
 
94
95
  printf("\n\n- Event: %s\n", eventname);
95
96
 
97
+ if (!exists(eventname)) {
98
+ throw(1);
99
+ }
96
100
  current_path(eventname);
97
101
 
98
102
 
@@ -146,7 +150,7 @@ int main(int argc, char* argv[])
146
150
  if (strcmp(command, "override") == 0) {
147
151
  fscanf(f, " %lf", &value2);
148
152
  override = true;
149
- sscanf(value,"%lf",&t1);
153
+ sscanf(value, "%lf", &t1);
150
154
  t2 = value2;
151
155
  }
152
156
  if (strcmp(command, "npeaks") == 0) {
@@ -223,7 +227,7 @@ int main(int argc, char* argv[])
223
227
  if (onlyupdate) {
224
228
  newpeaks = new dataset;
225
229
  newpeaks->length = 0;
226
- newpeaks->first = newpeaks->last=0;
230
+ newpeaks->first = newpeaks->last = 0;
227
231
  }
228
232
  else {
229
233
 
@@ -254,6 +258,10 @@ int main(int argc, char* argv[])
254
258
 
255
259
  f = fopen("LCToFit.txt", "r");
256
260
  fscanf(f, "%d", &np);
261
+ if (np == 0) {
262
+ printf("\n! No data !");
263
+ return -1;
264
+ }
257
265
 
258
266
  nfil = 1;
259
267
  dn = 0;
@@ -271,6 +279,10 @@ int main(int argc, char* argv[])
271
279
  dn = ifil;
272
280
  }
273
281
  fclose(f);
282
+ if (np == 0) {
283
+ printf("\n! No datasets match the chosen satellite!\n Check your usesatellite option.");
284
+ return -1;
285
+ }
274
286
  np++;
275
287
 
276
288
  tt = (double*)malloc(sizeof(double) * np);
@@ -878,7 +890,7 @@ int main(int argc, char* argv[])
878
890
 
879
891
  current_path(eventname);
880
892
 
881
- dn = 0;
893
+ dn = 0;
882
894
  if (strstr(modelcategories, "PS") != 0) {
883
895
  filebest = regex("PS.*\\.txt");
884
896
  strcpy(fileinit, "InitCondPS.txt");
@@ -3,10 +3,10 @@
3
3
 
4
4
  #include "LevMarFit.h"
5
5
 
6
- int main(int argc, char *argv[])
6
+ int main(int argc, char* argv[])
7
7
  {
8
- LevMar *MyLevMar= new LevMar(argc,argv);
9
- MyLevMar->Run();
8
+ LevMar* MyLevMar = new LevMar(argc, argv);
9
+ int err = MyLevMar->Run();
10
10
  delete MyLevMar;
11
- return 0;
11
+ return err;
12
12
  }
@@ -34,9 +34,9 @@ std::vector<std::vector<std::string>> parnames = { {"u0","tE","t0","rho"},
34
34
  {"s","q","u0","alpha","rho","tE","t0","piN","piE"},
35
35
  {"s","q","u0","alpha","rho","tE","t0","piN","piE","gamma1","gamma2","gammaz"},
36
36
  {"s","q","u0","alpha","rho","tE","t0","piN","piE","gamma1","gamma2","gammaz","sz_s","a_s3d"},
37
- {"s","q","u0","alpha","rho","tE","t0","s2","q2","beta"}};
37
+ {"s","q","u0","alpha","rho","tE","t0","s2","q2","beta"} };
38
38
 
39
- std::vector<std::vector<int>> logposs = {{0, 1, 3},
39
+ std::vector<std::vector<int>> logposs = { {0, 1, 3},
40
40
  {1, 3},
41
41
  {0, 1, 6},
42
42
  {2, 3, 9},
@@ -49,6 +49,7 @@ std::vector<std::vector<int>> logposs = {{0, 1, 3},
49
49
  const double epsilon = 1.e-100;
50
50
 
51
51
  LevMar::LevMar(int argc, char* argv[]) {
52
+ setbuf(stdout, nullptr);
52
53
  printf("******************************************\n");
53
54
  printf("************* LevMar **********\n");
54
55
  printf("******************************************\n\n\n");
@@ -230,7 +231,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
230
231
  model = &VBMicrolensing::BinSourceSingleLensXallarap;
231
232
  nps = 10;
232
233
  ReadOptions();
233
- double presigmapr[] = { 0.1,1,1,0.5,0.3,0.3,0.1,0.3,0.3, 2.3};
234
+ double presigmapr[] = { 0.1,1,1,0.5,0.3,0.3,0.1,0.3,0.3, 2.3 };
234
235
  double preleftlim[] = { -3.,-1.e100,-6.9,-11.5,-3.,-3.,0,-3,-6,-4.6 };
235
236
  double prerightlim[] = { 3.,1.e100,6.9,0.,3.,3.,1,3,6,1,+4.6 };
236
237
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -267,9 +268,9 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
267
268
  model = &VBMicrolensing::BinaryLightCurveParallax;
268
269
  nps = 9;
269
270
  ReadOptions();
270
- double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03};
271
- double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3. };
272
- double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3. };
271
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03 };
272
+ double preleftlim[] = { -4.0,-16.1,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3. };
273
+ double prerightlim[] = { 3.0,16.1,3.,12.56,-2.5,7.6,10.e100,3.,3. };
273
274
  error = InitCond(presigmapr, preleftlim, prerightlim);
274
275
  pr[0] = log(pr[0]);
275
276
  pr[1] = log(pr[1]);
@@ -285,8 +286,8 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
285
286
  nps = 12;
286
287
  ReadOptions();
287
288
  double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03,0.01,0.01,0.01 };
288
- double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7 };
289
- double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1 };
289
+ double preleftlim[] = { -4.0,-16.1,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7 };
290
+ double prerightlim[] = { 3.0,16.1,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1 };
290
291
  error = InitCond(presigmapr, preleftlim, prerightlim);
291
292
  pr[0] = log(pr[0]);
292
293
  pr[1] = log(pr[1]);
@@ -302,8 +303,8 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
302
303
  nps = 14;
303
304
  ReadOptions();
304
305
  double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03,0.1, 0.1 };
305
- double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7, -10,0.5001 };
306
- double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1,10,10 };
306
+ double preleftlim[] = { -4.0,-16.1,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7, -10,0.5001 };
307
+ double prerightlim[] = { 3.0,16.1,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1,10,10 };
307
308
  error = InitCond(presigmapr, preleftlim, prerightlim);
308
309
  pr[0] = log(pr[0]);
309
310
  pr[1] = log(pr[1]);
@@ -317,9 +318,9 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
317
318
  model = &VBMicrolensing::BinaryLightCurve;
318
319
  nps = 7;
319
320
  ReadOptions();
320
- double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.};
321
- double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100 };
322
- double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100 };
321
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5. };
322
+ double preleftlim[] = { -4.0,-16.1,-3.,-12.56,-11.5,-6.9,-10.e100 };
323
+ double prerightlim[] = { 3.0,16.1,3.,12.56,-2.5,7.6,10.e100 };
323
324
  error = InitCond(presigmapr, preleftlim, prerightlim);
324
325
  pr[0] = log(pr[0]);
325
326
  pr[1] = log(pr[1]);
@@ -355,8 +356,8 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
355
356
  model = &VBMicrolensing::TripleLightCurve;
356
357
  nps = 10;
357
358
  ReadOptions();
358
- double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5., 0.3, 0.5, 0.3};
359
- double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-4.0,-11.5,-12.56};
359
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5., 0.3, 0.5, 0.3 };
360
+ double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-4.0,-11.5,-12.56 };
360
361
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.0, 11.5, 12.56 };
361
362
  error = InitCond(presigmapr, preleftlim, prerightlim);
362
363
  pr[0] = log(pr[0]);
@@ -411,7 +412,7 @@ void LevMar::ReadOptions() {
411
412
  constraints = (double*)malloc(sizeof(double) * consnumber);
412
413
  consleft = (double*)malloc(sizeof(double) * consnumber);
413
414
  consright = (double*)malloc(sizeof(double) * consnumber);
414
- consvars = (double*)malloc(sizeof(double) * consnumber*(nps+1));
415
+ consvars = (double*)malloc(sizeof(double) * consnumber * (nps + 1));
415
416
  printf("\n\n- Reading Constraints.ini");
416
417
  f = fopen("Constraints.ini", "r");
417
418
  int conscurrent = 0;
@@ -425,12 +426,12 @@ void LevMar::ReadOptions() {
425
426
  else {
426
427
  consindex[conscurrent] = -1;
427
428
  strcpy(buffer, command);
428
- int flaglog = 0,flaglog2 = 0;
429
+ int flaglog = 0, flaglog2 = 0;
429
430
  buffer[4] = 0;
430
431
  for (int i = 0; i < parnames[modnumber].size(); i++) {
431
432
  if (strcmp(buffer, "log_") == 0) { // Log parameter
432
433
  if (strcmp(parnames[modnumber][i].c_str(), &command[4]) == 0) {
433
- consindex[conscurrent] = i;
434
+ consindex[conscurrent] = i;
434
435
  flaglog = 1;
435
436
  }
436
437
  }
@@ -696,7 +697,7 @@ void LevMar::ReadCurve() {
696
697
 
697
698
  }
698
699
 
699
- void LevMar::Run() {
700
+ int LevMar::Run() {
700
701
  FILE* f;
701
702
  int il, k, ichi, flag, ilam, bumpnum, bumpcounter;
702
703
  double minchi, bestchi, c1, c0, oldlambda, lambda, inclambda, fac, fac2;
@@ -802,8 +803,8 @@ void LevMar::Run() {
802
803
  for (int i = 0; i < nps; i++) {
803
804
  for (int j = 0; j < nps; j++) {
804
805
  A[i * nps + j] = Curv[i * nps + j];
805
- if (i == j) {
806
- A[i * nps + j] += lambda *Curv[i * nps + i];
806
+ if (i == j) {
807
+ A[i * nps + j] += lambda * Curv[i * nps + i];
807
808
  }
808
809
  }
809
810
  B[i] = B0[i];
@@ -988,7 +989,7 @@ void LevMar::Run() {
988
989
  fclose(f);
989
990
 
990
991
 
991
- if (modelcode[0]=='L' && il == nlc - offsetdegeneracy - 1) {
992
+ if (modelcode[0] == 'L' && il == nlc - offsetdegeneracy - 1) {
992
993
  // Find best model found so far and fit offset degeneracy model
993
994
  scanbumper2 = bumperlist;
994
995
  for (scanbumper = bumperlist; scanbumper; scanbumper = scanbumper->next) {
@@ -1000,10 +1001,14 @@ void LevMar::Run() {
1000
1001
 
1001
1002
  if (sin(pr[3]) != 0) {
1002
1003
  double s = exp(pr[0]);
1003
- double xc = pr[2] / sin(pr[3]);
1004
+ double q = exp(pr[1]);
1005
+ q /= 1 + q;
1006
+ double xc = pr[2] / sin(pr[3]) + s * q;
1004
1007
  double ac = 2 * s;
1005
1008
  double b = 1 - s * s + ac * xc;
1006
- pr[0] = log((b + sqrt(ac * ac + b * b)) / ac);
1009
+ double snew = (b + sqrt(ac * ac + b * b)) / ac;
1010
+ pr[0] = log(snew);
1011
+ pr[2] = (xc - snew * q) * sin(pr[3]);
1007
1012
  }
1008
1013
  scanbumper2 = stepchain;
1009
1014
  while (scanbumper2) {
@@ -1080,6 +1085,7 @@ void LevMar::Run() {
1080
1085
  error = 8;
1081
1086
  }
1082
1087
  }
1088
+ return error;
1083
1089
  }
1084
1090
 
1085
1091
  double LevMar::ChiSquared(double* pr) {
@@ -1181,11 +1187,11 @@ void LevMar::Grad() {
1181
1187
  prn[nps + 1 + i * 2] = (sumf[i] * sumy[i] - sumsigma[i] * sumfy[i]) / p1;
1182
1188
 
1183
1189
  if (prn[nps + 1 + i * 2] < 0) prn[nps + 1 + i * 2] = 0;
1184
- dFdp[(1 + 2 * i) * nps + j] = (prn[nps + i * 2] + prn[nps + 1 + i * 2] - pr[nps + i * 2] - pr[nps + 1 + i * 2]) / inc; // error on baseline FB+FS
1190
+ dFdp[(1 + 2 * i) * nps + j] = -1.08574 * ((prn[nps + i * 2] + prn[nps + 1 + i * 2]) / (pr[nps + i * 2] + pr[nps + 1 + i * 2]) - 1) / inc; // error on baseline -2.5log(FB+FS)/log(10) expanded to first order
1185
1191
  dFdp[(2 * i) * nps + j] = (prn[nps + i * 2] / prn[nps + 1 + i * 2] - pr[nps + i * 2] / pr[nps + 1 + i * 2]) / inc; // error on blending FB/FS
1186
1192
  }
1187
1193
  for (int icons = 0; icons < consnumber; icons++) { // Gradient of constraints
1188
- consvars[icons + (j+1) * consnumber] = ComputeConstraint(prn, icons);
1194
+ consvars[icons + (j + 1) * consnumber] = ComputeConstraint(prn, icons);
1189
1195
  p1 = (consvars[icons] - constraints[icons]);
1190
1196
  consvars[icons + (j + 1) * consnumber] = (consvars[icons + (j + 1) * consnumber] - consvars[icons]) / (((p1 > 0) ? consright[icons] : consleft[icons]) * inc);
1191
1197
  }
@@ -1204,7 +1210,7 @@ void LevMar::Grad() {
1204
1210
  }
1205
1211
  // Constraints in curvature
1206
1212
  for (int icons = 0; icons < consnumber; icons++) {
1207
- Curv[i * nps + j] += consvars[icons + (i+1) * consnumber]* consvars[icons + (j+1) * consnumber];
1213
+ Curv[i * nps + j] += consvars[icons + (i + 1) * consnumber] * consvars[icons + (j + 1) * consnumber];
1208
1214
  }
1209
1215
  }
1210
1216
  }
@@ -1219,12 +1225,12 @@ void LevMar::Grad() {
1219
1225
  for (int icons = 0; icons < consnumber; icons++) {
1220
1226
  p1 = (consvars[icons] - constraints[icons]);
1221
1227
  p1 /= (p1 > 0) ? consright[icons] : consleft[icons];
1222
- B0[i] -= p1 * consvars[icons + (i+1)*consnumber];
1228
+ B0[i] -= p1 * consvars[icons + (i + 1) * consnumber];
1223
1229
  }
1224
1230
  }
1225
1231
  }
1226
1232
 
1227
- inline double LevMar::ComputeConstraint(double *pr, int ic) {
1233
+ inline double LevMar::ComputeConstraint(double* pr, int ic) {
1228
1234
  int i = consindex[ic];
1229
1235
  if (i < 10000) {
1230
1236
  return pr[i];
@@ -1233,7 +1239,7 @@ inline double LevMar::ComputeConstraint(double *pr, int ic) {
1233
1239
  return pr[nps + (i - 10000) * 2] / pr[nps + (i - 10000) * 2 + 1];
1234
1240
  }
1235
1241
  if (i == 30000) {
1236
- int posN=-1, posE=-1;
1242
+ int posN = -1, posE = -1;
1237
1243
  for (int i = 0; i < nps; i++) {
1238
1244
  if (strcmp(parnames[modnumber][i].c_str(), "piN") == 0) posN = i;
1239
1245
  if (strcmp(parnames[modnumber][i].c_str(), "piE") == 0) posE = i;
@@ -1246,9 +1252,9 @@ inline double LevMar::ComputeConstraint(double *pr, int ic) {
1246
1252
  if (strcmp(parnames[modnumber][i].c_str(), "tE") == 0) postE = i;
1247
1253
  if (strcmp(parnames[modnumber][i].c_str(), "rho") == 0) posrho = i;
1248
1254
  }
1249
- return exp(pr[postE]+pr[posrho]);
1255
+ return exp(pr[postE] + pr[posrho]);
1250
1256
  }
1251
-
1257
+
1252
1258
  return 0;
1253
1259
  }
1254
1260
 
@@ -35,8 +35,8 @@ class LevMar {
35
35
  double* t, * y, * w, * delta, * maxdelta, * Curv, * A, * B, * B0, * Cov, * fb, ** Gr, * dFdp, * errs;
36
36
  double* pr, * prn, * sumy, * sumy2, * sumsigma, * sumfy, * sumf, * sumf2, * limbdarks;
37
37
 
38
- int consnumber, *consindex;
39
- double* constraints, * consleft, * consright, *consvars;
38
+ int consnumber, * consindex;
39
+ double* constraints, * consleft, * consright, * consvars;
40
40
  int modnumber;
41
41
 
42
42
  double Tol;
@@ -55,11 +55,11 @@ public:
55
55
  int InitCond(double* presigmapr, double* preleftlim, double* prerightlim);
56
56
  void ReadCurve();
57
57
  void ReadOptions();
58
- void Run();
58
+ int Run();
59
59
  double ChiSquared(double*);
60
60
  void Grad();
61
61
  void Covariance();
62
- double ComputeConstraint(double *pr, int i);
62
+ double ComputeConstraint(double* pr, int i);
63
63
 
64
64
  void PrintOutPS(double*);
65
65
  void PrintOutPX(double*);
@@ -88,4 +88,4 @@ public:
88
88
  double Determinant(double*, int);
89
89
  void Inverse(double*, double*, int);
90
90
 
91
- #endif
91
+ #endif
@@ -35,6 +35,7 @@ int main(int argc, char* argv[]) {
35
35
  bumper* bumperlist = 0, * scanbumper, * scanbumper2;
36
36
 
37
37
 
38
+ setbuf(stdout, nullptr);
38
39
  printf("******************************************\n");
39
40
  printf("********** Model selector *********\n");
40
41
  printf("******************************************\n\n\n");
@@ -69,6 +69,7 @@ int main(int argc, char *argv[])
69
69
 
70
70
  // Directory preliminaries. Reads event name from arguments.
71
71
 
72
+ setbuf(stdout, nullptr);
72
73
  printf("******************************************\n");
73
74
  printf("************* Reader **********\n");
74
75
  printf("******************************************\n\n");
@@ -1,4 +1,4 @@
1
- __version__ = "2.3"
1
+ __version__ = "2.4"
2
2
  __author__ = 'Valerio Bozza'
3
3
  __credits__ = 'University of Salerno, Italy'
4
4