Spaces:
Build error
Build error
pgzmnk
commited on
Commit
·
206c195
1
Parent(s):
f2d3305
Introduce logging instead of print statements.
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import datetime
|
|
|
2 |
import os
|
3 |
|
4 |
import duckdb
|
@@ -8,6 +9,8 @@ import pandas as pd
|
|
8 |
import plotly.graph_objects as go
|
9 |
import yaml
|
10 |
|
|
|
|
|
11 |
|
12 |
# Define constants
|
13 |
DATE = "2020-01-01"
|
@@ -87,7 +90,7 @@ class IndexGenerator:
|
|
87 |
try:
|
88 |
return yaml.safe_load(stream)
|
89 |
except yaml.YAMLError as e:
|
90 |
-
|
91 |
return None
|
92 |
|
93 |
def show_map(self, map=None):
|
@@ -142,7 +145,7 @@ class IndexGenerator:
|
|
142 |
raise Exception("Failed to generate dataset.")
|
143 |
if self.show and index_config.get("show"):
|
144 |
map.addLayer(dataset, index_config["viz"], index_config["name"])
|
145 |
-
|
146 |
return dataset
|
147 |
|
148 |
def zonal_mean_index(self, index_key):
|
@@ -172,13 +175,13 @@ class IndexGenerator:
|
|
172 |
# to-do: coefficient
|
173 |
}
|
174 |
|
175 |
-
|
176 |
df = pd.DataFrame(data)
|
177 |
return df
|
178 |
|
179 |
|
180 |
def set_up_duckdb():
|
181 |
-
|
182 |
# use `climatebase` db
|
183 |
if not os.getenv("motherduck_token"):
|
184 |
raise Exception(
|
@@ -195,7 +198,7 @@ def set_up_duckdb():
|
|
195 |
|
196 |
|
197 |
def authenticate_gee(gee_service_account, gee_service_account_credentials_file):
|
198 |
-
|
199 |
# to-do: alert if dataset filter date nan
|
200 |
credentials = ee.ServiceAccountCredentials(
|
201 |
gee_service_account, gee_service_account_credentials_file
|
@@ -209,16 +212,16 @@ def load_indices(indices_file):
|
|
209 |
try:
|
210 |
return yaml.safe_load(stream)
|
211 |
except yaml.YAMLError as e:
|
212 |
-
|
213 |
return None
|
214 |
|
215 |
|
216 |
def create_dataframe(years, project_name):
|
217 |
dfs = []
|
218 |
-
|
219 |
indices = load_indices(INDICES_FILE)
|
220 |
for year in years:
|
221 |
-
|
222 |
ig = IndexGenerator(
|
223 |
centroid=LOCATION,
|
224 |
roi_radius=ROI_RADIUS,
|
@@ -295,7 +298,7 @@ def calculate_biodiversity_score(start_year, end_year, project_name):
|
|
295 |
|
296 |
|
297 |
def view_all():
|
298 |
-
|
299 |
return con.sql(f"SELECT * FROM bioindicator").df()
|
300 |
|
301 |
|
@@ -307,7 +310,7 @@ def push_to_md():
|
|
307 |
ON CONFLICT (year, project_name) DO UPDATE SET value = excluded.value;
|
308 |
"""
|
309 |
)
|
310 |
-
|
311 |
|
312 |
|
313 |
with gr.Blocks() as demo:
|
|
|
1 |
import datetime
|
2 |
+
import logging
|
3 |
import os
|
4 |
|
5 |
import duckdb
|
|
|
9 |
import plotly.graph_objects as go
|
10 |
import yaml
|
11 |
|
12 |
+
# Logging
|
13 |
+
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
|
14 |
|
15 |
# Define constants
|
16 |
DATE = "2020-01-01"
|
|
|
90 |
try:
|
91 |
return yaml.safe_load(stream)
|
92 |
except yaml.YAMLError as e:
|
93 |
+
logging.error(e)
|
94 |
return None
|
95 |
|
96 |
def show_map(self, map=None):
|
|
|
145 |
raise Exception("Failed to generate dataset.")
|
146 |
if self.show and index_config.get("show"):
|
147 |
map.addLayer(dataset, index_config["viz"], index_config["name"])
|
148 |
+
logging.info(f"Generated index: {index_config['name']}")
|
149 |
return dataset
|
150 |
|
151 |
def zonal_mean_index(self, index_key):
|
|
|
175 |
# to-do: coefficient
|
176 |
}
|
177 |
|
178 |
+
logging.info("data", data)
|
179 |
df = pd.DataFrame(data)
|
180 |
return df
|
181 |
|
182 |
|
183 |
def set_up_duckdb():
|
184 |
+
logging.info("set up duckdb")
|
185 |
# use `climatebase` db
|
186 |
if not os.getenv("motherduck_token"):
|
187 |
raise Exception(
|
|
|
198 |
|
199 |
|
200 |
def authenticate_gee(gee_service_account, gee_service_account_credentials_file):
|
201 |
+
logging.info("authenticate_gee")
|
202 |
# to-do: alert if dataset filter date nan
|
203 |
credentials = ee.ServiceAccountCredentials(
|
204 |
gee_service_account, gee_service_account_credentials_file
|
|
|
212 |
try:
|
213 |
return yaml.safe_load(stream)
|
214 |
except yaml.YAMLError as e:
|
215 |
+
logging.error(e)
|
216 |
return None
|
217 |
|
218 |
|
219 |
def create_dataframe(years, project_name):
|
220 |
dfs = []
|
221 |
+
logging.info(years)
|
222 |
indices = load_indices(INDICES_FILE)
|
223 |
for year in years:
|
224 |
+
logging.info(year)
|
225 |
ig = IndexGenerator(
|
226 |
centroid=LOCATION,
|
227 |
roi_radius=ROI_RADIUS,
|
|
|
298 |
|
299 |
|
300 |
def view_all():
|
301 |
+
logging.info("view_all")
|
302 |
return con.sql(f"SELECT * FROM bioindicator").df()
|
303 |
|
304 |
|
|
|
310 |
ON CONFLICT (year, project_name) DO UPDATE SET value = excluded.value;
|
311 |
"""
|
312 |
)
|
313 |
+
logging.info("upsert records into motherduck")
|
314 |
|
315 |
|
316 |
with gr.Blocks() as demo:
|