|
5 | 5 |
|
6 | 6 | from __future__ import absolute_import, division, print_function, unicode_literals |
7 | 7 |
|
8 | | -import sys |
| 8 | +import glob |
9 | 9 | import numpy as np |
10 | 10 | import numpy.ma as ma |
11 | 11 | from netCDF4 import Dataset |
12 | | -from optparse import OptionParser |
| 12 | +from argparse import ArgumentParser |
13 | 13 | import matplotlib.pyplot as plt |
14 | 14 | import textwrap |
15 | 15 |
|
16 | 16 | rhoi = 910.0 |
17 | 17 | rhosw = 1028. |
18 | 18 |
|
19 | 19 | print("** Gathering information. (Invoke with --help for more details. All arguments are optional)") |
20 | | -parser = OptionParser(description=__doc__) |
21 | | -parser.add_option("-1", dest="file1inName", help="input filename", default="globalStats.nc", metavar="FILENAME") |
22 | | -parser.add_option("-2", dest="file2inName", help="input filename", metavar="FILENAME") |
23 | | -parser.add_option("-3", dest="file3inName", help="input filename", metavar="FILENAME") |
24 | | -parser.add_option("-4", dest="file4inName", help="input filename", metavar="FILENAME") |
25 | | -parser.add_option("-5", dest="file5inName", help="input filename", metavar="FILENAME") |
26 | | -parser.add_option("-6", dest="file6inName", help="input filename", metavar="FILENAME") |
27 | | -parser.add_option("-7", dest="file7inName", help="input filename", metavar="FILENAME") |
28 | | -parser.add_option("-u", dest="units", help="units for mass/volume: m3, kg, Gt", default="Gt", metavar="FILENAME") |
29 | | -parser.add_option("-c", dest="plotChange", help="plot time series as change from initial. (not applied to GL flux or calving flux) Without this option, the full magnitude of time series is used", action='store_true', default=False) |
30 | | -parser.add_option("-s", dest="saveFile", help="file name to save png", default=None) |
31 | | -options, args = parser.parse_args() |
32 | | - |
| 20 | +parser = ArgumentParser(description=__doc__) |
| 21 | +parser.add_argument('files', nargs='*', default=['globalStats.nc'], |
| 22 | + help='input filename(s)', metavar='FILENAME') |
| 23 | +parser.add_argument("-u", dest="units", help="units for mass/volume: m3, kg, Gt", default="Gt", metavar="UNITS") |
| 24 | +parser.add_argument("-c", dest="plotChange", help="plot time series as change from initial. (not applied to GL flux or calving flux) Without this option, the full magnitude of time series is used", action='store_true', default=False) |
| 25 | +parser.add_argument("-s", dest="saveFile", help="file name to save png", default=None) |
| 26 | +options = parser.parse_args() |
| 27 | + |
| 28 | +# Expand any quoted glob patterns (e.g. "output*.nc") |
| 29 | +expanded = [] |
| 30 | +for f in options.files: |
| 31 | + matches = glob.glob(f) |
| 32 | + if matches: |
| 33 | + expanded.extend(sorted(matches)) |
| 34 | + else: |
| 35 | + expanded.append(f) |
| 36 | + |
| 37 | +options.files = expanded |
33 | 38 | print("Using ice density of {} kg/m3 if required for unit conversions".format(rhoi)) |
34 | 39 |
|
35 | 40 |
|
@@ -290,26 +295,8 @@ def plotStat(fname): |
290 | 295 | f.close() |
291 | 296 |
|
292 | 297 |
|
293 | | -plotStat(options.file1inName) |
294 | | - |
295 | | - |
296 | | -if(options.file2inName): |
297 | | - plotStat(options.file2inName) |
298 | | - |
299 | | -if(options.file3inName): |
300 | | - plotStat(options.file3inName) |
301 | | - |
302 | | -if(options.file4inName): |
303 | | - plotStat(options.file4inName) |
304 | | - |
305 | | -if(options.file5inName): |
306 | | - plotStat(options.file5inName) |
307 | | - |
308 | | -if(options.file6inName): |
309 | | - plotStat(options.file6inName) |
310 | | - |
311 | | -if(options.file7inName): |
312 | | - plotStat(options.file7inName) |
| 298 | +for fname in options.files: |
| 299 | + plotStat(fname) |
313 | 300 |
|
314 | 301 | custom_legend() |
315 | 302 |
|
|
0 commit comments