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

Martin Reinecke's avatar
Martin Reinecke committed
19
from . import matplotlib_init
20

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'),
Theo Steininger's avatar
Theo Steininger committed
31
                                    ('pyfftw', 'fftw'),
32
                                    'pyHealpix',
Martin Reinecke's avatar
Martin Reinecke committed
33
                                    'plotly'])
34

35 36

def _fft_module_checker(z):
Theo Steininger's avatar
Theo Steininger committed
37
    if z == 'fftw_mpi':
38
        return hasattr(dependency_injector.get('fftw'), 'FFTW_MPI')
Theo Steininger's avatar
Theo Steininger committed
39
    if z == 'fftw':
40 41 42 43
        return ('fftw' in dependency_injector)
    if z == 'numpy':
        return True
    return False
44

45 46 47
# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
Theo Steininger's avatar
Theo Steininger committed
48 49
                               ['fftw_mpi', 'fftw', 'numpy'],
                               _fft_module_checker)
50 51


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

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

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

73 74 75 76 77 78
variable_harmonic_rg_base = keepers.Variable(
                                'harmonic_rg_base',
                                ['real', 'complex'],
                                lambda z: z in ['real', 'complex'],
                                genus='str')

79
nifty_configuration = keepers.get_Configuration(
80 81 82
                 name='NIFTy',
                 variables=[variable_fft_module,
                            variable_default_field_dtype,
83 84
                            variable_default_distribution_strategy,
                            variable_harmonic_rg_base],
85
                 file_name='NIFTy.conf',
Theo Steininger's avatar
Theo Steininger committed
86 87 88
                 search_paths=[os.path.expanduser('~') + "/.config/nifty/",
                               os.path.expanduser('~') + "/.config/",
                               './'])
89

90 91 92 93 94
########

try:
    nifty_configuration.load()
except:
95
    pass