Add date of estimation
Browse files
app.py
CHANGED
|
@@ -39,10 +39,12 @@ def run_all(latitude: float, longitude: float):
|
|
| 39 |
if err is not None or data is None:
|
| 40 |
return ("n/a", "n/a", "n/a")
|
| 41 |
cloud_cov = data["cloud"]
|
|
|
|
| 42 |
X = data["X"]
|
| 43 |
agb = predict_agbd(X)
|
| 44 |
carbon = carbon_from_agbd(agb)
|
| 45 |
-
return (f"{
|
|
|
|
| 46 |
f"{agb:.2f} t/ha",
|
| 47 |
f"{carbon:.2f} tC/ha")
|
| 48 |
except Exception as e:
|
|
@@ -60,17 +62,18 @@ with gr.Blocks(theme=gr.themes.Ocean(), fill_height=True) as demo:
|
|
| 60 |
clear = gr.Button("Clear")
|
| 61 |
submit = gr.Button("Submit", variant="primary")
|
| 62 |
with gr.Column(scale=1):
|
|
|
|
| 63 |
cloud = gr.Textbox(label="Cloud coverage")
|
| 64 |
agbd = gr.Textbox(label="Above ground biomass density (AGBD) t/ha")
|
| 65 |
cstock = gr.Textbox(label="Carbon stock density tC/ha")
|
| 66 |
|
| 67 |
def _on_submit(la, lo):
|
| 68 |
return run_all(la, lo)
|
| 69 |
-
submit.click(_on_submit, [lat, lon], [cloud, agbd, cstock]) # pylint: disable=no-member
|
| 70 |
|
| 71 |
def _on_clear():
|
| 72 |
return None, None, None, None, None
|
| 73 |
-
clear.click(_on_clear, outputs=[lat, lon, cloud, agbd, cstock]) # pylint: disable=no-member
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
demo.launch(share=True)
|
|
|
|
| 39 |
if err is not None or data is None:
|
| 40 |
return ("n/a", "n/a", "n/a")
|
| 41 |
cloud_cov = data["cloud"]
|
| 42 |
+
estimation_date = data["estimation_date"]
|
| 43 |
X = data["X"]
|
| 44 |
agb = predict_agbd(X)
|
| 45 |
carbon = carbon_from_agbd(agb)
|
| 46 |
+
return (f"{estimation_date}",
|
| 47 |
+
f"{cloud_cov:.2f} %",
|
| 48 |
f"{agb:.2f} t/ha",
|
| 49 |
f"{carbon:.2f} tC/ha")
|
| 50 |
except Exception as e:
|
|
|
|
| 62 |
clear = gr.Button("Clear")
|
| 63 |
submit = gr.Button("Submit", variant="primary")
|
| 64 |
with gr.Column(scale=1):
|
| 65 |
+
est_date = gr.Textbox(label="Date of estimation")
|
| 66 |
cloud = gr.Textbox(label="Cloud coverage")
|
| 67 |
agbd = gr.Textbox(label="Above ground biomass density (AGBD) t/ha")
|
| 68 |
cstock = gr.Textbox(label="Carbon stock density tC/ha")
|
| 69 |
|
| 70 |
def _on_submit(la, lo):
|
| 71 |
return run_all(la, lo)
|
| 72 |
+
submit.click(_on_submit, [lat, lon], [est_date, cloud, agbd, cstock]) # pylint: disable=no-member
|
| 73 |
|
| 74 |
def _on_clear():
|
| 75 |
return None, None, None, None, None
|
| 76 |
+
clear.click(_on_clear, outputs=[lat, lon, est_date, cloud, agbd, cstock]) # pylint: disable=no-member
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
demo.launch(share=True)
|
utils.py
CHANGED
|
@@ -136,8 +136,8 @@ def extract_from_gee(lat: float, lon: float, radius_m: int = 30):
|
|
| 136 |
return None, {"error": "No Sentinel-2 image available on ROI/time window."}
|
| 137 |
|
| 138 |
cloud_cover = ee.Number(img_s2.get("CLOUDY_PIXEL_PERCENTAGE")).getInfo()
|
| 139 |
-
|
| 140 |
-
|
| 141 |
|
| 142 |
s1 = (S1.filterBounds(roi)
|
| 143 |
.filterDate(start, end)
|
|
@@ -148,6 +148,13 @@ def extract_from_gee(lat: float, lon: float, radius_m: int = 30):
|
|
| 148 |
.select(s1_bands))
|
| 149 |
|
| 150 |
img_s1 = s1.sort(TIME_KEY, False).first()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
# DEM
|
| 153 |
s1_proj = img_s1.projection()
|
|
@@ -186,6 +193,6 @@ def extract_from_gee(lat: float, lon: float, radius_m: int = 30):
|
|
| 186 |
return {
|
| 187 |
"X": data,
|
| 188 |
"cloud": float(cloud_cover),
|
| 189 |
-
"
|
| 190 |
"ndvi_mean": ndvi_mean
|
| 191 |
}, None
|
|
|
|
| 136 |
return None, {"error": "No Sentinel-2 image available on ROI/time window."}
|
| 137 |
|
| 138 |
cloud_cover = ee.Number(img_s2.get("CLOUDY_PIXEL_PERCENTAGE")).getInfo()
|
| 139 |
+
acq_iso_s2 = ee.Date(img_s2.get(TIME_KEY)).format().getInfo()
|
| 140 |
+
days_s2 = days_since_utc(acq_iso_s2)
|
| 141 |
|
| 142 |
s1 = (S1.filterBounds(roi)
|
| 143 |
.filterDate(start, end)
|
|
|
|
| 148 |
.select(s1_bands))
|
| 149 |
|
| 150 |
img_s1 = s1.sort(TIME_KEY, False).first()
|
| 151 |
+
acq_iso_s1 = ee.Date(img_s1.get(TIME_KEY)).format().getInfo()
|
| 152 |
+
days_s1 = days_since_utc(acq_iso_s1)
|
| 153 |
+
|
| 154 |
+
if days_s1 > days_s2:
|
| 155 |
+
estimation_date = acq_iso_s2
|
| 156 |
+
else:
|
| 157 |
+
estimation_date = acq_iso_s1
|
| 158 |
|
| 159 |
# DEM
|
| 160 |
s1_proj = img_s1.projection()
|
|
|
|
| 193 |
return {
|
| 194 |
"X": data,
|
| 195 |
"cloud": float(cloud_cover),
|
| 196 |
+
"estimation_date": estimation_date.split("T")[0],
|
| 197 |
"ndvi_mean": ndvi_mean
|
| 198 |
}, None
|