CachedRasterRecipe

class buzzard.ASource(<implementation detail>)[source]

Base abstract class defining the common behavior of all sources opened in the Dataset.

Features Defined

  • Has a stored spatial reference

  • Has a virtual spatial reference that is influenced by the Dataset’s opening mode

  • Can be closed

property wkt_stored

The spatial reference that can be found in the metadata of a source, in wkt format.

string or None

property proj4_stored

The spatial reference that can be found in the metadata of a source, in proj4 format.

string or None

property wkt_virtual

The spatial reference considered to be written in the metadata of a source, in wkt format.

string or None

property proj4_virtual

The spatial reference considered to be written in the metadata of a source, in proj4 format.

string or None

get_keys()[source]

Get the list of keys under which this source is registered to in the Dataset

property close

Close a source with a call or a context management. The close attribute returns an object that can be both called and used in a with statement

Examples

>>> ds.dem.close()
>>> with ds.dem.close:
        # code...
>>> with ds.acreate_raster('result.tif', fp, float, 1).close as result:
        # code...
>>> with ds.acreate_vector('results.shp', 'linestring').close as roofs:
        # code...
__del__()[source]
class buzzard.ASourceRaster(<implementation detail>)[source]

Base abstract class defining the common behavior of all rasters.

Features Defined

  • Has a stored Footprint that defines the location of the raster

  • Has a Footprint that is influenced by the Dataset’s opening mode

  • Has a length that defines how many channels are available

  • Has a channels_schema that defines per channel attributes (e.g. nodata)

  • Has a dtype (like np.float32)

  • Has a get_data method that allows to read pixels in their current state to numpy arrays

property fp_stored
property fp
property channels_schema
property dtype
property nodata

Accessor for first channel’s nodata value

get_nodata(channel=0)[source]

Accessor for nodata value

__len__()[source]

Return the number of channels

get_data(fp=None, channels=None, dst_nodata=None, interpolation='cv_area', **kwargs)[source]

Read a rectangle of data on several channels from the source raster.

If fp is not fully within the source raster, the external pixels are set to nodata. If nodata is missing, 0 is used. If fp is not on the same grid as the source raster, remapping is performed using interpolation algorithm. (It fails if the allow_interpolation parameter is set to False in Dataset (default)). When remapping, the nodata values are not interpolated, they are correctly spread to the output.

If dst_nodata is provided, nodata pixels are set to dst_nodata.

Warning

The alpha channels are currently resampled like any other channels, this behavior may change in the future. To normalize an rgba array after a resampling operation, use this piece of code:

>>> arr = np.where(arr[..., -1] == 255, arr, 0)

Warning

Bands in GDAL are indexed from 1. Channels in buzzard are indexed from 0.

Parameters

fp: Footprint of shape (Y, X) or None

If None: return the full source raster

If Footprint: return this window from the raster

channels: None or int or slice or sequence of int (see Channels Parameter below)

The channels to be read

dst_nodata: nbr or None

nodata value in output array If None and raster.nodata is not None: raster.nodata is used If None and raster.nodata is None: 0 is used

interpolation: one of {‘cv_area’, ‘cv_nearest’, ‘cv_linear’, ‘cv_cubic’, ‘cv_lanczos4’} or None

OpenCV method used if intepolation is necessary

Returns

array: numpy.ndarray of shape (Y, X) or (Y, X, C)
  • If the channels parameter is -1, the returned array is of shape (Y, X) when C=1, (Y, X, C) otherwise.

  • If the channels parameter is an integer >=0, the returned array is of shape (Y, X).

  • If the channels parameter is a sequence or a slice, the returned array is always of shape (Y, X, C), no matter the size of C.

(see Channels Parameter below)

Channels Parameter

type

value

meaning

output shape

NoneType

None (default)

All channels

(Y, X) or (Y, X, C)

slice

slice(None), slice(1), slice(0, 2), slice(2, 0, -1)

Those channels

(Y, X, C)

int

0, 1, 2, -1, -2, -3

Channel idx

(Y, X)

(int, …)

[0], [1], [2], [-1], [-2], [-3], [0, 1], [-1, 2, 1]

Those channels

(Y, X, C)

class buzzard.AAsyncRaster(<implementation detail>)[source]

Base abstract class defining the common behavior of all rasters that are managed by the Dataset’s scheduler.

Features Defined

  • Has a queue_data, a low level method that can be used to query several arrays at once.

  • Has an iter_data, a higher level wrapper of queue_data.

queue_data(fps, channels=None, dst_nodata=None, interpolation='cv_area', max_queue_size=5, **kwargs)[source]

Read several rectangles of data on several channels from the source raster.

Using queue_data instead of multiple calls to get_data allows more parallelism. The fps parameter should contain a sequence of Footprint that will be mapped to numpy.ndarray. The first ones will be computed with a higher priority than the later ones.

Calling this method sends an asynchronous message to the Dataset’s scheduler with the input parameters and a queue. On the input side of the queue, the scheduler will call the put method with each array requested. On the output side of the queue, the get method should be called to retrieve the requested arrays.

The output queue will be created with a max queue size of max_queue_size, the scheduler will be careful to prepare only the arrays that can fit in the output queue. Thanks to this feature: backpressure can be entirely avoided.

If you wish to cancel your request, loose the reference to the queue and the scheduler will gracefuly cancel the query.

In general you should use the iter_data method instead of the queue_data one, it is much safer to use. However you will need to pass the queue_data method of a raster, to create another raster (a recipe) that depends on the first raster.

see rasters’ get_data documentation, it shares most of the concepts

Parameters

fps: sequence of Footprint

The Footprints at which the raster should be sampled.

channels:

see get_data method

dst_nodata:

see get_data method

interpolation:

see get_data method

max_queue_size: int

Maximum number of arrays to prepare in advance in the underlying queue.

Returns

queue: queue.Queue of ndarray

The arrays are put into the queue in the same order as in the fps parameter.

iter_data(fps, channels=None, dst_nodata=None, interpolation='cv_area', max_queue_size=5, **kwargs)[source]

Read several rectangles of data on several channels from the source raster.

The iter_data method is a higher level wrapper around the queue_data method. It returns a python generator and while waiting for data, it periodically probes the Dataset’s scheduler to reraise an exception if it crashed.

If you wish to cancel your request, loose the reference to the iterable and the scheduler will gracefully cancel the query.

see rasters’ get_data documentation, it shares most of the concepts see queue_data documentation, it is called from within the iter_data method

Parameters

fps: sequence of Footprint

The Footprints at which the raster should be sampled.

channels:

see get_data method

dst_nodata:

see get_data method

interpolation:

see get_data method

max_queue_size: int

Maximum number of arrays to prepare in advance in the underlying queue.

Returns

iterable: iterable of ndarray

The arrays are yielded into the generator in the same order as in the fps parameter.

class buzzard.ARasterRecipe(<implementation detail>)[source]

Base abstract class defining the common behavior of all rasters that compute data on the fly through the Dataset’s scheduler.

Features Defined

  • Has a primitives property, a dict that lists the primitive rasters declared at construction.

property primitives

dict of primitive name to Source, deduced from the queue_data_per_primitive provided at construction.

class buzzard.CachedRasterRecipe(<implementation detail>)[source]

Concrete class defining the behavior of a raster computed on the fly and fills a cache to avoid subsequent computations.

>>> help(Dataset.create_cached_raster_recipe)
property cache_tiles

Cache tiles provided or created at construction

property cache_dir

Cache directory path provided at construction