FV3 Bundle
QGOdb.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 #===============================================================================
10 # L950db
11 #
12 # A class to handle the observations used in L95 model
13 #===============================================================================
14 import numpy as np
15 from dateutil import parser
16 from datetime import tzinfo, timedelta, datetime
17 
18 class L95Odb:
19 
20  #=============================================================================
21  # Construct the odb object, read the observations and store them in a map
22  #=============================================================================
23  def __init__(self, fdbdir, odb_file):
24  self.datas = []
25  infile = open(fdbdir + "/" + odb_file, "r")
26  nbCols = int(infile.readline())
27  columns = []
28  for i in range(0, nbCols):
29  columns.append(infile.readline().strip())
30  nbRows = int(infile.readline())
31  for i in range(0, nbRows):
32  row = {}
33  col = infile.readline().split();
34  row["stringdate"] = col[1]
35  d = parser.parse(col[1])
36  row["date"] = d - timedelta(minutes=1)
37  row["x"] = col[2]
38  for j in range(0, nbCols) :
39  row[columns[j]] = col[j + 3]
40  self.datas.append(row)
41 
42  #=============================================================================
43  # get the observations at a date
44  #=============================================================================
45  def get(self, date):
46  obs = []
47  for o in self.datas:
48  if o["date"] == date:
49  obs.append(o)
50  return obs
51 
52  #=============================================================================
53  # get the observations at a date
54  #=============================================================================
55  def getXYAt(self, date, colName):
56  x = []
57  y = []
58  #try:
59  for o in self.datas:
60  if o["date"] == date:
61  x.append(float(o["x"]))
62  y.append(o[colName])
63  #except:
64  # x = []
65  # y = []
66  return x,y
67 
68  #=============================================================================
69  # get the observations at a date
70  #=============================================================================
71  def getAt(self, stringdate):
72  date = parser.parse(stringdate)
73  return self.get(date)
74 
def getXYAt(self, date, colName)
Definition: QGOdb.py:55
def getAt(self, stringdate)
Definition: QGOdb.py:71
def __init__(self, fdbdir, odb_file)
Definition: QGOdb.py:23
def get(self, date)
Definition: QGOdb.py:45