I'd like to take raster (satellite imagery) data, and build a Dataset
or DataArray
, to speed up my image processing (I have to work on multi-band, multi-date satellite imagery a lot).
The data comes as individual bands for each image date, and I understand how to convert each band-date to an xarray-DataArray
. I assume it'd make most sense to have one variable for each band, and within each band have the spatial (x, y) and time dimensions.
However, I can't figure out how to do that.
I've been working with some dummy bands to try to figure this out, so will include that to clarify what my data looks like and what I'm trying to do.
# Set up dummy 3 x 3 array
dA = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# Create 4 dummy images; 2 bands for each of 2 dates (using bands 4 and 5,
# because they're useful for vegetation measures)
d1_b4 = xr.DataArray((dA + 140),
coords={'x': ['1', '2', '3'], 'y': ['a', 'b', 'c']}, dims=('x', 'y'))
d1_b5 = xr.DataArray((dA + 150),
coords={'x': ['1', '2', '3'], 'y': ['a', 'b', 'c']}, dims=('x', 'y'))
d2_b4 = xr.DataArray((dA + 240),
coords={'x': ['1', '2', '3'], 'y': ['a', 'b', 'c']}, dims=('x', 'y'))
d2_b5 = xr.DataArray((dA + 250),
coords={'x': ['1', '2', '3'], 'y': ['a', 'b', 'c']}, dims=('x', 'y'))
# dummy values designed so I can keep track of which array is going
# where while I learn this
Then I want to combine these into one DataArray
, with two variables (Band4 and Band5), each containing the two image dates... but don't know how to proceed.
Do I need to add more coordinates, or dimensions when I create/import the arrays, and then concat
along those dimensions?