nifty_config.py 3.03 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
36
dependency_injector.register(('pyfftw', 'fftw_mpi'),
                             lambda z: hasattr(z, 'FFTW_MPI'))
dependency_injector.register(('pyfftw', 'fftw_scalar'))
37

38
39
40
41
42
43
44
45

def _fft_module_checker(z):
    if z == 'mpi_fftw':
        return 'fftw_mpi' in dependency_injector
    if z == 'scalar_fftw':
        return 'fftw_scalar' in dependency_injector
    return True

46
47
48
# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
49
50
                               ['mpi_fftw', 'scalar_fftw', 'scalar_numpy'],
                               lambda z: _fft_module_checker(z))
51
52


53
def dtype_validator(dtype):
54
55
56
57
58
59
60
61
62
63
    try:
        np.dtype(dtype)
    except(TypeError):
        return False
    else:
        return True

variable_default_field_dtype = keepers.Variable(
                              'default_field_dtype',
                              ['float'],
64
                              dtype_validator,
65
66
                              genus='str')

67
68
variable_default_distribution_strategy = keepers.Variable(
                              'default_distribution_strategy',
69
                              ['not', 'fftw', 'equal'],
70
71
72
                              lambda z: (('pyfftw' in dependency_injector)
                                         if z == 'fftw' else True),
                              genus='str')
73
74

nifty_configuration = keepers.get_Configuration(
75
76
77
                 name='NIFTy',
                 variables=[variable_fft_module,
                            variable_default_field_dtype,
78
                            variable_default_distribution_strategy],
79
                 file_name='NIFTy.conf',
Theo Steininger's avatar
Theo Steininger committed
80
81
82
                 search_paths=[os.path.expanduser('~') + "/.config/nifty/",
                               os.path.expanduser('~') + "/.config/",
                               './'])
83

84
85
86
87
88
########

try:
    nifty_configuration.load()
except:
89
    pass