Commit 0ae77e50 authored by Justin Reid's avatar Justin Reid
Browse files

Added new command line tool for dumping pure NCML without XSL for NetCDF-4 files.

parent 0b2936c4
Pipeline #295 skipped
......@@ -21,7 +21,7 @@ class MetadataTransformer:
self.nc_dump_path = ""
self.nc_classic_path = ""
self.in_file = os.path.basename(netcdf_path)
self._out_path = out_path
self.out_path = out_path
self.out_file = ""
def dump_nc_file(self):
......@@ -30,7 +30,7 @@ class MetadataTransformer:
:return:
"""
self.nc_dump_path = os.path.join(
self._out_path,
self.out_path,
self.in_file.replace(".nc", "_dumped.txt")
)
......@@ -49,7 +49,7 @@ class MetadataTransformer:
"""
self.nc_classic_path = os.path.join(
self._out_path,
self.out_path,
self.nc_dump_path.replace(".txt", "_classic.nc")
)
......@@ -65,7 +65,7 @@ class MetadataTransformer:
:return:
"""
self.out_file = os.path.join(
self._out_path,
self.out_path,
self.in_file.replace(".nc", ".xml")
)
......@@ -87,7 +87,7 @@ class MetadataTransformer:
:return:
"""
final_xml = os.path.join(
self._out_path,
self.out_path,
self.out_file.replace(".xml", "_transformed.xml")
)
......
......@@ -69,7 +69,7 @@ class GetNCMetadataTests(unittest.TestCase):
self.transformer.dump_nc_file()
self.transformer.get_classic_nc()
self.transformer.get_ncml()
self.assertTrue(os.path.exists(self.transformer._out_path))
self.assertTrue(os.path.exists(self.transformer.out_path))
def testGetTransformedXML(self):
"""
......
"""
This tool dumps NCML from a NetCDF-4 dataset. It intends
to mimic the behavior of the ncdump -x command, but for
NetCDF-4 files.
- Justin Lynn Reid
"""
import argparse
import os
from ncmltransformdemo.metadatatransformer import MetadataTransformer
class Ncml4Dump:
@staticmethod
def create_arg_parser():
"""
Get command line arguments
:return: ArgParser instances containing command line arguments
"""
parser = argparse.ArgumentParser(description="A utility for dumping NCML from NetCDF-4 data")
parser.add_argument("--in_netcdf", dest="in_netcdf", help="Input Netcdf")
parser.add_argument(
"--out_dir", dest="out_dir",
default=os.path.expanduser("~"), help="Output dir"
)
return parser.parse_args()
@staticmethod
def main():
"""
Main method
:return: Null
"""
# Get command line arguments
args = Ncml4Dump.create_arg_parser()
# Make instance of transformer and perform xml transformation
meta_transformer = MetadataTransformer(
os.path.expanduser(args.in_netcdf),
os.path.expanduser(args.out_dir)
)
meta_transformer.dump_nc_file()
meta_transformer.get_classic_nc()
meta_transformer.get_ncml()
# Delete all created side files on filesystem
os.remove(meta_transformer.nc_classic_path)
os.remove(meta_transformer.nc_dump_path)
print("XML file {0} has been successfully created!".format(meta_transformer.out_file))
if __name__ == "__main__":
Ncml4Dump.main()
\ No newline at end of file
......@@ -11,7 +11,7 @@ setup(
name="ncmltransformdemo",
version=1.0,
packages=find_packages(),
scripts=["ncmltransformdemo/ncmltransform.py"],
scripts=["ncmltransformdemo/ncmltransform.py", "ncmltransformdemo/ncml4dump.py"],
test_suite='nose.collector',
tests_require='nose'
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment