{ "metadata": { "name": "", "signature": "sha256:ad9f4c68ddba2ca1959cc0ca7feb3d42145cc3ed37c3d5a0376de78a6bc2049c" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
HDF5 (Hierarchical Data Format)Link to Kyle's [Bitbucket Repo](https://bitbucket.org/yingkaisha/python-in-remote-sensing/src/tip/_libs/) and some [testing data-sets](https://bitbucket.org/yingkaisha/python-in-remote-sensing/src/tip/_data/_demos/)
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Links toHDF5 & Python\n",
"\n",
"\n", "
HDF5 & Python, you'll need to install 2 libraries/packages from the Anaconda distribuion.\n",
"Type the following commands into the terminal prompt.\n",
"
HDF5 File Structure\n",
"The 3 components of an HDF5 file (files appended with a \".h5\").\n",
"
DatasetsGroupsdatasets and other groups\n",
"Attributesdatasets (and groups)\n",
"Primary benefits of HDF5-files:\n",
"
Groups and Attributes.Groups act like folders, allowing related datasets to be stored together.Attributes allows the direct attachement of metadata to the actual data they describe.HDF5 files (taken from book 'Python and HDF5')HDF5 files shows the organizational structure...\n", "In the above code-chunk:\n", "
/15/... is similar to a folder system on a computer./15/... is stored under the /15/... (e.g. Temperature & Wind).\n",
"Similarly, accessing the metadata attributes can be done in the following way...\n",
"
\n", "
attr attribute of a dataset, which is a dictionary with key-value pairs.h5dump() module from Kyle's Bitbucket Repoexample.h5 into the notebook.h5 fileHDF5 files\n", "There are a few ways of viewing the stored metadata...\n", "
\n", "\n", "One is to use h5dump() (contribution from Kyle). This routine essentially prints out all of the material stored within the .h5 file.
h5dump on \"example.h5\"\n",
"The loaded .h5 file is a organized as an [OrderedDict](https://docs.python.org/2/library/collections.html#collections.OrderedDict) data-container (recall [Python dictionaries](https://docs.python.org/2/tutorial/datastructures.html)).\n",
"
key-value pairs, or all groups and datasets) stored in the .h5 file\n",
"Accessing the .items() method of an .h5 file will give you all of the stored datasets and groups.\n",
"
\n",
"If only the keys are desired, then simply use the .keys() method.\n",
"
dataset or group\n",
"Can use the print_attrs() routine (thanks Kyle). A look at the routine...\n",
"
datasetgroupData Fields subgroup in f['MonthlyRain'] & accessing its metadata.value() method.