I am using depth argument in the function da.map_overlap to provide the buffer boundary for my interpolation method usage. However, some situations happened that I didn’t know how to solve. Could anyone help me with this?
Question 01: cannot directly using .compute()
Question 02: cannot trim the buffer
Please see my code below.
Code:
Step 01: Convert to dask.array
slon = da.from_array(lon, chunks=(400,400))
slat = da.from_array(lat, chunks=(400,400))
sdat = da.from_array(data,chunks=(400,400))
Step 2: define a function for map_overlap use
def tantan2(lon,lat,data, hex_res=10):
#-- Generate the parameters for h3 and shapely.geometry usage.
hex_col = 'hex' + str(hex_res)
lon_max, lon_min = lon.max(), lon.min()
lat_max, lat_min = lat.max(), lat.min()
#-- Using shapely.geometry.box to generate domain bounds for h3
b = box(lon_min, lat_min, lon_max, lat_max, ccw=True)
b = transform(lambda x, y: (y, x), b)
b = mapping(b)
#-- Using Pandas to generate h3 hexagonal grid with associated long/lat
target_df = pd.DataFrame(h3.polyfill( b, hex_res), columns=[hex_col])
target_df['lat'] = target_df[hex_col].apply(lambda x: h3.h3_to_geo(x)[0])
target_df['lon'] = target_df[hex_col].apply(lambda x: h3.h3_to_geo(x)[1])
tlon, tlat = target_df[['lon','lat']].values.T
#-- Using the input lon/lat and generated h3-lon/lat for interpoaltion
abc = lNDI(points=(lon.ravel(), lat.ravel()),
values= data.ravel())(tlon,tlat)
#-- stack target h3-lon/lat and interpolation output and send it to return.
dec = np.stack([tlon, tlat, abc],axis=1)
return dec
Step 3: apply da.map_overlap
c = da.map_overlap(tantan2,
slon,
slat,
data,
depth=10,
trim=True,
boundary=None,
align_arrays=False,
dtype='float64',
)
It looks like my output is changing the shape compared with the input array; therefore, my output always returns an empty array to me when trim=True. As such, because of the empty array, I kept receiving errors when using .compute().
In addition, if I turn the trim=False, the .compute() function is still not working. What I believe is because of the changing shape.
ValueError: could not broadcast input array from shape (1090,3) into shape (1065,3)
Any possible solution to trim the points in the buffer region?