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

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

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


Revision 1.2 - (hide annotations) (download) (as text)
Wed May 9 11:36:59 2018 UTC (5 years, 11 months ago) by mlosch
Branch: MAIN
Changes since 1.1: +0 -1 lines
File MIME type: text/x-python
remove spurious print statement

1 mlosch 1.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[0:]):
43     if iters0[k]<iters0[k-1]:
44     iters0[k:] = iters0[k:]+(iters0[k-1]-iters0[k]+1)
45    
46     fig, ax1 = plt.subplots()
47     ax1.semilogy(iters0,(np.asarray(fc)-fc[-1]),'bx-')
48     ax1.set_xlabel('iterations')
49     ax1.set_ylabel('fc-min(fc)', color='b')
50     ax1.tick_params('y', colors='b')
51     ax1.grid()
52    
53     ax2 = ax1.twinx()
54     ax2.plot(iters0,simuls, 'r.')
55     ax2.set_ylabel('# simulations', color='r')
56     ax2.tick_params('y', colors='r')
57    
58     plt.show()

  ViewVC Help
Powered by ViewVC 1.1.22