YashMK89 commited on
Commit
5f64e85
·
verified ·
1 Parent(s): 64eee83

update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -106,7 +106,7 @@ def convert_to_ee_geometry(geometry):
106
  else:
107
  raise ValueError("Unsupported geometry input type. Supported types are Shapely, GeoJSON, and KML.")
108
 
109
- # Function to calculate custom formula with dynamic scale handling and normalization
110
  def calculate_custom_formula(image, geometry, selected_bands, custom_formula, reducer_choice, dataset_id, user_scale=None):
111
  try:
112
  # Fetch the nominal scales of the selected bands
@@ -446,7 +446,9 @@ elif imagery_base == "Custom Input":
446
  if custom_dataset_id.startswith("ee.ImageCollection("):
447
  custom_dataset_id = custom_dataset_id.replace("ee.ImageCollection('", "").replace("')", "")
448
  collection = ee.ImageCollection(custom_dataset_id)
449
- band_names = collection.first().bandNames().getInfo()
 
 
450
  data = {
451
  f"Custom Dataset: {custom_dataset_id}": {
452
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
@@ -454,6 +456,7 @@ elif imagery_base == "Custom Input":
454
  }
455
  }
456
  st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
 
457
  except Exception as e:
458
  st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
459
  data = {}
@@ -463,6 +466,7 @@ elif imagery_base == "Custom Input":
463
  if not data:
464
  st.error("No valid dataset available. Please check your inputs.")
465
  st.stop()
 
466
  st.markdown("<hr><h5><b>{}</b></h5>".format(imagery_base), unsafe_allow_html=True)
467
  main_selection = st.selectbox(f"Select {imagery_base} Dataset Category", list(data.keys()))
468
  sub_selection = None
@@ -474,6 +478,16 @@ if main_selection:
474
  st.write(f"You selected: {main_selection} -> {sub_options[sub_selection]}")
475
  st.write(f"Dataset ID: {sub_selection}")
476
  dataset_id = sub_selection
 
 
 
 
 
 
 
 
 
 
477
  st.markdown("<hr><h5><b>Earth Engine Index Calculator</b></h5>", unsafe_allow_html=True)
478
  if main_selection and sub_selection:
479
  dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
@@ -516,6 +530,7 @@ if main_selection and sub_selection:
516
  st.warning("Please enter a custom formula to proceed.")
517
  st.stop()
518
  st.write(f"Custom Formula: {custom_formula}")
 
519
  reducer_choice = st.selectbox(
520
  "Select Reducer (e.g, mean , sum , median , min , max , count)",
521
  ['mean', 'sum', 'median', 'min', 'max', 'count'],
@@ -572,6 +587,7 @@ user_scale = st.number_input(
572
  value=float(default_scale),
573
  help=f"Default scale for this dataset is {default_scale} meters. Adjust if needed."
574
  )
 
575
  file_upload = st.file_uploader(f"Upload your {shape_type} data (CSV, GeoJSON, KML)", type=["csv", "geojson", "kml"])
576
  locations_df = pd.DataFrame()
577
  original_lat_col = None
 
106
  else:
107
  raise ValueError("Unsupported geometry input type. Supported types are Shapely, GeoJSON, and KML.")
108
 
109
+ # Function to calculate custom formula with dynamic scale handling
110
  def calculate_custom_formula(image, geometry, selected_bands, custom_formula, reducer_choice, dataset_id, user_scale=None):
111
  try:
112
  # Fetch the nominal scales of the selected bands
 
446
  if custom_dataset_id.startswith("ee.ImageCollection("):
447
  custom_dataset_id = custom_dataset_id.replace("ee.ImageCollection('", "").replace("')", "")
448
  collection = ee.ImageCollection(custom_dataset_id)
449
+ first_image = collection.first()
450
+ default_scale = first_image.projection().nominalScale().getInfo()
451
+ band_names = first_image.bandNames().getInfo()
452
  data = {
453
  f"Custom Dataset: {custom_dataset_id}": {
454
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
 
456
  }
457
  }
458
  st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
459
+ st.write(f"Default Scale for Dataset: {default_scale} meters")
460
  except Exception as e:
461
  st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
462
  data = {}
 
466
  if not data:
467
  st.error("No valid dataset available. Please check your inputs.")
468
  st.stop()
469
+
470
  st.markdown("<hr><h5><b>{}</b></h5>".format(imagery_base), unsafe_allow_html=True)
471
  main_selection = st.selectbox(f"Select {imagery_base} Dataset Category", list(data.keys()))
472
  sub_selection = None
 
478
  st.write(f"You selected: {main_selection} -> {sub_options[sub_selection]}")
479
  st.write(f"Dataset ID: {sub_selection}")
480
  dataset_id = sub_selection
481
+
482
+ # Print default scale for the selected dataset
483
+ try:
484
+ collection = ee.ImageCollection(dataset_id)
485
+ first_image = collection.first()
486
+ default_scale = first_image.projection().nominalScale().getInfo()
487
+ st.write(f"Default Scale for Selected Dataset: {default_scale} meters")
488
+ except Exception as e:
489
+ st.error(f"Error fetching default scale: {str(e)}")
490
+
491
  st.markdown("<hr><h5><b>Earth Engine Index Calculator</b></h5>", unsafe_allow_html=True)
492
  if main_selection and sub_selection:
493
  dataset_bands = data[main_selection]["bands"].get(sub_selection, [])
 
530
  st.warning("Please enter a custom formula to proceed.")
531
  st.stop()
532
  st.write(f"Custom Formula: {custom_formula}")
533
+
534
  reducer_choice = st.selectbox(
535
  "Select Reducer (e.g, mean , sum , median , min , max , count)",
536
  ['mean', 'sum', 'median', 'min', 'max', 'count'],
 
587
  value=float(default_scale),
588
  help=f"Default scale for this dataset is {default_scale} meters. Adjust if needed."
589
  )
590
+
591
  file_upload = st.file_uploader(f"Upload your {shape_type} data (CSV, GeoJSON, KML)", type=["csv", "geojson", "kml"])
592
  locations_df = pd.DataFrame()
593
  original_lat_col = None