Skip to content

Commit 40138f1

Browse files
committed
Initial commit
0 parents  commit 40138f1

19 files changed

+10244
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
.DS_Store
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
share/python-wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
MANIFEST
30+
31+
# PyInstaller
32+
# Usually these files are written by a python script from a template
33+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
34+
*.manifest
35+
*.spec
36+
37+
# Installer logs
38+
pip-log.txt
39+
pip-delete-this-directory.txt
40+
41+
# Unit test / coverage reports
42+
htmlcov/
43+
.tox/
44+
.nox/
45+
.coverage
46+
.coverage.*
47+
.cache
48+
nosetests.xml
49+
coverage.xml
50+
*.cover
51+
*.py,cover
52+
.hypothesis/
53+
.pytest_cache/
54+
cover/
55+
56+
# Translations
57+
*.mo
58+
*.pot
59+
60+
# Django stuff:
61+
*.log
62+
local_settings.py
63+
db.sqlite3
64+
db.sqlite3-journal
65+
66+
# Flask stuff:
67+
instance/
68+
.webassets-cache
69+
70+
# Scrapy stuff:
71+
.scrapy
72+
73+
# Sphinx documentation
74+
docs/_build/
75+
76+
# PyBuilder
77+
.pybuilder/
78+
target/
79+
80+
# Jupyter Notebook
81+
.ipynb_checkpoints
82+
83+
# IPython
84+
profile_default/
85+
ipython_config.py
86+
87+
# pyenv
88+
# For a library or package, you might want to ignore these files since the code is
89+
# intended to run in multiple environments; otherwise, check them in:
90+
# .python-version
91+
92+
# pipenv
93+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
95+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
96+
# install all needed dependencies.
97+
#Pipfile.lock
98+
99+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
100+
__pypackages__/
101+
102+
# Celery stuff
103+
celerybeat-schedule
104+
celerybeat.pid
105+
106+
# SageMath parsed files
107+
*.sage.py
108+
109+
# Environments
110+
.env
111+
.venv
112+
env/
113+
venv/
114+
ENV/
115+
env.bak/
116+
venv.bak/
117+
118+
# Spyder project settings
119+
.spyderproject
120+
.spyproject
121+
122+
# Rope project settings
123+
.ropeproject
124+
125+
# mkdocs documentation
126+
/site
127+
128+
# mypy
129+
.mypy_cache/
130+
.dmypy.json
131+
dmypy.json
132+
133+
# Pyre type checker
134+
.pyre/
135+
136+
# pytype static type analyzer
137+
.pytype/
138+
139+
# Cython debug symbols
140+
cython_debug/

LICENCE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Attila Bodi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
[![Image](https://img.shields.io/badge/tutorials-%E2%9C%93-blue.svg)](https://github.com/astrobatty/polyfitter/tree/master/examples)
2+
<!--- [![Image](https://img.shields.io/badge/arXiv-1909.00446-blue.svg)](https://arxiv.org/abs/1909.00446) -->
3+
4+
# polyfitter - Polynomial chain fitting and classification based on light curve morphology for binary stars.
5+
6+
The mathematical background of polynomial chain fitting (polyfit) is published in [Prša et al.,2008,ApJ,687,542](https://ui.adsabs.harvard.edu/abs/2008ApJ...687..542P/abstract).
7+
The paper that related to this code can be found [here](https://ui.adsabs.harvard.edu/abs/maybeoneday).
8+
This code is built upon the original [polyfit](https://github.com/aprsa/polyfit).
9+
10+
## Installation
11+
12+
This code depends on the GNU Scientific Library (GSL)[https://www.gnu.org/software/gsl/]. Before installation, make sure it is properly installed, e.g. running the following, which should return the location of the library:
13+
14+
```bash
15+
pkg-config --cflags --libs gsl
16+
```
17+
18+
To install the package clone this git and go the directory:
19+
```bash
20+
git clone https://github.com/astrobatty/polyfitter+git
21+
22+
cd ./polyfitter
23+
```
24+
25+
As `polyfitter` is dependent on certain python package versions, the easiest way to install it is through creating a conda environment:
26+
```bash
27+
conda create -n polyfit python=3.7 scikit-learn=0.23.2 cython=0.29.20
28+
29+
conda activate polyfit
30+
31+
python setup.py install
32+
```
33+
34+
If the code is not used, the environment can be deactivated:
35+
```bash
36+
conda deactivate
37+
```
38+
39+
If you want to access this environment from jupyter you can do the followings:
40+
```bash
41+
conda install -c anaconda ipykernel
42+
43+
python -m ipykernel install --user --name=polyfit
44+
```
45+
46+
Then after restarting your jupyter you'll be able to select this kernel.
47+
48+
## Example interactive usage
49+
50+
To create your own photomery, you'll need a Target Pixel File, such as [this one.](https://github.com/zabop/autoeap/blob/master/examples/ktwo212466080-c17_lpd-targ.fits)
51+
Then, after starting Python, you can do:
52+
```python
53+
from polyfitter import Polyfitter
54+
55+
import numpy as np
56+
57+
# Parameters from OGLE database
58+
ID = 'OGLE-BLG-ECL-040474'
59+
P=1.8995918
60+
t0=7000.90650
61+
62+
# Load light curve from OGLE database
63+
# This is in magnitude scale
64+
path_to_ogle = 'http://ogledb.astrouw.edu.pl/~ogle/OCVS/data/I/'+ID[-2:]+'/'+ID+'.dat'
65+
lc = np.loadtxt(path_to_ogle).T
66+
67+
# For clarity
68+
time = lc[0]
69+
mag = lc[1]
70+
err = lc[2]
71+
72+
# Create Polyfitter instance by setting the brightness scale of your data
73+
# Set "mag" or "flux" scale
74+
pf = Polyfitter(scale='mag')
75+
76+
# Run polynomial chain fitting
77+
t0new, phase, polyfit, messages = pf.get_polyfit(time,mag,err,P,t0)
78+
```
79+
80+
Plotting our results gives:
81+
```python
82+
import matplotlib.pyplot as plt
83+
84+
plt.errorbar((time-t0new)/P%1,mag,err,fmt='k.')
85+
plt.errorbar((time-t0new)/P%1-1,mag,err,fmt='k.')
86+
plt.plot(phase,polyfit,c='r',zorder=10)
87+
plt.plot(phase+1,polyfit,c='r',zorder=10)
88+
plt.xlabel('Phase')
89+
plt.ylabel('Magnitude')
90+
plt.xlim(-0.5,1)
91+
plt.gca().invert_yaxis()
92+
plt.show()
93+
```
94+
![example fit](https://raw.githubusercontent.com/astrobatty/polyfitter/master/docs/OGLE-BLG-ECL-040474.jpg)
95+
96+
And the morphology classification:
97+
```python
98+
morp_array = pf.c
99+
print('Morphology type =' , morp_array[0] )
100+
```
101+
102+
You can find a Google Colab friendly tutorial [in the examples](https://github.com/astrobatty/polyfitter/tree/master/examples/run_polyfit.ipynb).
103+
104+
## Running as python script
105+
106+
The difference from using the code interactively is that you have to put your code under a main function. See [here](https://github.com/astrobatty/polyfitter/tree/master/examples/run_polyfit_as_script.py) how to do it.
107+
108+
## Available options
109+
- Polyfitter class instance:
110+
- `scale` The scale of the input data that will be used with this instance. Must be "mag" or "flux".
111+
- `debug` If `True` each fit will be displayed with auxiliary messages.
112+
113+
- Getting polyfit:
114+
- `verbose` If `0` the fits will be done silently. Default is `1`.
115+
- `vertices` Number of equidistant vertices in the computed fit. Default is `1000`, which is mandatory to run the classification afterwards.
116+
- `maxiters` Maximum number of iterations. Default is `4000`.
117+
- `timeout` The time in seconds after a fit will be terminated. Default is `100`.
118+
119+
## Contributing
120+
Feel free to open PR / Issue.
121+
122+
## Citing
123+
If you find this code useful, please cite [X](https://ui.adsabs.harvard.edu/abs/maybeoneday), and [Prša et al.,2008,ApJ,687,542](https://ui.adsabs.harvard.edu/abs/2008ApJ...687..542P/abstract). Here are the BibTeX sources:
124+
```
125+
@ARTICLE{2008ApJ...687..542P,
126+
author = {{Pr{\v{s}}a}, A. and {Guinan}, E.~F. and {Devinney}, E.~J. and {DeGeorge}, M. and {Bradstreet}, D.~H. and {Giammarco}, J.~M. and {Alcock}, C.~R. and {Engle}, S.~G.},
127+
title = "{Artificial Intelligence Approach to the Determination of Physical Properties of Eclipsing Binaries. I. The EBAI Project}",
128+
journal = {\apj},
129+
keywords = {methods: data analysis, methods: numerical, binaries: eclipsing, stars: fundamental parameters, Astrophysics},
130+
year = 2008,
131+
month = nov,
132+
volume = {687},
133+
number = {1},
134+
pages = {542-565},
135+
doi = {10.1086/591783},
136+
archivePrefix = {arXiv},
137+
eprint = {0807.1724},
138+
primaryClass = {astro-ph},
139+
adsurl = {https://ui.adsabs.harvard.edu/abs/2008ApJ...687..542P},
140+
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
141+
}
142+
```
143+
144+
## Acknowledgements
145+
This project was made possible by the funding provided by the Lendület Program of the Hungarian Academy of Sciences, project No. LP2018-7.

docs/OGLE-BLG-ECL-040474.jpg

49.6 KB
Loading

0 commit comments

Comments
 (0)