Skip to content

Instantly share code, notes, and snippets.

@cburton12
Last active July 24, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cburton12/94e1f6d7b966d965c464cb56f3539859 to your computer and use it in GitHub Desktop.
Save cburton12/94e1f6d7b966d965c464cb56f3539859 to your computer and use it in GitHub Desktop.
Simple HDF5 Read
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"import requests\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"web_address = 'https://cburton.web.cern.ch/cburton/files/other/Run_0118_Output.hdf5'\n",
"web_file = requests.get(web_address)\n",
"open('Run_0118_Output.hdf5', 'wb').write(web_file.content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = h5py.File('Run_0118_Output.hdf5', 'r')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f['Measurement_0'].keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f['Measurement_0']['coluta']['frame1']['raw_data'].shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"raw_data = f['Measurement_0']['coluta']['frame1']['raw_data'][()]\n",
"raw_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"decimal_data = []\n",
"for i in raw_data:\n",
" raw_data_string = [str(_) for _ in i]\n",
" raw_data_string = ''.join(raw_data_string) + '000000'\n",
" raw_data_int = int(raw_data_string, 2)\n",
" decimal_data.append(raw_data_int)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(6, 6), dpi=100)\n",
"plt.plot(decimal_data, 'ro')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
h5py~=2.10
matplotlib~=3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment