RadGEEToolbox 1.6.8__py3-none-any.whl → 1.6.9__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.
@@ -2879,6 +2879,7 @@ class LandsatCollection:
2879
2879
  def iterate_zonal_stats(
2880
2880
  self,
2881
2881
  geometries,
2882
+ band=None,
2882
2883
  reducer_type="mean",
2883
2884
  scale=30,
2884
2885
  geometry_names=None,
@@ -2894,6 +2895,7 @@ class LandsatCollection:
2894
2895
 
2895
2896
  Args:
2896
2897
  geometries (ee.Geometry, ee.Feature, ee.FeatureCollection, list, or tuple): Input geometries for which to extract statistics. Can be a single ee.Geometry, an ee.Feature, an ee.FeatureCollection, a list of (lon, lat) tuples, or a list of ee.Geometry objects. Be careful to NOT provide coordinates as (lat, lon)!
2898
+ band (str, optional): The name of the band to use for statistics. If None, the first band is used. Defaults to None.
2897
2899
  reducer_type (str, optional): The ee.Reducer to use, e.g., 'mean', 'median', 'max', 'sum'. Defaults to 'mean'. Any ee.Reducer method can be used.
2898
2900
  scale (int, optional): Pixel scale in meters for the reduction. Defaults to 30.
2899
2901
  geometry_names (list, optional): A list of string names for the geometries. If provided, must match the number of geometries. Defaults to None.
@@ -2911,6 +2913,12 @@ class LandsatCollection:
2911
2913
  TypeError: If geometries input type is unsupported.
2912
2914
  """
2913
2915
  img_collection_obj = self
2916
+ if band:
2917
+ img_collection_obj = LandsatCollection(collection=img_collection_obj.collection.select(band))
2918
+ else:
2919
+ first_image = img_collection_obj.image_grab(0)
2920
+ first_band = first_image.bandNames().get(0)
2921
+ img_collection_obj = LandsatCollection(collection=img_collection_obj.collection.select([first_band]))
2914
2922
  # Filter collection by dates if provided
2915
2923
  if dates:
2916
2924
  img_collection_obj = LandsatCollection(
@@ -2993,18 +3001,33 @@ class LandsatCollection:
2993
3001
  stats_fc = image.reduceRegions(
2994
3002
  collection=features, reducer=reducer, scale=scale, tileScale=tileScale
2995
3003
  )
2996
- return stats_fc.map(lambda f: f.set('image_date', image_date))
3004
+
3005
+ def guarantee_reducer_property(f):
3006
+ has_property = f.propertyNames().contains(reducer_type)
3007
+ return ee.Algorithms.If(has_property, f, f.set(reducer_type, -9999))
3008
+ fixed_stats_fc = stats_fc.map(guarantee_reducer_property)
3009
+
3010
+ return fixed_stats_fc.map(lambda f: f.set('image_date', image_date))
2997
3011
 
2998
3012
  results_fc = ee.FeatureCollection(img_collection_obj.collection.map(calculate_stats_for_image)).flatten()
2999
3013
  df = LandsatCollection.ee_to_df(results_fc, remove_geom=True)
3000
3014
 
3001
3015
  # Checking for issues
3002
3016
  if df.empty:
3003
- print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
3004
- return df
3017
+ # print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
3018
+ # return df
3019
+ raise ValueError("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
3005
3020
  if reducer_type not in df.columns:
3006
3021
  print(f"Warning: Reducer '{reducer_type}' not found in results.")
3007
- return df
3022
+ # return df
3023
+
3024
+ # Get the number of rows before dropping nulls for a helpful message
3025
+ initial_rows = len(df)
3026
+ df.dropna(subset=[reducer_type], inplace=True)
3027
+ df = df[df[reducer_type] != -9999]
3028
+ dropped_rows = initial_rows - len(df)
3029
+ if dropped_rows > 0:
3030
+ print(f"Warning: Discarded {dropped_rows} results due to failed reductions (e.g., no valid pixels in geometry).")
3008
3031
 
3009
3032
  # Reshape DataFrame to have dates as index and geometry names as columns
3010
3033
  pivot_df = df.pivot(index='image_date', columns='geo_name', values=reducer_type)
@@ -1634,6 +1634,7 @@ class Sentinel1Collection:
1634
1634
  def iterate_zonal_stats(
1635
1635
  self,
1636
1636
  geometries,
1637
+ band=None,
1637
1638
  reducer_type="mean",
1638
1639
  scale=10,
1639
1640
  geometry_names=None,
@@ -1649,6 +1650,7 @@ class Sentinel1Collection:
1649
1650
 
1650
1651
  Args:
1651
1652
  geometries (ee.Geometry, ee.Feature, ee.FeatureCollection, list, or tuple): Input geometries for which to extract statistics. Can be a single ee.Geometry, an ee.Feature, an ee.FeatureCollection, a list of (lon, lat) tuples, or a list of ee.Geometry objects. Be careful to NOT provide coordinates as (lat, lon)!
1653
+ band (str, optional): The name of the band to use for statistics. If None, the first band is used. Defaults to None.
1652
1654
  reducer_type (str, optional): The ee.Reducer to use, e.g., 'mean', 'median', 'max', 'sum'. Defaults to 'mean'. Any ee.Reducer method can be used.
1653
1655
  scale (int, optional): Pixel scale in meters for the reduction. Defaults to 10.
1654
1656
  geometry_names (list, optional): A list of string names for the geometries. If provided, must match the number of geometries. Defaults to None.
@@ -1666,6 +1668,12 @@ class Sentinel1Collection:
1666
1668
  TypeError: If geometries input type is unsupported.
1667
1669
  """
1668
1670
  img_collection_obj = self
1671
+ if band:
1672
+ img_collection_obj = Sentinel1Collection(collection=img_collection_obj.collection.select(band))
1673
+ else:
1674
+ first_image = img_collection_obj.image_grab(0)
1675
+ first_band = first_image.bandNames().get(0)
1676
+ img_collection_obj = Sentinel1Collection(collection=img_collection_obj.collection.select([first_band]))
1669
1677
  # Filter collection by dates if provided
1670
1678
  if dates:
1671
1679
  img_collection_obj = Sentinel1Collection(
@@ -1748,18 +1756,33 @@ class Sentinel1Collection:
1748
1756
  stats_fc = image.reduceRegions(
1749
1757
  collection=features, reducer=reducer, scale=scale, tileScale=tileScale
1750
1758
  )
1751
- return stats_fc.map(lambda f: f.set('image_date', image_date))
1759
+
1760
+ def guarantee_reducer_property(f):
1761
+ has_property = f.propertyNames().contains(reducer_type)
1762
+ return ee.Algorithms.If(has_property, f, f.set(reducer_type, -9999))
1763
+ fixed_stats_fc = stats_fc.map(guarantee_reducer_property)
1764
+
1765
+ return fixed_stats_fc.map(lambda f: f.set('image_date', image_date))
1752
1766
 
1753
1767
  results_fc = ee.FeatureCollection(img_collection_obj.collection.map(calculate_stats_for_image)).flatten()
1754
1768
  df = Sentinel1Collection.ee_to_df(results_fc, remove_geom=True)
1755
1769
 
1756
1770
  # Checking for issues
1757
1771
  if df.empty:
1758
- print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
1759
- return df
1772
+ # print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
1773
+ # return df
1774
+ raise ValueError("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
1760
1775
  if reducer_type not in df.columns:
1761
1776
  print(f"Warning: Reducer '{reducer_type}' not found in results.")
1762
- return df
1777
+ # return df
1778
+
1779
+ # Get the number of rows before dropping nulls for a helpful message
1780
+ initial_rows = len(df)
1781
+ df.dropna(subset=[reducer_type], inplace=True)
1782
+ df = df[df[reducer_type] != -9999]
1783
+ dropped_rows = initial_rows - len(df)
1784
+ if dropped_rows > 0:
1785
+ print(f"Warning: Discarded {dropped_rows} results due to failed reductions (e.g., no valid pixels in geometry).")
1763
1786
 
1764
1787
  # Reshape DataFrame to have dates as index and geometry names as columns
1765
1788
  pivot_df = df.pivot(index='image_date', columns='geo_name', values=reducer_type)
@@ -4,7 +4,7 @@ import numpy as np
4
4
 
5
5
 
6
6
  # ---- Reflectance scaling for Sentinel-2 L2A (HARMONIZED) ----
7
- _S2_SR_BANDS = ["B1","B2","B3","B4","B5","B6","B7","B8","B8A","B9","B10","B11","B12"]
7
+ _S2_SR_BANDS = ["B1","B2","B3","B4","B5","B6","B7","B8","B8A","B9","B11","B12"]
8
8
  _S2_SCALE = 0.0001 # offset 0.0
9
9
 
10
10
  def _scale_s2_sr(img):
@@ -2497,18 +2497,33 @@ class Sentinel2Collection:
2497
2497
  stats_fc = image.reduceRegions(
2498
2498
  collection=features, reducer=reducer, scale=scale, tileScale=tileScale
2499
2499
  )
2500
- return stats_fc.map(lambda f: f.set('image_date', image_date))
2500
+
2501
+ def guarantee_reducer_property(f):
2502
+ has_property = f.propertyNames().contains(reducer_type)
2503
+ return ee.Algorithms.If(has_property, f, f.set(reducer_type, -9999))
2504
+ fixed_stats_fc = stats_fc.map(guarantee_reducer_property)
2505
+
2506
+ return fixed_stats_fc.map(lambda f: f.set('image_date', image_date))
2501
2507
 
2502
2508
  results_fc = ee.FeatureCollection(img_collection_obj.collection.map(calculate_stats_for_image)).flatten()
2503
2509
  df = Sentinel2Collection.ee_to_df(results_fc, remove_geom=True)
2504
2510
 
2505
2511
  # Checking for issues
2506
2512
  if df.empty:
2507
- print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
2508
- return df
2513
+ # print("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
2514
+ # return df
2515
+ raise ValueError("No results found for the given parameters. Check if the geometries intersect with the images, if the dates filter is too restrictive, or if the provided bands are empty.")
2509
2516
  if reducer_type not in df.columns:
2510
2517
  print(f"Warning: Reducer '{reducer_type}' not found in results.")
2511
- return df
2518
+ # return df
2519
+
2520
+ # Get the number of rows before dropping nulls for a helpful message
2521
+ initial_rows = len(df)
2522
+ df.dropna(subset=[reducer_type], inplace=True)
2523
+ df = df[df[reducer_type] != -9999]
2524
+ dropped_rows = initial_rows - len(df)
2525
+ if dropped_rows > 0:
2526
+ print(f"Warning: Discarded {dropped_rows} results due to failed reductions (e.g., no valid pixels in geometry).")
2512
2527
 
2513
2528
  # Reshape DataFrame to have dates as index and geometry names as columns
2514
2529
  pivot_df = df.pivot(index='image_date', columns='geo_name', values=reducer_type)
RadGEEToolbox/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.6.8"
1
+ __version__ = "1.6.9"
2
2
 
3
3
  from .CollectionStitch import CollectionStitch, MosaicByDate
4
4
  from .GetPalette import get_palette
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: RadGEEToolbox
3
- Version: 1.6.8
3
+ Version: 1.6.9
4
4
  Summary: Streamlined Multispectral & SAR Analysis for Google Earth Engine Python API
5
5
  Home-page: https://github.com/radwinskis/RadGEEToolbox
6
6
  Author: Mark Radwin
@@ -172,15 +172,15 @@ _____________
172
172
 
173
173
  ### Installing via pip
174
174
 
175
- To install `RadGEEToolbox` version 1.6.8 using pip (NOTE: it is recommended to create a new virtual environment):
175
+ To install `RadGEEToolbox` version 1.6.9 using pip (NOTE: it is recommended to create a new virtual environment):
176
176
 
177
177
  ```bash
178
- pip install RadGEEToolbox==1.6.8
178
+ pip install RadGEEToolbox==1.6.9
179
179
  ```
180
180
 
181
181
  ### Installing via Conda
182
182
 
183
- To install `RadGEEToolbox` version 1.6.8 using conda-forge (NOTE: it is recommended to create a new virtual environment):
183
+ To install `RadGEEToolbox` version 1.6.9 using conda-forge (NOTE: it is recommended to create a new virtual environment):
184
184
 
185
185
  ```bash
186
186
  conda install conda-forge::radgeetoolbox
@@ -211,7 +211,7 @@ To verify that `RadGEEToolbox` was installed correctly:
211
211
  python -c "import RadGEEToolbox; print(RadGEEToolbox.__version__)"
212
212
  ```
213
213
 
214
- You should see `1.6.8` printed as the version number.
214
+ You should see `1.6.9` printed as the version number.
215
215
 
216
216
  ### Want to Visualize Data? Install These Too
217
217
 
@@ -0,0 +1,12 @@
1
+ RadGEEToolbox/CollectionStitch.py,sha256=dLRzJZLZ1QTJqqbWPElyTjxb1m0T_WuBTo6wNzcCXq4,3884
2
+ RadGEEToolbox/GetPalette.py,sha256=YpAE9lzI5aXWHJKs1SXwZ62e8nKo8zfjKSpz5oJQSA8,2872
3
+ RadGEEToolbox/LandsatCollection.py,sha256=HlO-J2occ5Do5tCijI-cR1OJsbX_Zz7qASuLO-cMRYQ,146542
4
+ RadGEEToolbox/Sentinel1Collection.py,sha256=mG0JiRcds5oyjNtOrToMTQunBaJgwZJsvM8gIpfTypc,87632
5
+ RadGEEToolbox/Sentinel2Collection.py,sha256=Y4aAupQgx6H9-oRZN9u7Qyc4pR2gWVGnkoqLt6hSQtM,116567
6
+ RadGEEToolbox/VisParams.py,sha256=4aQV4l_IA-CjMBUXYDDLQ2fQyA3USSRN0A3VY07dGQ8,8571
7
+ RadGEEToolbox/__init__.py,sha256=ef7g5CJ2yM82g3fFlJc0wVcC-9qRN-B_uibyz8At1Lo,530
8
+ radgeetoolbox-1.6.9.dist-info/licenses/LICENSE.txt,sha256=5Xj9dwVkawz6d8zhCwJy0SmXvm0U4K_msJnOrkHLO1w,1089
9
+ radgeetoolbox-1.6.9.dist-info/METADATA,sha256=KTRVJ2W4wLn-_L-eaZB6dWJWbQa3onEfKJInNJk4Fs4,15571
10
+ radgeetoolbox-1.6.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ radgeetoolbox-1.6.9.dist-info/top_level.txt,sha256=W2E520tugQoptDkhctKFbzsheL2l_DyYLKqKXkD9G_E,14
12
+ radgeetoolbox-1.6.9.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- RadGEEToolbox/CollectionStitch.py,sha256=dLRzJZLZ1QTJqqbWPElyTjxb1m0T_WuBTo6wNzcCXq4,3884
2
- RadGEEToolbox/GetPalette.py,sha256=YpAE9lzI5aXWHJKs1SXwZ62e8nKo8zfjKSpz5oJQSA8,2872
3
- RadGEEToolbox/LandsatCollection.py,sha256=_ATVLz_7NDYbPZeg1mpk9RVltI9RA9H001phS71uHns,145106
4
- RadGEEToolbox/Sentinel1Collection.py,sha256=zd5XlxOZk80SeCN7OlOlpJfYstfXD90EawIWD9Mvghs,86192
5
- RadGEEToolbox/Sentinel2Collection.py,sha256=EGKq2bREsge7LCXrBmcVNFUafHIzykj9QajZmLmimb8,115660
6
- RadGEEToolbox/VisParams.py,sha256=4aQV4l_IA-CjMBUXYDDLQ2fQyA3USSRN0A3VY07dGQ8,8571
7
- RadGEEToolbox/__init__.py,sha256=Ij9uuIlvwFR39Ms6xYq5kih7AdjmO0366kYnME_KTsI,530
8
- radgeetoolbox-1.6.8.dist-info/licenses/LICENSE.txt,sha256=5Xj9dwVkawz6d8zhCwJy0SmXvm0U4K_msJnOrkHLO1w,1089
9
- radgeetoolbox-1.6.8.dist-info/METADATA,sha256=xAnfdPUVfPG54h5dJIiiYxHodaECGTeOMN5NmdVMvjw,15571
10
- radgeetoolbox-1.6.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- radgeetoolbox-1.6.8.dist-info/top_level.txt,sha256=W2E520tugQoptDkhctKFbzsheL2l_DyYLKqKXkD9G_E,14
12
- radgeetoolbox-1.6.8.dist-info/RECORD,,