__init__.py 2.81 KB
Newer Older
1
2
3
from .run import run
from .native2inputs import native2inputs
from .outputs2native import outputs2native
4
from .ini_periods import ini_periods
5
import shutil
6
from types import MethodType
7
import pandas as pd
8
9
from pycif.utils import path
from pycif.utils.check import verbose
10

11
12
13
14
15
requirements = {'domain': {'name': 'CHIMERE', 'version': 'std',
                           'empty': False, 'any': False},
                'chemistry': {'name': 'CHIMERE', 'version': 'gasJtab',
                              'empty': False, 'any': False},
                'fluxes': {'name': 'CHIMERE', 'version': 'AEMISSIONS',
16
17
                           'empty': True, 'any': False},
                'meteo': {'name': 'CHIMERE', 'version': 'std',
18
19
20
21
22
23
24
25
26
27
                          'empty': False, 'any': False},
                'latcond': {'name': 'CHIMERE', 'version': 'icbc',
                            'empty': True, 'any': False, 'type': 'fields',
                            'newplg': True},
                'topcond': {'name': 'CHIMERE', 'version': 'icbc',
                            'empty': True, 'any': False, 'type': 'fields',
                            'newplg': True},
                'inicond': {'name': 'CHIMERE', 'version': 'icbc',
                            'empty': True, 'any': False, 'type': 'fields',
                            'newplg': True}}
28
29


30
def ini_data(plugin, **kwargs):
31
32
33
34
35
36
37
38
39
40
41
42
43
    """Initializes CHIMERE

    Args:
        plugin (dict): dictionary defining the plugin
        **kwargs (dictionary): possible extra parameters

    Returns:
        loaded plugin and directory with executable

    """
    
    verbose("Initializing the model")
    
44
    workdir = getattr(plugin, 'workdir', './')
45
46
47
48
    
    # Initializes the directory
    path.init_dir('{}/model'.format(workdir))
    
49
50
    # Copying the executables
    target = '{}/model/'.format(workdir)
51
    
52
53
    source = '{}/src/fwdchimere.e'.format(plugin.direxec)
    shutil.copy(source, target)
54
    
55
56
    source = '{}/src_tl/tlchimere.e'.format(plugin.direxec)
    shutil.copy(source, target)
57
    
58
59
    source = '{}/src_ad/achimere.e'.format(plugin.direxec)
    shutil.copy(source, target)
60
    
61
    # Required inputs for running a CHIMERE simulation
62
    plugin.required_inputs = ['exe', 'nml', 'fluxes',
Espen Sollum's avatar
Espen Sollum committed
63
                              'meteo', 'inicond', 'boundcond']
64
65
66
67
    
    # Default values:
    # period: '1D'
    plugin.periods = getattr(plugin, 'periods', '1D')
68
69
    
    # Number of hours per period
70
    plugin.nhours = int(pd.to_timedelta(plugin.periods).total_seconds() / 3600)
71
    plugin.nho = '{:.0f}'.format(plugin.nhours)
72
    
73
74
    # Replace name for AEMISSION files
    plugin.fluxes.fic = plugin.fluxes.fic.format(nho=plugin.nho)
75
76
77
78
79

    # Replace name for BOUN_CONCS files
    plugin.latcond.fic = plugin.latcond.fic.format(nho=plugin.nho)
    plugin.topcond.fic = plugin.topcond.fic.format(nho=plugin.nho)

80
    return plugin