thydro-tsshow.py - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
(HTM) git clone git://src.adamsgaard.dk/pism
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
thydro-tsshow.py (1611B)
---
1 #!/usr/bin/env python3
2
3 """
4 Creates graph of three modeled hydrology-related time series from a single file.
5 """
6
7 # example from grid-sequencing example:
8 # $ ./hydro-tsshow.py foo.png ts_routing-decoupled.nc
9
10 from numpy import *
11 import pylab as plt
12 import sys
13 try:
14 import netCDF4 as netCDF
15 except:
16 print("netCDF4 is not installed!")
17 sys.exit(1)
18
19 NC = netCDF.Dataset
20
21 if len(sys.argv) < 3:
22 print("hydro-tsshow.py ERROR: ... FIXME ... exiting")
23 sys.exit(1)
24 outimage = sys.argv[1]
25 tsfile = sys.argv[2]
26
27 secpera = 31556926.0
28 scale = 10.0e3
29 scalestr = '$10^3$'
30 yaxismin = 1.0e-4 # in scale*kg/s
31 legloc = 'lower right'
32
33 labels = []
34 plt.figure(figsize=(9, 4))
35
36 print("opening file '%s' for reading ..." % tsfile)
37 try:
38 ncfile = NC(tsfile, "r")
39 except:
40 print("ERROR: can't open file %s for reading ..." % tsfile)
41 sys.exit(2)
42 print(" reading 'time' variable ...")
43 t = ncfile.variables["time"][:] / secpera
44
45 n = 3
46 style = ['b-', 'g-', 'r-']
47 labels = ['ocean_loss', 'ice_free_land_loss', 'negative_thickness_gain']
48 for k in range(n):
49 varname = 'hydro_' + labels[k]
50 print(" reading '%s' variable ..." % varname)
51 var = ncfile.variables[varname][:]
52 plt.semilogy(t, var / scale, style[k], linewidth=2.5)
53 plt.hold(True)
54
55 ncfile.close()
56
57 plt.hold(False)
58 yy = plt.getp(plt.gca(), 'ylim')
59 plt.setp(plt.gca(), 'ylim', (yaxismin, yy[1]))
60 plt.legend(labels, loc=legloc)
61 plt.xlabel("t (years)", size=16)
62 plt.ylabel("flux (%s kg/s)" % scalestr, size=16)
63 plt.grid(True)
64
65 print("saving image to file '%s' ..." % outimage)
66 # plt.show()
67 plt.savefig(outimage, bbox_inches='tight')