Navigate back: Main / Getting Started with HDF5
This tutorial enables you to get a feel for HDF5 by using the HDFView browser. It does NOT require any programming experience.
HDFView Installation
- Download and install HDFView. It can be downloaded from the Download HDFView page.
- Obtain the storm1.txt text file, used in the tutorial.
Begin Tutorial
Once you have HDFView installed, bring it up and you are ready to begin the tutorial.
Unable to complete tutorial because fields are greyed out?
This tutorial requires that the default HDFView File Access Mode be Read / Write. If fields are greyed out so that you cannot select them, then the File Access Mode is Read Only.
To change the File Access Mode follow these steps:
-
Bring up HDFView
-
Left-mouse click on the Tools pull-down menu and select User Options.
-
A Preferences window pops up with the General Settings tab selected. About half-way down you will see Default File Access Mode. Select Read / Write.
-
Click on Apply and Close at the bottom of the window.
-
Close down HDFView.
-
Bring HDFView back up and try the tutorial again. PLEASE BE AWARE that selecting a File Access Mode of Read / Write can result in changes to the timestamp of HDF files that are viewed with HDFView. In general, a File Access Mode of Read Only should be used to ensure that this does not occur.
|
Topics Covered
Following are the topics covered in the tutorial. The first topic creates the file that is used in the subsequent topics.
Topics
Creating a New HDF5 File with a Contiguous Dataset
The steps below describe how to create a file (storm.h5), group (/Data), and a contiguous dataset (/Data/Storm) using HDFView. A group is an HDF5 object that allows objects to be collected together. A dataset is an array of data values. A contiguous dataset is one that is stored as a single block in the HDF5 file.
-
Select the File pull-down menu at the top left, and then select New -> HDF5.
-
Specify a location and type in storm.h5 for the name of your file, and click on the Save button. You will see the storm.h5 file in the TableView:
-
Right click on storm.h5, and select New -> Group.
-
Enter Data for the name of the group and then click the Ok button. You will see the group Data in the TableView.
-
Right click on the group Data and select New -> Dataset.
-
A window pops up on the right. Fill in the information as follows, and then click Ok (leave the Datatype information as is):
Dataset Name | Storm |
Under Dataspace, Current size | 57x57 |
Layout | Contiguous (default) |
-
Click to expand the Data group in the tree view to see the Storm dataset:
-
Double left click on the Storm dataset in the tree view. A window with an empty spreadsheet pops open.
-
Copy the data from the storm1.txt file into the dataset.
If you downloaded storm1.txt, then click on the Import/Export Data menu and select Import Data from -> Text File. Specify a location, select storm1.txt and click on the Open button. Answer Yes in the dialog box that pops up (which asks if you wish to paste the selected data).
Alternately, you can copy/paste directly. Select and copy the data in a separate window. Position your cursor at (0,0) in your table, and select Paste from the Table menu.
The values will be entered into the spreadsheet.
-
Table -> Close the dataset, and save the data.
Displaying a Dataset as an Image
Any dataset can be viewed as an image in HDFView. Below are the steps that demonstrate this.
-
Right click on Storm in the tree view, and select Open As.
-
Select the Image button under Display As (near the top) in the Dataset Selection window that pops up. Then click OK at the bottom of the window to display the image.
-
The rainbow icon brings you to the Image Palette window. Click on that to play with the palette (GrayWave probably is the best choice). Close.
Creating Attributes
Additional information to describe an object can be stored in attributes. An attribute can be added to a group or dataset with HDFView.
The following illustrates how to add an attribute to the group /Data:
-
Click on the /Data folder in the tree view. You will see two tabs, Object Attribute Info and General Object Info, in the pane on the right site of the HDFView window.
-
With the left mouse button, select the Add Attribute button.
-
Select the Add Attribute button to add an attribute with these values:
Name | BatchID |
Type | INTEGER |
Size (bits) | 32 |
-
Select the Ok button. The attribute will show up under the Object Attribute Info tab.
-
Double-click the BatchID attribute line to open the data table for BatchID.
-
Click in the first cell and enter 3343 followed by the enter key.
-
Table -> Close, answer Yes in the dialog box that pops up (which asks if you wish to paste the selected data).
Adding an attribute to a dataset is very similar to adding an attribute to a group. For example, the following adds an attribute to the /Storm dataset:
-
Left mouse click on the /Storm dataset in the tree view. You will see the Object Attribute Info and General Object Info tabs on the right
-
In the Object Attribute Info pane select the Add Attribute button and enter an attribute with these values. (Be sure to add a String Length or the string will be truncated to one character!):
Name | Units |
Type | STRING |
String Length | 3 |
-
Select the Ok button. The attribute will show up under the Object Attribute Info tab.
-
Double-click the Units attribute line to open the data table for Units.
-
Click in the first cell and enter m/s followed by the enter key.
-
Table -> Close, answer Yes in the dialog box that pops up (which asks if you wish to paste the selected data).
Creating a Compressed and Chunked Dataset
A chunked and compressed dataset can be created using HDFView. A compressed dataset is a dataset whose size has been compressed to take up less space. In order to compress an HDF5 dataset, the dataset must be stored with a chunked dataset layout (as multiple chunks that are stored separately in the file).
Please note that the chunk sizes used in this topic are for demonstration purposes only. For information on chunking and specifying an appropriate chunk size, see the Chunking in HDF5 documentation.
Also see the HDF5 Tutorial topic on Creating a Compressed Dataset.
-
Right click on storm.h5. Select New -> Group.
-
Enter Image for the name of the group, and click the OK button to create the group.
-
Right click on the Image group, and select New -> Dataset.
-
Enter the following information for the dataset. Leave the Datatype as is (INTEGER):
Dataset name | Another Storm |
Under Dataspace, Current size | 57x57 |
Storage Layout | Chunked |
Chunk Size | 20x20 |
Compression | gzip |
Compression Level | 9 |
You will see the Another Storm dataset in the Image group:
-
Double left-mouse click on the Another Storm dataset to display the spreadsheet:
-
Copy the data from the storm1.txt file into the dataset. (See the previous topic for copying storm1.txt into a dataset.)
-
Table -> Close, and save the data.
-
Right click on Another Storm, and select Open As.
-
Select the Image button in the Dataset Selection window that pops up. Click the Ok button at the bottom of the window to view the dataset as an image.
Creating an Image and a Subset
A previous topic demonstrated how to view any dataset as an image in HDFView. With HDFView you can also create an image to begin with, as is shown below.
Creating a Table (Compound Dataset)
A dataset with a compound datatype contains data elements that consist of multiple fields. If the dataspace for the compound dataset is one-dimensional, then the dataset can be viewed as a table in HDFView, as is shown below.
Navigate back: Main / Getting Started with HDF5