30 likes | 157 Views
This use case showcases how to retrieve an HDF5 file from Configuration Management (CM) and insert CM metadata into it using Python and H5py. A Python script is designed to export the specified revision of an HDF5 file from a Subversion repository, capturing the revision number as an attribute within the file. By leveraging Python's capabilities alongside H5py and NumPy, developers can effortlessly manage HDF5 files with minimal coding effort, making it ideal for complex tasks in software development.
E N D
Use Case: A simple task done simply with Python and H5py* Daniel Kahn NPP Ozone PEATE Science Systems and Applications, Inc. 31 March 2009 Goal: Retrieve HDF5 file from Configuration Management (CM) and insert CM metadata into HDF5 file. *H5py was designed and written by Andrew Collette
Python script to retrieve file from CM and store Rev number as attribute. #! /usr/bin/env python import sys import os import h5py Rev = sys.argv[1] # Specifiy CM path on command line SVNFilepath = sys.argv[2] # Specify revision number on #comand line. command = 'svn export -r ' + Rev + ' ' + SVNFilepath #Subversion # Command InStream = os.popen(command,'r') ExportString = InStream.read() ExportReturnCode = InStream.close() Elements = SVNFilepath.split('/') # HDF5 code fid = h5py.File(Elements[-1]) # Elements[-1] is file name fid.attrs['SVN Path and Revision'] = SVNFilepath + '@' + Rev fid.close() H5py code in red. Note the minimal effort coding HDF5 calls.
Conclusion: Python and the H5py module provide a means of manipulating HDF5 files with minimal development effort. Other comments: Python a efficient environment in which to develop develop software where the problem to be solved is not completely understood. Python, H5py and the numerical package Numpy provide means of doing time efficient numerical manipulations in an array based environment. Python's design as a modern programming language makes it appropriate for complex tasks for which a more simplistic, e.g. shell scripting, approach would be cumbersome. Python and related modules are open source which is useful when administering a license is inconvenient or prohibitive.