voxcity 0.6.3__py3-none-any.whl → 0.6.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of voxcity might be problematic. Click here for more details.

voxcity/downloader/gee.py CHANGED
@@ -26,16 +26,21 @@ import geemap
26
26
  # Local imports
27
27
  # from ..geo.utils import convert_format_lat_lon
28
28
 
29
- def initialize_earth_engine():
30
- """Initialize the Earth Engine API.
31
-
32
- This function must be called before using any other Earth Engine functionality.
33
- It assumes that Earth Engine authentication has been set up properly.
34
-
35
- Raises:
36
- ee.EEException: If authentication fails or Earth Engine is unavailable
29
+ def initialize_earth_engine(**initialize_kwargs):
30
+ """Initialize the Earth Engine API if not already initialized.
31
+
32
+ Uses a public-behavior check to determine whether Earth Engine is already
33
+ initialized by attempting to access asset roots. If that call fails, it will
34
+ initialize Earth Engine using the provided keyword arguments.
35
+
36
+ Arguments are passed through to ``ee.Initialize`` to support contexts such as
37
+ specifying a ``project`` or service account credentials.
37
38
  """
38
- ee.Initialize()
39
+ try:
40
+ # If this succeeds, EE is already initialized
41
+ ee.data.getAssetRoots()
42
+ except Exception:
43
+ ee.Initialize(**initialize_kwargs)
39
44
 
40
45
  def get_roi(input_coords):
41
46
  """Create an Earth Engine region of interest polygon from coordinates.
@@ -243,7 +248,7 @@ def save_geotiff_esa_land_cover(roi, geotiff_path):
243
248
  resolution of the ESA WorldCover dataset.
244
249
  """
245
250
  # Initialize Earth Engine
246
- ee.Initialize()
251
+ initialize_earth_engine()
247
252
 
248
253
  # Load and clip the ESA WorldCover dataset
249
254
  esa = ee.ImageCollection("ESA/WorldCover/v200").first()
@@ -307,7 +312,7 @@ def save_geotiff_dynamic_world_v1(roi, geotiff_path, date=None):
307
312
  actual date used.
308
313
  """
309
314
  # Initialize Earth Engine
310
- ee.Initialize()
315
+ initialize_earth_engine()
311
316
 
312
317
  # Load and filter Dynamic World dataset
313
318
  # Load the Dynamic World dataset and filter by ROI
@@ -416,7 +421,7 @@ def save_geotiff_esri_landcover(roi, geotiff_path, year=None):
416
421
  differ from the requested year if data is not available for that time.
417
422
  """
418
423
  # Initialize Earth Engine
419
- ee.Initialize()
424
+ initialize_earth_engine()
420
425
 
421
426
  # Load the ESRI Land Cover dataset and filter by ROI
422
427
  esri_lulc = ee.ImageCollection("projects/sat-io/open-datasets/landcover/ESRI_Global-LULC_10m_TS").filterBounds(roi)
@@ -508,7 +513,7 @@ def save_geotiff_open_buildings_temporal(aoi, geotiff_path):
508
513
  - Areas without buildings will have no-data values
509
514
  """
510
515
  # Initialize Earth Engine
511
- ee.Initialize()
516
+ initialize_earth_engine()
512
517
 
513
518
  # Load the dataset
514
519
  collection = ee.ImageCollection('GOOGLE/Research/open-buildings-temporal/v1')
@@ -554,7 +559,7 @@ def save_geotiff_dsm_minus_dtm(roi, geotiff_path, meshsize, source):
554
559
  - The function requires both DSM and DTM data to be available for the region
555
560
  """
556
561
  # Initialize Earth Engine
557
- ee.Initialize()
562
+ initialize_earth_engine()
558
563
 
559
564
  # Add buffer around ROI to ensure smooth interpolation at edges
560
565
  buffer_distance = 100