Skip to main content

h5image

This package provides standard functions for interacting with HDF5 files as part of the CriticalMAAS project.

This package will create HDF5 files with the following structure:

  • group : all data associated with a single map
    • json : the raw json file used to create the map and layers
    • map : the actual map image
      • data : the actual bytes of the image
      • corners : the corners of the map where layers have data
      • patches : for each layer (key) a list of patches as a tuple (x, y)
      • layers_patch : for each patch (key is x_y) a list of layers
      • valid_patche : a list of locations across all layers as a tuple (x, y)
    • <layer> : a layer of the map, the name of the layer is the name of file
      • data : the actual layer data
      • patches : a list of patches as a tuple (x, y) for this specific layer

Installation

Install using pip:

pip install h5image

To convert a folder of images to a HDF5 file use the h5create program.

Quickstart example

The following code will create a new HDF5 file with a map and a layer, find the patch with most layers, and load the map and the layers at that patch.

import matplotlib.pyplot as plt
import numpy as np
import rasterio
from h5image import H5Image

# create map file
map = "CA_Sage"
h5i = H5Image(f"{map}.hdf5", "w")
h5i.add_image(f"{map}.json", folder="./data")

# get biggest patch
patches = h5i.get_patches(map, True)
sorted_patches = {k: v for k, v in sorted(patches.items(), key=lambda item: len(item[1]), reverse=True)}
loc, loc_layers = next(iter(sorted_patches.items()))
row = int(loc.split("_")[0])
col = int(loc.split("_")[1])
print(f"Biggest number of layers ({len(loc_layers)}) for {map} is at ( {row}, {col})")

# plot map
rgb = h5i.get_patch(row, col, map)
plt.imshow(rgb)
plt.title('map')
plt.axis('off')
plt.show()

# plot layers and legend
for layer in loc_layers:
    rgb = h5i.get_patch(row, col, map, layer=layer)
    plt.imshow(rgb, cmap=plt.colormaps['plasma'])
    plt.title(layer)
    plt.axis('off')
    plt.show()

    rgb = h5i.get_legend(map, layer)
    plt.imshow(rgb)
    plt.title("legend")
    plt.axis('off')
    plt.show()

# saving image as geotiff
# can also use h5i.save_image(map, 'map')
dset = h5i.get_map(map)
if dset.ndim == 3:
    image = dset[...].transpose(2, 0, 1)  # rasterio expects bands first
else:
    image = np.array(dset[...], ndmin=3)
rasterio.open(f"{map}.tif", 'w', driver='GTiff', compress='lzw',
              height=image.shape[1], width=image.shape[2], count=image.shape[0], dtype=image.dtype,
              crs=h5i.get_crs(map, layer), transform=h5i.get_transform(map, layer)).write(image)

# close file
h5i.close()

Metadata

Release files for h5image 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h5image 0.4.1
File Size Uploaded Provenance Actions
h5image-0.4.1.tar.gz 8.6 kB Without provenance Details for h5image-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for h5image 0.4.1
File Interpreter ABI Platform Actions
h5image-0.4.1-py3-none-any.whl Python 3 none any Details for h5image-0.4.1-py3-none-any.whl

Total release size: 16.7 kB

Release files / h5image-0.4.1.tar.gz

Download URL h5image-0.4.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f997b4e7767204dbdb4f02270d28f01a90e1c97699871b1c9fa88cf23fa7be8d
BLAKE2b-256 checksum
How to use checksums
09e2f7c1c51c93af1fc832091db0c31d7a8c63ae03a93fb735f4a59b0380b13e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / h5image-0.4.1-py3-none-any.whl

Download URL h5image-0.4.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3eb67d04c2c1ad231d607ef5a5ba5985cf89ffbe7ad5f3964486fe248cdc7dd
BLAKE2b-256 checksum
How to use checksums
8f4923b2645444016a30e818650933a54f8ff48849c7d088bb22a3e766859f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for h5image 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page