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

Removed 'mean' from carrier_mapper

parent 8d30b8fe
...@@ -93,10 +93,11 @@ RUN python setup.py install ...@@ -93,10 +93,11 @@ RUN python setup.py install
WORKDIR .. WORKDIR ..
#Hammurabi #Hammurabi
RUN git clone https://bitbucket.org/ricphy/hamx -b flexible_output RUN git clone https://bitbucket.org/ricphy/hamx -b maintenance
WORKDIR hamx WORKDIR hamx
RUN cp install/Makefile ./ RUN cp install/Makefile ./
RUN make -f Makefile RUN make -f Makefile
ENV HAMMURABI=/home/Downloads/hamx/bin/hamx
WORKDIR .. WORKDIR ..
#IMAGINE #IMAGINE
......
...@@ -33,12 +33,8 @@ def infinity_mapper(x, a=-np.inf, m=0, b=np.inf): ...@@ -33,12 +33,8 @@ def infinity_mapper(x, a=-np.inf, m=0, b=np.inf):
return y return y
def unity_mapper(x, a=0, m=0.5, b=1): def unity_mapper(x, a=0, b=1):
""" """
Maps x from [0, 1] into the interval [a, b] Maps x from [0, 1] into the interval [a, b]
""" """
# rescale and shift return x * (b-a) + a
if x <= 0.5:
return 2*x * (m-a) + a
else:
return (2*x-1) * (b-m) + m
...@@ -69,11 +69,11 @@ class MagneticFieldFactory(Loggable, object): ...@@ -69,11 +69,11 @@ class MagneticFieldFactory(Loggable, object):
@staticmethod @staticmethod
def _interval(mean, sigma, n): def _interval(mean, sigma, n):
return [mean-n*sigma, mean, mean+n*sigma] return [mean-n*sigma, mean+n*sigma]
@staticmethod @staticmethod
def _positive_interval(mean, sigma, n): def _positive_interval(mean, sigma, n):
return [max(0, mean-n*sigma), mean, mean+n*sigma] return [max(0, mean-n*sigma), mean+n*sigma]
@property @property
def parameter_defaults(self): def parameter_defaults(self):
...@@ -85,6 +85,15 @@ class MagneticFieldFactory(Loggable, object): ...@@ -85,6 +85,15 @@ class MagneticFieldFactory(Loggable, object):
for k, v in new_defaults.items() for k, v in new_defaults.items()
if k in self._parameter_defaults) if k in self._parameter_defaults)
@property
def variable_defaults(self):
variable_defaults = {}
for parameter in self.parameter_defaults:
low, high = self.variable_to_parameter_mappings[parameter]
default = self.parameter_defaults[parameter]
variable_defaults[parameter] = (default - low)/(high - low)
return variable_defaults
@property @property
def variable_to_parameter_mappings(self): def variable_to_parameter_mappings(self):
return self._variable_to_parameter_mappings return self._variable_to_parameter_mappings
...@@ -94,7 +103,7 @@ class MagneticFieldFactory(Loggable, object): ...@@ -94,7 +103,7 @@ class MagneticFieldFactory(Loggable, object):
""" """
The parameter-mapping must be a dictionary with The parameter-mapping must be a dictionary with
key: parameter-name key: parameter-name
value: [min, mean, max] value: [min, max]
""" """
for k, v in new_mapping.items(): for k, v in new_mapping.items():
if k in self._variable_to_parameter_mappings: if k in self._variable_to_parameter_mappings:
...@@ -111,8 +120,7 @@ class MagneticFieldFactory(Loggable, object): ...@@ -111,8 +120,7 @@ class MagneticFieldFactory(Loggable, object):
mapping = self.variable_to_parameter_mappings[variable_name] mapping = self.variable_to_parameter_mappings[variable_name]
mapped_variable = unity_mapper(variables[variable_name], mapped_variable = unity_mapper(variables[variable_name],
a=mapping[0], a=mapping[0],
m=mapping[1], b=mapping[1])
b=mapping[2])
# mapped_variable = carrier_mapper(variables[variable_name], # mapped_variable = carrier_mapper(variables[variable_name],
# a=mapping[0], # a=mapping[0],
# m=mapping[1], # m=mapping[1],
......
...@@ -31,7 +31,7 @@ class WMAP3yrMagneticFieldFactory(MagneticFieldFactory): ...@@ -31,7 +31,7 @@ class WMAP3yrMagneticFieldFactory(MagneticFieldFactory):
'psi0': self._positive_interval(27.0, 5.0, n), # psi0 astro-ph/0603450 'psi0': self._positive_interval(27.0, 5.0, n), # psi0 astro-ph/0603450
'psi1': self._positive_interval(0.9, 5.0, n), # psi1 astro-ph/0603450 'psi1': self._positive_interval(0.9, 5.0, n), # psi1 astro-ph/0603450
'chi0': self._positive_interval(25, 5.0, n), # xsi0 astro-ph/0603450 'chi0': self._positive_interval(25, 5.0, n), # xsi0 astro-ph/0603450
'random_rms': self._positive_interval(1.0, 2.0, n), 'random_rms': self._positive_interval(1.0, 1.0, n),
'random_rho': self._positive_interval(0.5, 1/6., n) 'random_rho': self._positive_interval(0.5, 0.166, n)
} }
return defaults return defaults
...@@ -98,62 +98,6 @@ class Hammurapy(Observer): ...@@ -98,62 +98,6 @@ class Hammurapy(Observer):
distribution_strategy='equal') distribution_strategy='equal')
return observable_dict return observable_dict
def _build_parameter_dict(self, parameter_dict, magnetic_field,
local_ensemble_index):
parameter_dict.update(self.magnetic_field_model.parameter_dict)
parameter_dict.update(
{('./Interface/fe_grid', 'read'): '1',
('./Interface/fe_grid', 'filename'):
os.path.join(self.input_directory, 'fe_grid.bin'),
})
# access the magnetic-field's random-seed d2o directly, since we
# know that the distribution strategy is the same for the
# randam samples and the magnetic field itself
random_seed = magnetic_field.random_seed.data[local_ensemble_index]
parameter_dict.update(
{('./Galaxy/MagneticField/Random', 'seed'): random_seed})
for key, value in magnetic_field.parameters.iteritems():
large_key = magnetic_field.descriptor_lookup[key]
parameter_dict[large_key] = value
grid_space = magnetic_field.domain[1]
lx, ly, lz = np.array(grid_space.shape)*np.array(grid_space.distances)
nx, ny, nz = grid_space.shape
parameter_dict.update({('./Grid/Box/lx', 'value'): lx,
('./Grid/Box/ly', 'value'): ly,
('./Grid/Box/lz', 'value'): lz,
('./Grid/Box/nx', 'value'): nx,
('./Grid/Box/ny', 'value'): ny,
('./Grid/Box/nz', 'value'): nz})
parameter_dict.update(
{('./Grid/Integration/nside', 'value'): self.nside})
def _write_parameter_file(self, working_directory):
# load the default xml
try:
default_parameters_xml = os.path.join(self.input_directory,
'default_parameters.xml')
tree = et.parse(default_parameters_xml)
except IOError:
import imagine
module_path = os.path.split(
imagine.observers.hammurapy.__file__)[0]
default_parameters_xml = os.path.join(
module_path, 'input/default_parameters.xml')
tree = et.parse(default_parameters_xml)
root = tree.getroot()
for key, value in parameter_dict.iteritems():
root.find(key[0]).set(key[1], str(value))
parameters_file_path = os.path.join(working_directory,
'parameters.xml')
tree.write(parameters_file_path)
def _write_parameter_xml(self, magnetic_field, local_ensemble_index, def _write_parameter_xml(self, magnetic_field, local_ensemble_index,
working_directory): working_directory):
# load the default xml # load the default xml
...@@ -175,6 +119,7 @@ class Hammurapy(Observer): ...@@ -175,6 +119,7 @@ class Hammurapy(Observer):
custom_parameters = [ custom_parameters = [
['./Grid/Integration/shell/auto/nside_min', 'value', ['./Grid/Integration/shell/auto/nside_min', 'value',
self.nside], self.nside],
['./Grid/Integration/nside_sim', 'value', self.nside],
['./Interface/fe_grid', 'read', '1'], ['./Interface/fe_grid', 'read', '1'],
['./Interface/fe_grid', 'filename', ['./Interface/fe_grid', 'filename',
os.path.join(self.input_directory, 'fe_grid.bin')] os.path.join(self.input_directory, 'fe_grid.bin')]
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
</shell> </shell>
<nside_sim value="16"/> <!-- output map resolution --> <nside_sim value="16"/> <!-- output map resolution -->
<!-- maximum radius in earth/Galactic centric frame --> <!-- maximum radius in earth/Galactic centric frame -->
<ec_r_max value="30.0"/> <!-- kpc --> <ec_r_max value="3.0"/> <!-- kpc -->
<gc_r_max value="20.0"/> <!-- kpc --> <gc_r_max value="20.0"/> <!-- kpc -->
<!-- maximum height in galactic centric frame --> <!-- maximum height in galactic centric frame -->
<gc_z_max value="10.0"/> <!-- kpc --> <gc_z_max value="10.0"/> <!-- kpc -->
...@@ -209,8 +209,7 @@ ...@@ -209,8 +209,7 @@
<!-- verification --> <!-- verification -->
<Verify> <Verify>
<n0 value="0.01"/> <!-- pccm --> <n0 value="0.01"/> <!-- pccm -->
<r0 value="20.0"/> <!-- kpc --> <r0 value="3.0"/> <!-- kpc -->
<z0 value="0.1"/> <!-- kpc -->
</Verify> </Verify>
</Regular> </Regular>
<!-- turbulent free electron --> <!-- turbulent free electron -->
...@@ -257,8 +256,7 @@ ...@@ -257,8 +256,7 @@
<!-- verification --> <!-- verification -->
<Verify> <Verify>
<alpha value="3.0"/> <alpha value="3.0"/>
<r0 value="20.0"/> <!-- kpc --> <r0 value="3.0"/> <!-- kpc -->
<z0 value="1.0"/> <!-- kpc -->
<je value="0.25"/> <!-- local CRE flux norm factor @ 10GeV --> <je value="0.25"/> <!-- local CRE flux norm factor @ 10GeV -->
</Verify> </Verify>
......
Supports Markdown
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