Skip to content

Commit

Permalink
📊📨 -> Add api route for classifier using Cuttle in #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Oct 14, 2022
1 parent 2696cc4 commit 28d0994
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 658 deletions.
25 changes: 25 additions & 0 deletions Ansible/Generator/Detection/TransitTimeVariation.ipynb
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
}
805 changes: 152 additions & 653 deletions Ansible/Generator/Identifier.ipynb

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions Ansible/Generator/Star Generation/StellarVariability.ipynb
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
}
31 changes: 31 additions & 0 deletions Ansible/docs/API/cuttle-process.md
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
6 changes: 6 additions & 0 deletions server/api/Views/TIC.py
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
5 changes: 5 additions & 0 deletions server/api/main.py
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)
10 changes: 5 additions & 5 deletions server/notebook/data/PlanetStats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@
}
],
"source": [
"%matplotlib notebook\n",
"%matplotlib inline\n",
"\n",
"import sys\n",
"!{sys.executable} -m pip install numpy\n",
"!{sys.executable} -m pip install lightkurve\n",
"!{sys.executable} -m pip install matplotlib\n",
"!{sys.executable} -m pip install astropy\n",
"#!{sys.executable} -m pip install numpy\n",
"#!{sys.executable} -m pip install lightkurve\n",
"#!{sys.executable} -m pip install matplotlib\n",
"#!{sys.executable} -m pip install astropy\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import lightkurve as lk\n",
Expand Down
9 changes: 9 additions & 0 deletions server/notebook/data/cuttle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"environments": {
"sailor-api": {
"platform": "linux",
"transformer": "flask"
}
},
"notebook": "PlanetStats.ipynb"
}
25 changes: 25 additions & 0 deletions server/notebook/data/mnist.ipynb
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
}
75 changes: 75 additions & 0 deletions server/notebook/data/output/sailor-api/main.py
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()

0 comments on commit 28d0994

Please sign in to comment.