Spaces:
Running
Running
update app.py
Browse files
app.py
CHANGED
@@ -55,23 +55,127 @@ with open(os.path.expanduser("~/.config/earthengine/credentials"), "w") as f:
|
|
55 |
f.write(earthengine_credentials)
|
56 |
|
57 |
ee.Initialize(project='ee-yashsacisro24')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Imagery base selection
|
59 |
-
imagery_base = st.selectbox("Select Imagery Base", ["Sentinel", "Landsat"], index=0)
|
60 |
|
61 |
# Load the appropriate dataset based on imagery base
|
62 |
if imagery_base == "Sentinel":
|
63 |
dataset_file = "sentinel_datasets.json"
|
64 |
-
|
|
|
|
|
65 |
dataset_file = "landsat_datasets.json"
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Display the title for the Streamlit app
|
71 |
st.title(f"{imagery_base} Dataset")
|
72 |
|
73 |
# Select dataset category (main selection)
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
# Initialize sub_selection and dataset_id as None
|
77 |
sub_selection = None
|
@@ -92,7 +196,7 @@ if main_selection:
|
|
92 |
st.header("Earth Engine Index Calculator")
|
93 |
|
94 |
# Load band information based on selected dataset
|
95 |
-
if main_selection and sub_selection:
|
96 |
dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
|
97 |
st.write(f"Available Bands for {sub_options[sub_selection]}: {', '.join(dataset_bands)}")
|
98 |
|
|
|
55 |
f.write(earthengine_credentials)
|
56 |
|
57 |
ee.Initialize(project='ee-yashsacisro24')
|
58 |
+
# # Imagery base selection
|
59 |
+
# imagery_base = st.selectbox("Select Imagery Base", ["Sentinel", "Landsat"], index=0)
|
60 |
+
|
61 |
+
# # Load the appropriate dataset based on imagery base
|
62 |
+
# if imagery_base == "Sentinel":
|
63 |
+
# dataset_file = "sentinel_datasets.json"
|
64 |
+
# else:
|
65 |
+
# dataset_file = "landsat_datasets.json"
|
66 |
+
|
67 |
+
# with open(dataset_file) as f:
|
68 |
+
# data = json.load(f)
|
69 |
+
|
70 |
+
# # Display the title for the Streamlit app
|
71 |
+
# st.title(f"{imagery_base} Dataset")
|
72 |
+
|
73 |
+
# # Select dataset category (main selection)
|
74 |
+
# main_selection = st.selectbox(f"Select {imagery_base} Dataset Category", list(data.keys()))
|
75 |
+
|
76 |
+
# # Initialize sub_selection and dataset_id as None
|
77 |
+
# sub_selection = None
|
78 |
+
# dataset_id = None
|
79 |
+
|
80 |
+
# # If a category is selected, display the sub-options (specific datasets)
|
81 |
+
# if main_selection:
|
82 |
+
# sub_options = data[main_selection]["sub_options"]
|
83 |
+
# sub_selection = st.selectbox(f"Select Specific {imagery_base} Dataset ID", list(sub_options.keys()))
|
84 |
+
|
85 |
+
# # Display the selected dataset ID based on user input
|
86 |
+
# if sub_selection:
|
87 |
+
# st.write(f"You selected: {main_selection} -> {sub_options[sub_selection]}")
|
88 |
+
# st.write(f"Dataset ID: {sub_selection}")
|
89 |
+
# dataset_id = sub_selection # Use the key directly as the dataset ID
|
90 |
+
|
91 |
+
# # Earth Engine Index Calculator Section
|
92 |
+
# st.header("Earth Engine Index Calculator")
|
93 |
+
|
94 |
+
# # Load band information based on selected dataset
|
95 |
+
# if main_selection and sub_selection: # Now safe because sub_selection is initialized
|
96 |
+
# dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
|
97 |
+
# st.write(f"Available Bands for {sub_options[sub_selection]}: {', '.join(dataset_bands)}")
|
98 |
+
|
99 |
+
# # Allow user to select 1 or 2 bands
|
100 |
+
# selected_bands = st.multiselect(
|
101 |
+
# "Select 1 or 2 Bands for Calculation",
|
102 |
+
# options=dataset_bands,
|
103 |
+
# default=[dataset_bands[0]] if dataset_bands else [],
|
104 |
+
# help=f"Select 1 or 2 bands from: {', '.join(dataset_bands)}"
|
105 |
+
# )
|
106 |
+
|
107 |
+
# # Ensure minimum 1 and maximum 2 bands are selected
|
108 |
+
# if len(selected_bands) < 1:
|
109 |
+
# st.warning("Please select at least one band.")
|
110 |
+
# st.stop()
|
111 |
+
# elif len(selected_bands) > 2:
|
112 |
+
# st.warning("You can select a maximum of 2 bands.")
|
113 |
+
# st.stop()
|
114 |
+
|
115 |
+
# # Show custom formula input if bands are selected
|
116 |
+
# if selected_bands:
|
117 |
+
# # Provide a default formula based on the number of selected bands
|
118 |
+
# if len(selected_bands) == 1:
|
119 |
+
# default_formula = f"{selected_bands[0]}"
|
120 |
+
# example = f"'{selected_bands[0]} * 2' or '{selected_bands[0]} + 1'"
|
121 |
+
# else: # len(selected_bands) == 2
|
122 |
+
# default_formula = f"({selected_bands[0]} - {selected_bands[1]}) / ({selected_bands[0]} + {selected_bands[1]})"
|
123 |
+
# example = f"'{selected_bands[0]} * {selected_bands[1]} / 2' or '({selected_bands[0]} - {selected_bands[1]}) / ({selected_bands[0]} + {selected_bands[1]})'"
|
124 |
+
|
125 |
+
# custom_formula = st.text_input(
|
126 |
+
# "Enter Custom Formula",
|
127 |
+
# value=default_formula,
|
128 |
+
# help=f"Use only these bands: {', '.join(selected_bands)}. Examples: {example}"
|
129 |
+
# )
|
130 |
+
|
131 |
# Imagery base selection
|
132 |
+
imagery_base = st.selectbox("Select Imagery Base", ["Sentinel", "Landsat", "MODIS", "Custom Input"], index=0)
|
133 |
|
134 |
# Load the appropriate dataset based on imagery base
|
135 |
if imagery_base == "Sentinel":
|
136 |
dataset_file = "sentinel_datasets.json"
|
137 |
+
with open(dataset_file) as f:
|
138 |
+
data = json.load(f)
|
139 |
+
elif imagery_base == "Landsat":
|
140 |
dataset_file = "landsat_datasets.json"
|
141 |
+
with open(dataset_file) as f:
|
142 |
+
data = json.load(f)
|
143 |
+
elif imagery_base == "MODIS":
|
144 |
+
dataset_file = "modis_datasets.json"
|
145 |
+
with open(dataset_file) as f:
|
146 |
+
data = json.load(f)
|
147 |
+
elif imagery_base == "Custom Input":
|
148 |
+
custom_dataset_id = st.text_input("Enter Custom Earth Engine Dataset ID (e.g., ee.ImageCollection('AHN/AHN4'))", value="")
|
149 |
+
if custom_dataset_id:
|
150 |
+
try:
|
151 |
+
# Remove potential "ee.ImageCollection()" wrapper for simplicity
|
152 |
+
if custom_dataset_id.startswith("ee.ImageCollection("):
|
153 |
+
custom_dataset_id = custom_dataset_id.replace("ee.ImageCollection('", "").replace("')", "")
|
154 |
+
# Fetch dataset info from GEE
|
155 |
+
collection = ee.ImageCollection(custom_dataset_id)
|
156 |
+
band_names = collection.first().bandNames().getInfo()
|
157 |
+
data = {
|
158 |
+
f"Custom Dataset: {custom_dataset_id}": {
|
159 |
+
"sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
|
160 |
+
"bands": {custom_dataset_id: band_names}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
|
164 |
+
except Exception as e:
|
165 |
+
st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
|
166 |
+
data = {}
|
167 |
+
else:
|
168 |
+
st.warning("Please enter a custom dataset ID to proceed.")
|
169 |
+
data = {}
|
170 |
|
171 |
# Display the title for the Streamlit app
|
172 |
st.title(f"{imagery_base} Dataset")
|
173 |
|
174 |
# Select dataset category (main selection)
|
175 |
+
if data:
|
176 |
+
main_selection = st.selectbox(f"Select {imagery_base} Dataset Category", list(data.keys()))
|
177 |
+
else:
|
178 |
+
main_selection = None
|
179 |
|
180 |
# Initialize sub_selection and dataset_id as None
|
181 |
sub_selection = None
|
|
|
196 |
st.header("Earth Engine Index Calculator")
|
197 |
|
198 |
# Load band information based on selected dataset
|
199 |
+
if main_selection and sub_selection:
|
200 |
dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
|
201 |
st.write(f"Available Bands for {sub_options[sub_selection]}: {', '.join(dataset_bands)}")
|
202 |
|