__init__.py 2.2 KB
Newer Older
1
2
import shutil
from distutils.dir_util import copy_tree
Antoine Berchet's avatar
Antoine Berchet committed
3

4
from logging import debug
5
from ....utils.path import init_dir
Antoine Berchet's avatar
Antoine Berchet committed
6
7
from .make_chemistry import create_chemicalscheme
from .read_chemistry import read_chemicalscheme
8

9
10
11
_name = "CHIMERE"
_version = "gasJtab"

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
input_arguments = {
    "schemeid": {
        "doc": "Name of the chemical scheme",
        "accepted": str
    },
    "nreactamax": {
        "doc": "Max number of reactants/reaction",
        "default": 4,
        "accepted": int
    },
    "ntemps": {
        "doc": "Number of tabul. temperatures for stoichio.",
        "default": 4,
        "accepted": int
    },
    "ntabmax": {
        "doc": "Max number of rate constants",
        "default": 22,
        "accepted": int
    },
    "nlevphotmax": {
        "doc": "Max number of tabulated photolysis levels",
        "default": 50,
        "accepted": int
    },
    "ntabuzenmax": {
        "doc": "Max number of tabulated zenith angles",
        "default": 20,
        "accepted": int
    },
    "nphotmax": {
        "doc": "Max number of photolysis reactions",
        "default": 50,
        "accepted": int
    },
    "dir_precomp": {
        "doc": "Directory where pre-defined chemical schemes are stored. The "
               "assumed structure is: ``${dir_precomp}/${schemeid}/``",
        "optional": True,
        "accepted": str
    }
53
54
55
}


56
57
58
59
60
61
62
63
64
65
def ini_data(self, **kwargs):
    """Initializes the chemistry depending on the model used
    for the inversion.

    Args:
        plugin (ChemistryPlugin): chemistry definition

    Returns:
        Updates on the fly the chemistry
    """
66

67
    debug("Initializing the Chemistry")
Antoine Berchet's avatar
Antoine Berchet committed
68

69
70
    # Copying the chemical scheme to the working directory
    workdir = self.workdir
Antoine Berchet's avatar
Antoine Berchet committed
71
    dirchem_ref = "{}/chemical_scheme/{}/".format(workdir, self.schemeid)
72
    self.dirchem_ref = dirchem_ref
Antoine Berchet's avatar
Antoine Berchet committed
73

74
75
    shutil.rmtree(dirchem_ref, ignore_errors=True)
    init_dir(dirchem_ref)
Antoine Berchet's avatar
Antoine Berchet committed
76
    
77
    # If pre-computed scheme is specified
Antoine Berchet's avatar
Antoine Berchet committed
78
    try:
Antoine Berchet's avatar
Antoine Berchet committed
79
80
81
82
        copy_tree(
            "{}/{}/".format(self.dir_precomp, self.schemeid), dirchem_ref
        )

83
84
        # Read chemistry
        self.read_chemicalscheme(**kwargs)
Antoine Berchet's avatar
Antoine Berchet committed
85

86
    # Otherwise, initialize files from the yaml
Antoine Berchet's avatar
Antoine Berchet committed
87
    except:
88
        self.create_chemicalscheme()