-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
81 lines (60 loc) · 2.32 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import Flask, render_template, flash, redirect, session, url_for, request, g, Markup, jsonify, abort
import requests
import imageio
import torch
import time
import matplotlib.pyplot as plt
from core import Product
app = Flask(__name__)
# name = "AVHRR_OI_L4_GHRSST_NCEI"
name = "20190914_GHRSST"
product = Product(name, device="cuda", offset=-273.15) # 298.15
breakpoint()
@app.route("/wmts")
def wmts():
args = request.args
tilecol = int(args["TileCol"])
tilerow = int(args["TileRow"])
tilematrix = int(args['TileMatrix'])
with torch.no_grad():
# s = time.time()
config = {key : args[key] for key in ["device", "min_value", "max_value", "use_cache", 'cmap', 'device', 'filter', 'scale'] if key in args}
# config["cmap"] = "VIIRS_SNPP_Brightness_Temp_BandI5_Day"
# config["method"] = "avg"
# config["filter"] = "sobel"
tile = product.gettile(tilecol, tilerow, tilematrix, config = config)
# e = time.time()
# print("Retrieving tilecol {} tilerow {} tilematrix {} took {} seconds".format(tilecol, tilerow, tilematrix, e - s))
if tile is None:
abort(404)
tile = imageio.imwrite(imageio.RETURN_BYTES, tile, format="png")
return tile, 200, {'Content-Type' : 'image/png'}
@app.route("/getstats")
def stats():
args = request.args
bbox = [float(x) for x in args["bbox"].split(",")]
with torch.no_grad():
stats = product.getstats(*bbox)
return jsonify(stats), 200, {'Content-Type' : 'json'}
@app.route("/clearcache")
def clearcache():
product.cache.clear()
product.random = None
return "cache cleared", 200
if __name__ == "__main__":
while True:
print("enter tilecolumn: ", end="")
tilecol = int(input())
print("enter tilerow: ", end="")
tilerow = int(input())
print("enter tilematrix: ", end="")
tilematrix = int(input())
s = time.time()
tile = product.gettile(tilecol, tilerow, tilematrix, {"method" : "avg", "device" : "cuda"})
e = time.time()
print("Retrieving tilecol {} tilerow {} tilematrix {} took {} seconds".format(tilecol, tilerow, tilematrix, e - s))
# imageio.imwrite("exampledown.png", tile)
if tile is not None:
plt.imshow(tile)
plt.show()
del tile