/[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.3 - (hide annotations) (download) (as text)
Wed May 9 11:43:12 2018 UTC (5 years, 11 months ago) by mlosch
Branch: MAIN
Changes since 1.2: +5 -3 lines
File MIME type: text/x-python
fix sorting the iteration count after restarts

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

  ViewVC Help
Powered by ViewVC 1.1.22