Browse files

ENH: Various command line tools.

The following command line tools are now available:

* anytocfradial: create a CF/Radial file from any radar file.
* radar_info: print out information about a radar file.
* radar_plot: create a plot for a radar file.
* check_cfradial: check that a file meets CF/Radial standards.

The main setup.py file updated to install the above scripts during install,
and PEP8 cleanup was performed on this file.
  • Loading branch information...
1 parent 2632d0f commit 0433b14fa183412d730557051ae6b7a1ebaef309 @jjhelmus jjhelmus committed Oct 25, 2013
Showing with 282 additions and 13 deletions.
  1. +3 −3 pyart/io/radar.py
  2. +69 −0 scripts/anytocfradial
  3. 0 scripts/{check_cfradial.py → check_cfradial}
  4. +63 −0 scripts/radar_info
  5. +131 −0 scripts/radar_plot
  6. +16 −10 setup.py
View
6 pyart/io/radar.py
@@ -183,17 +183,17 @@ def info(self, level='standard', out=sys.stdout):
self._dic_info('azimuth', level, out)
self._dic_info('elevation', level, out)
+ print('fields:', file=out)
for field_name, field_dic in self.fields.iteritems():
- print('fields:', file=out)
self._dic_info(field_name, level, out, field_dic, 1)
self._dic_info('fixed_angle', level, out)
if self.instrument_parameters is None:
print('instrument_parameters: None', file=out)
else:
+ print('instrument_parameters:', file=out)
for name, dic in self.instrument_parameters.iteritems():
- print('instrument_parameters:', file=out)
self._dic_info(name, level, out, dic, 1)
self._dic_info('latitude', level, out)
@@ -206,8 +206,8 @@ def info(self, level='standard', out=sys.stdout):
if self.radar_calibration is None:
print('radar_calibration: None', file=out)
else:
+ print('radar_calibration:', file=out)
for name, dic in self.radar_calibration.iteritems():
- print('radar_calibration:', file=out)
self._dic_info(name, level, out, dic, 1)
self._dic_info('range', level, out)
View
69 scripts/anytocfradial
@@ -0,0 +1,69 @@
+#! /usr/bin/env python
+
+import pyart
+import argparse
+
+if __name__ == '__main__':
+
+ # parse the arguments
+ parser = argparse.ArgumentParser(
+ description='Convert a radar file to CF/Radial format.')
+ parser.add_argument('infile', type=str, help='radar file to convert')
+ parser.add_argument('outfile', type=str, help='file to save file to')
+
+ igroup = parser.add_argument_group(
+ title='ingest method, optional',
+ description=('The method of file ingest can be specified. '
+ 'If no ingest is specified, the format of the file will '
+ 'be used to determine the best ingest method. '
+ 'Specify only one of the following:'))
+
+ igroup.add_argument('--sigmet', action='store_true',
+ help='Sigmet/IRIS ingest')
+ igroup.add_argument('--mdv', action='store_true', help='MDV ingest')
+ igroup.add_argument('--cfradial', action='store_true',
+ help='CF/Radial ingest')
+ igroup.add_argument('--rsl', action='store_true',
+ help='RSL ingest')
+ igroup.add_argument('--nexrad_archive', action='store_true',
+ help='NEXRAD level 2 archive ingest')
+ igroup.add_argument('--nexrad_cdm', action='store_true',
+ help='NEXRAD level 2 CDM ingest')
+
+ fgroup = parser.add_mutually_exclusive_group()
+ fgroup.add_argument('--netcdf3_classic', action='store_const',
+ const='NETCDF3_CLASSIC', dest='netcdf_format',
+ help='create a NetCDF3 classic formatted file')
+ fgroup.add_argument('--netcdf3_64bit', action='store_const',
+ const='NETCDF3_64BIT', dest='netcdf_format',
+ help='create a NetCDF3 64-bit offset formatted file')
+ fgroup.add_argument('--netcdf4', action='store_const',
+ const='NETCDF4', dest='netcdf_format',
+ help='create a NetCDF4 formatted file (default)')
+ fgroup.add_argument('--netcdf4_classic', action='store_const',
+ const='NETCDF4_CLASSIC', dest='netcdf_format',
+ help='create a NetCDF4 classic formatted file')
+ parser.set_defaults(netcdf_format='NETCDF4')
+
+ parser.add_argument('-v', '--version', action='version',
+ version='Py-ART version %s' % (pyart.__version__))
+ args = parser.parse_args()
+
+ # read in the file
+ if args.sigmet:
+ radar = pyart.io.read_sigmet(args.infile)
+ elif args.mdv:
+ radar = pyart.io.read_mdv(args.infile)
+ elif args.cfradial:
+ radar = pyart.io.read_cfradial(args.infile)
+ elif args.rsl:
+ radar = pyart.io.read_rsl(args.infile)
+ elif args.nexrad_archive:
+ radar = pyart.io.read_nexrad_archive(args.infile)
+ elif args.nexrad_cdm:
+ radar = pyart.io.read_nexrad_cdm(args.infile)
+ else:
+ radar = pyart.io.read(args.infile)
+
+ # convert to CF/Radial
+ pyart.io.write_cfradial(args.outfile, radar, format=args.netcdf_format)
View
0 scripts/check_cfradial.py → scripts/check_cfradial
File renamed without changes.
View
63 scripts/radar_info
@@ -0,0 +1,63 @@
+#! /usr/bin/env python
+
+import pyart
+import argparse
+
+if __name__ == '__main__':
+
+ # parse the arguments
+ parser = argparse.ArgumentParser(
+ description='Print information on a radar file.')
+ parser.add_argument('filename', type=str, help='radar file to check')
+
+ group = parser.add_mutually_exclusive_group()
+ group.add_argument('-f', '--full', dest='level', action='store_const',
+ const='f', help='print out all information')
+ group.add_argument('-s', '-standard', dest='level', action='store_const',
+ const='s', help='print out standard information')
+ group.add_argument('-c', '--compact', dest='level', action='store_const',
+ const='c',
+ help='print out minimal information (default)')
+ parser.set_defaults(level='c')
+
+ igroup = parser.add_argument_group(
+ title='ingest method, optional',
+ description=('The method of file ingest can be specified. '
+ 'If no ingest is specified, the format of the file will '
+ 'be used to determine the best ingest method. '
+ 'Specify only one of the following:'))
+
+ igroup.add_argument('--sigmet', action='store_true',
+ help='Sigmet/IRIS ingest')
+ igroup.add_argument('--mdv', action='store_true', help='MDV ingest')
+ igroup.add_argument('--cfradial', action='store_true',
+ help='CF/Radial ingest')
+ igroup.add_argument('--rsl', action='store_true',
+ help='RSL ingest')
+ igroup.add_argument('--nexrad_archive', action='store_true',
+ help='NEXRAD level 2 archive ingest')
+ igroup.add_argument('--nexrad_cdm', action='store_true',
+ help='NEXRAD level 2 CDM ingest')
+
+ parser.add_argument('-v', '--version', action='version',
+ version='Py-ART version %s' % (pyart.__version__))
+ args = parser.parse_args()
+
+ # read in the file
+ if args.sigmet:
+ radar = pyart.io.read_sigmet(args.filename)
+ elif args.mdv:
+ radar = pyart.io.read_mdv(args.filename)
+ elif args.cfradial:
+ radar = pyart.io.read_cfradial(args.filename)
+ elif args.rsl:
+ radar = pyart.io.read_rsl(args.filename)
+ elif args.nexrad_archive:
+ radar = pyart.io.read_nexrad_archive(args.filename)
+ elif args.nexrad_cdm:
+ radar = pyart.io.read_nexrad_cdm(args.filename)
+ else:
+ radar = pyart.io.read(args.filename)
+
+ # print out information
+ radar.info(args.level)
View
131 scripts/radar_plot
@@ -0,0 +1,131 @@
+#! /usr/bin/env python
+
+import argparse
+
+import matplotlib.pyplot as plt
+import pyart
+
+if __name__ == '__main__':
+
+ # parse the arguments
+ parser = argparse.ArgumentParser(
+ description='Plot a field from a radar file.')
+
+ # positional arguments
+ parser.add_argument('filename', type=str, help='name of radar file')
+ parser.add_argument('field', type=str, help='field in radar to plot')
+ parser.add_argument('figname', type=str, nargs='?',
+ help=('file to save figure as, if not specified '
+ 'figure is displayed on screen'))
+
+ # value optional arguments
+ parser.add_argument('--tilt', type=int, default=0,
+ help=('radar tilt/sweep to plot. ' 'A value of 0, '
+ 'the first tilt, is used if not specified.'))
+ parser.add_argument('--vmin', type=float, default=None,
+ help='luminance minimum value')
+ parser.add_argument('--vmax', type=float, default=None,
+ help='luminance maximum value')
+ parser.add_argument('--cmap', type=str, default='jet',
+ help='name of colormap used to plot data')
+ parser.add_argument('--title', type=str, default=None,
+ help='title of the plot')
+ parser.add_argument('--axis_labels', type=str, nargs=2,
+ default=(None, None),
+ metavar=('XAXIS_LABEL', 'YAXIS_LABEL'),
+ help='x-axis and y-axis labels')
+ parser.add_argument('--colorbar_label', type=str, default=None,
+ help='colorbar label')
+
+ # boolean optional arguments
+ parser.add_argument('--no_mask_outside', action='store_true',
+ help='do not mask data outside of vmin and vmax')
+ parser.add_argument('--no_title', action='store_true',
+ help='do not title the figure')
+ parser.add_argument('--no_axis_labels', action='store_true',
+ help='do not label the axes')
+ parser.add_argument('--no_colorbar', action='store_true',
+ help='do not create a colorbar')
+
+ parser.add_argument('-v', '--version', action='version',
+ version='Py-ART version %s' % (pyart.__version__))
+
+ # ingest arguments
+ igroup = parser.add_argument_group(
+ title='ingest method, optional',
+ description=('The method of file ingest can be specified. '
+ 'If no ingest is specified, the format of the file will '
+ 'be used to determine the best ingest method. '
+ 'Specify only one of the following:'))
+
+ igroup.add_argument('--sigmet', action='store_true',
+ help='Sigmet/IRIS ingest')
+ igroup.add_argument('--mdv', action='store_true', help='MDV ingest')
+ igroup.add_argument('--cfradial', action='store_true',
+ help='CF/Radial ingest')
+ igroup.add_argument('--rsl', action='store_true',
+ help='RSL ingest')
+ igroup.add_argument('--nexrad_archive', action='store_true',
+ help='NEXRAD level 2 archive ingest')
+ igroup.add_argument('--nexrad_cdm', action='store_true',
+ help='NEXRAD level 2 CDM ingest')
+
+ args = parser.parse_args()
+
+ # read in the file
+ if args.sigmet:
+ radar = pyart.io.read_sigmet(args.filename)
+ elif args.mdv:
+ radar = pyart.io.read_mdv(args.filename)
+ elif args.cfradial:
+ radar = pyart.io.read_cfradial(args.filename)
+ elif args.rsl:
+ radar = pyart.io.read_rsl(args.filename)
+ elif args.nexrad_archive:
+ radar = pyart.io.read_nexrad_archive(args.filename)
+ elif args.nexrad_cdm:
+ radar = pyart.io.read_nexrad_cdm(args.filename)
+ else:
+ radar = pyart.io.read(args.filename)
+
+ # create the plot
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+
+ if args.field not in radar.fields:
+ print "Valid fields:"
+ for f in radar.fields:
+ print '\t' + f
+ raise ValueError('invalid field: ' + args.field)
+
+ display = pyart.graph.RadarDisplay(radar)
+ if radar.scan_type == 'ppi':
+ display.plot_ppi(
+ args.field, args.tilt, ax=ax, fig=fig,
+ vmin=args.vmin, vmax=args.vmax, cmap=args.cmap,
+ mask_outside=(not args.no_mask_outside),
+ title_flag=(not args.no_title),
+ axislabels_flag=(not args.no_axis_labels),
+ colorbar_flag=(not args.no_colorbar),
+ title=args.title,
+ axislabels=args.axis_labels,
+ colorbar_label=args.colorbar_label)
+ elif radar.scan_type == 'rhi':
+ display.plot_rhi(
+ args.field, args.tilt, ax=ax, fig=fig,
+ vmin=args.vmin, vmax=args.vmax, cmap=args.cmap,
+ mask_outside=(not args.no_mask_outside),
+ title_flag=(not args.no_title),
+ axislabels_flag=(not args.no_axis_labels),
+ colorbar_flag=(not args.no_colorbar),
+ title=args.title,
+ axislabels=args.axis_labels,
+ colorbar_label=args.colorbar_label)
+ else:
+ raise ValueError('Cannot plot radar scan_type: ' + radar.scan_type)
+
+ # show the plot if no figname provided, otherwise save the figure
+ if args.figname is None:
+ plt.show()
+ else:
+ fig.savefig(args.figname)
View
26 setup.py
@@ -21,6 +21,7 @@
import sys
import re
import subprocess
+import glob
if sys.version_info[0] < 3:
import __builtin__ as builtins
@@ -58,6 +59,8 @@
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
+SCRIPTS = glob.glob('scripts/*')
+
# Return the git revision as a string
def git_version():
@@ -73,7 +76,7 @@ def _minimal_ext_cmd(cmd):
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
- cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
+ cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out
try:
@@ -86,7 +89,8 @@ def _minimal_ext_cmd(cmd):
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
-if os.path.exists('MANIFEST'): os.remove('MANIFEST')
+if os.path.exists('MANIFEST'):
+ os.remove('MANIFEST')
# This is a bit hackish: we are setting a global variable so that the main
# pyart __init__ can detect if it is being loaded by the setup routine, to
@@ -117,8 +121,8 @@ def write_version_py(filename='pyart/version.py'):
try:
from pyart.version import git_revision as GIT_REVISION
except ImportError:
- raise ImportError("Unable to import git_revision. Try removing " \
- "pyart/version.py and the build directory " \
+ raise ImportError("Unable to import git_revision. Try removing "
+ "pyart/version.py and the build directory "
"before building.")
else:
GIT_REVISION = "Unknown"
@@ -129,13 +133,14 @@ def write_version_py(filename='pyart/version.py'):
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION,
- 'full_version' : FULLVERSION,
- 'git_revision' : GIT_REVISION,
+ 'full_version': FULLVERSION,
+ 'git_revision': GIT_REVISION,
'isrelease': str(ISRELEASED)})
finally:
a.close()
-def configuration(parent_package='',top_path=None):
+
+def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
config.set_options(ignore_setup_xxx_py=True,
@@ -155,7 +160,7 @@ def setup_package():
write_version_py()
from numpy.distutils.core import setup
-
+
setup(
name=NAME,
maintainer=MAINTAINER,
@@ -166,8 +171,9 @@ def setup_package():
download_url=DOWNLOAD_URL,
license=LICENSE,
classifiers=CLASSIFIERS,
- platforms = PLATFORMS,
- configuration=configuration
+ platforms=PLATFORMS,
+ configuration=configuration,
+ scripts=SCRIPTS,
)
if __name__ == '__main__':

0 comments on commit 0433b14

Please sign in to comment.