Commit 513e9f8c authored by Theo Steininger's avatar Theo Steininger

Added mixin classes for JF12 and RM.

parent 2e7a2f32
......@@ -57,7 +57,7 @@ WORKDIR ../..
RUN git clone https://github.com/JohannesBuchner/PyMultiNest.git
WORKDIR PyMultiNest
RUN python setup.py install --user
RUN python setup.py install
WORKDIR ..
......@@ -67,7 +67,7 @@ RUN pip install mpi4py
RUN pip install cython healpy
RUN git clone https://gitlab.mpcdf.mpg.de/ift/NIFTy.git -b master
WORKDIR NIFTy
RUN python setup.py install --user
RUN python setup.py install
WORKDIR ..
......
# -*- coding: utf-8 -*-
from imagine.likelihoods.likelihood import Likelihood
class EnsembleLikelihood(Likelihood):
def __init__(self, measured_data, data_covariance):
self.measured_data = measured_data
self.data_covariance = data_covariance
def __call__(self, observable):
mean = observable.mean(spaces=0)
# -*- coding: utf-8 -*-
from mixins import *
from hammurapy_base import HammurapyBase
from observable_mixins import *
from model_mixins import *
from hammurapy import Hammurapy
......@@ -11,21 +11,23 @@ import numpy as np
from d2o import distributed_data_object
from imagine.observers.observer import Observer
from imagine.magnetic_fields.magnetic_field import MagneticField
class HammurapyBase(Observer):
class Hammurapy(Observer):
def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.'):
working_directory_base='.', nside=128):
self.hammurabi_executable = os.path.abspath(hammurabi_executable)
self.conf_directory = os.path.abspath(conf_directory)
self.working_directory_base = os.path.abspath(working_directory_base)
self.nside = nside
self.last_call_log = ""
self.basic_parameters = {'obs_shell_index_numb': '1',
'total_shell_numb': '1',
'obs_NSIDE': '128',
'vec_size_R': '100',
'total_shell_numb': '3',
'vec_size_R': '500',
'max_radius': '35',
'B_field_transform_lon': '-999',
'B_field_transform_lat': '-999',
......@@ -33,7 +35,13 @@ class HammurapyBase(Observer):
'TE_nx': '400',
'TE_ny': '400',
'TE_nz': '80',
'B_field_do_random': 'T',
'TE_interp' : 'T',
'B_field_do_random': 'S',
'obs_freq_GHz': '22',
'B_field_RMS_uG': '2',
'B_analytic_beta': '0',
'B_field_interp': 'T',
'use_B_analytic': 'F',
'B_ran_mem_lim': '4',
'do_sync_emission': 'F',
'do_rm': 'F',
......@@ -44,8 +52,8 @@ class HammurapyBase(Observer):
}
@abc.abstractproperty
def valid_magnetic_field_class(self):
return object
def magnetic_field_class(self):
return MagneticField
def _make_temp_folder(self):
prefix = os.path.join(self.working_directory_base, 'temp_hammurabi_')
......@@ -66,7 +74,7 @@ class HammurapyBase(Observer):
else:
self.logger.warning('Could not delete %s' % path)
def _read_fits_file(self, path, name):
def _read_fits_file(self, path, name, nside):
map_path = os.path.join(path, name)
result_list = []
i = 0
......@@ -74,7 +82,7 @@ class HammurapyBase(Observer):
try:
loaded_map = healpy.read_map(map_path, verbose=False,
field=i)
loaded_map = healpy.ud_grade(loaded_map, nside_out=128)
loaded_map = healpy.ud_grade(loaded_map, nside_out=nside)
result_list += [loaded_map]
i += 1
except IndexError:
......@@ -105,6 +113,7 @@ class HammurapyBase(Observer):
'B_field_ny': ny,
'B_field_nz': nz,
})
parameter_dict.update({'obs_NSIDE': self.nside})
def _write_parameter_dict(self, parameter_dict, working_directory):
parameters_string = ''
......@@ -122,6 +131,10 @@ class HammurapyBase(Observer):
def __call__(self, magnetic_field):
if not isinstance(magnetic_field, self.magnetic_field_class):
raise ValueError("Given magnetic field is not a subclass of" +
" %s" % str(self.magnetic_field_class))
observable_dict = {}
self._initialize_observable_dict(observable_dict=observable_dict,
magnetic_field=magnetic_field)
......
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.jf12_magnetic_field import JF12MagneticField
from hammurapy_base import HammurapyBase
class HammurapyJF12(HammurapyBase):
@property
def valid_magnetic_field_descriptor(self):
return JF12MagneticField
# -*- coding: utf-8 -*-
from hammurapy_rm_mixin import HammurapyRMMixin
from jf12_mixin import JF12Mixin
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.jf12_magnetic_field import JF12MagneticField
class JF12Mixin(object):
@property
def magnetic_field_class(self):
return JF12MagneticField
def _build_parameter_dict(self, parameter_dict, magnetic_field,
working_directory, local_ensemble_index):
parameter_dict['B_field_type'] = '51'
parameter_dict.update(magnetic_field.parameters)
super(JF12Mixin, self)._build_parameter_dict(parameter_dict,
magnetic_field,
working_directory,
local_ensemble_index)
# -*- coding: utf-8 -*-
from rm_mixin import RMMixin
......@@ -5,37 +5,36 @@ import os
from nifty import Field, HPSpace
class HammurapyRMMixin(object):
class RMMixin(object):
def _initialize_observable_dict(self, observable_dict, magnetic_field):
ensemble_space = magnetic_field.domain[0]
hp128 = HPSpace(nside=128)
hpSpace = HPSpace(nside=self.nside)
observable_dict['rm'] = Field(domain=(ensemble_space, hp128),
observable_dict['rm'] = Field(domain=(ensemble_space, hpSpace),
distribution_strategy='equal')
super(HammurapyRMMixin, self)._initialize_observable_dict(
observable_dict,
magnetic_field)
super(RMMixin, self)._initialize_observable_dict(observable_dict,
magnetic_field)
def _build_parameter_dict(self, parameter_dict, magnetic_field,
working_directory, local_ensemble_index):
obs_RM_file_name = os.path.join(working_directory, 'rm.fits')
parameter_dict['do_rm'] = 'T'
parameter_dict['obs_RM_file_name'] = obs_RM_file_name
super(HammurapyRMMixin, self)._build_parameter_dict(
parameter_dict,
magnetic_field,
working_directory,
local_ensemble_index)
super(RMMixin, self)._build_parameter_dict(parameter_dict,
magnetic_field,
working_directory,
local_ensemble_index)
def _fill_observable_dict(self, observable_dict, working_directory,
local_ensemble_index):
self.logger.debug('Reading RM-map.')
[rm_map] = self._read_fits_file(working_directory, 'rm.fits')
[rm_map] = self._read_fits_file(path=working_directory,
name='rm.fits',
nside=self.nside)
rm_field = observable_dict['rm']
rm_field.val.data[local_ensemble_index] = rm_map
super(HammurapyRMMixin, self)._fill_observable_dict(
observable_dict,
working_directory,
local_ensemble_index)
super(RMMixin, self)._fill_observable_dict(observable_dict,
working_directory,
local_ensemble_index)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment