Spaces:
Running
Running
update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import json
|
|
4 |
import ee
|
5 |
import os
|
6 |
import pandas as pd
|
|
|
7 |
import geopandas as gpd
|
8 |
from datetime import datetime
|
9 |
import leafmap.foliumap as leafmap
|
@@ -521,6 +522,46 @@ st.markdown("<hr><h5><b>Earth Engine Index Calculator</b></h5>", unsafe_allow_ht
|
|
521 |
if main_selection and sub_selection:
|
522 |
dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
|
523 |
st.write(f"Available Bands for {sub_options[sub_selection]}: {', '.join(dataset_bands)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
selected_bands = st.multiselect(
|
525 |
"Select 1 or 2 Bands for Calculation",
|
526 |
options=dataset_bands,
|
@@ -614,8 +655,16 @@ elif shape_type.lower() == "polygon":
|
|
614 |
help="Check to include pixels on the polygon boundary; uncheck to exclude them."
|
615 |
)
|
616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
st.markdown("<h5>Calculation Scale</h5>", unsafe_allow_html=True)
|
618 |
-
default_scale = ee.ImageCollection(dataset_id).first().select(0).projection().nominalScale().getInfo()
|
619 |
user_scale = st.number_input(
|
620 |
"Enter Calculation Scale (meters) [Leave blank to use dataset's default scale]",
|
621 |
min_value=1.0,
|
|
|
4 |
import ee
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
+
import numpy as np
|
8 |
import geopandas as gpd
|
9 |
from datetime import datetime
|
10 |
import leafmap.foliumap as leafmap
|
|
|
522 |
if main_selection and sub_selection:
|
523 |
dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
|
524 |
st.write(f"Available Bands for {sub_options[sub_selection]}: {', '.join(dataset_bands)}")
|
525 |
+
|
526 |
+
|
527 |
+
# Fetch nominal scales for all bands in the selected dataset
|
528 |
+
if dataset_id:
|
529 |
+
try:
|
530 |
+
# Fetch the first image from the collection to extract band information
|
531 |
+
collection = ee.ImageCollection(dataset_id)
|
532 |
+
first_image = collection.first()
|
533 |
+
band_names = first_image.bandNames().getInfo()
|
534 |
+
|
535 |
+
# Extract scales for all bands
|
536 |
+
band_scales = []
|
537 |
+
for band in band_names:
|
538 |
+
band_scale = first_image.select(band).projection().nominalScale().getInfo()
|
539 |
+
band_scales.append(band_scale)
|
540 |
+
|
541 |
+
# Identify unique scales using np.unique
|
542 |
+
unique_scales = np.unique(band_scales)
|
543 |
+
|
544 |
+
# Display the unique scales to the user
|
545 |
+
st.write(f"Nominal Scales for Bands: {band_scales}")
|
546 |
+
st.write(f"Unique Scales in Dataset: {unique_scales}")
|
547 |
+
|
548 |
+
# If there are multiple unique scales, allow the user to choose one
|
549 |
+
if len(unique_scales) > 1:
|
550 |
+
selected_scale = st.selectbox(
|
551 |
+
"Select a Scale for Calculation (meters)",
|
552 |
+
options=unique_scales,
|
553 |
+
index=0,
|
554 |
+
help="Choose a scale from the unique scales available in the dataset."
|
555 |
+
)
|
556 |
+
default_scale = selected_scale
|
557 |
+
else:
|
558 |
+
default_scale = unique_scales[0]
|
559 |
+
st.write(f"Default Scale for Dataset: {default_scale} meters")
|
560 |
+
|
561 |
+
except Exception as e:
|
562 |
+
st.error(f"Error fetching band scales: {str(e)}")
|
563 |
+
default_scale = 30 # Fallback to 30 meters if an error occurs
|
564 |
+
|
565 |
selected_bands = st.multiselect(
|
566 |
"Select 1 or 2 Bands for Calculation",
|
567 |
options=dataset_bands,
|
|
|
655 |
help="Check to include pixels on the polygon boundary; uncheck to exclude them."
|
656 |
)
|
657 |
|
658 |
+
# st.markdown("<h5>Calculation Scale</h5>", unsafe_allow_html=True)
|
659 |
+
# default_scale = ee.ImageCollection(dataset_id).first().select(0).projection().nominalScale().getInfo()
|
660 |
+
# user_scale = st.number_input(
|
661 |
+
# "Enter Calculation Scale (meters) [Leave blank to use dataset's default scale]",
|
662 |
+
# min_value=1.0,
|
663 |
+
# value=float(default_scale),
|
664 |
+
# help=f"Default scale for this dataset is {default_scale} meters. Adjust if needed."
|
665 |
+
# )
|
666 |
+
|
667 |
st.markdown("<h5>Calculation Scale</h5>", unsafe_allow_html=True)
|
|
|
668 |
user_scale = st.number_input(
|
669 |
"Enter Calculation Scale (meters) [Leave blank to use dataset's default scale]",
|
670 |
min_value=1.0,
|