RadGEEToolbox 1.7.3__py3-none-any.whl → 1.7.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.
- RadGEEToolbox/CollectionStitch.py +16 -3
- RadGEEToolbox/Export.py +16 -0
- RadGEEToolbox/GenericCollection.py +130 -34
- RadGEEToolbox/LandsatCollection.py +249 -50
- RadGEEToolbox/Sentinel1Collection.py +179 -37
- RadGEEToolbox/Sentinel2Collection.py +202 -51
- RadGEEToolbox/__init__.py +4 -4
- {radgeetoolbox-1.7.3.dist-info → radgeetoolbox-1.7.4.dist-info}/METADATA +6 -6
- radgeetoolbox-1.7.4.dist-info/RECORD +14 -0
- radgeetoolbox-1.7.3.dist-info/RECORD +0 -14
- {radgeetoolbox-1.7.3.dist-info → radgeetoolbox-1.7.4.dist-info}/WHEEL +0 -0
- {radgeetoolbox-1.7.3.dist-info → radgeetoolbox-1.7.4.dist-info}/licenses/LICENSE.txt +0 -0
- {radgeetoolbox-1.7.3.dist-info → radgeetoolbox-1.7.4.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ee
|
|
2
2
|
import pandas as pd
|
|
3
3
|
import numpy as np
|
|
4
|
+
import warnings
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
# ---- Reflectance scaling for Sentinel-2 L2A (HARMONIZED) ----
|
|
@@ -68,7 +69,7 @@ class Sentinel2Collection:
|
|
|
68
69
|
... cloud_percentage_threshold=20,
|
|
69
70
|
... nodata_threshold=10,
|
|
70
71
|
... )
|
|
71
|
-
>>> mosaic_collection = image_collection.
|
|
72
|
+
>>> mosaic_collection = image_collection.mosaicByDate #mosaic images/tiles with same date
|
|
72
73
|
>>> cloud_masked = mosaic_collection.masked_clouds_collection #mask out clouds
|
|
73
74
|
>>> latest_image = cloud_masked.image_grab(-1) #grab latest image for viewing
|
|
74
75
|
>>> ndwi_collection = cloud_masked.ndwi #calculate ndwi for all images
|
|
@@ -196,6 +197,14 @@ class Sentinel2Collection:
|
|
|
196
197
|
self._PixelAreaSumCollection = None
|
|
197
198
|
self._Reflectance = None
|
|
198
199
|
|
|
200
|
+
def __call__(self):
|
|
201
|
+
"""
|
|
202
|
+
Allows the object to be called as a function, returning itself.
|
|
203
|
+
This enables property-like methods to be accessed with or without parentheses
|
|
204
|
+
(e.g., .mosaicByDate or .mosaicByDate()).
|
|
205
|
+
"""
|
|
206
|
+
return self
|
|
207
|
+
|
|
199
208
|
@staticmethod
|
|
200
209
|
def image_dater(image):
|
|
201
210
|
"""
|
|
@@ -564,7 +573,7 @@ class Sentinel2Collection:
|
|
|
564
573
|
return image.addBands(anomaly_image, overwrite=True)
|
|
565
574
|
|
|
566
575
|
@staticmethod
|
|
567
|
-
def
|
|
576
|
+
def maskClouds(image):
|
|
568
577
|
"""
|
|
569
578
|
Function to mask clouds using SCL band data.
|
|
570
579
|
|
|
@@ -579,7 +588,14 @@ class Sentinel2Collection:
|
|
|
579
588
|
return image.updateMask(CloudMask).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
580
589
|
|
|
581
590
|
@staticmethod
|
|
582
|
-
def
|
|
591
|
+
def MaskCloudsS2(image):
|
|
592
|
+
warnings.warn("MaskCloudsS2 is deprecated. Please use maskClouds instead.",
|
|
593
|
+
DeprecationWarning,
|
|
594
|
+
stacklevel=2)
|
|
595
|
+
return Sentinel2Collection.maskClouds(image)
|
|
596
|
+
|
|
597
|
+
@staticmethod
|
|
598
|
+
def maskShadows(image):
|
|
583
599
|
"""
|
|
584
600
|
Function to mask cloud shadows using SCL band data.
|
|
585
601
|
|
|
@@ -592,9 +608,16 @@ class Sentinel2Collection:
|
|
|
592
608
|
SCL = image.select("SCL")
|
|
593
609
|
ShadowMask = SCL.neq(3)
|
|
594
610
|
return image.updateMask(ShadowMask).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
611
|
+
|
|
612
|
+
@staticmethod
|
|
613
|
+
def MaskShadowsS2(image):
|
|
614
|
+
warnings.warn("MaskShadowsS2 is deprecated. Please use maskShadows instead.",
|
|
615
|
+
DeprecationWarning,
|
|
616
|
+
stacklevel=2)
|
|
617
|
+
return Sentinel2Collection.maskShadows(image)
|
|
595
618
|
|
|
596
619
|
@staticmethod
|
|
597
|
-
def
|
|
620
|
+
def maskWater(image):
|
|
598
621
|
"""
|
|
599
622
|
Function to mask water pixels using SCL band data.
|
|
600
623
|
|
|
@@ -607,9 +630,16 @@ class Sentinel2Collection:
|
|
|
607
630
|
SCL = image.select("SCL")
|
|
608
631
|
WaterMask = SCL.neq(6)
|
|
609
632
|
return image.updateMask(WaterMask).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
633
|
+
|
|
634
|
+
@staticmethod
|
|
635
|
+
def MaskWaterS2(image):
|
|
636
|
+
warnings.warn("MaskWaterS2 is deprecated. Please use maskWater instead.",
|
|
637
|
+
DeprecationWarning,
|
|
638
|
+
stacklevel=2)
|
|
639
|
+
return Sentinel2Collection.maskWater(image)
|
|
610
640
|
|
|
611
641
|
@staticmethod
|
|
612
|
-
def
|
|
642
|
+
def maskWaterByNDWI(image, threshold):
|
|
613
643
|
"""
|
|
614
644
|
Function to mask water pixels (mask land and cloud pixels) for all bands based on NDWI and a set threshold where
|
|
615
645
|
all pixels less than NDWI threshold are masked out.
|
|
@@ -626,9 +656,16 @@ class Sentinel2Collection:
|
|
|
626
656
|
) # green-NIR / green+NIR -- full NDWI image
|
|
627
657
|
water = image.updateMask(ndwi_calc.lt(threshold)).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
628
658
|
return water
|
|
659
|
+
|
|
660
|
+
@staticmethod
|
|
661
|
+
def MaskWaterS2ByNDWI(image, threshold):
|
|
662
|
+
warnings.warn("MaskWaterS2ByNDWI is deprecated. Please use maskWaterByNDWI instead.",
|
|
663
|
+
DeprecationWarning,
|
|
664
|
+
stacklevel=2)
|
|
665
|
+
return Sentinel2Collection.maskWaterByNDWI(image, threshold)
|
|
629
666
|
|
|
630
667
|
@staticmethod
|
|
631
|
-
def
|
|
668
|
+
def maskToWater(image):
|
|
632
669
|
"""
|
|
633
670
|
Function to mask to water pixels (mask land and cloud pixels) using SCL band data.
|
|
634
671
|
|
|
@@ -641,6 +678,13 @@ class Sentinel2Collection:
|
|
|
641
678
|
SCL = image.select("SCL")
|
|
642
679
|
WaterMask = SCL.eq(6)
|
|
643
680
|
return image.updateMask(WaterMask).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
681
|
+
|
|
682
|
+
@staticmethod
|
|
683
|
+
def MaskToWaterS2(image):
|
|
684
|
+
warnings.warn("MaskToWaterS2 is deprecated. Please use maskToWater instead.",
|
|
685
|
+
DeprecationWarning,
|
|
686
|
+
stacklevel=2)
|
|
687
|
+
return Sentinel2Collection.maskToWater(image)
|
|
644
688
|
|
|
645
689
|
@staticmethod
|
|
646
690
|
def halite_mask(image, threshold):
|
|
@@ -748,7 +792,7 @@ class Sentinel2Collection:
|
|
|
748
792
|
return band_to_mask_image.updateMask(mask).rename(band_to_mask).copyProperties(image_to_mask).set('system:time_start', image_to_mask.get('system:time_start'))
|
|
749
793
|
|
|
750
794
|
@staticmethod
|
|
751
|
-
def
|
|
795
|
+
def maskToWaterByNDWI(image, threshold):
|
|
752
796
|
"""
|
|
753
797
|
Function to mask all bands to water pixels (mask land and cloud pixels) based on NDWI.
|
|
754
798
|
|
|
@@ -764,9 +808,16 @@ class Sentinel2Collection:
|
|
|
764
808
|
) # green-NIR / green+NIR -- full NDWI image
|
|
765
809
|
water = image.updateMask(ndwi_calc.gte(threshold)).copyProperties(image).set('system:time_start', image.get('system:time_start'))
|
|
766
810
|
return water
|
|
811
|
+
|
|
812
|
+
@staticmethod
|
|
813
|
+
def MaskToWaterS2ByNDWI(image, threshold):
|
|
814
|
+
warnings.warn("MaskToWaterS2ByNDWI is deprecated. Please use maskToWaterByNDWI instead.",
|
|
815
|
+
DeprecationWarning,
|
|
816
|
+
stacklevel=2)
|
|
817
|
+
return Sentinel2Collection.maskToWaterByNDWI(image, threshold)
|
|
767
818
|
|
|
768
819
|
@staticmethod
|
|
769
|
-
def
|
|
820
|
+
def pixelAreaSum(
|
|
770
821
|
image, band_name, geometry, threshold=-1, scale=10, maxPixels=1e12
|
|
771
822
|
):
|
|
772
823
|
"""
|
|
@@ -825,8 +876,17 @@ class Sentinel2Collection:
|
|
|
825
876
|
# Call to iterate the calculate_and_set_area function over the list of bands, starting with the original image
|
|
826
877
|
final_image = ee.Image(bands.iterate(calculate_and_set_area, image))
|
|
827
878
|
return final_image
|
|
879
|
+
|
|
880
|
+
@staticmethod
|
|
881
|
+
def PixelAreaSum(
|
|
882
|
+
image, band_name, geometry, threshold=-1, scale=10, maxPixels=1e12
|
|
883
|
+
):
|
|
884
|
+
warnings.warn("PixelAreaSum is deprecated. Please use pixelAreaSum instead.",
|
|
885
|
+
DeprecationWarning,
|
|
886
|
+
stacklevel=2)
|
|
887
|
+
return Sentinel2Collection.pixelAreaSum(image, band_name, geometry, threshold, scale, maxPixels)
|
|
828
888
|
|
|
829
|
-
def
|
|
889
|
+
def pixelAreaSumCollection(
|
|
830
890
|
self, band_name, geometry, threshold=-1, scale=10, maxPixels=1e12, output_type='ImageCollection', area_data_export_path=None
|
|
831
891
|
):
|
|
832
892
|
"""
|
|
@@ -853,7 +913,7 @@ class Sentinel2Collection:
|
|
|
853
913
|
collection = self.collection
|
|
854
914
|
# Area calculation for each image in the collection, using the PixelAreaSum function
|
|
855
915
|
AreaCollection = collection.map(
|
|
856
|
-
lambda image: Sentinel2Collection.
|
|
916
|
+
lambda image: Sentinel2Collection.pixelAreaSum(
|
|
857
917
|
image,
|
|
858
918
|
band_name=band_name,
|
|
859
919
|
geometry=geometry,
|
|
@@ -869,17 +929,25 @@ class Sentinel2Collection:
|
|
|
869
929
|
|
|
870
930
|
# If an export path is provided, the area data will be exported to a CSV file
|
|
871
931
|
if area_data_export_path:
|
|
872
|
-
Sentinel2Collection(collection=self._PixelAreaSumCollection).
|
|
932
|
+
Sentinel2Collection(collection=self._PixelAreaSumCollection).exportProperties(property_names=prop_names, file_path=area_data_export_path+'.csv')
|
|
873
933
|
# Returning the result in the desired format based on output_type argument or raising an error for invalid input
|
|
874
934
|
if output_type == 'ImageCollection' or output_type == 'ee.ImageCollection':
|
|
875
935
|
return self._PixelAreaSumCollection
|
|
876
936
|
elif output_type == 'Sentinel2Collection':
|
|
877
937
|
return Sentinel2Collection(collection=self._PixelAreaSumCollection)
|
|
878
938
|
elif output_type == 'DataFrame' or output_type == 'Pandas' or output_type == 'pd' or output_type == 'dataframe' or output_type == 'df':
|
|
879
|
-
return Sentinel2Collection(collection=self._PixelAreaSumCollection).
|
|
939
|
+
return Sentinel2Collection(collection=self._PixelAreaSumCollection).exportProperties(property_names=prop_names)
|
|
880
940
|
else:
|
|
881
941
|
raise ValueError("Incorrect `output_type`. The `output_type` argument must be one of the following: 'ImageCollection', 'ee.ImageCollection', 'Sentinel2Collection', 'DataFrame', 'Pandas', 'pd', 'dataframe', or 'df'.")
|
|
882
942
|
|
|
943
|
+
def PixelAreaSumCollection(
|
|
944
|
+
self, band_name, geometry, threshold=-1, scale=10, maxPixels=1e12, output_type='ImageCollection', area_data_export_path=None
|
|
945
|
+
):
|
|
946
|
+
warnings.warn("PixelAreaSumCollection is deprecated. Please use pixelAreaSumCollection instead.",
|
|
947
|
+
DeprecationWarning,
|
|
948
|
+
stacklevel=2)
|
|
949
|
+
return self.pixelAreaSumCollection(band_name, geometry, threshold, scale, maxPixels, output_type, area_data_export_path)
|
|
950
|
+
|
|
883
951
|
@staticmethod
|
|
884
952
|
def add_month_property_fn(image):
|
|
885
953
|
"""
|
|
@@ -960,8 +1028,13 @@ class Sentinel2Collection:
|
|
|
960
1028
|
return Sentinel2Collection(collection=ee.ImageCollection(paired.map(_pair_two)))
|
|
961
1029
|
|
|
962
1030
|
# Preferred path: merge many singleband products into the parent
|
|
963
|
-
if not isinstance(collections, list) or len(collections) == 0:
|
|
964
|
-
|
|
1031
|
+
# if not isinstance(collections, list) or len(collections) == 0:
|
|
1032
|
+
# raise ValueError("Provide a non-empty list of Sentinel2Collection objects in `collections`.")
|
|
1033
|
+
if not isinstance(collections, list):
|
|
1034
|
+
collections = [collections]
|
|
1035
|
+
|
|
1036
|
+
if len(collections) == 0:
|
|
1037
|
+
raise ValueError("Provide a non-empty list of LandsatCollection objects in `collections`.")
|
|
965
1038
|
|
|
966
1039
|
result = self.collection
|
|
967
1040
|
for extra in collections:
|
|
@@ -1018,7 +1091,7 @@ class Sentinel2Collection:
|
|
|
1018
1091
|
self._dates = dates
|
|
1019
1092
|
return self._dates
|
|
1020
1093
|
|
|
1021
|
-
def
|
|
1094
|
+
def exportProperties(self, property_names, file_path=None):
|
|
1022
1095
|
"""
|
|
1023
1096
|
Fetches and returns specified properties from each image in the collection as a list, and returns a pandas DataFrame and optionally saves the results to a csv file.
|
|
1024
1097
|
|
|
@@ -1073,6 +1146,13 @@ class Sentinel2Collection:
|
|
|
1073
1146
|
print(f"Properties saved to {file_path}")
|
|
1074
1147
|
|
|
1075
1148
|
return df
|
|
1149
|
+
|
|
1150
|
+
def ExportProperties(self, property_names, file_path=None):
|
|
1151
|
+
warnings.warn(
|
|
1152
|
+
"The `ExportProperties` method is deprecated and will be removed in future versions. Please use the `exportProperties` method instead.",
|
|
1153
|
+
DeprecationWarning,
|
|
1154
|
+
stacklevel=2)
|
|
1155
|
+
return self.exportProperties(property_names, file_path)
|
|
1076
1156
|
|
|
1077
1157
|
def get_filtered_collection(self):
|
|
1078
1158
|
"""
|
|
@@ -2678,7 +2758,7 @@ class Sentinel2Collection:
|
|
|
2678
2758
|
Sentinel2Collection: Sentinel2Collection image collection.
|
|
2679
2759
|
"""
|
|
2680
2760
|
if self._masked_water_collection is None:
|
|
2681
|
-
col = self.collection.map(Sentinel2Collection.
|
|
2761
|
+
col = self.collection.map(Sentinel2Collection.maskWater)
|
|
2682
2762
|
self._masked_water_collection = Sentinel2Collection(collection=col)
|
|
2683
2763
|
return self._masked_water_collection
|
|
2684
2764
|
|
|
@@ -2690,7 +2770,7 @@ class Sentinel2Collection:
|
|
|
2690
2770
|
Sentinel2Collection: Sentinel2Collection image collection.
|
|
2691
2771
|
"""
|
|
2692
2772
|
col = self.collection.map(
|
|
2693
|
-
lambda image: Sentinel2Collection.
|
|
2773
|
+
lambda image: Sentinel2Collection.maskWaterByNDWI(
|
|
2694
2774
|
image, threshold=threshold
|
|
2695
2775
|
)
|
|
2696
2776
|
)
|
|
@@ -2705,7 +2785,7 @@ class Sentinel2Collection:
|
|
|
2705
2785
|
Sentinel2Collection: Sentinel2Collection image collection.
|
|
2706
2786
|
"""
|
|
2707
2787
|
if self._masked_to_water_collection is None:
|
|
2708
|
-
col = self.collection.map(Sentinel2Collection.
|
|
2788
|
+
col = self.collection.map(Sentinel2Collection.maskToWater)
|
|
2709
2789
|
self._masked_water_collection = Sentinel2Collection(collection=col)
|
|
2710
2790
|
return self._masked_water_collection
|
|
2711
2791
|
|
|
@@ -2717,7 +2797,7 @@ class Sentinel2Collection:
|
|
|
2717
2797
|
Sentinel2Collection: Sentinel2Collection image collection.
|
|
2718
2798
|
"""
|
|
2719
2799
|
col = self.collection.map(
|
|
2720
|
-
lambda image: Sentinel2Collection.
|
|
2800
|
+
lambda image: Sentinel2Collection.maskToWaterByNDWI(
|
|
2721
2801
|
image, threshold=threshold
|
|
2722
2802
|
)
|
|
2723
2803
|
)
|
|
@@ -2732,7 +2812,7 @@ class Sentinel2Collection:
|
|
|
2732
2812
|
Sentinel2Collection: masked Sentinel2Collection image collection.
|
|
2733
2813
|
"""
|
|
2734
2814
|
if self._masked_clouds_collection is None:
|
|
2735
|
-
col = self.collection.map(Sentinel2Collection.
|
|
2815
|
+
col = self.collection.map(Sentinel2Collection.maskClouds)
|
|
2736
2816
|
self._masked_clouds_collection = Sentinel2Collection(collection=col)
|
|
2737
2817
|
return self._masked_clouds_collection
|
|
2738
2818
|
|
|
@@ -2745,7 +2825,7 @@ class Sentinel2Collection:
|
|
|
2745
2825
|
Sentinel2Collection: Sentinel2Collection image collection
|
|
2746
2826
|
"""
|
|
2747
2827
|
if self._masked_shadows_collection is None:
|
|
2748
|
-
col = self.collection.map(Sentinel2Collection.
|
|
2828
|
+
col = self.collection.map(Sentinel2Collection.maskShadows)
|
|
2749
2829
|
self._masked_shadows_collection = Sentinel2Collection(collection=col)
|
|
2750
2830
|
return self._masked_shadows_collection
|
|
2751
2831
|
|
|
@@ -2760,20 +2840,15 @@ class Sentinel2Collection:
|
|
|
2760
2840
|
Sentinel2Collection: masked Sentinel2Collection image collection.
|
|
2761
2841
|
|
|
2762
2842
|
"""
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
mask = ee.Image.constant(1).clip(polygon)
|
|
2843
|
+
# Convert the polygon to a mask
|
|
2844
|
+
mask = ee.Image.constant(1).clip(polygon)
|
|
2766
2845
|
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
# Update the internal collection state
|
|
2771
|
-
self._geometry_masked_collection = Sentinel2Collection(
|
|
2772
|
-
collection=masked_collection
|
|
2773
|
-
)
|
|
2846
|
+
# Update the mask of each image in the collection
|
|
2847
|
+
masked_collection = self.collection.map(lambda img: img.updateMask(mask)\
|
|
2848
|
+
.copyProperties(img).set('system:time_start', img.get('system:time_start')))
|
|
2774
2849
|
|
|
2775
2850
|
# Return the updated object
|
|
2776
|
-
return
|
|
2851
|
+
return Sentinel2Collection(collection=masked_collection)
|
|
2777
2852
|
|
|
2778
2853
|
def mask_out_polygon(self, polygon):
|
|
2779
2854
|
"""
|
|
@@ -2786,23 +2861,17 @@ class Sentinel2Collection:
|
|
|
2786
2861
|
Sentinel2Collection: masked Sentinel2Collection image collection.
|
|
2787
2862
|
|
|
2788
2863
|
"""
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
full_mask = ee.Image.constant(1)
|
|
2792
|
-
|
|
2793
|
-
# Use paint to set pixels inside polygon as 0
|
|
2794
|
-
area = full_mask.paint(polygon, 0)
|
|
2864
|
+
# Convert the polygon to a mask
|
|
2865
|
+
full_mask = ee.Image.constant(1)
|
|
2795
2866
|
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
# Update the internal collection state
|
|
2800
|
-
self._geometry_masked_out_collection = Sentinel2Collection(
|
|
2801
|
-
collection=masked_collection
|
|
2802
|
-
)
|
|
2867
|
+
# Use paint to set pixels inside polygon as 0
|
|
2868
|
+
area = full_mask.paint(polygon, 0)
|
|
2803
2869
|
|
|
2870
|
+
# Update the mask of each image in the collection
|
|
2871
|
+
masked_collection = self.collection.map(lambda img: img.updateMask(area)\
|
|
2872
|
+
.copyProperties(img).set('system:time_start', img.get('system:time_start')))
|
|
2804
2873
|
# Return the updated object
|
|
2805
|
-
return
|
|
2874
|
+
return Sentinel2Collection(collection=masked_collection)
|
|
2806
2875
|
|
|
2807
2876
|
def mask_halite(self, threshold):
|
|
2808
2877
|
"""
|
|
@@ -2977,6 +3046,9 @@ class Sentinel2Collection:
|
|
|
2977
3046
|
|
|
2978
3047
|
if geometry is not None and not isinstance(geometry, ee.Geometry):
|
|
2979
3048
|
raise ValueError(f'The chosen `geometry`: {geometry} is not a valid ee.Geometry object.')
|
|
3049
|
+
|
|
3050
|
+
native_projection = image_collection.first().select(target_band).projection()
|
|
3051
|
+
|
|
2980
3052
|
# define the join, which will join all images newer than the current image
|
|
2981
3053
|
# use system:time_start if the image does not have a Date_Filter property
|
|
2982
3054
|
if join_method == 'system:time_start':
|
|
@@ -3032,7 +3104,7 @@ class Sentinel2Collection:
|
|
|
3032
3104
|
# convert the image collection to an image of s_statistic values per pixel
|
|
3033
3105
|
# where the s_statistic is the sum of partial s values
|
|
3034
3106
|
# renaming the band as 's_statistic' for later usage
|
|
3035
|
-
final_s_image = partial_s_col.sum().rename('s_statistic')
|
|
3107
|
+
final_s_image = partial_s_col.sum().rename('s_statistic').setDefaultProjection(native_projection)
|
|
3036
3108
|
|
|
3037
3109
|
|
|
3038
3110
|
########## PART 2 - VARIANCE and Z-SCORE ##########
|
|
@@ -3095,7 +3167,7 @@ class Sentinel2Collection:
|
|
|
3095
3167
|
mask = ee.Image(1).clip(geometry)
|
|
3096
3168
|
final_image = final_image.updateMask(mask)
|
|
3097
3169
|
|
|
3098
|
-
return final_image
|
|
3170
|
+
return final_image.setDefaultProjection(native_projection)
|
|
3099
3171
|
|
|
3100
3172
|
def sens_slope_trend(self, target_band=None, join_method='system:time_start', geometry=None):
|
|
3101
3173
|
"""
|
|
@@ -3130,6 +3202,8 @@ class Sentinel2Collection:
|
|
|
3130
3202
|
|
|
3131
3203
|
if geometry is not None and not isinstance(geometry, ee.Geometry):
|
|
3132
3204
|
raise ValueError(f'The chosen `geometry`: {geometry} is not a valid ee.Geometry object.')
|
|
3205
|
+
|
|
3206
|
+
native_projection = image_collection.first().select(target_band).projection()
|
|
3133
3207
|
|
|
3134
3208
|
# Add Year Band (Time X-Axis)
|
|
3135
3209
|
def add_year_band(image):
|
|
@@ -3158,7 +3232,7 @@ class Sentinel2Collection:
|
|
|
3158
3232
|
mask = ee.Image(1).clip(geometry)
|
|
3159
3233
|
slope_band = slope_band.updateMask(mask)
|
|
3160
3234
|
|
|
3161
|
-
return slope_band
|
|
3235
|
+
return slope_band.setDefaultProjection(native_projection)
|
|
3162
3236
|
|
|
3163
3237
|
|
|
3164
3238
|
def mask_via_band(self, band_to_mask, band_for_mask, threshold=-1, mask_above=True, add_band_to_original_image=False):
|
|
@@ -3302,7 +3376,7 @@ class Sentinel2Collection:
|
|
|
3302
3376
|
new_col = self.collection.filter(ee.Filter.eq("Date_Filter", img_date))
|
|
3303
3377
|
return new_col.first()
|
|
3304
3378
|
|
|
3305
|
-
def
|
|
3379
|
+
def collectionStitch(self, img_col2):
|
|
3306
3380
|
"""
|
|
3307
3381
|
Function to mosaic two Sentinel2Collection objects which share image dates.
|
|
3308
3382
|
Mosaics are only formed for dates where both image collections have images.
|
|
@@ -3356,8 +3430,15 @@ class Sentinel2Collection:
|
|
|
3356
3430
|
# Return a Sentinel2Collection instance
|
|
3357
3431
|
return Sentinel2Collection(collection=new_col)
|
|
3358
3432
|
|
|
3433
|
+
def CollectionStitch(self, img_col2):
|
|
3434
|
+
warnings.warn(
|
|
3435
|
+
"The `CollectionStitch` method is deprecated and will be removed in future versions. Please use the `collectionStitch` method instead.",
|
|
3436
|
+
DeprecationWarning,
|
|
3437
|
+
stacklevel=2)
|
|
3438
|
+
return self.collectionStitch(img_col2)
|
|
3439
|
+
|
|
3359
3440
|
@property
|
|
3360
|
-
def
|
|
3441
|
+
def mosaicByDateDepr(self):
|
|
3361
3442
|
"""
|
|
3362
3443
|
Property attribute function to mosaic collection images that share the same date. The properties CLOUD_PIXEL_PERCENTAGE and NODATA_PIXEL_PERCENTAGE
|
|
3363
3444
|
for each image are used to calculate an overall mean, which replaces the CLOUD_PIXEL_PERCENTAGE and NODATA_PIXEL_PERCENTAGE for each mosaiced image.
|
|
@@ -3423,6 +3504,76 @@ class Sentinel2Collection:
|
|
|
3423
3504
|
self._MosaicByDate = col
|
|
3424
3505
|
|
|
3425
3506
|
return self._MosaicByDate
|
|
3507
|
+
|
|
3508
|
+
@property
|
|
3509
|
+
def mosaicByDate(self):
|
|
3510
|
+
"""
|
|
3511
|
+
Property attribute function to mosaic collection images that share the same date.
|
|
3512
|
+
|
|
3513
|
+
The property CLOUD_COVER for each image is used to calculate an overall mean,
|
|
3514
|
+
which replaces the CLOUD_COVER property for each mosaiced image.
|
|
3515
|
+
Server-side friendly.
|
|
3516
|
+
|
|
3517
|
+
NOTE: if images are removed from the collection from cloud filtering, you may have mosaics composed of only one image.
|
|
3518
|
+
|
|
3519
|
+
Returns:
|
|
3520
|
+
LandsatCollection: LandsatCollection image collection with mosaiced imagery and mean CLOUD_COVER as a property
|
|
3521
|
+
"""
|
|
3522
|
+
if self._MosaicByDate is None:
|
|
3523
|
+
distinct_dates = self.collection.distinct("Date_Filter")
|
|
3524
|
+
|
|
3525
|
+
# Define a join to link images by Date_Filter
|
|
3526
|
+
filter_date = ee.Filter.equals(leftField="Date_Filter", rightField="Date_Filter")
|
|
3527
|
+
join = ee.Join.saveAll(matchesKey="date_matches")
|
|
3528
|
+
|
|
3529
|
+
# Apply the join
|
|
3530
|
+
# Primary: Distinct dates collection
|
|
3531
|
+
# Secondary: The full original collection
|
|
3532
|
+
joined_col = ee.ImageCollection(join.apply(distinct_dates, self.collection, filter_date))
|
|
3533
|
+
|
|
3534
|
+
# Define the mosaicking function
|
|
3535
|
+
def _mosaic_day(img):
|
|
3536
|
+
# Recover the list of images for this day
|
|
3537
|
+
daily_list = ee.List(img.get("date_matches"))
|
|
3538
|
+
daily_col = ee.ImageCollection.fromImages(daily_list)
|
|
3539
|
+
|
|
3540
|
+
# Create the mosaic
|
|
3541
|
+
mosaic = daily_col.mosaic().setDefaultProjection(img.projection())
|
|
3542
|
+
|
|
3543
|
+
# Calculate means for Sentinel-2 specific props
|
|
3544
|
+
cloud_pct = daily_col.aggregate_mean("CLOUDY_PIXEL_PERCENTAGE")
|
|
3545
|
+
nodata_pct = daily_col.aggregate_mean("NODATA_PIXEL_PERCENTAGE")
|
|
3546
|
+
|
|
3547
|
+
# Properties to preserve from the representative image
|
|
3548
|
+
props_of_interest = [
|
|
3549
|
+
"SPACECRAFT_NAME",
|
|
3550
|
+
"SENSING_ORBIT_NUMBER",
|
|
3551
|
+
"SENSING_ORBIT_DIRECTION",
|
|
3552
|
+
"MISSION_ID",
|
|
3553
|
+
"PLATFORM_IDENTIFIER",
|
|
3554
|
+
"system:time_start"
|
|
3555
|
+
]
|
|
3556
|
+
|
|
3557
|
+
# Return mosaic with properties set
|
|
3558
|
+
return mosaic.copyProperties(img, props_of_interest).set({
|
|
3559
|
+
"CLOUDY_PIXEL_PERCENTAGE": cloud_pct,
|
|
3560
|
+
"NODATA_PIXEL_PERCENTAGE": nodata_pct
|
|
3561
|
+
})
|
|
3562
|
+
|
|
3563
|
+
# 5. Map the function and wrap the result
|
|
3564
|
+
mosaiced_col = joined_col.map(_mosaic_day)
|
|
3565
|
+
self._MosaicByDate = Sentinel2Collection(collection=mosaiced_col)
|
|
3566
|
+
|
|
3567
|
+
# Convert the list of mosaics to an ImageCollection
|
|
3568
|
+
return self._MosaicByDate
|
|
3569
|
+
|
|
3570
|
+
@property
|
|
3571
|
+
def MosaicByDate(self):
|
|
3572
|
+
warnings.warn(
|
|
3573
|
+
"The `MosaicByDate` property is deprecated and will be removed in future versions. Please use the `mosaicByDate` property instead.",
|
|
3574
|
+
DeprecationWarning,
|
|
3575
|
+
stacklevel=2)
|
|
3576
|
+
return self.mosaicByDate
|
|
3426
3577
|
|
|
3427
3578
|
@staticmethod
|
|
3428
3579
|
def ee_to_df(
|
RadGEEToolbox/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
__version__ = "1.7.
|
|
1
|
+
__version__ = "1.7.4"
|
|
2
2
|
|
|
3
|
-
from .CollectionStitch import
|
|
3
|
+
from .CollectionStitch import collectionStitch, mosaicByDate
|
|
4
4
|
from .Export import ExportToDrive
|
|
5
5
|
from .GetPalette import get_palette
|
|
6
6
|
from .LandsatCollection import LandsatCollection
|
|
@@ -10,9 +10,9 @@ from .GenericCollection import GenericCollection
|
|
|
10
10
|
from .VisParams import get_visualization_params
|
|
11
11
|
|
|
12
12
|
__all__ = [
|
|
13
|
-
"
|
|
13
|
+
"collectionStitch",
|
|
14
14
|
"ExportToDrive",
|
|
15
|
-
"
|
|
15
|
+
"mosaicByDate",
|
|
16
16
|
"get_palette",
|
|
17
17
|
"LandsatCollection",
|
|
18
18
|
"Sentinel1Collection",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: RadGEEToolbox
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.4
|
|
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
|
|
@@ -43,7 +43,7 @@ Designed for both new and advanced users of Google Earth Engine, RadGEEToolbox m
|
|
|
43
43
|
|
|
44
44
|
Although similar packages exist (eemont, geetools, etc.), `RadGEEToolbox` extends functionality and provides cohesive, chainable methods for research oriented projects working with Landsat TM & OLI, Sentinel-1 SAR, and/or Sentinel-2 MSI datasets (Table 1). The ultimate goal of `RadGEEToolbox` is to make satellite image processing easier and faster for real world applications relying on the most commonly utilized remote sensing platforms.
|
|
45
45
|
|
|
46
|
-
As of version `1.7.
|
|
46
|
+
As of version `1.7.4`, `RadGEEToolbox` supports any generic image collection via the `GenericCollection` module which allows for utilization of the same data management, temporal reduction, zonal statistics, and data export tools available for the `LandsatCollection`, `Sentinel1Collection`, and `Sentinel2Collection` modules. This allows users to provide their own image collection of choice, such as PRISM or MODIS data, to benefit from the tools available with `RadGEEToolbox`.
|
|
47
47
|
|
|
48
48
|
***Table 1.*** *Comparison of functionality between RadGEEToolbox, eemont, and geetools.*
|
|
49
49
|
|
|
@@ -185,15 +185,15 @@ _____________
|
|
|
185
185
|
|
|
186
186
|
### Installing via pip
|
|
187
187
|
|
|
188
|
-
To install `RadGEEToolbox` version 1.7.
|
|
188
|
+
To install `RadGEEToolbox` version 1.7.4 using pip (NOTE: it is recommended to create a new virtual environment):
|
|
189
189
|
|
|
190
190
|
```bash
|
|
191
|
-
pip install RadGEEToolbox==1.7.
|
|
191
|
+
pip install RadGEEToolbox==1.7.4
|
|
192
192
|
```
|
|
193
193
|
|
|
194
194
|
### Installing via Conda
|
|
195
195
|
|
|
196
|
-
To install `RadGEEToolbox` version 1.7.
|
|
196
|
+
To install `RadGEEToolbox` version 1.7.4 using conda-forge (NOTE: it is recommended to create a new virtual environment):
|
|
197
197
|
|
|
198
198
|
```bash
|
|
199
199
|
conda install conda-forge::radgeetoolbox
|
|
@@ -224,7 +224,7 @@ To verify that `RadGEEToolbox` was installed correctly:
|
|
|
224
224
|
python -c "import RadGEEToolbox; print(RadGEEToolbox.__version__)"
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
You should see `1.7.
|
|
227
|
+
You should see `1.7.4` printed as the version number.
|
|
228
228
|
|
|
229
229
|
### Want to Visualize Data? Install These Too
|
|
230
230
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
RadGEEToolbox/CollectionStitch.py,sha256=za_UHSgPqkflNcapg42ruu8-Mk6QCeRNQi3fPx2SMvU,4399
|
|
2
|
+
RadGEEToolbox/Export.py,sha256=FLQZw6Hy3iwYxsLqV1HomGex3pZo9ynUr5FoiP15Cfk,11017
|
|
3
|
+
RadGEEToolbox/GenericCollection.py,sha256=pUdjxsFCXBjYDBxqbvnIx3N7XBvzUhqvTBDEoG0ZW4k,174261
|
|
4
|
+
RadGEEToolbox/GetPalette.py,sha256=Ve7vYzs0EYHZyvFwaB_k8FR4uo5RRDy4pcq7eBK9yM0,7145
|
|
5
|
+
RadGEEToolbox/LandsatCollection.py,sha256=i6OAeFMp2iWPrmhdsBMukW2GkAeK0XV_vNEHkaZbHSs,246222
|
|
6
|
+
RadGEEToolbox/Sentinel1Collection.py,sha256=J73mcL0sjVTUYxs7x7nzBtMMRAbSkQOpMEzqbZZNqPU,164138
|
|
7
|
+
RadGEEToolbox/Sentinel2Collection.py,sha256=rvkBmr3se6nHCaduuNaKjkZ172p5tOZug_NBRMnSzZ8,213228
|
|
8
|
+
RadGEEToolbox/VisParams.py,sha256=ONjnJd83jfaM1r-hbtlcIxiBOGMoJGtdHF0mw1iaw5c,8183
|
|
9
|
+
RadGEEToolbox/__init__.py,sha256=Z-zYmSkUHwNTz4X5FQP1bBzAGprcF-pwH50yFyJ388c,663
|
|
10
|
+
radgeetoolbox-1.7.4.dist-info/licenses/LICENSE.txt,sha256=5Xj9dwVkawz6d8zhCwJy0SmXvm0U4K_msJnOrkHLO1w,1089
|
|
11
|
+
radgeetoolbox-1.7.4.dist-info/METADATA,sha256=E19ilMYT7Scq8ImzeOXZkfH65ib4fOM0mH7QDfehMeA,17737
|
|
12
|
+
radgeetoolbox-1.7.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
radgeetoolbox-1.7.4.dist-info/top_level.txt,sha256=W2E520tugQoptDkhctKFbzsheL2l_DyYLKqKXkD9G_E,14
|
|
14
|
+
radgeetoolbox-1.7.4.dist-info/RECORD,,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
RadGEEToolbox/CollectionStitch.py,sha256=dLRzJZLZ1QTJqqbWPElyTjxb1m0T_WuBTo6wNzcCXq4,3884
|
|
2
|
-
RadGEEToolbox/Export.py,sha256=H815I3uqs3M-pPcStRiseDbK1y3VWhIMRmH0XuCqGA4,10470
|
|
3
|
-
RadGEEToolbox/GenericCollection.py,sha256=MF8kBNEf1PjlzVTKMQ9IKVGISrxDgudvxrOMpxv7KMI,169993
|
|
4
|
-
RadGEEToolbox/GetPalette.py,sha256=Ve7vYzs0EYHZyvFwaB_k8FR4uo5RRDy4pcq7eBK9yM0,7145
|
|
5
|
-
RadGEEToolbox/LandsatCollection.py,sha256=JhkTfISIvSCHQ853MKi7Lgh8bv9vpwZC018pwzkzo6s,237720
|
|
6
|
-
RadGEEToolbox/Sentinel1Collection.py,sha256=IZqC33vW3m5pO8zRuKanISElB10dEVgCZEYAt_v_qhY,158637
|
|
7
|
-
RadGEEToolbox/Sentinel2Collection.py,sha256=bKwfSccjX-mvIf3awiSLBVGKFXaVZEXAMEu9O39aBy4,206150
|
|
8
|
-
RadGEEToolbox/VisParams.py,sha256=ONjnJd83jfaM1r-hbtlcIxiBOGMoJGtdHF0mw1iaw5c,8183
|
|
9
|
-
RadGEEToolbox/__init__.py,sha256=cWtHRpPpNh1vo3DWsp_4d96QRZwMe25mS-Zz0bvoOSE,663
|
|
10
|
-
radgeetoolbox-1.7.3.dist-info/licenses/LICENSE.txt,sha256=5Xj9dwVkawz6d8zhCwJy0SmXvm0U4K_msJnOrkHLO1w,1089
|
|
11
|
-
radgeetoolbox-1.7.3.dist-info/METADATA,sha256=vQig4v_Ie9opc7LCvXjXPCDRpxMW-G1qUKXh5vGQu5k,17737
|
|
12
|
-
radgeetoolbox-1.7.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
-
radgeetoolbox-1.7.3.dist-info/top_level.txt,sha256=W2E520tugQoptDkhctKFbzsheL2l_DyYLKqKXkD9G_E,14
|
|
14
|
-
radgeetoolbox-1.7.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|