Skip to content

Commit db1fc4a

Browse files
committed
rearrange the Array to process the given rgb array by scale_percentile instead of the surface reflectance function
1 parent b012e79 commit db1fc4a

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

cleopatra/array.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ def __init__(
3939
exclude_value: List = np.nan,
4040
extent: List = None,
4141
rgb: List[int] = None,
42-
surface_reflectance: int = 10000,
42+
surface_reflectance: int = None,
4343
cutoff: List = None,
4444
ax: Axes = None,
4545
fig: Figure = None,
46+
percentile: int = 1,
4647
**kwargs,
4748
):
4849
"""Array.
@@ -62,6 +63,8 @@ def __init__(
6263
cutoff: List, Default is None.
6364
clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff
6465
and scale them back to between 0 and 1.
66+
percentile: int
67+
The percentile value to be used for scaling.
6568
6669
the object does not need any parameters to be initialized.
6770
@@ -105,11 +108,12 @@ def __init__(
105108
f"{array.shape[0]}"
106109
)
107110
else:
108-
array = self._prepare_sentinel_rgb(
111+
array = self.prepare_array(
109112
array,
110113
rgb=rgb,
111114
surface_reflectance=surface_reflectance,
112115
cutoff=cutoff,
116+
percentile=percentile,
113117
)
114118
else:
115119
self.rgb = False
@@ -141,14 +145,15 @@ def __init__(
141145
else:
142146
self.fig, self.ax = fig, ax
143147

144-
def _prepare_sentinel_rgb(
148+
def prepare_array(
145149
self,
146150
array: np.ndarray,
147151
rgb: List[int] = None,
148-
surface_reflectance: int = 10000,
152+
surface_reflectance: int = None,
149153
cutoff: List = None,
154+
percentile: int = 1,
150155
) -> np.ndarray:
151-
"""Prepare for RGB plot.
156+
"""Prepare Array.
152157
153158
Parameters
154159
----------
@@ -161,6 +166,8 @@ def _prepare_sentinel_rgb(
161166
cutoff: List, Default is None.
162167
clip the range of pixel values for each band. (take only the pixel values from 0 to the value of the cutoff
163168
and scale them back to between 0 and 1).
169+
percentile: int
170+
The percentile value to be used for scaling.
164171
165172
Returns
166173
-------
@@ -170,6 +177,44 @@ def _prepare_sentinel_rgb(
170177
# take the rgb arrays and reorder them to have the red-green-blue, if the order is not given, assume the
171178
# order as sentinel data. [3, 2, 1]
172179
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+
"""
173218
array = np.clip(array / surface_reflectance, 0, 1)
174219
if cutoff is not None:
175220
array[0] = np.clip(rgb[0], 0, cutoff[0]) / cutoff[0]

0 commit comments

Comments
 (0)