pgzmnk commited on
Commit
fe79a15
1 Parent(s): a805f1e

Debug bioindicator table generation.

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. utils/indicators.py +12 -6
app.py CHANGED
@@ -5,7 +5,7 @@ from utils.gradio import get_window_url_params
5
  from utils.indicators import IndexGenerator
6
 
7
  # Instantiate outside gradio app to avoid re-initializing GEE, which is slow
8
- indexgenerator = IndexGenerator(indices=["NDWI", "Water", "Protected", "Air"])
9
 
10
  with gr.Blocks() as demo:
11
  with gr.Column():
 
5
  from utils.indicators import IndexGenerator
6
 
7
  # Instantiate outside gradio app to avoid re-initializing GEE, which is slow
8
+ indexgenerator = IndexGenerator(indices=["NDWI", "Water", "Protected", "Habitat"])
9
 
10
  with gr.Blocks() as demo:
11
  with gr.Column():
utils/indicators.py CHANGED
@@ -126,16 +126,22 @@ class IndexGenerator:
126
  def zonal_mean_index(self, index_key, year):
127
  index_config = self.indices[index_key]
128
  dataset = self.generate_index(index_config, year)
129
- # zm = self._zonal_mean(single, index_config.get('bandname') or 'constant')
 
130
  out = dataset.reduceRegion(
131
  **{
132
  "reducer": ee.Reducer.mean(),
133
  "geometry": self.roi,
134
- "scale": 200, # map scale
 
 
135
  }
136
  ).getInfo()
 
137
  if index_config.get("bandname"):
138
  return out[index_config.get("bandname")]
 
 
139
  return out
140
 
141
  def generate_composite_index_df(self, year, project_geometry, indices=[]):
@@ -145,7 +151,8 @@ class IndexGenerator:
145
  "centroid": "",
146
  "project_name": "",
147
  "value": list(map(self.zonal_mean_index, indices, repeat(year))),
148
- "area": self.roi.area().getInfo(), # m^2 to-do: calculate with duckdb
 
149
  "geojson": "",
150
  # to-do: coefficient
151
  }
@@ -189,10 +196,9 @@ class IndexGenerator:
189
 
190
  # Concatenate all dataframes
191
  df_concat = pd.concat(dfs)
192
- df_concat["centroid"] = project_centroid
193
  df_concat["project_name"] = project_name
194
- df_concat["geojson"] = project_geometry
195
- breakpoint()
196
  return df_concat
197
 
198
  # h/t: https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/12
 
126
  def zonal_mean_index(self, index_key, year):
127
  index_config = self.indices[index_key]
128
  dataset = self.generate_index(index_config, year)
129
+
130
+ logging.info(f"Calculating zonal mean for {index_key}...")
131
  out = dataset.reduceRegion(
132
  **{
133
  "reducer": ee.Reducer.mean(),
134
  "geometry": self.roi,
135
+ "scale": 2000, # map scale
136
+ "bestEffort": True,
137
+ "maxPixels": 1e3,
138
  }
139
  ).getInfo()
140
+
141
  if index_config.get("bandname"):
142
  return out[index_config.get("bandname")]
143
+
144
+ logging.info(f"Calculated zonal mean for {index_key}.")
145
  return out
146
 
147
  def generate_composite_index_df(self, year, project_geometry, indices=[]):
 
151
  "centroid": "",
152
  "project_name": "",
153
  "value": list(map(self.zonal_mean_index, indices, repeat(year))),
154
+ # to-do: calculate with duckdb; also, should be part of project table instead
155
+ "area": self.roi.area().getInfo(), # m^2
156
  "geojson": "",
157
  # to-do: coefficient
158
  }
 
196
 
197
  # Concatenate all dataframes
198
  df_concat = pd.concat(dfs)
199
+ df_concat["centroid"] = str(project_centroid)
200
  df_concat["project_name"] = project_name
201
+ df_concat["geojson"] = str(project_geometry)
 
202
  return df_concat
203
 
204
  # h/t: https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/12