2022-10-11 11:19:48 -07:00
|
|
|
from flask import Flask, render_template, request
|
2022-10-11 13:46:53 -07:00
|
|
|
import numpy as np
|
|
|
|
from ratio_pyrometry import ratio_pyrometry_pipeline
|
|
|
|
import base64
|
2022-10-11 16:03:00 -07:00
|
|
|
import cv2 as cv
|
2022-10-27 12:01:35 -07:00
|
|
|
import plotly.figure_factory as ff
|
|
|
|
from scipy import stats
|
2022-10-11 11:19:48 -07:00
|
|
|
|
2022-10-11 16:03:00 -07:00
|
|
|
app = Flask(
|
|
|
|
__name__,
|
2022-10-20 17:33:15 -07:00
|
|
|
static_folder='static',
|
2022-10-11 16:03:00 -07:00
|
|
|
static_url_path='/s/'
|
|
|
|
)
|
|
|
|
|
2022-10-11 11:19:48 -07:00
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def index():
|
2022-10-11 13:46:53 -07:00
|
|
|
return render_template('index.jinja2')
|
2022-10-11 11:19:48 -07:00
|
|
|
|
|
|
|
@app.route('/ratio_pyro', methods=['POST'])
|
|
|
|
def ratio_pyro():
|
|
|
|
f = request.files['file']
|
2022-10-11 13:46:53 -07:00
|
|
|
f_bytes = np.fromstring(f.read(), np.uint8)
|
2022-10-27 12:01:35 -07:00
|
|
|
img_orig, img_res, key, ptemps = ratio_pyrometry_pipeline(
|
2022-10-11 13:46:53 -07:00
|
|
|
f_bytes,
|
|
|
|
ISO=float(request.form['iso']),
|
|
|
|
I_Darkcurrent=float(request.form['i_darkcurrent']),
|
|
|
|
exposure_time=float(request.form['exposure_time']),
|
|
|
|
f_stop=float(request.form['f_stop']),
|
|
|
|
MAX_TEMP=float(request.form['max_temp']),
|
2022-10-12 17:37:31 -07:00
|
|
|
MIN_TEMP=float(request.form['min_temp']),
|
|
|
|
smoothing_radius=int(request.form['smoothing_radius']),
|
2022-10-20 17:33:15 -07:00
|
|
|
key_entries=int(request.form['legend_entries']),
|
|
|
|
eqn_scaling_factor=float(request.form['equation_scaling_factor'])
|
2022-10-11 13:46:53 -07:00
|
|
|
)
|
|
|
|
|
2022-10-27 12:01:35 -07:00
|
|
|
# get base64 encoded images
|
2022-10-12 12:27:52 -07:00
|
|
|
img_orig_b64 = base64.b64encode(cv.imencode('.png', img_orig)[1]).decode(encoding='utf-8')
|
|
|
|
img_res_b64 = base64.b64encode(cv.imencode('.png', img_res)[1]).decode(encoding='utf-8')
|
|
|
|
|
2022-10-27 12:01:35 -07:00
|
|
|
# generate prob. distribution histogram & return embed
|
|
|
|
fig = ff.create_distplot(
|
|
|
|
[ptemps],
|
2022-10-27 12:05:52 -07:00
|
|
|
group_labels=[f.filename],
|
2022-10-27 12:01:35 -07:00
|
|
|
show_rug=False,
|
|
|
|
show_hist=False,
|
|
|
|
)
|
|
|
|
fig.update_layout(
|
|
|
|
autosize=False,
|
|
|
|
width=800,
|
|
|
|
height=600,
|
|
|
|
)
|
|
|
|
fig.update_xaxes(
|
|
|
|
title_text="Temperature (°C)",
|
|
|
|
)
|
2022-10-27 12:05:52 -07:00
|
|
|
fig.update_yaxes(
|
2022-10-27 12:01:35 -07:00
|
|
|
title_text="Probability (1/°C)",
|
|
|
|
)
|
|
|
|
freq_plot = fig.to_html()
|
|
|
|
|
2022-10-11 13:46:53 -07:00
|
|
|
return render_template(
|
|
|
|
'results.jinja2',
|
2022-10-12 12:27:52 -07:00
|
|
|
img_orig_b64=img_orig_b64,
|
|
|
|
img_res_b64=img_res_b64,
|
2022-10-27 12:01:35 -07:00
|
|
|
legend=key,
|
|
|
|
freq_plot=freq_plot
|
2022-10-11 13:46:53 -07:00
|
|
|
)
|