Skip to content

Instantly share code, notes, and snippets.

@StanczakDominik
Last active June 16, 2018 16:50
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 StanczakDominik/d7a6468eb41b92433676bcb08744af88 to your computer and use it in GitHub Desktop.
Save StanczakDominik/d7a6468eb41b92433676bcb08744af88 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<HDF5 file \"data00000255.h5\" (mode r+)>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import h5py\n",
"f = h5py.File(\"data00000255.h5\")\n",
"f"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['data']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(f.keys())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['255']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(f['data'].keys())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['fields', 'particles']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(f['data']['255'].keys())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['E', 'rho']"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(f['data']['255']['fields'].keys())"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['x', 'y', 'z']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(f['data']['255']['fields']['E'].keys())"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<HDF5 dataset \"rho\": shape (51, 201), type \"<f8\">"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f['data']['255']['fields']['rho']"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(51, 201)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f['data']['255']['fields']['rho'].shape"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['unitSI',\n",
" 'position',\n",
" 'unitDimension',\n",
" 'timeOffset',\n",
" 'geometry',\n",
" 'gridSpacing',\n",
" 'axisLabels',\n",
" 'gridGlobalOffset',\n",
" 'dataOrder',\n",
" 'gridUnitSI',\n",
" 'fieldSmoothing']"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rho = f['data']['255']['fields']['rho']\n",
"list(rho.attrs)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'unitSI': 1.0,\n",
" 'position': array([0., 0.]),\n",
" 'unitDimension': array([-3., 0., 1., 1., 0., 0., 0.]),\n",
" 'timeOffset': 0.0,\n",
" 'geometry': b'cartesian',\n",
" 'gridSpacing': array([6.e-07, 1.e-07]),\n",
" 'axisLabels': array([b'x', b'z'], dtype='|S1'),\n",
" 'gridGlobalOffset': array([-1.50e-05, 1.02e-05]),\n",
" 'dataOrder': b'C',\n",
" 'gridUnitSI': 1.0,\n",
" 'fieldSmoothing': b'none'}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict(rho.attrs.items())"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'unitDimension': array([ 1., 1., -3., -1., 0., 0., 0.]),\n",
" 'timeOffset': 0.0,\n",
" 'geometry': b'cartesian',\n",
" 'gridSpacing': array([6.e-07, 1.e-07]),\n",
" 'axisLabels': array([b'x', b'z'], dtype='|S1'),\n",
" 'gridGlobalOffset': array([-1.50e-05, 1.02e-05]),\n",
" 'dataOrder': b'C',\n",
" 'gridUnitSI': 1.0,\n",
" 'fieldSmoothing': b'none'}"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"E = f['data']['255']['fields']['E']\n",
"dict(E.attrs.items())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(51, 201)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"E['x'].shape"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Attributes of HDF5 object at 139982125851224>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"E['x'].attrs"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'meshesPath': b'fields/',\n",
" 'softwareVersion': b'4',\n",
" 'date': b'2018-02-06 09:36:49 -0800',\n",
" 'openPMD': b'1.1.0',\n",
" 'software': b'warp',\n",
" 'iterationFormat': b'data%T.h5',\n",
" 'basePath': b'/data/%T/',\n",
" 'particlesPath': b'particles/',\n",
" 'openPMDextension': 1,\n",
" 'iterationEncoding': b'fileBased'}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict(f.attrs)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'unitSI': 1.0,\n",
" 'position': array([0., 0.]),\n",
" 'unitDimension': array([-3., 0., 1., 1., 0., 0., 0.]),\n",
" 'timeOffset': 0.0,\n",
" 'geometry': b'cartesian',\n",
" 'gridSpacing': array([6.e-07, 1.e-07]),\n",
" 'axisLabels': array([b'x', b'z'], dtype='|S1'),\n",
" 'gridGlobalOffset': array([-1.50e-05, 1.02e-05]),\n",
" 'dataOrder': b'C',\n",
" 'gridUnitSI': 1.0,\n",
" 'fieldSmoothing': b'none'}"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict(rho.attrs)"
]
}
],
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

OpenPMD notes

Fields, spatial quantities are records.

Position.x - a component of a record.

Each record has attributes:

Squashing constant data

Provide a common interface (.value, .unitSI, .shape) for arrays and constants via treating the latter like hdf5 groups.

Charge-as-an-array:

  • particles (group)
    • electrons (group):
      • charge (array)
        • unitSI (attribut)

Charge-an-a-group:

  • particles (group)
    • electrons (group):
      • charge (group)
        • value (attribute, float)
        • unitSI (attribute)
        • shape (attribute)

For Cartesian 2D (z=const) you can have z-as-a-group.

Existing tools:

neat Zenodo poster

https://zenodo.org/record/822396

@StanczakDominik
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment