Skip to content

Commit

Permalink
added notebook example for h5image
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Aug 23, 2024
1 parent 49b5504 commit d382879
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
1 change: 1 addition & 0 deletions .hsds/data/hsdstest/home/test_user1/test/.domain.json
Original file line number Diff line number Diff line change
@@ -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}
154 changes: 154 additions & 0 deletions examples/notebooks/h5image_example.ipynb
Original file line number Diff line number Diff line change
@@ -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": [
"<HDF5 dataset \"dset1.1.1\": shape (10, 10), type \">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
}
2 changes: 1 addition & 1 deletion h5pyd/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d382879

Please sign in to comment.