FV3 Bundle
L95Plot.py
Go to the documentation of this file.
1 # (C) Copyright 2009-2016 ECMWF.
2 #
3 # This software is licensed under the terms of the Apache Licence Version 2.0
4 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 # In applying this licence, ECMWF does not waive the privileges and immunities
6 # granted to it by virtue of its status as an intergovernmental organisation nor
7 # does it submit to any jurisdiction.
8 
9 import numpy as np
10 import matplotlib.pyplot as plt
11 from matplotlib.figure import Figure
12 
13 class L95Plot:
14 
15  #===========================================================================
16  # __init__
17  # Constructor:
18  # Create the Figure for the plot
19  #===========================================================================
20  def __init__(self):
21  self.__f = Figure()
22  self.state = None
23  self.increment = None
24 
25  #=============================================================================
26  # setPlot
27  # put the datas to plot
28  #=============================================================================
29  def setPlot(self, title, expeData, bgData, obsData):
30  n = len(expeData)
31  x = np.arange(0, n)
32  xobs = []
33 
34  self.title = self.__f.suptitle(title)
35  self.state = self.__f.add_subplot(211)
36  #self.state.set_title("State:")
37  self.state.plot(x, expeData, 'b', label='state')
38 
39  if obsData is not None:
40  for iobs in obsData['x']:
41  xobs.append(n * iobs)
42  yobs = obsData['y']
43  self.state.plot(xobs, yobs, 'rx', label='obs')
44 
45  mini = np.amin(expeData) - 1
46  maxi = np.amax(expeData) + 3
47  self.state.axis([0, n, mini, maxi])
48 
49  # Compute increment Data
50  incrData = None
51  if bgData is not None:
52  incrData = []
53  for i in range(0, len(expeData)):
54  incrData.append(expeData[i] - bgData[i])
55  self.state.plot(x, bgData, 'b:', label='background')
56  self.state.legend()
57 
58  if xobs is not None:
59  yDep = []
60  for i in range(0, len(xobs)):
61  yDep.append(float(yobs[i]) - bgData[int(xobs[i])])
62 
63  self.increment = self.__f.add_subplot(212)
64  #self.increment.set_title("Increment:")
65  self.increment.plot([0, n], [0.0, 0.0], 'k-', label='')
66 
67  ax = self.__f.gca()
68  ax.set_xticks(np.arange(0, 40, 5))
69  ax.set_yticks(np.arange(-5., 5., 0.5))
70  self.increment.grid()
71  if incrData is not None:
72  self.increment.plot(x, incrData, 'b', label='increment')
73  if len(xobs) > 0:
74  self.increment.plot(xobs, yDep, 'rx', label='departure')
75  self.increment.axis([0, n, -2, 2])
76  self.increment.legend()
77 
78  #=============================================================================
79  # getFigure
80  # Accessor for the figure
81  #=============================================================================
82  def getFigure(self):
83  return self.__f
84 
85  #=============================================================================
86  # clear
87  # Clear the plot
88  #=============================================================================
89  def clear(self):
90  self.__f.texts = []
91  if self.state is not None:
92  self.state.clear()
93  if self.increment is not None:
94  self.increment.clear()
95  self.state = None
96  self.increment = None
def __init__(self)
Definition: L95Plot.py:20
def clear(self)
Definition: L95Plot.py:89
def getFigure(self)
Definition: L95Plot.py:82
def setPlot(self, title, expeData, bgData, obsData)
Definition: L95Plot.py:29