<jupyter_start><jupyter_text>If you are in Google Colab, first install GSL<jupyter_code>!wget ftp://ftp.gnu.org/gnu/gsl/gsl-2.6.tar.gz
!tar -xf gsl-2.6.tar.gz
!cd gsl-2.6/; ./configure --prefix=/usr --disable-static && make
!cd gsl-2.6/; sudo make install

import os
os.environ['LD_LIBRARY_PATH'] = '/usr/lib'<jupyter_output><empty_output><jupyter_text>Then the package<jupyter_code>!pip install scikit-learn==0.23.2
!git clone https://github.com/astrobatty/polyfitter.git; cd ./polyfitter; python setup.py install<jupyter_output><empty_output><jupyter_text>__After this step, you have restart the runtime.__  This example shows how to run Polyfitter interactively<jupyter_code>from polyfitter import Polyfitter

import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>Polynomial chain fit to OGLE-BLG-ECL-040474<jupyter_code># Parameters from OGLE database
ID = 'OGLE-BLG-ECL-040474'
P=1.8995918
t0=7000.90650

# Load light curve from OGLE database
# This is in magnitude scale
path_to_ogle = 'http://ogledb.astrouw.edu.pl/~ogle/OCVS/data/I/'+ID[-2:]+'/'+ID+'.dat'
lc = np.loadtxt(path_to_ogle).T

# For clarity
time = lc[0]
mag  = lc[1]
err  = lc[2]

# Create Polyfitter instance by setting the brightness scale of your data
# Set "mag" or "flux" scale
pf = Polyfitter(scale='mag')

# Run polynomial chain fitting
t0new, phase, polyfit, messages = pf.get_polyfit(time,mag,err,P,t0)

# Note: if you want to fit silently set verbosity (e.g. inside a for loop)
# t0new, phase, polyfit, messages = pf.get_polyfit(time,mag,err,P,t0,verbose=0)<jupyter_output>Fitting polyfits...
Comparing polyfit models...
Fitting polyfits...
Comparing polyfit models...
Fitting polyfits...
Comparing polyfit models...<jupyter_text>Plot phase curve and polyfit<jupyter_code>plt.errorbar((time-t0new)/P%1,mag,err,fmt='k.')
plt.errorbar((time-t0new)/P%1-1,mag,err,fmt='k.')
plt.plot(phase,polyfit,c='r',zorder=10)
plt.plot(phase+1,polyfit,c='r',zorder=10)
plt.xlabel('Phase')
plt.ylabel('Magnitude')
plt.xlim(-0.5,1)
plt.gca().invert_yaxis()
plt.show()<jupyter_output><empty_output><jupyter_text>Get morphology classification<jupyter_code>morp_array = pf.c
print('Morphology type =' , morp_array[0] )<jupyter_output>Morphology type = 0.4207379453872869<jupyter_text>Check original and new epochs<jupyter_code>print('Original epoch: {} -> new epoch: {}'.format(t0,t0new) )<jupyter_output>Original epoch: 7000.9065 -> new epoch: 7000.9065<jupyter_text>Messages that would be printed out by the original polyfit code are stored in a list<jupyter_code>messages<jupyter_output><empty_output><jupyter_text>Assuming that you have two (or more) polyfits generated earlierTo classify them the fits must have 1000 equidistant points.Then the fits can be converted to a numpy ndarray with shape of (n fits,1000):<jupyter_code>multiple_polyfits = np.vstack((polyfit,polyfit))

multiple_polyfits.shape<jupyter_output><empty_output><jupyter_text>and the morphology classes will be returned as an array:<jupyter_code>pf.get_c( multiple_polyfits )<jupyter_output><empty_output><jupyter_text>Polynomial chain fit to KIC 10417986 from the Kepler catalog<jupyter_code># Load light curve
KIC = '10417986'
lc = np.loadtxt('http://keplerebs.villanova.edu/data/?k='+KIC+'.00&cadence=lc&data=data')

# Parameters from the Kepler catalog
P  = 0.0737309
t0 = 55000.027476

# To decrease running time
# only the first 2000 measurements are used
time = lc[:2000,0]
flux = lc[:2000,6]
err  = lc[:2000,3]

# Create Polyfitter instance by setting the brightness scale to flux!
pf = Polyfitter(scale='flux')

# Run polynomial chain fitting
# To prevent the fitter from timing out
# the maximum waiting time is set to 10,000 seconds
t0new, phase, polyfit, messages = pf.get_polyfit(time,flux,err,P,t0,timeout=10000)<jupyter_output>Fitting polyfits...
Comparing polyfit models...<jupyter_text>Plot phase curve and polyfit<jupyter_code>plt.errorbar((time-t0new)/P%1,flux,err,fmt='k.')
plt.errorbar((time-t0new)/P%1-1,flux,err,fmt='k.')
plt.plot(phase,polyfit,c='r',zorder=10)
plt.plot(phase+1,polyfit,c='r',zorder=10)
plt.xlabel('Phase')
plt.ylabel('Relative flux')
plt.xlim(-0.5,1)
plt.show()<jupyter_output><empty_output><jupyter_text>Get morphology classification<jupyter_code>morp_array = pf.c
print('Morphology type =' , morp_array[0] )<jupyter_output>Morphology type = 0.9786215313817448<jupyter_text>Check original and new epochs<jupyter_code>print('Original epoch: {} -> new epoch: {}'.format(t0,t0new) )<jupyter_output>Original epoch: 55000.027476 -> new epoch: 55000.027476<jupyter_text>Messages that would be printed out by the original polyfit code are stored in a list<jupyter_code>messages<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13173525668222316, 'fraction_numerical': 0.04921510394569368, 'mean_word_length': 6.617124394184168, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '610158', 'license': 'MIT', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1763, 'n_words': 389, 'path': 'examples/run_polyfit.ipynb', 'repo_name': 'astrobatty/polyfitter', 'size': '4714'}