nifty_config.py 2.86 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

Martin Reinecke's avatar
Martin Reinecke committed
34
35
dependency_injector.register(('pyfftw','fftw_mpi'), lambda z: hasattr(z, 'FFTW_MPI'))
dependency_injector.register(('pyfftw','fftw_scalar'))
36
37
38
39

# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
Martin Reinecke's avatar
Martin Reinecke committed
40
41
42
                               ['mpi', 'scalar'],
                               lambda z: (('fftw_mpi' in dependency_injector)
                                          if z == 'mpi' else True))
43
44


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

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

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

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

76
77
78
79
80
########

try:
    nifty_configuration.load()
except:
81
    pass