@@ -39,10 +39,11 @@ def __init__(
39
39
exclude_value : List = np .nan ,
40
40
extent : List = None ,
41
41
rgb : List [int ] = None ,
42
- surface_reflectance : int = 10000 ,
42
+ surface_reflectance : int = None ,
43
43
cutoff : List = None ,
44
44
ax : Axes = None ,
45
45
fig : Figure = None ,
46
+ percentile : int = 1 ,
46
47
** kwargs ,
47
48
):
48
49
"""Array.
@@ -62,6 +63,8 @@ def __init__(
62
63
cutoff: List, Default is None.
63
64
clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff
64
65
and scale them back to between 0 and 1.
66
+ percentile: int
67
+ The percentile value to be used for scaling.
65
68
66
69
the object does not need any parameters to be initialized.
67
70
@@ -105,11 +108,12 @@ def __init__(
105
108
f"{ array .shape [0 ]} "
106
109
)
107
110
else :
108
- array = self ._prepare_sentinel_rgb (
111
+ array = self .prepare_array (
109
112
array ,
110
113
rgb = rgb ,
111
114
surface_reflectance = surface_reflectance ,
112
115
cutoff = cutoff ,
116
+ percentile = percentile ,
113
117
)
114
118
else :
115
119
self .rgb = False
@@ -141,14 +145,15 @@ def __init__(
141
145
else :
142
146
self .fig , self .ax = fig , ax
143
147
144
- def _prepare_sentinel_rgb (
148
+ def prepare_array (
145
149
self ,
146
150
array : np .ndarray ,
147
151
rgb : List [int ] = None ,
148
- surface_reflectance : int = 10000 ,
152
+ surface_reflectance : int = None ,
149
153
cutoff : List = None ,
154
+ percentile : int = 1 ,
150
155
) -> np .ndarray :
151
- """Prepare for RGB plot .
156
+ """Prepare Array .
152
157
153
158
Parameters
154
159
----------
@@ -161,6 +166,8 @@ def _prepare_sentinel_rgb(
161
166
cutoff: List, Default is None.
162
167
clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff
163
168
and scale them back to between 0 and 1).
169
+ percentile: int
170
+ The percentile value to be used for scaling.
164
171
165
172
Returns
166
173
-------
@@ -170,6 +177,44 @@ def _prepare_sentinel_rgb(
170
177
# take the rgb arrays and reorder them to have the red-green-blue, if the order is not given, assume the
171
178
# order as sentinel data. [3, 2, 1]
172
179
array = array [rgb ].transpose (1 , 2 , 0 )
180
+
181
+ if surface_reflectance is None :
182
+ array = self .scale_percentile (array , percentile = percentile )
183
+ else :
184
+ array = self ._prepare_sentinel_rgb (
185
+ array ,
186
+ rgb = rgb ,
187
+ surface_reflectance = surface_reflectance ,
188
+ cutoff = cutoff ,
189
+ )
190
+ return array
191
+
192
+ def _prepare_sentinel_rgb (
193
+ self ,
194
+ array : np .ndarray ,
195
+ rgb : List [int ] = None ,
196
+ surface_reflectance : int = 10000 ,
197
+ cutoff : List = None ,
198
+ ) -> np .ndarray :
199
+ """Prepare for RGB plot.
200
+
201
+ Parameters
202
+ ----------
203
+ array: np.ndarray
204
+ array.
205
+ rgb: List, Default is [3,2,1]
206
+ the indices of the red, green, and blue bands in the given array.
207
+ surface_reflectance: int, Default is 10000.
208
+ surface reflectance value of the sentinel data.
209
+ cutoff: List, Default is None.
210
+ clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff
211
+ and scale them back to between 0 and 1).
212
+
213
+ Returns
214
+ -------
215
+ np.ndarray:
216
+ the rgb 3d array is converted into 2d array to be plotted using the plt.imshow function.
217
+ """
173
218
array = np .clip (array / surface_reflectance , 0 , 1 )
174
219
if cutoff is not None :
175
220
array [0 ] = np .clip (rgb [0 ], 0 , cutoff [0 ]) / cutoff [0 ]
0 commit comments