Spaces:
Build error
Build error
pgzmnk
commited on
Commit
•
49af784
1
Parent(s):
7732544
Cleanup comments. Remove roi. wip
Browse files- app.py +1 -16
- utils/indicators.py +11 -9
app.py
CHANGED
@@ -2,24 +2,10 @@ import gradio as gr
|
|
2 |
|
3 |
from utils import duckdb_queries as dq
|
4 |
from utils.gradio import get_window_url_params
|
5 |
-
from utils.indicators import
|
6 |
|
7 |
-
# Define constants
|
8 |
-
LOCATION = [-74.653370, 5.845328]
|
9 |
-
ROI_RADIUS = 20000
|
10 |
-
INDICES_FILE = "indices.yaml"
|
11 |
-
|
12 |
-
|
13 |
-
# Instantiate outside gradio app to avoid re-initializing GEE, which is slow
|
14 |
-
indexgenerator = IndexGenerator(
|
15 |
-
centroid=LOCATION,
|
16 |
-
roi_radius=ROI_RADIUS,
|
17 |
-
indices_file=INDICES_FILE,
|
18 |
-
)
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
-
print("start gradio app")
|
22 |
-
|
23 |
with gr.Column():
|
24 |
m1 = gr.Plot()
|
25 |
with gr.Row():
|
@@ -49,7 +35,6 @@ with gr.Blocks() as demo:
|
|
49 |
def update_project_dropdown_list(url_params):
|
50 |
username = url_params.get("username", "default")
|
51 |
projects = dq.list_projects_by_author(author_id=username)
|
52 |
-
# to-do: filter projects based on user
|
53 |
return gr.Dropdown.update(choices=projects["name"].tolist())
|
54 |
|
55 |
# Get url params
|
|
|
2 |
|
3 |
from utils import duckdb_queries as dq
|
4 |
from utils.gradio import get_window_url_params
|
5 |
+
from utils.indicators import indexgenerator
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
with gr.Blocks() as demo:
|
|
|
|
|
9 |
with gr.Column():
|
10 |
m1 = gr.Plot()
|
11 |
with gr.Row():
|
|
|
35 |
def update_project_dropdown_list(url_params):
|
36 |
username = url_params.get("username", "default")
|
37 |
projects = dq.list_projects_by_author(author_id=username)
|
|
|
38 |
return gr.Dropdown.update(choices=projects["name"].tolist())
|
39 |
|
40 |
# Get url params
|
utils/indicators.py
CHANGED
@@ -13,9 +13,9 @@ from utils import duckdb_queries as dq
|
|
13 |
|
14 |
from . import logging
|
15 |
|
16 |
-
GEE_SERVICE_ACCOUNT =
|
17 |
-
|
18 |
-
|
19 |
|
20 |
|
21 |
class IndexGenerator:
|
@@ -32,8 +32,6 @@ class IndexGenerator:
|
|
32 |
|
33 |
def __init__(
|
34 |
self,
|
35 |
-
centroid,
|
36 |
-
roi_radius,
|
37 |
indices_file,
|
38 |
map=None,
|
39 |
):
|
@@ -42,9 +40,6 @@ class IndexGenerator:
|
|
42 |
|
43 |
# Set instance variables
|
44 |
self.indices = self._load_indices(indices_file)
|
45 |
-
self.centroid = centroid
|
46 |
-
self.roi = ee.Geometry.Point(*centroid).buffer(roi_radius)
|
47 |
-
# self.project_name = project_name
|
48 |
self.map = map
|
49 |
if self.map is not None:
|
50 |
self.show = True
|
@@ -158,7 +153,7 @@ class IndexGenerator:
|
|
158 |
data = {
|
159 |
"metric": indices,
|
160 |
"year": year,
|
161 |
-
"centroid": str(self.centroid),
|
162 |
"project_name": self.project_name,
|
163 |
"value": list(map(self.zonal_mean_index, indices, repeat(year))),
|
164 |
"area": self.roi.area().getInfo(), # m^2
|
@@ -297,3 +292,10 @@ class IndexGenerator:
|
|
297 |
logging.info("upserted records into motherduck")
|
298 |
scores = dq.get_project_scores(project_name, start_year, end_year)
|
299 |
return scores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
from . import logging
|
15 |
|
16 |
+
GEE_SERVICE_ACCOUNT = "climatebase-july-2023@ee-geospatialml-aquarry.iam.gserviceaccount.com"
|
17 |
+
ROI_RADIUS = 20000
|
18 |
+
INDICES_FILE = "indices.yaml"
|
19 |
|
20 |
|
21 |
class IndexGenerator:
|
|
|
32 |
|
33 |
def __init__(
|
34 |
self,
|
|
|
|
|
35 |
indices_file,
|
36 |
map=None,
|
37 |
):
|
|
|
40 |
|
41 |
# Set instance variables
|
42 |
self.indices = self._load_indices(indices_file)
|
|
|
|
|
|
|
43 |
self.map = map
|
44 |
if self.map is not None:
|
45 |
self.show = True
|
|
|
153 |
data = {
|
154 |
"metric": indices,
|
155 |
"year": year,
|
156 |
+
"centroid": str(self.centroid), # to-do: self.roi.centroid().getInfo()
|
157 |
"project_name": self.project_name,
|
158 |
"value": list(map(self.zonal_mean_index, indices, repeat(year))),
|
159 |
"area": self.roi.area().getInfo(), # m^2
|
|
|
292 |
logging.info("upserted records into motherduck")
|
293 |
scores = dq.get_project_scores(project_name, start_year, end_year)
|
294 |
return scores
|
295 |
+
|
296 |
+
|
297 |
+
# Instantiate outside gradio app to avoid re-initializing GEE, which is slow
|
298 |
+
indexgenerator = IndexGenerator(
|
299 |
+
roi_radius=ROI_RADIUS,
|
300 |
+
indices_file=INDICES_FILE,
|
301 |
+
)
|