From d3828797832d13e43fa24b133a91fc143fc2b239 Mon Sep 17 00:00:00 2001 From: John Readey Date: Fri, 23 Aug 2024 09:17:50 -0500 Subject: [PATCH] added notebook example for h5image --- .../home/test_user1/test/.domain.json | 1 + examples/notebooks/h5image_example.ipynb | 154 ++++++++++++++++++ h5pyd/_hl/files.py | 2 +- 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 .hsds/data/hsdstest/home/test_user1/test/.domain.json create mode 100644 examples/notebooks/h5image_example.ipynb diff --git a/.hsds/data/hsdstest/home/test_user1/test/.domain.json b/.hsds/data/hsdstest/home/test_user1/test/.domain.json new file mode 100644 index 0000000..9b56834 --- /dev/null +++ b/.hsds/data/hsdstest/home/test_user1/test/.domain.json @@ -0,0 +1 @@ +{"owner": "test_user1", "acls": {"test_user1": {"create": true, "read": true, "update": true, "delete": true, "readACL": true, "updateACL": true}, "default": {"create": false, "read": true, "update": false, "delete": false, "readACL": false, "updateACL": false}}, "created": 1720720711.2741823, "lastModified": 1720720711.2741823} diff --git a/examples/notebooks/h5image_example.ipynb b/examples/notebooks/h5image_example.ipynb new file mode 100644 index 0000000..1e1b562 --- /dev/null +++ b/examples/notebooks/h5image_example.ipynb @@ -0,0 +1,154 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import h5py\n", + "from h5pyd import H5Image" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# create an HDF5 file image domain\n", + "! hsload --h5image s3://hdfgroup/data/hdf5test/tall.h5 hdf5://home/test_user1/test/tall_image.h5" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# open the file using the H5Image \"file-like object\" class\n", + "f = h5py.File(H5Image(\"hdf5://home/test_user1/test/tall_image.h5\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "72057594037927936" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f.id.id" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['g1', 'g2']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "i4\">" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dset111 = f[\"/g1/g1.1/dset1.1.1\"]\n", + "dset111" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", + " [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n", + " [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],\n", + " [ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27],\n", + " [ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36],\n", + " [ 0, 5, 10, 15, 20, 25, 30, 35, 40, 45],\n", + " [ 0, 6, 12, 18, 24, 30, 36, 42, 48, 54],\n", + " [ 0, 7, 14, 21, 28, 35, 42, 49, 56, 63],\n", + " [ 0, 8, 16, 24, 32, 40, 48, 56, 64, 72],\n", + " [ 0, 9, 18, 27, 36, 45, 54, 63, 72, 81]], dtype='>i4')" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dset111[:,:]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "f.close()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "hs", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/h5pyd/_hl/files.py b/h5pyd/_hl/files.py index 5b4d3a4..edc32f3 100644 --- a/h5pyd/_hl/files.py +++ b/h5pyd/_hl/files.py @@ -50,7 +50,7 @@ def __init__(self, domain_path, h5path="h5image", logger=None): self._domain_path = "hdf5:/" + domain_path f = File(domain_path) if h5path not in f: - raise IOError("Expected 'data' dataset") + raise IOError(f"Expected '{h5path}' dataset") dset = f[h5path] if len(dset.shape) != 1: raise IOError("Expected one-dimensional dataset")