Name | h5image JSON |
Version |
0.4.1
JSON |
| download |
home_page | |
Summary | Load and save images to HDF5 files |
upload_time | 2024-02-09 04:32:25 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.6 |
license | |
keywords |
hdf5
image
map
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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.
```python
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()
```
Raw data
{
"_id": null,
"home_page": "",
"name": "h5image",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "Rob Kooper <kooper@illinois.edu>",
"keywords": "hdf5,image,map",
"author": "",
"author_email": "Rob Kooper <kooper@illinois.edu>",
"download_url": "https://files.pythonhosted.org/packages/09/e2/f7c1c51c93af1fc832091db0c31d7a8c63ae03a93fb735f4a59b0380b13e/h5image-0.4.1.tar.gz",
"platform": null,
"description": "# h5image\n\nThis package provides standard functions for interacting with HDF5 files as\npart of the CriticalMAAS project.\n\nThis package will create HDF5 files with the following structure:\n\n- group : all data associated with a single map\n - `json` : the raw json file used to create the map and layers\n - `map` : the actual map image\n - `data` : the actual bytes of the image\n - `corners` : the corners of the map where layers have data\n - `patches` : for each layer (key) a list of patches as a tuple (x, y)\n - `layers_patch` : for each patch (key is x_y) a list of layers\n - `valid_patche` : a list of locations across all layers as a tuple (x, y)\n - `<layer>` : a layer of the map, the name of the layer is the name of file\n - `data` : the actual layer data\n - `patches` : a list of patches as a tuple (x, y) for this specific layer\n\nInstallation\n------------\n\nInstall using pip:\n\n```\npip install h5image\n```\n\nTo convert a folder of images to a HDF5 file use the `h5create` program.\n\nQuickstart example\n------------------\n\nThe following code will create a new HDF5 file with a map and a layer, find the\npatch with most layers, and load the map and the layers at that patch.\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport rasterio\nfrom h5image import H5Image\n\n# create map file\nmap = \"CA_Sage\"\nh5i = H5Image(f\"{map}.hdf5\", \"w\")\nh5i.add_image(f\"{map}.json\", folder=\"./data\")\n\n# get biggest patch\npatches = h5i.get_patches(map, True)\nsorted_patches = {k: v for k, v in sorted(patches.items(), key=lambda item: len(item[1]), reverse=True)}\nloc, loc_layers = next(iter(sorted_patches.items()))\nrow = int(loc.split(\"_\")[0])\ncol = int(loc.split(\"_\")[1])\nprint(f\"Biggest number of layers ({len(loc_layers)}) for {map} is at ( {row}, {col})\")\n\n# plot map\nrgb = h5i.get_patch(row, col, map)\nplt.imshow(rgb)\nplt.title('map')\nplt.axis('off')\nplt.show()\n\n# plot layers and legend\nfor layer in loc_layers:\n rgb = h5i.get_patch(row, col, map, layer=layer)\n plt.imshow(rgb, cmap=plt.colormaps['plasma'])\n plt.title(layer)\n plt.axis('off')\n plt.show()\n\n rgb = h5i.get_legend(map, layer)\n plt.imshow(rgb)\n plt.title(\"legend\")\n plt.axis('off')\n plt.show()\n\n# saving image as geotiff\n# can also use h5i.save_image(map, 'map')\ndset = h5i.get_map(map)\nif dset.ndim == 3:\n image = dset[...].transpose(2, 0, 1) # rasterio expects bands first\nelse:\n image = np.array(dset[...], ndmin=3)\nrasterio.open(f\"{map}.tif\", 'w', driver='GTiff', compress='lzw',\n height=image.shape[1], width=image.shape[2], count=image.shape[0], dtype=image.dtype,\n crs=h5i.get_crs(map, layer), transform=h5i.get_transform(map, layer)).write(image)\n\n# close file\nh5i.close()\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Load and save images to HDF5 files",
"version": "0.4.1",
"project_urls": {
"Homepage": "https://git.ncsa.illinois.edu/criticalmaas/h5image",
"Issues": "https://git.ncsa.illinois.edu/criticalmaas/h5image/-/issues"
},
"split_keywords": [
"hdf5",
"image",
"map"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8f4923b2645444016a30e818650933a54f8ff48849c7d088bb22a3e766859f5f",
"md5": "7d185738d9a6e3b035b91e81f1bd5972",
"sha256": "b3eb67d04c2c1ad231d607ef5a5ba5985cf89ffbe7ad5f3964486fe248cdc7dd"
},
"downloads": -1,
"filename": "h5image-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7d185738d9a6e3b035b91e81f1bd5972",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8105,
"upload_time": "2024-02-09T04:32:23",
"upload_time_iso_8601": "2024-02-09T04:32:23.593732Z",
"url": "https://files.pythonhosted.org/packages/8f/49/23b2645444016a30e818650933a54f8ff48849c7d088bb22a3e766859f5f/h5image-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09e2f7c1c51c93af1fc832091db0c31d7a8c63ae03a93fb735f4a59b0380b13e",
"md5": "baa237d5e188d10c16350da9bca55125",
"sha256": "f997b4e7767204dbdb4f02270d28f01a90e1c97699871b1c9fa88cf23fa7be8d"
},
"downloads": -1,
"filename": "h5image-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "baa237d5e188d10c16350da9bca55125",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8644,
"upload_time": "2024-02-09T04:32:25",
"upload_time_iso_8601": "2024-02-09T04:32:25.151556Z",
"url": "https://files.pythonhosted.org/packages/09/e2/f7c1c51c93af1fc832091db0c31d7a8c63ae03a93fb735f4a59b0380b13e/h5image-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-09 04:32:25",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "h5image"
}