-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📊📨 -> Add api route for classifier using Cuttle in #1
- Loading branch information
1 parent
2696cc4
commit 28d0994
Showing
10 changed files
with
363 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def odd_even_phase(lc, period, t0, plot_size = False, same_axes = False, binning = False):\n", | ||
" lc = lc.normalise()\n", | ||
"\n", | ||
" if binning != False:\n", | ||
" lc = lc.bin(binning/60/24)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.10.4 64-bit", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python", | ||
"version": "3.10.4" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Import data | ||
Split data into training and testing set | ||
Train model on training set | ||
Evaluate model on testing set | ||
|
||
|
||
Hide data from cuttle: | ||
```py | ||
#cuttle-environment-disable sailor-api | ||
``` | ||
|
||
API Route config: | ||
```py | ||
#cuttle-environment-set-config sailor-api route=/api/predict method=POST | ||
# (Flask Transformer) | ||
|
||
file = open("./images/mnist3.png", "rb") #cuttle-environment-get-config sailor-apiu request.files['files'] | ||
|
||
# Return variable as api response | ||
c = str(digit) # cuttle-environment-set-config sailor-api response | ||
``` | ||
|
||
Transform notebook: | ||
```bash | ||
cuttle transform sailor-api | ||
``` | ||
Note: make sure to comment out `%matplotlib inline` / `matplotlib notebook` | ||
|
||
# Flask configuration | ||
Users will import TIC data into flask using the POST method | ||
This will then be processed by the notebook function and passed into the other blueprints inside Flask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask import Flask, request, Blueprint | ||
|
||
TIC_Page = Blueprint('TIC_Page', __name__, template_folder='templates') | ||
@TIC_Page.route('/tic_planet') | ||
def show(page): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Flask, request, Blueprint, render_template | ||
#from .TIC_Page import TIC_page | ||
|
||
app = Flask(__name__) | ||
app.register_blueprint(TIC_Page) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"environments": { | ||
"sailor-api": { | ||
"platform": "linux", | ||
"transformer": "flask" | ||
} | ||
}, | ||
"notebook": "PlanetStats.ipynb" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import tensorflow as tf\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"import cv2\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
from flask import Flask | ||
from flask import request | ||
app = Flask(__name__) | ||
|
||
#%matplotlib inline | ||
|
||
import sys | ||
#!{sys.executable} -m pip install numpy | ||
#!{sys.executable} -m pip install lightkurve | ||
#!{sys.executable} -m pip install matplotlib | ||
#!{sys.executable} -m pip install astropy | ||
|
||
import matplotlib.pyplot as plt | ||
import lightkurve as lk | ||
import astropy | ||
import numpy as np | ||
|
||
TIC = 'TIC 284475976' # TIC Star ID | ||
sector_data = lk.search_lightcurve(TIC, author = 'SPOC', sector = 23) # can remove each arg if needed | ||
sector_data | ||
|
||
lc = sector_data.download_all() | ||
lc.plot() | ||
|
||
lc = sector_data.download_all() | ||
lc.plot() | ||
sector_data = lk.search_lightcurve(TIC, author = 'SPOC', sector=23) | ||
sector_data | ||
lc = sector_data.download_all() | ||
lc.plot(linewidth = 0, marker = '.') | ||
lc.plot(linewidth = 0, marker = '.', color = 'lightcyan', alpha = 0.3) | ||
|
||
TIC_2 = 'TIC 55525572' | ||
available_data_all = lk.search_lightcurve(TIC_2, author = 'SPOC') | ||
available_data_all | ||
|
||
select_sector = available_data_all[0:4] | ||
select_sector | ||
|
||
lc_collection = select_sector.download_all() # download all the sectors ([0:4]) | ||
lc_collection | ||
|
||
lc_collection.plot(linewidth = 0, marker = '.') | ||
|
||
lc_collection_stitched = lc_collection.stitch() | ||
lc_collection_stitched.plot(linewidth = 0, marker = '.', color = 'red') | ||
lc.normalise().plot() | ||
|
||
bin_time = 15/24/60 # LK uses day units, this is 15 minutes over 24 hours | ||
lc_collection_binned = lc_collection.bin(bin_time) | ||
lc_collection_binned.plot() | ||
|
||
available_data_select = lk.search_lightcurve(TIC, author = 'SPOC')[0:9] # Query data, select data from mutliple sectors (e.g. all availablke first year TESS data) | ||
lc_collection = available_data_select.download_all().stitch() | ||
fig, ax = plt.subplots(figsize = (8,4)) | ||
lc_collection.plot(ax = ax, linewidth = 0, marker = 'o', color = 'purple', markersize = 1, alpha = 0.7) | ||
|
||
period = 83.8979 | ||
t0 = 2125.847 | ||
|
||
lc_phased = lc_collection.fold(period = period, epoch_time = t0) | ||
lc_phased.plot(linewidth = 0, color = 'gold', marker = '.', markersize = 1, alpha = 0.7) | ||
|
||
lc_phased_binned = lc_phased.bin(15/24/60) | ||
fig, ax = plt.subplots(figsize = (8,5)) # defines a plotting region to plot multiple data sets | ||
lc_phased.plot(ax = ax, marker = '.', linewidth = 0, color = 'blue', alpha = 0.4, markersize = 3, label = 'unbinned') | ||
lc_phased_binned.plot(ax = ax, marker = 'o', linewidth = 0, color = 'purple', alpha = 0.8, markersize = 6, label = 'binned') | ||
|
||
plt.xlim(-2, 2) # upper and lower limit for x-axis, zooming in from -40, 40 wide to -2, 2 wide | ||
plt.ylim(0.996, 1.004) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run() |