Utilities to build blocks in UP42.
Project description
(BETA) Python package with utilities to build blocks in UP42.
Documentation • UP42.com • Support
Highlights
- Python package with utilities to build blocks in UP42.
- For UP42 partners and customers interested in creating blocks!
- Base classes for data and processing blocks.
- Facilities to easily create tests, ensuring production ready blocks.
Overview
The UP42 blockutils
package provides several modules with specific concerns:
- Blocks: Base classes for data and processing blocks.
- Common: Directory and query/parameter input handling.
- Logging: Standard logging facility.
- Data Path: Input and output file handling.
- Exceptions: Shared exceptions between blocks.
- Format: Exotic file handling (DIMAP and NETCDF).
- Geometry: Generic recurrent geometry operations.
- Windows: Raster windowed read and write helper, useful for large file handling.
- STAC: Handling STAC type queries.
- Synthetic Image: Image generator, especially useful for mock testing.
See the full code reference here.
Template repositories
For your convenience, we have created two template repositories hosted on GitHub
that include this package and generic make
utilities for building and pushing blocks:
Install
The package requires Python > 3.6.
pip install up42-blockutils
Quickstart
The example below shows a minimal processing block that takes a raster file and returns
the raster values to the power of 2. In this example we make use of the logging
,
blocks
, exceptions
, datapath
and windows
modules.
from pathlib import Path
import rasterio as rio
from geojson import FeatureCollection
import blockutils
logger = blockutils.logging.getLogger(__name__)
class AProcessingBlock(blockutils.blocks.ProcessingBlock):
def process(
self, input_fc: FeatureCollection)
) -> FeatureCollection:
output_fc = FeatureCollection([])
if not input_fc.features:
raise blockutils.exceptions.UP42Error(
blockutils.exceptions.SupportedErrors.NO_INPUT_ERROR
)
for feat in input_fc["features"]:
logger.info(f"Processing {feat}...")
input_path = Path("/tmp/input/") / Path(get_data_path(feat))
with rio.open(input_path) as src:
src_win = blockutils.windows.WindowsUtil(src)
(
output_name,
output_path,
) = blockutils.datapath.get_output_filename_and_path(
input_path.name, postfix="processed"
)
dst_meta = src.meta.copy()
with rio.open(output_path, "w", **dst_meta) as dst:
for win in src_win.windows_regular():
exp = src.read(window=win) ** 2
dst.write(exp, window=win)
out_feat = Feature(bbox=feat.bbox, geometry=feat.geometry)
out_feat["properties"] = self.get_metadata(feat)
out_feat = blockutils.datapath.set_data_path(out_feat, output_name)
logger.info(f"Processed {out_feat}...")
output_fc.features.append(out_feat)
return output_fc
AProcessingBlock().run()
Support
For any issues or help please contact us via Email support@up42.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for up42_blockutils-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e3eddc287c1327a2f0d2530470bd64b25d18fb62eae28668ea3049a0b52630 |
|
MD5 | e2b5f7e36a61da9cabe417b475115cf6 |
|
BLAKE2b-256 | b26e9339360e41fe44e38891d3b30a3c40a50c049bad317dc8e43a0b507cf1ed |