obs.py 2.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python
# obs.py

"""
Author : peters 

Revision History:
File created on 28 Jul 2010.

"""
import os
import sys
import logging
import datetime

16
17
identifier = 'Observation baseclass'
version    = '0.0'
18

19
################### Begin Class Observation ###################
20

21
22
class Observation(object):
    """ an object that holds data + methods and attributes needed to manipulate observations for a DA cycle """
23

24
    def __init__(self):
25
26
        self.Identifier = self.getid()
        self.Version    = self.getversion()
27
        self.Data       = ObservationList([])  # Initialize with an empty list of obs
28

29
30
31
32
33
34
35
        msg                 = 'Observation object initialized: %s'%self.Identifier ; logging.info(msg)

    def getid(self):
        return identifier

    def getversion(self):
        return identifier
36
37

    def __str__(self):
38
39
40
41
42
43
44
45
46
47
48
49
        """ Prints a list of Observation objects"""
        return "This is a %s object, version %s"%(self.Identifier,self.Version)

    def Initialize(self):
        """ Perform all steps needed to start working with observational data, this can include moving data, concatenating files,
            selecting datasets, etc.
        """

    def Validate(self):
        """ Make sure that data needed for the ObservationOperator (such as observation input lists, or parameter files)
            are present.
        """
50

51
52
53
54
55
56
    def AddObs(self):
        """ Add the observation data to the Observation object. This is in a form of a list that goes under the name Data. The
            list has as only requirement that it can return the observed+simulated values through a method "getvalues"
        """

    def AddSimulations(self):
57
58
59
        """ Add the simulation data to the Observation object. 
        """

60
61
62
63
64
65
    def AddModelDataMismatch(self, DaCycle):
        """ 
            Get the model-data mismatch values for this cycle.

        """

66
67
68
    def WriteSampleInfo(self, DaCycle):
        """ 
            Write the information needed by the observation operator to a file. Return the filename that was written for later use
69
        """
70
71


72
73
74
75
76
77
78

################### End Class Observations ###################

################### Begin Class ObservationList ###################

class ObservationList(list):
    """ This is a special type of list that holds observed sample objects. It has methods to extract data from such a list easily """
79
80
81
82
83
84
85
86
87
88
89
90
    from numpy import array, ndarray

    def getvalues(self,name,constructor=array):
            from numpy import ndarray
            result = constructor([getattr(o,name) for o in self])
            if isinstance(result,ndarray): 
                return result.squeeze()
            else:
                return result

################### End Class MixingRatioList ###################