/[MITgcm]/MITgcm_contrib/mlosch/optim_m1qn3/plotfc.py
ViewVC logotype

Contents of /MITgcm_contrib/mlosch/optim_m1qn3/plotfc.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Wed May 9 11:43:38 2018 UTC (5 years, 10 months ago) by mlosch
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -1 lines
File MIME type: text/x-python
too fast, remove print statement

1 #!/usr/bin/env python
2 # -*- coding: iso-8859-15 -*-
3 ######################## -*- coding: utf-8 -*-
4 """Usage: plotfc.py INPUTFILE
5 """
6 import matplotlib.pyplot as plt
7 import numpy as np
8 import sys
9 from getopt import gnu_getopt as getopt
10 # parse command-line arguments
11 try:
12 optlist,args = getopt(sys.argv[1:], ':', ['verbose'])
13 assert len(args) == 1
14 except (AssertionError):
15 sys.exit(__doc__)
16
17 fname=args[0]
18 print("reading from "+fname)
19
20 def get_output (fname, mystring):
21 """parse fname and get some numbers out"""
22 iters = []
23 simuls= []
24 fc = []
25 try:
26 f=open(fname)
27 except:
28 print(fname + " does not exist, continuing")
29 else:
30 for line in f:
31 if mystring in line:
32 ll = line.split()
33 iters.append( int(ll[2].replace(',','')))
34 simuls.append(int(ll[4].replace(',','')))
35 fc.append( float(ll[6].replace('D','e').replace(',','')))
36
37 return iters, simuls, fc
38
39 iters, simuls, fc = get_output(fname, "f=")
40 # sort out restarts
41 iters0 = np.asarray(iters)
42 for k,it in enumerate(iters[1:]):
43 kp1=k+1
44 if iters0[kp1]<iters0[kp1-1]:
45 iters0[kp1:] = iters0[kp1:]+(iters0[k]-iters0[kp1]+1)
46
47 fig, ax1 = plt.subplots()
48 ax1.semilogy(iters0,(np.asarray(fc)-fc[-1]),'bx-')
49 ax1.set_xlabel('iterations')
50 ax1.set_ylabel('fc-min(fc)', color='b')
51 ax1.tick_params('y', colors='b')
52 ax1.grid()
53
54 ax2 = ax1.twinx()
55 ax2.plot(iters0,simuls, 'r.')
56 ax2.set_ylabel('# simulations', color='r')
57 ax2.tick_params('y', colors='r')
58
59 plt.show()

  ViewVC Help
Powered by ViewVC 1.1.22