update: fix rotation
This commit is contained in:
parent
e1b44ed2f9
commit
9a4efca7c2
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,4 +4,7 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
result
|
result
|
||||||
staged
|
staged
|
||||||
res.md
|
res.md
|
||||||
|
dist
|
||||||
|
*.spec
|
||||||
|
build
|
||||||
@ -1,11 +1,15 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from flask_cors import CORS
|
||||||
import src
|
import src
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
CORS(app)
|
||||||
|
|
||||||
app.register_blueprint(src.tc_module, url_prefix='/tc')
|
app.register_blueprint(src.tc_module, url_prefix='/tc')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=35000)
|
# get port from env 'VERTEX_PORT'
|
||||||
|
port = os.getenv('VERTEX_PORT', 35000)
|
||||||
|
app.run(debug=True, host='0.0.0.0', port=port)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ def render():
|
|||||||
data_this_day = data["data"][:, :, int(day)]
|
data_this_day = data["data"][:, :, int(day)]
|
||||||
|
|
||||||
map = create_heatmap(data_this_day, shift=(
|
map = create_heatmap(data_this_day, shift=(
|
||||||
0, 180), colormap='hot', rotate_90=1)
|
0, -180), colormap='hot', rotate_90=3)
|
||||||
|
|
||||||
buff = BytesIO()
|
buff = BytesIO()
|
||||||
map.save(buff, format="PNG")
|
map.save(buff, format="PNG")
|
||||||
|
|||||||
13
src/plot.py
13
src/plot.py
@ -80,12 +80,21 @@ def create_heatmap(data,
|
|||||||
# 创建颜色映射
|
# 创建颜色映射
|
||||||
if colormap == 'hot':
|
if colormap == 'hot':
|
||||||
# 红色到黄色的渐变
|
# 红色到黄色的渐变
|
||||||
|
# 非线性变换,使得低值更容易区分。 使用 sqrt(x) 作为映射函数
|
||||||
def get_color(value):
|
def get_color(value):
|
||||||
|
# 首先把原value从0~0.1映射到0~1。如果value大于0.1,就直接取1
|
||||||
|
value = min(value / 0.4, 1)
|
||||||
if np.isnan(value):
|
if np.isnan(value):
|
||||||
return (0, 0, 0, 0)
|
return (0, 0, 0, 0)
|
||||||
r = int(min(255, value * 510))
|
r = int(min(255, np.sqrt(value) * 256))
|
||||||
g = int(max(0, min(255, value * 510 - 255)))
|
g = int(max(0, min(255, np.sqrt(value) * 256 - 256)))
|
||||||
return (r, g, 0, int(value * 255))
|
return (r, g, 0, int(value * 255))
|
||||||
|
# def get_color(value):
|
||||||
|
# if np.isnan(value):
|
||||||
|
# return (0, 0, 0, 0)
|
||||||
|
# r = int(min(255, value * 510))
|
||||||
|
# g = int(max(0, min(255, value * 510 - 255)))
|
||||||
|
# return (r, g, 0, int(value * 255))
|
||||||
|
|
||||||
# 填充像素
|
# 填充像素
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user