YashMK89 commited on
Commit
662503e
·
verified ·
1 Parent(s): 52df9d7

update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -8
app.py CHANGED
@@ -399,23 +399,52 @@ elif imagery_base == "VIIRS":
399
  st.error(f"Dataset file '{dataset_file}' not found.")
400
  data = {}
401
  elif imagery_base == "Custom Input":
402
- custom_dataset_id = st.text_input("Enter Custom Earth Engine Dataset ID (e.g., AHN/AHN4)", value="")
 
 
 
 
 
403
  if custom_dataset_id:
404
  try:
 
405
  if custom_dataset_id.startswith("ee.ImageCollection("):
406
- custom_dataset_id = custom_dataset_id.replace("ee.ImageCollection('", "").replace("')", "")
407
- collection = ee.ImageCollection(custom_dataset_id)
408
- band_names = collection.first().bandNames().getInfo()
409
  data = {
410
  f"Custom Dataset: {custom_dataset_id}": {
411
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
412
- "bands": {custom_dataset_id: band_names}
413
  }
414
  }
415
- st.write(f"Fetched bands for {custom_dataset_id}: {', '.join(band_names)}")
416
- st.write(f"Default Scale for Dataset: {default_scale} meters")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  except Exception as e:
418
- st.error(f"Error fetching dataset: {str(e)}. Please check the dataset ID and ensure it's valid in Google Earth Engine.")
419
  data = {}
420
  else:
421
  st.warning("Please enter a custom dataset ID to proceed.")
 
399
  st.error(f"Dataset file '{dataset_file}' not found.")
400
  data = {}
401
  elif imagery_base == "Custom Input":
402
+ custom_dataset_id = st.text_input(
403
+ "Enter Custom Earth Engine Dataset ID (e.g., MODIS/006/MOD13Q1)",
404
+ value="",
405
+ help="Enter the full path of the EE dataset (e.g., 'COPERNICUS/S2_SR')"
406
+ )
407
+
408
  if custom_dataset_id:
409
  try:
410
+ # Clean input if it includes ee.ImageCollection syntax
411
  if custom_dataset_id.startswith("ee.ImageCollection("):
412
+ custom_dataset_id = custom_dataset_id.replace("ee.ImageCollection('", "").replace("')", "").strip()
413
+
414
+ # Initialize dataset structure
415
  data = {
416
  f"Custom Dataset: {custom_dataset_id}": {
417
  "sub_options": {custom_dataset_id: f"Custom Dataset ({custom_dataset_id})"},
418
+ "bands": {custom_dataset_id: []}
419
  }
420
  }
421
+
422
+ # Fetch collection and metadata
423
+ collection = ee.ImageCollection(custom_dataset_id)
424
+ first_image = collection.first()
425
+ band_names = first_image.bandNames().getInfo()
426
+
427
+ # Get the native scale from GEE (DO NOT DEFAULT TO 30)
428
+ try:
429
+ default_scale = first_image.select(0).projection().nominalScale().getInfo()
430
+ if not isinstance(default_scale, (int, float)) or default_scale <= 0:
431
+ raise ValueError("Invalid scale from GEE")
432
+ except:
433
+ # If scale detection fails, use GEE's default instead of forcing 30
434
+ default_scale = None # Let GEE handle it
435
+
436
+ # Update data structure
437
+ data[f"Custom Dataset: {custom_dataset_id}"]["bands"][custom_dataset_id] = band_names
438
+
439
+ st.success(f"✅ Successfully loaded: {custom_dataset_id}")
440
+ st.write(f"Available Bands: {', '.join(band_names)}")
441
+ if default_scale:
442
+ st.write(f"Native Scale: {default_scale} meters")
443
+ else:
444
+ st.write("Native Scale: Letting GEE use its default resolution")
445
+
446
  except Exception as e:
447
+ st.error(f"Error loading dataset: {str(e)}")
448
  data = {}
449
  else:
450
  st.warning("Please enter a custom dataset ID to proceed.")