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.03736887,  0.3822506 , -0.1281077 ],
       [ 1.12565292, -0.19720587, -0.71401116]])
Coordinates:
  * x        (x) int64 16B 10 20
Dimensions without coordinates: y

In [6]: print(data.gw)
<geowombat.core.geoxarray.GeoWombatAccessor object at 0x7f099d1e4520>

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-f76a38cf5a66a7e54eebac0d30c2d07f<this-array>, shape=(4, 403, 515), dtype=uint8, chunksize=(4, 64, 64), chunktype=numpy.ndarray>
Coordinates:
  * band     (band) int64 32B 1 2 3 4
  * x        (x) float64 4kB 7.93e+05 7.93e+05 7.93e+05 ... 7.956e+05 7.956e+05
  * y        (y) float64 3kB 2.05e+06 2.05e+06 2.05e+06 ... 2.048e+06 2.048e+06
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
    AREA_OR_POINT:       Area
    DataType:            Generic
    _data_are_separate:  0
    _data_are_stacked:   0
<geowombat.core.geoxarray.GeoWombatAccessor object at 0x7f099d17eeb0>

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)