RTModel 2.0__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.
RTModel-2.0/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,6 @@
1
+ include RTModel/bin/Reader.exe
2
+ graft RTModel/data
3
+ graft RTModel/lib
4
+ graft RTModel/include
5
+ graft RTModel/bin
6
+ global-exclude RTModel/lib/*.o*
RTModel-2.0/PKG-INFO ADDED
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.1
2
+ Name: RTModel
3
+ Version: 2.0
4
+ Summary: RTModel is a tool for microlensing event interpretation.
5
+ Author-email: Valerio Bozza <valboz@sa.infn.it>
6
+ License: GPL-3.0
7
+ Project-URL: Homepage, https://github.com/valboz/RTModel
8
+ Keywords: Microlensing analysis and fitting
9
+ Classifier: Development Status :: 1 - Planning
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: <4,>=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: numpy
17
+ Requires-Dist: pytest
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: tqdm
20
+ Requires-Dist: VBBinaryLensing>=3.7.0
21
+
22
+ # RTModel
23
+ `RTModel` is a package for modeling and interpretation of microlensing events. It uses photometric time series collected from ground and/or space telescopes to propose one or more possible models among the following:
24
+ - Single-lens-single-source microlensing (i.e. Paczynski)
25
+ - Single-lens-binary-source microlensing (with or without xallarap)
26
+ - Binary-lens-single-source microlensing (including planetary microlensing, parallax and orbital motion)
27
+
28
+ All models include the finite-size of the source(s).
29
+
30
+ The modeling strategy is based on a grid search in the parameter space for single-lens models, whereas a **template library** for binary-lens models is used including all possible geometries of the source trajectory with respect to the caustics. In addition to this global search, planets are searched where maximal deviations from a Paczynski model occurs.
31
+
32
+ The library is in the form of a standard Python package that launches specific subprocesses for different tasks. Model fitting is executed in **parallel** exploiting available processors in the machine. The full modeling may take from one to three hours depending on the event and on the machine speed. The results of modeling are given in the form of a text **assessment file**; in addition, **final models** are made available with their parameters and covariance matrices.
33
+
34
+ `RTModel` also includes a subpackage **`RTModel.plotmodel`** that allows an immediate visualization of models and the possibility to review each individual fitting process as an animated gif.
35
+
36
+ ## Attribution
37
+
38
+ A paper is in preparation describing all algorithms behind RTModel in detail.
39
+ At the moment, any use of this code for scientific publications should be acknowledged by citing this GitHub repository.
40
+
41
+ ## Installation
42
+
43
+ The easiest way to install `RTModel` is through `pip`
44
+ ```
45
+ pip install RTModel
46
+ ```
47
+
48
+ Currently, `RTModel` works on Linux and Windows, requiring Python >= 3.6.
49
+ A C++ compiler compatible with C++17 standard is needed for installation.
50
+ `RTModel` also incorporates version 3.7 of [`VBBinaryLensing`](https://github.com/valboz/VBBinaryLensing).
51
+
52
+ Example Jupyter notebooks will be included in `examples/`.
53
+
54
+ ## Documentation
55
+ Provisional [documentation for the use of RTModel](docs/README.md) is available and under development.
56
+
57
+ ## License
58
+ `RTModel` is freely available to the community under the
59
+ GNU Lesser General Public License Version 3 included in this repository.
60
+
61
+
RTModel-2.0/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # RTModel
2
+ `RTModel` is a package for modeling and interpretation of microlensing events. It uses photometric time series collected from ground and/or space telescopes to propose one or more possible models among the following:
3
+ - Single-lens-single-source microlensing (i.e. Paczynski)
4
+ - Single-lens-binary-source microlensing (with or without xallarap)
5
+ - Binary-lens-single-source microlensing (including planetary microlensing, parallax and orbital motion)
6
+
7
+ All models include the finite-size of the source(s).
8
+
9
+ The modeling strategy is based on a grid search in the parameter space for single-lens models, whereas a **template library** for binary-lens models is used including all possible geometries of the source trajectory with respect to the caustics. In addition to this global search, planets are searched where maximal deviations from a Paczynski model occurs.
10
+
11
+ The library is in the form of a standard Python package that launches specific subprocesses for different tasks. Model fitting is executed in **parallel** exploiting available processors in the machine. The full modeling may take from one to three hours depending on the event and on the machine speed. The results of modeling are given in the form of a text **assessment file**; in addition, **final models** are made available with their parameters and covariance matrices.
12
+
13
+ `RTModel` also includes a subpackage **`RTModel.plotmodel`** that allows an immediate visualization of models and the possibility to review each individual fitting process as an animated gif.
14
+
15
+ ## Attribution
16
+
17
+ A paper is in preparation describing all algorithms behind RTModel in detail.
18
+ At the moment, any use of this code for scientific publications should be acknowledged by citing this GitHub repository.
19
+
20
+ ## Installation
21
+
22
+ The easiest way to install `RTModel` is through `pip`
23
+ ```
24
+ pip install RTModel
25
+ ```
26
+
27
+ Currently, `RTModel` works on Linux and Windows, requiring Python >= 3.6.
28
+ A C++ compiler compatible with C++17 standard is needed for installation.
29
+ `RTModel` also incorporates version 3.7 of [`VBBinaryLensing`](https://github.com/valboz/VBBinaryLensing).
30
+
31
+ Example Jupyter notebooks will be included in `examples/`.
32
+
33
+ ## Documentation
34
+ Provisional [documentation for the use of RTModel](docs/README.md) is available and under development.
35
+
36
+ ## License
37
+ `RTModel` is freely available to the community under the
38
+ GNU Lesser General Public License Version 3 included in this repository.
39
+
40
+
@@ -0,0 +1,293 @@
1
+
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import glob
6
+ import time
7
+ import inspect
8
+ from tqdm import tqdm
9
+ import shutil
10
+
11
+
12
+ class RTModel:
13
+ def __init__(self, event = None):
14
+ # Directory preliminaries
15
+ print('*********************')
16
+ print('**** RTModel ****')
17
+ print('*********************')
18
+ self.pathtoRTM = inspect.getfile(RTModel)
19
+ self.bindir = os.path.dirname(self.pathtoRTM) + '/bin/'
20
+ if os.name =='nt':
21
+ self.readerexe = 'Reader.exe'
22
+ self.initcondexe = 'InitCond.exe'
23
+ self.levmarexe = 'LevMar.exe'
24
+ self.modelselectorexe = 'ModelSelector.exe'
25
+ self.finalizerexe = 'Finalizer.exe'
26
+ else:
27
+ self.readerexe = 'Reader'
28
+ self.initcondexe = 'InitCond'
29
+ self.levmarexe = 'LevMar'
30
+ self.modelselectorexe = 'ModelSelector'
31
+ self.finalizerexe = 'Finalizer'
32
+ if(event == None):
33
+ self.eventname = os.getcwd()
34
+ else:
35
+ self.eventname = os.path.realpath(event)
36
+ print("Event name: " + self.eventname)
37
+ self.inidir = "ini"
38
+ self.modelcodes = ['PS', 'PX', 'BS', 'BO', 'LS', 'LX', 'LO']
39
+ self.endphase = len(self.modelcodes)*2+3
40
+ self.eventinifile = 'event.ini'
41
+ self.nprocessors = os.cpu_count()
42
+ print('Number of processors: {}'.format(self.nprocessors))
43
+ self.config_Reader()
44
+ self.config_InitCond()
45
+ self.config_LevMar()
46
+ self.config_ModelSelector()
47
+ self.satellitedir = '.'
48
+
49
+ def set_processors(self, nprocessors):
50
+ self.nprocessors = nprocessors
51
+
52
+ def set_event(self, event):
53
+ self.eventname = os.path.realpath(event)
54
+
55
+ def set_satellite_dir(self, satellitedir):
56
+ self.satellitedir = satellitedir
57
+
58
+ def config_Reader(self, tau = 0.1, binning = 4000, otherseasons = 1, renormalize = 1, thresholdoutliers = 10):
59
+ self.Reader_tau= tau # conventional correlation time for consecutive points
60
+ self.Reader_binning = binning # maximum number of points left after re-binning
61
+ self.Reader_otherseasons = otherseasons # How to use other seasons (0 = Yes, 1 = decrease significance, 2 = remove)
62
+ self.Reader_renormalize = renormalize # Re-normalize error bars if non-zero
63
+ self.Reader_thresholdoutliers = thresholdoutliers # Threshold in sigmas for removing outliers
64
+
65
+ def Reader(self):
66
+ if(not os.path.exists(self.eventname + '/' + self.inidir)):
67
+ os.makedirs(self.eventname + '/' + self.inidir)
68
+ with open(self.eventname + '/' + self.inidir + '/Reader.ini','w') as f:
69
+ f.write('tau = ' + str(self.Reader_tau) + '\n')
70
+ f.write('binning = ' + str(self.Reader_binning) + '\n')
71
+ f.write('otherseasons = ' + str(self.Reader_otherseasons) + '\n')
72
+ f.write('renormalize = ' + str(self.Reader_renormalize) + '\n')
73
+ f.write('thresholdoutliers = ' + str(self.Reader_thresholdoutliers) + '\n')
74
+ print('- Launching: Reader')
75
+ print(' Pre-processing data...')
76
+ completedprocess = subprocess.run([self.bindir+self.readerexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
77
+ if(completedprocess.returncode != 0):
78
+ print('! Error in pre-processing. Please check your data!')
79
+ self.done = True
80
+ else:
81
+ print(' OK')
82
+
83
+ def config_InitCond(self, npeaks = 2, peakthreshold = 10.0, oldmodels = 4, override = None, nostatic = False, onlyorbital = False, usesatellite = 0):
84
+ self.InitCond_npeaks = npeaks # Number of peaks in the observed light curve to be considered for setting initial conditions.
85
+ self.InitCond_peakthreshold = peakthreshold # Number of sigmas necessary for a deviation to be identified as a maximum or a minimum.
86
+ self.InitCond_oldmodels = oldmodels # Maximum number of old models to include in new run as initial conditions
87
+ self.InitCond_override = override # Override peak identification and manually set peak times
88
+ self.InitCond_nostatic = nostatic or onlyorbital # No static models will be calculated.
89
+ self.InitCond_noparallax = onlyorbital; # Only orbital motion models will be calculated.
90
+ self.InitCond_usesatellite = usesatellite; # Satellite to be used for initial conditions. Ground telescopes by default.
91
+
92
+ def InitCond(self):
93
+ if(not os.path.exists(self.eventname + '/' + self.inidir)):
94
+ os.makedirs(self.eventname + '/' + self.inidir)
95
+ with open(self.eventname + '/' + self.inidir + '/InitCond.ini','w') as f:
96
+ f.write('npeaks = ' + str(self.InitCond_npeaks) + '\n')
97
+ f.write('peakthreshold = ' + str(self.InitCond_peakthreshold) + '\n')
98
+ f.write('oldmodels = ' + str(self.InitCond_oldmodels) + '\n')
99
+ f.write('usesatellite = ' + str(self.InitCond_usesatellite) + '\n')
100
+ if(self.InitCond_nostatic):
101
+ f.write('nostatic = 1\n')
102
+ if(self.InitCond_noparallax):
103
+ f.write('noparallax = 1\n')
104
+ if(self.InitCond_override != None):
105
+ f.write('override = ' + str(self.InitCond_override[0])+ ' ' + str(self.InitCond_override[1]) + '\n')
106
+ print('- Launching: InitCond')
107
+ print(' Setting initial conditions...')
108
+ completedprocess = subprocess.run([self.bindir+self.initcondexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
109
+ if(completedprocess.returncode != 0):
110
+ print('! Error in setting initial conditions!')
111
+ self.done = True
112
+ else:
113
+ print(' OK')
114
+
115
+ def config_LevMar(self, nfits = 5, timelimit = 600.0, maxsteps = 50, bumperpower = 2.0):
116
+ self.LevMar_nfits = nfits # Number of models to be calculated from the same initial condition using the bumper method
117
+ self.LevMar_maxsteps = maxsteps # Maximum number of steps in each fit
118
+ self.LevMar_timelimit = timelimit # Maximum time in seconds for total execution
119
+ self.LevMar_bumperpower = bumperpower # Repulsion factor of bumpers
120
+
121
+ def LevMar(self,strmodel):
122
+ if(not os.path.exists(self.eventname + '/' + self.inidir)):
123
+ os.makedirs(self.eventname + '/' + self.inidir)
124
+ with open(self.eventname + '/' + self.inidir + '/LevMar.ini','w') as f:
125
+ f.write('nfits = ' + str(self.LevMar_nfits) + '\n')
126
+ f.write('maxsteps = ' + str(self.LevMar_maxsteps) + '\n')
127
+ f.write('timelimit = ' + str(self.LevMar_timelimit) + '\n')
128
+ f.write('bumperpower = ' + str(self.LevMar_bumperpower) + '\n')
129
+ print('- Launching: LevMar')
130
+ print(' Fitting ' + strmodel + ' ...')
131
+ completedprocess = subprocess.run([self.bindir+self.levmarexe,self.eventname, strmodel,self.satellitedir], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
132
+ if(completedprocess.returncode != 0):
133
+ print('! Error in fit!')
134
+ self.done = True
135
+ else:
136
+ print(' OK')
137
+
138
+ def launch_fits(self,modelcode):
139
+ if(not os.path.exists(self.eventname + '/' + self.inidir)):
140
+ os.makedirs(self.eventname + '/' + self.inidir)
141
+ with open(self.eventname + '/' + self.inidir + '/LevMar.ini','w') as f:
142
+ f.write('nfits = ' + str(self.LevMar_nfits) + '\n')
143
+ f.write('maxsteps = ' + str(self.LevMar_maxsteps) + '\n')
144
+ f.write('timelimit = ' + str(self.LevMar_timelimit) + '\n')
145
+ f.write('bumperpower = ' + str(self.LevMar_bumperpower) + '\n')
146
+ stringfits = {'PS' : '- Single-lens-Single-source fits',
147
+ 'PX' : '- Single-lens-Single-source fits with parallax',
148
+ 'BS' : '- Single-lens-Binary-source fits',
149
+ 'BO' : '- Single-lens-Binary-source fits with xallarap',
150
+ 'LS' : '- Binary-lens-Single-source fits',
151
+ 'LX' : '- Binary-lens-Single-source fits with parallax',
152
+ 'LO' : '- Binary-lens-Single-source fits with orbital motion'}
153
+ print(stringfits[modelcode])
154
+ initcondfile = self.eventname + '/InitCond/' + 'InitCond'+ modelcode + '.txt'
155
+ if(os.path.exists(initcondfile)):
156
+ with open(self.eventname + '/InitCond/' + 'InitCond'+ modelcode + '.txt') as f:
157
+ line = f.readline().split()
158
+ npeaks = int(line[0])
159
+ ninitconds = int(line[1])
160
+ processes = []
161
+ procnumbers = []
162
+ iinitcond = 0
163
+ finitcond = 0
164
+ finitcondold = -1
165
+ pbar = tqdm(total = ninitconds,desc = 'Fits completed',file=sys.stdout, colour='GREEN', smoothing = 0)
166
+ while(finitcond < ninitconds):
167
+ i=0
168
+ while i < len(processes):
169
+ if(processes[i].poll() != None):
170
+ processes.pop(i)
171
+ procnumbers.pop(i)
172
+ finitcond += 1
173
+ else:
174
+ i += 1
175
+ while(iinitcond < ninitconds and len(processes) < self.nprocessors):
176
+ strmodel = modelcode + '{:0>4}'.format(str(iinitcond))
177
+ if(glob.glob(self.eventname +'/PreModels/' + strmodel + '/t' + strmodel + '.dat')==[]):
178
+ processes.append(subprocess.Popen([self.bindir+self.levmarexe,self.eventname, strmodel,self.satellitedir], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL))
179
+ procnumbers.append(iinitcond)
180
+ else:
181
+ finitcond += 1
182
+ iinitcond += 1
183
+ if(finitcond != finitcondold):
184
+ #print(' Fits launched: {}; completed: {}/{}'.format(iinitcond, finitcond, ninitconds))
185
+ pbar.update(finitcond - max(finitcondold,0))
186
+ finitcondold =finitcond
187
+ time.sleep(0.1)
188
+ pbar.close()
189
+ else:
190
+ print('- No initial conditions for this class')
191
+
192
+ def config_ModelSelector(self, sigmasoverlap = 3.0, sigmachisquare = 1.0, maxmodels = 10):
193
+ self.ModelSelector_sigmasoverlap = sigmasoverlap # factor multiplying the inverse covariance in search for superpositions (models are incompatible if farther than sigmasoverlap*sigma)
194
+ self.ModelSelector_sigmachisquare = sigmachisquare # number of sigmas in the chi square distribution for accepting alternative models after the best one
195
+ self.ModelSelector_maxmodels = maxmodels # maximum number of models returned
196
+
197
+ def ModelSelector(self, modelcode):
198
+ if(not os.path.exists(self.eventname + '/' + self.inidir)):
199
+ os.makedirs(self.eventname + '/' + self.inidir)
200
+ with open(self.eventname + '/' + self.inidir + '/ModelSelector.ini','w') as f:
201
+ f.write('sigmasoverlap = ' + str(self.ModelSelector_sigmasoverlap) + '\n')
202
+ f.write('sigmachisquare = ' + str(self.ModelSelector_sigmachisquare) + '\n')
203
+ f.write('maxmodels = ' + str(self.ModelSelector_maxmodels) + '\n')
204
+ stringmodels = {'PS' : '- Selecting models for Single-lens-Single-source fits',
205
+ 'PX' : '- Selecting models for Single-lens-Single-source fits with parallax',
206
+ 'BS' : '- Selecting models for Single-lens-Binary-source fits',
207
+ 'BO' : '- Selecting models for Single-lens-Binary-source fits with xallarap',
208
+ 'LS' : '- Selecting models for Binary-lens-Single-source fits',
209
+ 'LX' : '- Selecting models for Binary-lens-Single-source fits with parallax',
210
+ 'LO' : '- Selecting models for Binary-lens-Single-source fits with orbital motion'}
211
+ print(stringmodels[modelcode])
212
+ completedprocess = subprocess.run([self.bindir+self.modelselectorexe,self.eventname, modelcode], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
213
+ if(completedprocess.returncode != 0):
214
+ print('! Error in model selection!')
215
+ self.done = True
216
+ else:
217
+ print(' OK')
218
+
219
+ def Finalizer(self):
220
+ print('- Launching: Finalizer')
221
+ print(' Making final assessment for this event')
222
+ completedprocess = subprocess.run([self.bindir+self.finalizerexe,self.eventname], cwd = self.bindir, shell = False, stdout=subprocess.DEVNULL)
223
+ if(completedprocess.returncode != 0):
224
+ print('! Error in finalization. Maybe there are problems with models')
225
+ self.done = True
226
+ else:
227
+ with open(self.eventname + '/Nature.txt') as f:
228
+ for line in f.readlines():
229
+ print(" " + line,end='')
230
+ print(" OK")
231
+
232
+ def run(self, event = None):
233
+ phase =0
234
+ if(event!= None):
235
+ self.eventname = os.path.realpath(event)
236
+ self.done = False
237
+ while not(self.done):
238
+ print("o " + time.asctime())
239
+ # Check that event directory exists
240
+ if phase == 0:
241
+ if(os.path.exists(self.eventname + '/Data')):
242
+ print('- Analyzing event: ',self.eventname)
243
+ phase = 1
244
+ else:
245
+ print('! Event data for ' + self.eventname + ' not found !')
246
+ self.done = True
247
+ # Launch Reader
248
+ elif phase == 1:
249
+ self.Reader()
250
+ phase = 2
251
+ # Launch InitCond
252
+ elif phase == 2:
253
+ self.InitCond()
254
+ phase = 3
255
+ # Launch Finalizer
256
+ elif phase == self.endphase:
257
+ self.Finalizer()
258
+ phase += 1
259
+ # Conclude analysis
260
+ elif phase > self.endphase:
261
+ print("- Analysis of " + self.eventname + " successfully completed!")
262
+ self.done = True
263
+ # Launch LevMar for next class
264
+ elif phase%2 == 1:
265
+ self.launch_fits(self.modelcodes[phase//2-1])
266
+ phase += 1
267
+ # Launch ModelSelector for this class
268
+ else:
269
+ self.ModelSelector(self.modelcodes[phase//2-2])
270
+ phase += 1
271
+
272
+ def archive_run(self, destination = None):
273
+ olddir = os.getcwd()
274
+ os.chdir(self.eventname)
275
+ if(os.path.exists('LCToFit.txt')):
276
+ previousrunslist = glob.glob('run-*')
277
+ previousrunslist.sort()
278
+ if(destination == None):
279
+ if(len(previousrunslist)>0):
280
+ lastrun = int(previousrunslist[-1].split('-')[-1])
281
+ else:
282
+ lastrun = 0
283
+ rundir = 'run-' + str(lastrun+1). zfill(4)
284
+ else:
285
+ rundir = destination
286
+ alllist = glob.glob('*')
287
+ alllist.remove('Data')
288
+ filelist = list(set(alllist) - set(previousrunslist))
289
+ os.mkdir(rundir)
290
+ shutil.copytree('Data',rundir+'/Data')
291
+ for nam in filelist:
292
+ shutil.move(nam,rundir)
293
+ os.chdir(olddir)
@@ -0,0 +1,5 @@
1
+ __version__ = "2.0.0"
2
+ __author__ = 'Valerio Bozza'
3
+ __credits__ = 'University of Salerno, Italy'
4
+
5
+ from .RTModel import RTModel
Binary file
Binary file
Binary file
Binary file
Binary file