dasystem.py 4.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
"""CarbonTracker Data Assimilation Shell (CTDAS) Copyright (C) 2017 Wouter Peters. 
Users are recommended to contact the developers (wouter.peters@wur.nl) to receive
updates of the code. See also: http://www.carbontracker.eu. 

This program is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software Foundation, 
version 3. This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 

You should have received a copy of the GNU General Public License along with this 
program. If not, see <http://www.gnu.org/licenses/>."""
13
14
15
16
#!/usr/bin/env python
# control.py

"""
Peters, Wouter's avatar
Peters, Wouter committed
17
18
.. module:: dasystem
.. moduleauthor:: Wouter Peters 
19
20
21
22

Revision History:
File created on 26 Aug 2010.

Peters, Wouter's avatar
Peters, Wouter committed
23
The DaSystem class is found in the module :mod:`dasystem`, or in a specific implementation under the da/ source tree. It is derived from the standard python :class:`dictionary` object. 
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
It describes the details of the data assimilation system used (i.e., CarbonTracker, or CT Methane, or ....) ::

    datadir         : /Volumes/Storage/CO2/carbontracker/input/ct08/   ! The directory where input data is found
    obs.input.dir   : ${datadir}/obsnc/with_fillvalue                  ! the observation input dir
    obs.input.fname : obs_forecast.nc                                  ! the observation input file
    ocn.covariance  : ${datadir}/oif_p3_era40.dpco2.2000.01.hdf        ! the ocean flux covariance file
    bio.covariance  : ${datadir}/covariance_bio_olson19.nc             ! the biosphere flux covariance file
    deltaco2.prefix : oif_p3_era40.dpco2                               ! the type of ocean product used
    regtype         : olson19_oif30                                    ! the ecoregion definitions
    nparameters     : 240                                              ! the number of parameters to solve for
    random.seed     : 4385                                             ! the random seed for the first cycle
    regionsfile     : transcom_olson19_oif30.hdf                       ! the ecoregion defintion mask file

    ! Info on the sites file used

    obs.sites.rc        : ${datadir}/sites_and_weights_co2.ct10.rc     ! the weights in the covariance matric of each obs
41
42
43
44
45
46

The full baseclass description:

.. autoclass:: da.baseclasses.dasystem.DaSystem
   :members:

47
48
49
"""

import logging
50
import da.tools.rc as rc 
51
52
53
################### Begin Class DaSystem ###################

class DaSystem(dict):
Peters, Wouter's avatar
Peters, Wouter committed
54
55
    """ 
    Information on the data assimilation system used. This is normally an rc-file with settings.
56
57
    """

karolina's avatar
karolina committed
58
    def __init__(self, rcfilename):
59
        """
Peters, Wouter's avatar
Peters, Wouter committed
60
61
        Initialization occurs from passed rc-file name, items in the rc-file will be added
        to the dictionary
62
63
        """

karolina's avatar
karolina committed
64
        self.ID = 'CarbonTracker CO2'    # the identifier gives the platform name
65
        self.load_rc(rcfilename)
66

67
        logging.debug("Data Assimilation System initialized: %s" % self.ID)
68

karolina's avatar
karolina committed
69
    def load_rc(self, rcfilename):
70
71
72
        """ 
        This method loads a DA System Info rc-file with settings for this simulation 
        """
brunner's avatar
brunner committed
73
        for k, v in rc.read(rcfilename).items():
karolina's avatar
karolina committed
74
            self[k] = v
karolina's avatar
karolina committed
75
76
        
        logging.debug("DA System Info rc-file (%s) loaded successfully" % rcfilename)
77
78


79
    def validate(self):
80
        """ 
81
        validate the contents of the rc-file given a dictionary of required keys
82
        """
karolina's avatar
karolina committed
83
        needed_rc_items = {}
84

brunner's avatar
brunner committed
85
        for k, v in self.items():
karolina's avatar
karolina committed
86
87
88
89
            if v == 'True' : 
                self[k] = True
            if v == 'False': 
                self[k] = False
90
91

        for key in needed_rc_items:
brunner's avatar
brunner committed
92
            if key not in self:
karolina's avatar
karolina committed
93
                msg = 'Missing a required value in rc-file : %s' % key
94
                logging.error(msg)
brunner's avatar
brunner committed
95
                raise IOError(msg)
karolina's avatar
karolina committed
96
        logging.debug('DA System Info settings have been validated succesfully')
97
98
99
100
101
102

################### End Class DaSystem ###################


if __name__ == "__main__":
    pass