I am trying to extract an image patch from Earth Engine imagery. The location of the patch coincides with the edge of a single image, so I first mosaic two adjacent images to form a bigger image that includes the patch, and then use sampleRectangle to extract the image patch. However, this returns the error "EEException: Image.sampleRectangle: Fully masked pixels / pixels outside of the image footprint when sampling band 'R' with no default value set."
Any idea what I should do?
Here is my full code:
import matplotlib.pyplot as plt
import numpy as np
import geemap
import ee
ee.Initialize()
patch = ee.Geometry.BBox(-113.01284266119998,33.7460453388,-113.01014333879999,33.74874466120001)
mosaic_img = ee.ImageCollection('USDA/NAIP/DOQQ') \
.filterDate('2007-05-01', '2007-07-01') \
.filterBounds(patch)\
.mosaic()
band_arrs = mosaic_img.sampleRectangle(region=patch)
band_arr_R = band_arrs.get('R')
band_arr_G = band_arrs.get('G')
band_arr_B = band_arrs.get('B')
np_arr_R = np.array(band_arr_R.getInfo())
np_arr_G = np.array(band_arr_G.getInfo())
np_arr_B = np.array(band_arr_B.getInfo())
np_arr_R = np.expand_dims(np_arr_R, 2)
np_arr_G = np.expand_dims(np_arr_G, 2)
np_arr_B = np.expand_dims(np_arr_B, 2)
rgb_img = np.concatenate((np_arr_R, np_arr_G, np_arr_B), 2).astype('uint8')
plt.imshow(rgb_img_test)