__init__.py 2.91 KB
Newer Older
1
import os
Antoine Berchet's avatar
Antoine Berchet committed
2
3
import shutil

4
5
from inputs.fluxes import *
from inputs.meteo import *
Antoine Berchet's avatar
Antoine Berchet committed
6
7
8
from pycif.utils import path
from pycif.utils.check import verbose
from pycif.utils.classes.baseclass import Plugin
9
10
11
12
13
14
from .flushrun import flushrun
from .ini_periods import ini_periods
from .inputs import make_input
from .native2inputs import native2inputs
from .outputs2native import outputs2native
from .run import run
15

16
requirements = {'domain': {'name': 'LMDZ', 'version': 'std', 'empty': False},
17
                'fluxes': {'name': 'LMDZ', 'version': 'bin', 'empty': True},
18
19
20
21
                'chemistry': {'name': 'CHIMERE', 'version': 'gasJtab',
                              'empty': False},
                'emis_species': {'name': 'LMDZ', 'version': 'sflx',
                                 'empty': True, 'type': 'fluxes'},
22
                'meteo': {'name': 'LMDZ', 'version': 'mass-fluxes',
Espen Sollum's avatar
Espen Sollum committed
23
                          'empty': False}}
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


def ini_data(plugin, **kwargs):
    """Initializes LMDZ
    
    Args:
        plugin (Plugin): the model plugin to initialize
        **kwargs (dictionary): possible extra parameters
        
    Returns:
        loaded plugin and directory with executable
        
    """
    
    verbose("Initializing the model")
39
    
40
41
    workdir = getattr(plugin, 'workdir', './')
    
42
43
44
    # Cleaning the model working directory
    shutil.rmtree('{}/model/'.format(workdir), ignore_errors=True)
    
45
46
47
    # Initializes the directory
    path.init_dir('{}/model'.format(workdir))
    
Antoine Berchet's avatar
Antoine Berchet committed
48
    # copying the executable
49
50
    target = '{}/model/'.format(workdir) + os.path.basename(plugin.ficexec)
    source = plugin.ficexec
Antoine Berchet's avatar
Antoine Berchet committed
51
    shutil.copy(source, target)
52
    
Antoine Berchet's avatar
Antoine Berchet committed
53
54
55
56
    # copying the definition file
    target = '{}/model/run.def'.format(workdir)
    source = plugin.ficdef
    shutil.copy(source, target)
57
58
59
60
61
62
63
64
65
66
    
    # LMDZ has a fixed integration time step
    plugin.tstep = 0
    
    # Required inputs for running a LMDz simulations
    plugin.required_inputs = ['fluxes', 'meteo', 'inicond', 'def',
                              'chem_fields', 'prescrconcs', 'prodloss3d',
                              'traj']
    
    # Initializes default values
Antoine Berchet's avatar
Antoine Berchet committed
67
    # Period of sub-simulations: default = 1 month
68
69
    if not hasattr(plugin, 'periods'):
        plugin.periods = '1MS'
Antoine Berchet's avatar
Antoine Berchet committed
70
71
72
73
        
    # Convection scheme: default = TK = Tiedke
    if not hasattr(plugin, 'conv_scheme'):
        plugin.conv_scheme = 'TK'
Joel Thanwerdas's avatar
Joel Thanwerdas committed
74

75
    # Loading input fluxes if specified, otherwise, loads default inputs
76
77
    for spec in plugin.emis_species.attributes:
        tracer = getattr(plugin.emis_species, spec)
78
79
80
81
82
83
84
85
86
87
88
        
        if hasattr(tracer, 'provider') and hasattr(tracer, 'format'):
            name = tracer.provider
            version = tracer.format
        
        else:
            name = 'LMDZ'
            version = 'sflx'
        
        tracer.fluxes = Plugin.load_registered(name, version, 'fluxes',
                                               plg_orig=tracer)
89
90
    
    return plugin