nifty_config.py 3.03 KB
Newer Older
1
2
3
# -*- coding: utf-8 -*-

import os
Theo Steininger's avatar
Theo Steininger committed
4
5
from distutils.version import LooseVersion as lv

6
import numpy as np
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import keepers

# Setup the dependency injector
dependency_injector = keepers.DependencyInjector(
                                   [('mpi4py.MPI', 'MPI'),
                                    'gfft',
                                    ('nifty.dummys.gfft_dummy', 'gfft_dummy'),
                                    'healpy',
                                    'libsharp_wrapper_gl'])

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


# Initialize the variables
variable_fft_module = keepers.Variable(
                               'fft_module',
                               ['pyfftw', 'gfft', 'gfft_dummy'],
                               lambda z: z in dependency_injector)

Theo Steininger's avatar
Theo Steininger committed
26
27
28
29
30

def _healpy_validator(use_healpy):
    if not isinstance(use_healpy, bool):
        return False
    if not use_healpy:
31
        return True
Theo Steininger's avatar
Theo Steininger committed
32
33
34
35
36
37
38
39
    if 'healpy' not in dependency_injector:
        return False
    healpy = dependency_injector['healpy']
    if lv(healpy.__version__) < lv('1.8.1'):
        return False
    return True


40
41
42
variable_use_healpy = keepers.Variable(
                          'use_healpy',
                          [True, False],
Theo Steininger's avatar
Theo Steininger committed
43
                          _healpy_validator,
44
45
46
                          genus='boolean')

variable_use_libsharp = keepers.Variable(
47
48
49
50
51
52
                         'use_libsharp',
                         [True, False],
                         lambda z: (('libsharp_wrapper_gl' in
                                     dependency_injector)
                                    if z else True) and isinstance(z, bool),
                         genus='boolean')
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

def _dtype_validator(dtype):
    try:
        np.dtype(dtype)
    except(TypeError):
        return False
    else:
        return True

variable_default_field_dtype = keepers.Variable(
                              'default_field_dtype',
                              ['float'],
                              _dtype_validator,
                              genus='str')

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

nifty_configuration = keepers.get_Configuration(
77
78
79
80
81
                 name='NIFTy',
                 variables=[variable_fft_module,
                            variable_use_healpy,
                            variable_use_libsharp,
                            variable_default_field_dtype,
82
                            variable_default_distribution_strategy],
83
84
85
86
87
                 file_name='NIFTy.conf',
                 search_pathes=[os.path.expanduser('~') + "/.config/nifty/",
                                os.path.expanduser('~') + "/.config/",
                                './'])

88
89
90
91
92
93
94
########
########

try:
    nifty_configuration.load()
except:
    pass