Skip to content

Commit 0363b4d

Browse files
committed
Update ogc_clients.py
Convert the image to RGBA. If the image is not in RGB(A) then the color is messed up during the regrid process if any. Remove the part handling RGB as the image is now RGBA.
1 parent 7f92c73 commit 0363b4d

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/cartopy/io/ogc_clients.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def _warped_located_image(image, source_projection, source_extent,
122122
else:
123123
# Convert Image to numpy array (flipping so that origin
124124
# is 'lower').
125-
img, extent = warp_array(np.asanyarray(image)[::-1],
125+
# Convert to RGBA to keep the color palette in the regrid process
126+
# if any
127+
img, extent = warp_array(np.asanyarray(image.convert('RGBA'))[::-1],
126128
source_proj=source_projection,
127129
source_extent=source_extent,
128130
target_proj=output_projection,
@@ -136,19 +138,9 @@ def _warped_located_image(image, source_projection, source_extent,
136138
# This avoids unsightly grey boundaries appearing when the
137139
# extent is limited (i.e. not global).
138140
if np.ma.is_masked(img):
139-
if img.shape[2:3] == (3,):
140-
# RGB
141-
old_img = img
142-
img = np.zeros(img.shape[:2] + (4,), dtype=img.dtype)
143-
img[:, :, 0:3] = old_img
144-
img[:, :, 3] = ~ np.any(old_img.mask, axis=2)
145-
if img.dtype.kind == 'u':
146-
img[:, :, 3] *= 255
147-
elif img.shape[2:3] == (4,):
148-
# RGBA
149-
img[:, :, 3] = np.where(np.any(img.mask, axis=2), 0,
150-
img[:, :, 3])
151-
img = img.data
141+
img[:, :, 3] = np.where(np.any(img.mask, axis=2), 0,
142+
img[:, :, 3])
143+
img = img.data
152144

153145
# Convert warped image array back to an Image, undoing the
154146
# earlier flip.

0 commit comments

Comments
 (0)