ttsshow.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
       ---
       ttsshow.py (2459B)
       ---
            1 #!/usr/bin/env python3
            2 
            3 """
            4 Creates graph of modeled time series from multiple files.  See figures
            5 in the "Getting Started" section of the User's Manual.
            6 """
            7 
            8 # example from grid-sequencing example:
            9 #   $ ./tsshow.py ice_volume_glacierized ice_volume_glacierized-gridseq.png ts_g20km_10ka_hy.nc '20 km for 10 ka' ts_g10km_gridseq.nc '10 km for 2 ka' ts_g5km_gridseq.nc '5 km for 200 a'
           10 # example from paramstudy/:
           11 #   $ ../tsshow.py ice_volume_glacierized ice_volume_glacierized-param.png ts_p10km_q0.1_e1.nc '(0.1,1)' ts_p10km_q0.5_e1.nc '(0.5,1)' ts_p10km_q1.0_e1.nc '(1.0,1)' ts_p10km_q0.1_e3.nc '(0.1,3)' ts_p10km_q0.5_e3.nc '(0.5,3)' ts_p10km_q1.0_e3.nc '(1.0,3)' ts_p10km_q0.1_e6.nc '(0.1,6)' ts_p10km_q0.5_e6.nc '(0.5,6)' ts_p10km_q1.0_e6.nc '(1.0,6)'
           12 
           13 from numpy import *
           14 import pylab as plt
           15 import sys
           16 try:
           17     import netCDF4 as netCDF
           18 except:
           19     print("netCDF4 is not installed!")
           20     sys.exit(1)
           21 
           22 NC = netCDF.Dataset
           23 
           24 if len(sys.argv) < 5:
           25     print("tsshow.py ERROR: at least 4 arguments needed")
           26     print("usage:")
           27     print()
           28     print("   $ python tsshow.py FIELD OUTIMAGE TSFILE1 LABEL1 ... TSFILEn LABELn")
           29     print()
           30     print("where strings LABEL1 ... LABELn go in the legend")
           31     print("example:")
           32     print("   $ python tsshow.py ice_volume_glacierized foo.png ts_g20km.nc '20 km' ts_g10km.nc '10 km'")
           33     sys.exit(1)
           34 
           35 field = sys.argv[1]
           36 outimage = sys.argv[2]
           37 
           38 legloc = 'lower right'
           39 
           40 secpera = 31556926.0
           41 vfactor = 1.0e6 * 1.0e9
           42 
           43 n = (len(sys.argv) - 3) / 2
           44 labels = []
           45 plt.figure(figsize=(9, 4))
           46 
           47 style = ['b-',  'g-',  'r-',  'c-',  'm-',  'y-',  'k-',
           48          'b--', 'g--', 'r--', 'c--', 'm--', 'y--', 'k--']
           49 for k in range(n):
           50 
           51     tsfile = sys.argv[2 * k + 3]
           52     labels.append(sys.argv[2 * k + 4])
           53 
           54     try:
           55         ncfile = NC(tsfile, "r")
           56     except:
           57         print("ERROR: can't read from file %s ..." % tsfile)
           58         sys.exit(2)
           59     t = ncfile.variables["time"][:] / secpera
           60     var = ncfile.variables[field][:]
           61     ncfile.close()
           62     print("read variable '%s' from time-series file '%s' ..." % (field, tsfile))
           63 
           64     plt.plot(t, var / vfactor, style[k], linewidth=2.5)  # automatic colors; default order
           65     # blue, green, red, cyan, magenta, ...
           66     plt.hold(True)
           67 
           68 plt.hold(False)
           69 plt.legend(labels, loc=legloc)
           70 plt.xlabel("t (years)", size=16)
           71 plt.ylabel("%s ($10^6$ km$^3$)" % field, size=16)
           72 plt.grid(True)
           73 print("saving image to file '%s' ..." % outimage)
           74 # plt.show()
           75 plt.savefig(outimage, bbox_inches='tight')