tilezilla.db package

Module contents

Database for tilezilla

This submodule assists with access to the database that indexes products ingested by tilezilla. The chief way of accessing the database is via the Database, DatacubeResource, and DatasetResource.

The “resources” are designed to be a higher level access to the database. As such, DatacubeResource and DatasetResource both return instances of the object type (a tile specification, a tile, a product, a band) requested while Database will return a SqlAlchemy ORM object instance retrieved from the database.

The DatacubeResource handles tile specifications and tiles while the DatasetResource deals with products and bands.

TODO: * Searches

  • Search using filter_by by combining keyword arguments for each database level (Tile, Product, Band) and dictionaries passed to these keyword arguments
  • Tie this search into click CLI (multiple key=value flags)
class tilezilla.db.Database(engine, session)[source]

Bases: object

The database connection

classmethod connect(uri, connect_args=None, debug=False)[source]

Return a Database for a given URI

Parameters:
  • URI (str) – Resource location
  • connect_args (dict) – Optional connection arguments
  • debug (bool) – Turn on sqlalchemy debug echo
Returns:

Database

create_band(band)[source]

Band to TableBand without a product_id

create_product(product)[source]
create_tile(tilespec_id, storage, collection, horizontal, vertical, bounds)[source]
ensure_band(product_id, band)[source]
ensure_product(tile_id, product)[source]
ensure_tile(tilespec_id, storage, collection, horizontal, vertical, bounds)[source]
ensure_tilespec(desc, ul, crs, res, size)[source]

Get or add a TileSpec to the database

classmethod from_config(config=None)[source]
get_band(id_)[source]
get_band_by_name(product_id, name)[source]
get_product(id_)[source]
get_product_by_name(tile_id, name)[source]
get_products_by_name(name)[source]
get_tile(id_)[source]
get_tile_by_tile_index(tilespec_id, storage, collection, horizontal, vertical)[source]
get_tilespec(id_)[source]
get_tilespec_by_name(name)[source]
scope()[source]

Session as a context manager

Intended to be used as follows:

..code-block:: python

with db.scope() as scope:
# do stuff
update_band(product_id, band)[source]
update_product(tile_id, product)[source]
class tilezilla.db.DatacubeResource(db, tilespec, storage)[source]

Bases: object

Tiles of products for a given tile specification

Parameters:
  • db (Database) – Database connection
  • tilespec (TileSpec) – Tile specification for datacube
  • storage (str) – Storage type from tilezilla.stores.STORAGE_TYPES
ensure_tile(collection, horizontal, vertical)[source]
get_tile(id_)[source]
get_tile_by_tile_index(collection, horizontal, vertical)[source]
init_tilespec(tilespec)[source]
class tilezilla.db.DatasetResource(db, datacube)[source]

Bases: object

Individual dataset product observations

ensure_band(product_id, band)[source]

Add a band to index, creating if necessary

Parameters:
  • product_id (int) – ID of product that band belongs to
  • band (Band) – An observation in some band belonging to a product
Returns:

Database ID for the band added or retrieved

Return type:

int

ensure_product(tile_id, product)[source]

Add a product to index, creating if needed

Returns:Database ID of the product added or retrieved
Return type:int
get_band(_id)[source]

Return Band by ID

get_product(id_)[source]

Get product by id

get_product_bands(tile_id, product)[source]

Return list of Bands indexed from a product for a given tile

Parameters:
  • tile_id (int) – Check for products in this tile
  • product (BaseProduct) – The product to check for
Returns:

A list of :class:`Band`s indexed for this product and tile

Return type:

list[Band]

get_product_by_name(tile_id, name)[source]

Get product by name within a tile

get_products_by_name(name)[source]

Get all products matching timeseries_id, regardless of tile

get_products_by_tile(tile_id)[source]

Get all products within a tile

update_band(product_id, band)[source]

Add a new band, updating existing band if necessary

Parameters:
  • product_id (int) – ID of product that band belongs to
  • band (Band) – An observation in some band belonging to a product
Returns:

Database ID for band added or updated

Return type:

int