Revision 8b7a963110a428ecd7572dc2db64c84f9e0fd04b authored by Zhang Yunjun on 05 March 2019, 20:28:43 UTC, committed by Zhang Yunjun on 05 March 2019, 20:28:43 UTC
1 parent d2e1acc
remove_hdf5_dataset.py
#!/usr/bin/env python3
############################################################
# Program is part of PySAR #
# Copyright(c) 2018, Zhang Yunjun #
# Author: Zhang Yunjun #
############################################################
import os
import argparse
import h5py
from pysar.utils import writefile
###########################################################################################
EXAMPLE = """Example:
remove_hdf5_dataset.py ifgramStack.h5 unwrapPhase_phaseClosure
remove_hdf5_dataset.py ifgramStack.h5 unwrapPhase_phaseClosure unwrapPhase_bridging
remove_hdf5_dataset.py velocity.h5 velocityStd
"""
def create_parser():
parser = argparse.ArgumentParser(description='Remove an existing dataset from HDF5 file',
formatter_class=argparse.RawTextHelpFormatter,
epilog=EXAMPLE)
parser.add_argument('file', type=str, help='HDF5 file of interest')
parser.add_argument('dset', type=str, nargs='+', help='dataset to be removed.')
return parser
def cmd_line_parse(iargs=None):
parser = create_parser()
inps = parser.parse_args(args=iargs)
if os.path.splitext(inps.file)[1] not in ['.h5', '.he5']:
raise ValueError('input file is not HDF5: {}'.format(inps.file))
return inps
###########################################################################################
def main(iargs=None):
inps = cmd_line_parse(iargs)
with h5py.File(inps.file, 'r') as f:
dset_list = list(f.keys())
if any(i not in dset_list for i in inps.dset):
raise ValueError(('input dataset do not exists: {}'
'\navailable datasets:\n{}').format(inps.dset, dset_list))
inps.file = writefile.remove_hdf5_dataset(inps.file, inps.dset, print_msg=True)
print('Done.')
return inps.file
###########################################################################################
if __name__ == '__main__':
main()
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...