nifty_config.py 2.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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/>.
Theo Steininger's avatar
Theo Steininger committed
13
14
15
16
17
#
# Copyright(C) 2013-2017 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
18

19
20
import matplotlib_init

21
import os
Theo Steininger's avatar
Theo Steininger committed
22

23
import numpy as np
24
25
import keepers

26
27
__all__ = ['dependency_injector', 'nifty_configuration']

28
29
30
# Setup the dependency injector
dependency_injector = keepers.DependencyInjector(
                                   [('mpi4py.MPI', 'MPI'),
31
                                    'pyHealpix',
Martin Reinecke's avatar
Martin Reinecke committed
32
                                    'plotly'])
33
34
35
36
37
38

dependency_injector.register('pyfftw', lambda z: hasattr(z, 'FFTW_MPI'))

# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
Theo Steininger's avatar
Theo Steininger committed
39
40
41
                               ['fftw', 'numpy'],
                               lambda z: (('pyfftw' in dependency_injector)
                                          if z == 'fftw' else True))
42
43


44
def dtype_validator(dtype):
45
46
47
48
49
50
51
52
53
54
    try:
        np.dtype(dtype)
    except(TypeError):
        return False
    else:
        return True

variable_default_field_dtype = keepers.Variable(
                              'default_field_dtype',
                              ['float'],
55
                              dtype_validator,
56
57
                              genus='str')

58
59
variable_default_distribution_strategy = keepers.Variable(
                              'default_distribution_strategy',
60
                              ['fftw', 'equal', 'not'],
61
62
63
                              lambda z: (('pyfftw' in dependency_injector)
                                         if z == 'fftw' else True),
                              genus='str')
64
65

nifty_configuration = keepers.get_Configuration(
66
67
68
                 name='NIFTy',
                 variables=[variable_fft_module,
                            variable_default_field_dtype,
69
                            variable_default_distribution_strategy],
70
                 file_name='NIFTy.conf',
Theo Steininger's avatar
Theo Steininger committed
71
72
73
                 search_paths=[os.path.expanduser('~') + "/.config/nifty/",
                               os.path.expanduser('~') + "/.config/",
                               './'])
74

75
76
77
78
79
########

try:
    nifty_configuration.load()
except:
80
    pass