Commit fccf4f53 authored by Theo Steininger's avatar Theo Steininger
Browse files

Fixed default parameters in magnetic field models.

parent 9ab60e4f
...@@ -91,13 +91,5 @@ class EnsembleLikelihood(Likelihood): ...@@ -91,13 +91,5 @@ class EnsembleLikelihood(Likelihood):
(result_1, result_2, result)) (result_1, result_2, result))
# result_array[i] = result # result_array[i] = result
# total_result = result_array.mean() # total_result = result_array.mean()
total_result = result
normalization = measured_data.dot(measured_data) return result
normalized_total_result = total_result / normalization
self.logger.info("Applied normalization for total result: "
"%f / %f = %f" %
(total_result,
normalization,
normalized_total_result))
return normalized_total_result
...@@ -15,7 +15,7 @@ class JF12MagneticField(MagneticField): ...@@ -15,7 +15,7 @@ class JF12MagneticField(MagneticField):
'b51_b0_smooth', 'b51_b0_x', 'b51_Xtheta', 'b51_b0_smooth', 'b51_b0_x', 'b51_Xtheta',
'b51_r0_x', 'b51_h_disk', 'b51_Bn', 'b51_Bs', 'b51_r0_x', 'b51_h_disk', 'b51_Bn', 'b51_Bs',
'b51_z0_halo', 'b51_b_ring', 'b51_b0_interior', 'b51_z0_halo', 'b51_b_ring', 'b51_b0_interior',
'b51_reg_b0', 'b51_shift'] 'b51_shift', 'B_analytic_beta']
return parameter_list return parameter_list
def _create_field(self): def _create_field(self):
......
...@@ -13,8 +13,7 @@ class JF12MagneticFieldFactory(MagneticFieldFactory): ...@@ -13,8 +13,7 @@ class JF12MagneticFieldFactory(MagneticFieldFactory):
@property @property
def _initial_parameter_defaults(self): def _initial_parameter_defaults(self):
defaults = {'B_field_RMS_uG': 1., defaults = {'b51_ran_b1': 10.8,
'b51_ran_b1': 10.8,
'b51_ran_b2': 6.96, 'b51_ran_b2': 6.96,
'b51_ran_b3': 9.59, 'b51_ran_b3': 9.59,
'b51_ran_b4': 6.96, 'b51_ran_b4': 6.96,
...@@ -42,8 +41,8 @@ class JF12MagneticFieldFactory(MagneticFieldFactory): ...@@ -42,8 +41,8 @@ class JF12MagneticFieldFactory(MagneticFieldFactory):
'b51_z0_halo': 5.3, 'b51_z0_halo': 5.3,
'b51_b_ring': 0.1, 'b51_b_ring': 0.1,
'b51_b0_interior': 7.63, 'b51_b0_interior': 7.63,
'b51_reg_b0': 1., 'b51_shift': 0.,
'b51_shift': 0.} 'B_analytic_beta': 1.36}
return defaults return defaults
@property @property
...@@ -52,7 +51,6 @@ class JF12MagneticFieldFactory(MagneticFieldFactory): ...@@ -52,7 +51,6 @@ class JF12MagneticFieldFactory(MagneticFieldFactory):
def _generate_variable_to_parameter_mapping_defaults(self, n): def _generate_variable_to_parameter_mapping_defaults(self, n):
defaults = { defaults = {
'B_field_RMS_uG': self._interval(1., 0.3, n),
'b51_ran_b1': self._interval(10.8, 2.33, n), # b_1, 1210.7820 'b51_ran_b1': self._interval(10.8, 2.33, n), # b_1, 1210.7820
'b51_ran_b2': self._interval(6.96, 1.58, n), # b_2, 1210.7820 'b51_ran_b2': self._interval(6.96, 1.58, n), # b_2, 1210.7820
'b51_ran_b3': self._interval(9.59, 1.10, n), # b_3, 1210.7820 'b51_ran_b3': self._interval(9.59, 1.10, n), # b_3, 1210.7820
...@@ -89,7 +87,7 @@ class JF12MagneticFieldFactory(MagneticFieldFactory): ...@@ -89,7 +87,7 @@ class JF12MagneticFieldFactory(MagneticFieldFactory):
# r_x^c is missing, 1204.3662 # r_x^c is missing, 1204.3662
'b51_r0_x': self._positive_interval(2.9, 0.1, n), # r_x, 1204.3662 'b51_r0_x': self._positive_interval(2.9, 0.1, n), # r_x, 1204.3662
# gamma is missing (1204.3662) # gamma is missing (1204.3662)
'b51_reg_b0': [0, 1, 2],
'b51_shift': [-2, 0, 2], 'b51_shift': [-2, 0, 2],
'B_analytic_beta': self._interval(1.36, 0.4, n),
} }
return defaults return defaults
...@@ -16,11 +16,14 @@ from imagine.magnetic_fields.magnetic_field import MagneticField ...@@ -16,11 +16,14 @@ from imagine.magnetic_fields.magnetic_field import MagneticField
class Hammurapy(Observer): class Hammurapy(Observer):
def __init__(self, hammurabi_executable, conf_directory='./confs', def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.', nside=128): working_directory_base='.', nside=128,
analytic_ensemble_mean=False):
self.hammurabi_executable = os.path.abspath(hammurabi_executable) self.hammurabi_executable = os.path.abspath(hammurabi_executable)
self.conf_directory = os.path.abspath(conf_directory) self.conf_directory = os.path.abspath(conf_directory)
self.working_directory_base = os.path.abspath(working_directory_base) self.working_directory_base = os.path.abspath(working_directory_base)
self.analytic_ensemble_mean = bool(analytic_ensemble_mean)
self.nside = int(nside) self.nside = int(nside)
self.last_call_log = "" self.last_call_log = ""
...@@ -30,7 +33,7 @@ class Hammurapy(Observer): ...@@ -30,7 +33,7 @@ class Hammurapy(Observer):
dust_template_fname = os.path.join(self.conf_directory, dust_template_fname = os.path.join(self.conf_directory,
'IQU_dust.fits') 'IQU_dust.fits')
self.basic_parameters = {'B_ran_mem_lim': '4', self.basic_parameters = {'B_ran_mem_lim': '6',
'obs_shell_index_numb': '1', 'obs_shell_index_numb': '1',
'total_shell_numb': '3', 'total_shell_numb': '3',
'vec_size_R': '500', 'vec_size_R': '500',
...@@ -41,7 +44,7 @@ class Hammurapy(Observer): ...@@ -41,7 +44,7 @@ class Hammurapy(Observer):
'TE_nx': '400', 'TE_nx': '400',
'TE_ny': '400', 'TE_ny': '400',
'TE_nz': '80', 'TE_nz': '80',
'TE_interp': 'T', 'TE_interp': 'F',
'do_sync_emission': 'F', 'do_sync_emission': 'F',
'do_rm': 'F', 'do_rm': 'F',
'do_dm': 'F', 'do_dm': 'F',
...@@ -192,44 +195,45 @@ class Hammurapy(Observer): ...@@ -192,44 +195,45 @@ class Hammurapy(Observer):
finally: finally:
self._remove_folder(working_directory) self._remove_folder(working_directory)
# compute ensemble_mean on the last node and add it to the observables if self.analytic_ensemble_mean:
rank = dummy.comm.rank # compute ensemble_mean on last node and add it to the observables
size = dummy.comm.size rank = dummy.comm.rank
size = dummy.comm.size
if rank + 1 == size:
self.logger.debug("Processing ensemble mean.") if rank + 1 == size:
# create a temporary folder self.logger.debug("Processing ensemble mean.")
working_directory = self._make_temp_folder() # create a temporary folder
working_directory = self._make_temp_folder()
# create dictionary for parameter file
parameter_dict = self.basic_parameters.copy() # create dictionary for parameter file
parameter_dict = self.basic_parameters.copy()
# set the parameters for an analytic run
parameter_dict['use_B_analytic'] = 'T' # set the parameters for an analytic run
parameter_dict['use_B_analytic'] = 'T'
self._build_parameter_dict(
parameter_dict=parameter_dict, self._build_parameter_dict(
magnetic_field=magnetic_field, parameter_dict=parameter_dict,
working_directory=working_directory, magnetic_field=magnetic_field,
local_ensemble_index=None) working_directory=working_directory,
local_ensemble_index=None)
self._write_parameter_dict(parameter_dict=parameter_dict,
working_directory=working_directory) self._write_parameter_dict(parameter_dict=parameter_dict,
working_directory=working_directory)
# call hammurabi
self._call_hammurabi(working_directory) # call hammurabi
self._call_hammurabi(working_directory)
# if hammurabi failed, _add_ensemble_mean will fail
try: # if hammurabi failed, _add_ensemble_mean will fail
try:
self._add_ensemble_mean(observable_dict, working_directory)
except:
self.logger.critical("Hammurabi failed! Last call log:\n" +
self.last_call_log)
raise
finally:
self._remove_folder(working_directory)
else:
working_directory = None
self._add_ensemble_mean(observable_dict, working_directory) self._add_ensemble_mean(observable_dict, working_directory)
except:
self.logger.critical("Hammurabi failed! Last call log:\n" +
self.last_call_log)
raise
finally:
self._remove_folder(working_directory)
else:
working_directory = None
self._add_ensemble_mean(observable_dict, working_directory)
return observable_dict return observable_dict
...@@ -7,12 +7,14 @@ from imagine.magnetic_fields.galmag_field import GalMagField ...@@ -7,12 +7,14 @@ from imagine.magnetic_fields.galmag_field import GalMagField
class GalMagMixin(object): class GalMagMixin(object):
def __init__(self, hammurabi_executable, conf_directory='./confs', def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.', nside=128): working_directory_base='.', nside=128,
analytic_ensemble_mean=False):
self.__parameter_dict = {'B_field_type': '6'} self.__parameter_dict = {'B_field_type': '6'}
super(GalMagMixin, self).__init__(hammurabi_executable, super(GalMagMixin, self).__init__(hammurabi_executable,
conf_directory, conf_directory,
working_directory_base, working_directory_base,
nside) nside,
analytic_ensemble_mean)
@property @property
def magnetic_field_class(self): def magnetic_field_class(self):
......
...@@ -5,11 +5,13 @@ from imagine.magnetic_fields.jaffe13_magnetic_field import Jaffe13MagneticField ...@@ -5,11 +5,13 @@ from imagine.magnetic_fields.jaffe13_magnetic_field import Jaffe13MagneticField
class Jaffe13Mixin(object): class Jaffe13Mixin(object):
def __init__(self, hammurabi_executable, conf_directory='./confs', def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.', nside=128): working_directory_base='.', nside=128,
analytic_ensemble_mean=False):
self.__parameter_dict = {'B_field_type': '10', self.__parameter_dict = {'B_field_type': '10',
'B_field_do_random': 'T', 'B_field_do_random': 'T',
'B_analytic_beta': '0', 'B_analytic_beta': '0',
'B_field_RMS_uG': '3.5', 'B_f_ord': '1.0',
'B_field_RMS_uG': '1.0',
'bb_molr_aniso': 'T', 'bb_molr_aniso': 'T',
'bb_ord_interarm': 'T', 'bb_ord_interarm': 'T',
'bb_scale_coh_amps': 'T', 'bb_scale_coh_amps': 'T',
...@@ -19,7 +21,8 @@ class Jaffe13Mixin(object): ...@@ -19,7 +21,8 @@ class Jaffe13Mixin(object):
super(Jaffe13Mixin, self).__init__(hammurabi_executable, super(Jaffe13Mixin, self).__init__(hammurabi_executable,
conf_directory, conf_directory,
working_directory_base, working_directory_base,
nside) nside,
analytic_ensemble_mean)
@property @property
def magnetic_field_class(self): def magnetic_field_class(self):
......
...@@ -5,14 +5,18 @@ from imagine.magnetic_fields.jf12_magnetic_field import JF12MagneticField ...@@ -5,14 +5,18 @@ from imagine.magnetic_fields.jf12_magnetic_field import JF12MagneticField
class JF12Mixin(object): class JF12Mixin(object):
def __init__(self, hammurabi_executable, conf_directory='./confs', def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.', nside=128): working_directory_base='.', nside=128,
analytic_ensemble_mean=False):
self.__parameter_dict = {'B_field_type': '7', self.__parameter_dict = {'B_field_type': '7',
'B_field_do_random': 'T', 'B_field_do_random': 'T',
'B_analytic_beta': '1.36'} 'B_field_RMS_uG': '1.0',
'b51_reg_b0': '1.0',
}
super(JF12Mixin, self).__init__(hammurabi_executable, super(JF12Mixin, self).__init__(hammurabi_executable,
conf_directory, conf_directory,
working_directory_base, working_directory_base,
nside) nside,
analytic_ensemble_mean)
@property @property
def magnetic_field_class(self): def magnetic_field_class(self):
......
...@@ -15,12 +15,14 @@ from imagine.observables import Observable ...@@ -15,12 +15,14 @@ from imagine.observables import Observable
class MixinBase(object): class MixinBase(object):
def __init__(self, hammurabi_executable, conf_directory='./confs', def __init__(self, hammurabi_executable, conf_directory='./confs',
working_directory_base='.', nside=128): working_directory_base='.', nside=128,
analytic_ensemble_mean=False):
self.__hpSpace = HPSpace(nside=int(nside)) self.__hpSpace = HPSpace(nside=int(nside))
super(MixinBase, self).__init__(hammurabi_executable, super(MixinBase, self).__init__(hammurabi_executable,
conf_directory, conf_directory,
working_directory_base, working_directory_base,
nside) nside,
analytic_ensemble_mean)
@property @property
def __config_dict(self): def __config_dict(self):
......
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