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([[-1.15678064,  0.04569194, -0.65803448],
       [ 0.24859086, -1.02120985,  0.43843843]])
Coordinates:
  * x        (x) int64 16B 10 20
Dimensions without coordinates: y

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

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-b2d13b66c2943e829fbd41033004fd37<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
    ...                  ...
    AREA_OR_POINT:       Area
    DataType:            Generic
    filename:            /home/docs/checkouts/readthedocs.org/user_builds/geo...
    resampling:          nearest
    _data_are_separate:  0
    _data_are_stacked:   0
<geowombat.core.geoxarray.GeoWombatAccessor object at 0x7f27f9d75910>

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)