-
Notifications
You must be signed in to change notification settings - Fork 321
Using XArray and dask in satpy
Martin Raspaud edited this page Mar 1, 2018
·
24 revisions
import xarray as xrXArray's DataArray is now the standard data structure for arrays in satpy. They allow the array to have define dimensions, coordinates, and attributes (that we use for the metadata).
To create such an array, you can do for example
my_dataarray = xr.DataArray(my_data, dims=['y', 'x'],
coords={'x': np.arange(...)},
attrs={'sensor': 'olci'})my_data can be a regular numpy array, a numpy memmap, or, if you want to keep things lazy, a dask array (more on dask later).
In satpy, the dimension of the arrays should include
-
xfor the x or pixel dimension -
yfor the y or line dimension -
bandsfor composites -
timecan also be provided, but we have limited support for it at the moment. Use metadata for common cases (start_time,end_time)
Dimensions are accessible through my_dataarray.dims. To get the size of a given dimension, use sizes:
my_dataarray.sizes['x']Coordinates can be defined for those dimensions when it makes sense:
-
xandy: they are usually defined when the data's area is an AreaDefinition, and the contain the projection coordinates in x and y. -
bands: they contain the letter of the color they represent, eg['R', 'G', 'B']for an RGB composite.
This allows then to select for example a single band like this:
red = my_composite.sel(bands='R')or even multiple bands:
red_and_blue = my_composite.sel(bands=['R', 'B'])import dask.array as daHelpful functions:
map_blocksmap_overlapatopstoretokenize