diff --git a/imagine/__init__.py b/imagine/__init__.py index 23f5d894c618883893fca8da970e306d190f1cd1..8cf04f1d75096c09e85a5258ad4e41c1402bc8dd 100644 --- a/imagine/__init__.py +++ b/imagine/__init__.py @@ -6,6 +6,8 @@ from magnetic_fields import * from observers import * from priors import * +from pymultinest import pymultinest + from pipeline import Pipeline import nifty diff --git a/imagine/carrier_mapper.py b/imagine/carrier_mapper.py index 55e632a5333cee1f697bbc0c27e549b8ee8acd90..9f97563ea77cf46562e93ac7d664f2e166b0286a 100644 --- a/imagine/carrier_mapper.py +++ b/imagine/carrier_mapper.py @@ -3,7 +3,7 @@ import numpy as np -def carrier_mapper(x, a=-np.inf, m=0, b=np.inf): +def infinity_mapper(x, a=-np.inf, m=0, b=np.inf): """ Maps x from [-inf, inf] into the interval [a, b], where x=0 -> m """ @@ -31,3 +31,11 @@ def carrier_mapper(x, a=-np.inf, m=0, b=np.inf): # strech y to the interval [a,b] y = y*(b-a) + a return y + + +def unity_mapper(x, a=0, b=1): + """ + Maps x from [0, 1] into the interval [a, b] + """ + # rescale and shift + return x * (b-a) + a diff --git a/imagine/magnetic_fields/magnetic_field/magnetic_field_factory.py b/imagine/magnetic_fields/magnetic_field/magnetic_field_factory.py index cdedf7118f516b65971c4b5060bf384d78331c73..ebcb145c64bc2a215fe514fd77d439fd4f76bc6a 100644 --- a/imagine/magnetic_fields/magnetic_field/magnetic_field_factory.py +++ b/imagine/magnetic_fields/magnetic_field/magnetic_field_factory.py @@ -4,7 +4,7 @@ import numpy as np from keepers import Loggable -from imagine.carrier_mapper import carrier_mapper +from imagine.carrier_mapper import unity_mapper from nifty import FieldArray, RGSpace @@ -96,10 +96,13 @@ class MagneticFieldFactory(Loggable, object): for variable_name in variables: if variable_name in self.variable_to_parameter_mappings: mapping = self.variable_to_parameter_mappings[variable_name] - mapped_variable = carrier_mapper(variables[variable_name], - a=mapping[0], - m=mapping[1], - b=mapping[2]) + mapped_variable = unity_mapper(variables[variable_name], + a=mapping[0], + b=mapping[2]) +# mapped_variable = carrier_mapper(variables[variable_name], +# a=mapping[0], +# m=mapping[1], +# b=mapping[2]) else: mapped_variable = np.float(variables[variable_name]) parameter_dict[variable_name] = mapped_variable diff --git a/imagine/pymultinest/__init__.py b/imagine/pymultinest/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..199a3821ac4ca9c24c88ae27de895edbd21dc329 --- /dev/null +++ b/imagine/pymultinest/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from pymultinest import pymultinest diff --git a/imagine/pymultinest/mpi4py_shadow.py b/imagine/pymultinest/mpi4py_shadow.py new file mode 100644 index 0000000000000000000000000000000000000000..25fe49c6ac3f0b5ec16e8be03a43a4eda5c1f265 --- /dev/null +++ b/imagine/pymultinest/mpi4py_shadow.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + + +class _MPI(object): + def __init__(self): + self.COMM_WORLD = _COMM_WORLD() + + +class _COMM_WORLD(object): + def Get_size(self): + return 1 + +MPI = _MPI() diff --git a/imagine/pymultinest/pymultinest.py b/imagine/pymultinest/pymultinest.py new file mode 100644 index 0000000000000000000000000000000000000000..a7e7f850be17ad1cb71ae157e2a472b49957d55c --- /dev/null +++ b/imagine/pymultinest/pymultinest.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +import sys +import mpi4py +import mpi4py_shadow + +mpi4py_backup = sys.modules['mpi4py'] +sys.modules['mpi4py'] = mpi4py_shadow + +import pymultinest + +sys.modules['mpi4py'] = mpi4py_backup