Quick overview#
Here are some quick examples of what you can do with geowombat objects.
To begin, import GeoWombat and Xarray:
In [1]: import geowombat as gw
In [2]: import numpy as np
In [3]: import xarray as xr
Instantiate an xarray.DataArray with a GeoWombat accessor#
Any xarray.DataArray will have the geowombat accessors appended. That is, the xarray.DataArray will have
an xarray.DataArray.gw object.
In [4]: data = xr.DataArray(
...: np.random.randn(2, 3),
...: dims=('x', 'y'),
...: coords={'x': [10, 20]}
...: )
...:
In [5]: print(data)
<xarray.DataArray (x: 2, y: 3)> Size: 48B
array([[ 0.48921286, -0.04324876, -1.13817765],
[ 0.1304323 , -0.55332648, -1.50719617]])
Coordinates:
* x (x) int64 16B 10 20
Dimensions without coordinates: y
In [6]: print(data.gw)
<geowombat.core.geoxarray.GeoWombatAccessor object at 0x7f2348860090>
Open a raster file#
GeoWombat has its own file opening API through geowombat.open() (see Raster I/O for details).
In [7]: from geowombat.data import rgbn
In [8]: with gw.open(rgbn) as src:
...: print(src)
...: print(src.gw)
...:
<xarray.DataArray (band: 4, y: 403, x: 515)> Size: 830kB
dask.array<open_rasterio-e6ba7c4526a03bfa4f7e352b5b574cc7<this-array>, shape=(4, 403, 515), dtype=uint8, chunksize=(4, 64, 64), chunktype=numpy.ndarray>
Coordinates:
* band (band) int64 32B 1 2 3 4
* y (y) float64 3kB 2.05e+06 2.05e+06 2.05e+06 ... 2.048e+06 2.048e+06
* x (x) float64 4kB 7.93e+05 7.93e+05 7.93e+05 ... 7.956e+05 7.956e+05
Attributes: (12/14)
transform: (5.0, 0.0, 792988.0, 0.0, -5.0, 2050382.0)
crs: 32618
res: (5.0, 5.0)
is_tiled: 1
nodatavals: (nan, nan, nan, nan)
_FillValue: nan
... ...
filename: /home/docs/checkouts/readthedocs.org/user_builds/geo...
resampling: nearest
DataType: Generic
AREA_OR_POINT: Area
_data_are_separate: 0
_data_are_stacked: 0
<geowombat.core.geoxarray.GeoWombatAccessor object at 0x7f234856f1d0>
Write a raster#
Save an xarray.DataArray to file with geowombat.save().
import geowombat as gw
with gw.open(l8_224077_20200518_B4, chunks=1024) as src:
# Xarray drops attributes
attrs = src.attrs.copy()
# Apply operations on the DataArray
src = src * 10.0
src.attrs = attrs
# Write the data to a GeoTiff
src.gw.save('output.tif', num_workers=4)