Skip to content

Instantly share code, notes, and snippets.

@rly
Created January 10, 2023 22:59
Show Gist options
  • Save rly/57eb8fb09b5e5c3cc9c52914cfbe59d6 to your computer and use it in GitHub Desktop.
Save rly/57eb8fb09b5e5c3cc9c52914cfbe59d6 to your computer and use it in GitHub Desktop.
Get the number of chunks in an h5py.Dataset
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "26900f83-f5ab-441c-9eae-72477b91c5f2",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"import h5py"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "241b6349-82cc-44f4-b1cd-6a2af8b41232",
"metadata": {},
"outputs": [],
"source": [
"f = h5py.File(\"/Users/rly/Documents/NWB_Data/GiocomoData_dandiset53/000053/sub-npI1/sub-npI1_ses-20190413_behavior+ecephys.nwb\", \"r\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "95f6c144-1fc4-4364-954e-249d5e742e09",
"metadata": {},
"outputs": [],
"source": [
"data = f[\"/acquisition/ElectricalSeries/data\"]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b139cff1-3c05-4f9d-bc16-7d192b390722",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(141969007, 384)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b6abfeb7-5889-4c8e-add8-ffc826701903",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(277284, 1)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.chunks"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7e330610-e679-4cfc-b653-b7d248cea666",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"512"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.ceil(141969007/277284)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "810a02f8-eeef-44c5-88c5-b1e06bb82d27",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"196608"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.ceil(141969007/277284) * 384"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b2ade0ac-6f6e-4fd5-b925-67cf8c7bea57",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"196608"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.id.get_num_chunks()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "2710c3e9-5aeb-4d68-8202-89d84c2940b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"196608"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.ceil(data.shape[0]/data.chunks[0]) * math.ceil(data.shape[1]/data.chunks[1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf06897e-e369-449f-afc6-1042f3e29486",
"metadata": {},
"outputs": [],
"source": [
"math.ceil(data.shape[0]/data.chunks[0]) * math.ceil(data.shape[1]/data.chunks[1]) * math.ceil(data.shape[2]/data.chunks[2])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment