__init__.py 2.07 KB
Newer Older
1
2
3
4
5
6
7
from .init_y0 import init_y0
from .init_rinvprod import init_rinvprod
from .native2obsvect import native2obsvect
from .obsvect2native import obsvect2native
from .rinvprod import rinvprod
from pycif.plugins.obsvects.standard.utils.check_monitor import check_monitor

8
9
10
11
from types import MethodType

# It is necessary to have some measurements and some info about the meteo
# to initialize the observation vector
12
13
requirements = {'measurements': {'any': True, 'empty': True},
                'model': {'any': True, 'empty': False}}
14
15
16
17
18
19
20
21


def ini_data(plugin, **kwargs):
    """Initializes the observation vector from information in the Yaml file

    Args:

    """
22
23
24
25
26
27
28
29
30

    # Set dump type if not defined; default is nc
    if not hasattr(plugin, 'dump_type'):
        plugin.dump_type = 'nc'
        
    # Set default fic_obsvect
    fic_default = '{}/obsvect/monitor.{}' .format(plugin.workdir,
                                                  plugin.dump_type)
    plugin.fic_obsvect = getattr(plugin, 'fic_obsvect', fic_default)
31
    
32
33
    # Keeping check_monitor as a class method
    plugin.check_monitor = MethodType(check_monitor, plugin)
34
    
35
    # Initializing y0
36
37
38
39
    measurements = plugin.measurements
    plugin.dump_type = getattr(plugin, 'dump_type', 'nc')
    init_y0(plugin, measurements, **kwargs)
    
40
    # Initialize R if any observation
41
42
    if plugin.datastore.size > 0:
        init_rinvprod(plugin, measurements, **kwargs)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    
    # Link satellite files to the working directory
    if hasattr(plugin, 'dir_satellites'):
        path.init_dir('{}/obsvect/satellites/'.format(plugin.workdir))
        for dd in plugin.model.subsimu_dates[:-1]:
            sat_fics = glob.glob(
                dd.strftime('{}/infos_*%Y%m%d%H%M.nc')
                    .format(plugin.dir_satellites))
            for fic in sat_fics:
                target = '{}/obsvect/satellites/{}'\
                    .format(plugin.workdir, os.path.basename(fic))
                path.link(fic, target)

    plugin.has_satellites = False
    if np.where((plugin.datastore['level'] < 0))[0].size > 0:
        plugin.has_satellites = True