YashMK89 commited on
Commit
3a4f9a5
·
verified ·
1 Parent(s): 1a9e9b1

update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -3,8 +3,11 @@ import json
3
  import ee
4
  import geemap
5
  import os
 
6
  import pandas as pd
 
7
  from datetime import datetime
 
8
 
9
  # Set up the page layout
10
  st.set_page_config(layout="wide")
@@ -56,18 +59,6 @@ custom_formula = ""
56
  if index_choice == 'Custom Formula':
57
  custom_formula = st.text_input("Enter Custom Formula (e.g., 'B5 - B4 / B5 + B4')")
58
 
59
- # Show Cloud Pixel Percentage option if NDVI or NDWI is selected
60
- cloud_threshold = None
61
- if index_choice in ['NDVI', 'NDWI']:
62
- cloud_threshold = st.slider(
63
- "Set Cloud Pixel Percentage Threshold",
64
- min_value=0,
65
- max_value=100,
66
- value=20,
67
- step=1,
68
- help="Cloud coverage threshold (in percentage) to mask out cloud pixels."
69
- )
70
-
71
  # Function to read points from CSV
72
  def read_csv(file_path):
73
  df = pd.read_csv(file_path)
@@ -190,11 +181,10 @@ if locations_df is not None:
190
  # Define the region of interest (ROI) using the current latitude and longitude
191
  roi = ee.Geometry.Point([longitude, latitude])
192
 
193
- # Load the image collection based on the user's selection
194
- collection = ee.ImageCollection('COPERNICUS/S2') \
195
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str)) \
196
- .filterBounds(roi) \
197
- .filter(ee.Filter.lt('system:cloud_coverage', cloud_threshold)) # Apply cloud coverage filter
198
 
199
  # Check if the collection has images for the selected date range
200
  image_count = collection.size().getInfo()
@@ -202,6 +192,7 @@ if locations_df is not None:
202
  st.warning(f"No images found for {location_name}.")
203
  else:
204
  st.write(f"Found {image_count} images for {location_name}.")
 
205
  image = collection.first()
206
 
207
  # Perform calculation based on user selection
@@ -210,12 +201,19 @@ if locations_df is not None:
210
  elif index_choice == 'NDWI':
211
  result = calculate_ndwi(image, roi)
212
  elif index_choice == 'Average NO₂':
213
- result = calculate_avg_no2_sentinel5p(image, roi)
 
 
 
 
 
214
  elif index_choice == 'Custom Formula' and custom_formula:
215
  result = calculate_custom_formula(image, roi, custom_formula)
216
 
217
  if result:
218
  st.write(f"Result for {location_name}: {result.getInfo()}")
 
 
219
  results.append({'Location': location_name, 'Result': result.getInfo()})
220
 
221
  # Convert results to DataFrame for download
 
3
  import ee
4
  import geemap
5
  import os
6
+ import time
7
  import pandas as pd
8
+ import geopandas as gpd
9
  from datetime import datetime
10
+ from shapely.geometry import Point
11
 
12
  # Set up the page layout
13
  st.set_page_config(layout="wide")
 
59
  if index_choice == 'Custom Formula':
60
  custom_formula = st.text_input("Enter Custom Formula (e.g., 'B5 - B4 / B5 + B4')")
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # Function to read points from CSV
63
  def read_csv(file_path):
64
  df = pd.read_csv(file_path)
 
181
  # Define the region of interest (ROI) using the current latitude and longitude
182
  roi = ee.Geometry.Point([longitude, latitude])
183
 
184
+ # Load Sentinel-2 image collection
185
+ collection = ee.ImageCollection(sub_options[sub_selection]) \
186
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str)) \
187
+ .filterBounds(roi)
 
188
 
189
  # Check if the collection has images for the selected date range
190
  image_count = collection.size().getInfo()
 
192
  st.warning(f"No images found for {location_name}.")
193
  else:
194
  st.write(f"Found {image_count} images for {location_name}.")
195
+
196
  image = collection.first()
197
 
198
  # Perform calculation based on user selection
 
201
  elif index_choice == 'NDWI':
202
  result = calculate_ndwi(image, roi)
203
  elif index_choice == 'Average NO₂':
204
+ # Check if NO2 is available in the current dataset (Sentinel-2 does not have NO2)
205
+ if 'NO2' in image.bandNames().getInfo():
206
+ result = calculate_avg_no2_sentinel5p(image, roi)
207
+ else:
208
+ st.warning(f"No NO2 band found for {location_name}. Please use Sentinel-5P for NO₂ data.")
209
+ result = None
210
  elif index_choice == 'Custom Formula' and custom_formula:
211
  result = calculate_custom_formula(image, roi, custom_formula)
212
 
213
  if result:
214
  st.write(f"Result for {location_name}: {result.getInfo()}")
215
+
216
+ # Add the result to a list for output
217
  results.append({'Location': location_name, 'Result': result.getInfo()})
218
 
219
  # Convert results to DataFrame for download