YashMK89 commited on
Commit
6b232af
·
verified ·
1 Parent(s): fcddad3

update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -59,20 +59,6 @@ ee.Initialize(project='ee-yashsacisro24')
59
  # Imagery base selection
60
  imagery_base = st.selectbox("Select Imagery Base", ["Sentinel", "Landsat", "MODIS", "Custom Input"], index=0)
61
 
62
- # Function to fetch date range from GEE
63
- def fetch_date_range(dataset_id):
64
- try:
65
- collection = ee.ImageCollection(dataset_id)
66
- date_range = collection.reduceColumns(
67
- ee.Reducer.minMax(),
68
- ["system:time_start"]
69
- ).getInfo()
70
- start_date = datetime.fromtimestamp(date_range['min'] / 1000).strftime('%Y-%m-%d')
71
- end_date = datetime.fromtimestamp(date_range['max'] / 1000).strftime('%Y-%m-%d')
72
- return start_date, end_date
73
- except Exception as e:
74
- return None, None
75
-
76
  # Load the appropriate dataset based on imagery base
77
  if imagery_base == "Sentinel":
78
  dataset_file = "sentinel_datasets.json"
@@ -96,7 +82,6 @@ elif imagery_base == "Custom Input":
96
  # Fetch dataset info from GEE
97
  collection = ee.ImageCollection(custom_dataset_id)
98
  band_names = collection.first().bandNames().getInfo()
99
- start_date, end_date = fetch_date_range(custom_dataset_id)
100
  data = {
101
  f"Custom Dataset: {custom_dataset_id}": {
102
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
@@ -104,10 +89,6 @@ elif imagery_base == "Custom Input":
104
  }
105
  }
106
  st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
107
- if start_date and end_date:
108
- st.info(f"Valid Date Range: {start_date} to {end_date}")
109
- else:
110
- st.warning("Could not fetch date range for this dataset.")
111
  except Exception as e:
112
  st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
113
  data = {}
@@ -133,18 +114,36 @@ if main_selection:
133
  sub_options = data[main_selection]["sub_options"]
134
  sub_selection = st.selectbox(f"Select Specific {imagery_base} Dataset ID", list(sub_options.keys()))
135
 
136
- # Display the selected dataset ID and fetch date range
137
  if sub_selection:
138
  st.write(f"You selected: {main_selection} -> {sub_options[sub_selection]}")
139
  st.write(f"Dataset ID: {sub_selection}")
140
  dataset_id = sub_selection # Use the key directly as the dataset ID
141
 
142
- # Fetch and display the date range for the selected dataset
143
- start_date, end_date = fetch_date_range(dataset_id)
144
- if start_date and end_date:
145
- st.info(f"Valid Date Range for {dataset_id}: {start_date} to {end_date}")
146
- else:
147
- st.warning(f"Could not fetch date range for {dataset_id}.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  # Earth Engine Index Calculator Section
150
  st.header("Earth Engine Index Calculator")
@@ -178,7 +177,7 @@ if main_selection and sub_selection:
178
  example = f"'{selected_bands[0]} * {selected_bands[1]} / 2' or '({selected_bands[0]} - {selected_bands[1]}) / ({selected_bands[0]} + {selected_bands[1]})'"
179
 
180
  custom_formula = st.text_input(
181
- "Enter Custom Formula",
182
  value=default_formula,
183
  help=f"Use only these bands: {', '.join(selected_bands)}. Examples: {example}"
184
  )
 
59
  # Imagery base selection
60
  imagery_base = st.selectbox("Select Imagery Base", ["Sentinel", "Landsat", "MODIS", "Custom Input"], index=0)
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # Load the appropriate dataset based on imagery base
63
  if imagery_base == "Sentinel":
64
  dataset_file = "sentinel_datasets.json"
 
82
  # Fetch dataset info from GEE
83
  collection = ee.ImageCollection(custom_dataset_id)
84
  band_names = collection.first().bandNames().getInfo()
 
85
  data = {
86
  f"Custom Dataset: {custom_dataset_id}": {
87
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
 
89
  }
90
  }
91
  st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
 
 
 
 
92
  except Exception as e:
93
  st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
94
  data = {}
 
114
  sub_options = data[main_selection]["sub_options"]
115
  sub_selection = st.selectbox(f"Select Specific {imagery_base} Dataset ID", list(sub_options.keys()))
116
 
117
+ # Display the selected dataset ID and its availability based on user input
118
  if sub_selection:
119
  st.write(f"You selected: {main_selection} -> {sub_options[sub_selection]}")
120
  st.write(f"Dataset ID: {sub_selection}")
121
  dataset_id = sub_selection # Use the key directly as the dataset ID
122
 
123
+ # Fetch and display dataset availability
124
+ try:
125
+ # Create an Earth Engine ImageCollection object for the selected dataset
126
+ collection = ee.ImageCollection(dataset_id)
127
+
128
+ # Get the date range of the collection
129
+ range_info = collection.reduceColumns(
130
+ reducer=ee.Reducer.minMax(),
131
+ selectors=['system:time_start']
132
+ ).getInfo()
133
+
134
+ # Extract min and max timestamps (in milliseconds) and convert to readable dates
135
+ min_time = range_info.get('min', None)
136
+ max_time = range_info.get('max', None)
137
+
138
+ if min_time and max_time:
139
+ start_date = datetime.fromtimestamp(min_time / 1000).strftime('%Y-%m-%d')
140
+ end_date = datetime.fromtimestamp(max_time / 1000).strftime('%Y-%m-%d')
141
+ st.markdown(f"**Dataset Availability:** From {start_date} to {end_date}", unsafe_allow_html=True)
142
+ else:
143
+ st.markdown("**Dataset Availability:** Date range not available.", unsafe_allow_html=True)
144
+
145
+ except Exception as e:
146
+ st.error(f"Error fetching dataset availability: {str(e)}")
147
 
148
  # Earth Engine Index Calculator Section
149
  st.header("Earth Engine Index Calculator")
 
177
  example = f"'{selected_bands[0]} * {selected_bands[1]} / 2' or '({selected_bands[0]} - {selected_bands[1]}) / ({selected_bands[0]} + {selected_bands[1]})'"
178
 
179
  custom_formula = st.text_input(
180
+ "Enter Custom Formula (e.g (B8 - B4) / (B8 + B4) , B4*B3/2)",
181
  value=default_formula,
182
  help=f"Use only these bands: {', '.join(selected_bands)}. Examples: {example}"
183
  )