nifty_config.py 3.7 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':
38 39 40 41
        return ('fftw' in dependency_injector)
    if z == 'numpy':
        return True
    return False
42

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


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

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

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

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

77 78 79 80 81 82
variable_threads = keepers.Variable(
                                'threads',
                                [1],
                                lambda z: np.int(abs(z)) == z,
                                genus='int')

Theo Steininger's avatar
Theo Steininger committed
83 84 85 86 87 88
variable_loglevel = keepers.Variable(
                                'loglevel',
                                [10],
                                lambda z: np.int(z) == z and 0 <= z <= 50,
                                genus='int')

89
nifty_configuration = keepers.get_Configuration(
90 91 92
                 name='NIFTy',
                 variables=[variable_fft_module,
                            variable_default_field_dtype,
93
                            variable_default_distribution_strategy,
94
                            variable_harmonic_rg_base,
Theo Steininger's avatar
Theo Steininger committed
95 96
                            variable_threads,
                            variable_loglevel],
97
                 file_name='NIFTy.conf',
Theo Steininger's avatar
Theo Steininger committed
98 99 100
                 search_paths=[os.path.expanduser('~') + "/.config/nifty/",
                               os.path.expanduser('~') + "/.config/",
                               './'])
101

102 103 104 105 106
########

try:
    nifty_configuration.load()
except:
107
    pass