Commit 6c8d5721 authored by Theo Steininger's avatar Theo Steininger

Merge branch 'imagine_on_hamx' into 'master'

Imagine on hamx

See merge request !4
parents 7d179bd2 1a2cb14e
......@@ -40,7 +40,7 @@ class EnsembleLikelihood(Likelihood):
n = observable.shape[1]
obs_val = observable.val.get_full_data()
obs_mean = observable.ensemble_mean().get_full_data()
obs_mean = observable.ensemble_mean().val.get_full_data()
# divide out profile
obs_val /= profile
......
......@@ -6,11 +6,5 @@ from magnetic_field import MagneticField, \
from constant_magnetic_field import ConstantMagneticField, \
ConstantMagneticFieldFactory
from jaffe13_magnetic_field import Jaffe13MagneticField, \
Jaffe13MagneticFieldFactory
from jf12_magnetic_field import JF12MagneticField, \
JF12MagneticFieldFactory
from wmap3yr_magnetic_field import WMAP3yrMagneticField, \
WMAP3yrMagneticFieldFactory
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field import MagneticField
try:
import galmag
except ImportError:
galmag_available = False
else:
galmag_available = True
class GalMagField(MagneticField):
def __init__(self, parameters=[], domain=None, val=None, dtype=None,
distribution_strategy=None, copy=False, random_seed=None):
if not galmag_available:
raise ImportError("GalMag module needed but not available.")
super(MagneticField, self).__init__(
parameters=parameters,
domain=domain,
val=val,
dtype=dtype,
distribution_strategy=distribution_strategy,
copy=copy,
random_seed=random_seed)
@property
def parameter_list(self):
parameter_list = ['b_x', 'b_y', 'b_z']
return parameter_list
def _create_field(self):
grid_domain = self.domain[1]
box_resolution = grid_domain.shape
bl = np.array(grid_domain.distances) * box_resolution
box_limits = [[-bl[0], bl[0]],
[-bl[1], bl[1]],
[-bl[2], bl[2]]]
ensemble_size = self.shape[0]
val = self.cast(None)
for i in ensemble_size:
b = galmag.B_field.B_field(box_limits, box_resolution)
val[i, :, :, :, 0] = b.x
val[i, :, :, :, 1] = b.y
val[i, :, :, :, 2] = b.z
return val
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field.magnetic_field_factory \
import MagneticFieldFactory
from galmag_field import GalMagField
class GalMagFieldFactory(MagneticFieldFactory):
@property
def magnetic_field_class(self):
return GalMagField
@property
def _initial_parameter_defaults(self):
defaults = {'b_x': 0,
'b_y': 0,
'b_z': 0}
return defaults
@property
def _initial_variable_to_parameter_mappings(self):
return {'b_x': [-100, 0, 100],
'b_y': [-100, 0, 100],
'b_z': [-100, 0, 100]}
# -*- coding: utf-8 -*-
from jaffe13_magnetic_field import Jaffe13MagneticField
from jaffe13_magnetic_field_factory import Jaffe13MagneticFieldFactory
\ No newline at end of file
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field import MagneticField
class Jaffe13MagneticField(MagneticField):
@property
def parameter_list(self):
parameter_list = ['B_f_ord', 'B_field_alpha', 'B_field_cutoff',
'B_ran_b2', 'B_ran_h_d', 'B_ran_h_d2', 'B_ran_h_r',
'B_ran_h_r2', 'bb_amps_0', 'bb_amps_1',
'bb_amps_2', 'bb_amps_3', 'bb_amps_4', 'bb_bar_a',
'bb_bar_boa', 'bb_bar_phi0_deg', 'bb_cr0_coh',
'bb_cr0_iso', 'bb_cr0_ord', 'bb_d0_iso', 'bb_d0',
'bb_delta_phi_iso_deg', 'bb_delta_phi_ord_deg',
'bb_disk_b0', 'bb_disk_h_d', 'bb_halo_b0',
'bb_halo_h_d', 'bb_phi0_deg', 'bb_pitch_biso',
'bb_pitch', 'bb_r_compconst', 'bb_r_innercut',
'bb_r_peak', 'bb_r_scale', 'bb_rmax_arms',
'bb_spiral_cpow', 'bb_spiral_h_d']
return parameter_list
def _create_field(self):
raise NotImplementedError
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field.magnetic_field_factory \
import MagneticFieldFactory
from jaffe13_magnetic_field import Jaffe13MagneticField
class Jaffe13MagneticFieldFactory(MagneticFieldFactory):
@property
def magnetic_field_class(self):
return Jaffe13MagneticField
@property
def _initial_parameter_defaults(self):
defaults = {'B_f_ord': 0.5,
'B_field_RMS_uG': 1.,
'B_field_alpha': -2.37,
'B_field_cutoff': 5.,
'B_ran_b2': 0.1,
'B_ran_h_d': 4.,
'B_ran_h_d2': 1.,
'B_ran_h_r': 15.,
'B_ran_h_r2': 15.,
'bb_amps_0': 2.,
'bb_amps_1': 0.133,
'bb_amps_2': -3.78,
'bb_amps_3': 0.32,
'bb_amps_4': -0.023,
'bb_bar_a': 0.,
'bb_bar_boa': 1.,
'bb_bar_phi0_deg': 45.,
'bb_cr0_coh': 0.5,
'bb_cr0_iso': 0.3,
'bb_cr0_ord': 0.5,
'bb_d0_iso': 0.3,
'bb_d0': 0.3,
'bb_delta_phi_iso_deg': 0.,
'bb_delta_phi_ord_deg': 0.,
'bb_disk_b0': 0.167,
'bb_disk_h_d': 0.1,
'bb_halo_b0': 1.38,
'bb_halo_h_d': 3.,
'bb_phi0_deg': 70.,
'bb_pitch_biso': -11.,
'bb_pitch': -11.5,
'bb_r_compconst': 12.,
'bb_r_innercut': 0.5,
'bb_r_peak': -1.,
'bb_r_scale': 20.,
'bb_rmax_arms': 30.,
'bb_spiral_cpow': 3.,
'bb_spiral_h_d': 0.1,
}
return defaults
@property
def _initial_variable_to_parameter_mappings(self):
return self._generate_variable_to_parameter_mapping_defaults(n=3)
def _generate_variable_to_parameter_mapping_defaults(self, n):
defaults = {'B_f_ord': self._interval(0.5, 1, n),
'B_field_RMS_uG': self._interval(1., 0.3, n),
'B_field_alpha': self._interval(-2.37, 1., n),
'B_field_cutoff': self._interval(5., 1., n),
'B_ran_b2': self._interval(0.1, 0.3, n),
'B_ran_h_d': self._interval(4., 1., n),
'B_ran_h_d2': self._interval(1., 1., n),
'B_ran_h_r': self._interval(15., 4., n),
'B_ran_h_r2': self._interval(15., 4., n),
'bb_amps_0': self._interval(2., 1., n),
'bb_amps_1': self._interval(0.133, 1., n),
'bb_amps_2': self._interval(-3.78, 1., n),
'bb_amps_3': self._interval(0.32, 1., n),
'bb_amps_4': self._interval(-0.023, 1., n),
'bb_bar_a': self._interval(0., 1., n),
'bb_bar_boa': self._interval(1., 1., n),
'bb_bar_phi0_deg': self._interval(45., 15., n),
'bb_cr0_coh': self._interval(0.5, 1., n),
'bb_cr0_iso': self._interval(0.3, 1., n),
'bb_cr0_ord': self._interval(0.5, 1., n),
'bb_d0_iso': self._interval(0.3, 0.1, n),
'bb_d0': self._interval(0.3, 0.1, n),
'bb_delta_phi_iso_deg': self._interval(0., 1., n),
'bb_delta_phi_ord_deg': self._interval(0., 1., n),
'bb_disk_b0': self._interval(0.167, 1., n),
'bb_disk_h_d': self._interval(0.1, 1., n),
'bb_halo_b0': self._interval(1.38, 1., n),
'bb_halo_h_d': self._interval(3., 0.9, n),
'bb_phi0_deg': self._interval(70., 20., n),
'bb_pitch_biso': self._interval(-11, 5., n),
'bb_pitch': self._interval(-11.5, 5., n),
'bb_r_compconst': self._interval(12., 3., n),
'bb_r_innercut': self._interval(0.5, 1., n),
'bb_r_peak': self._interval(-1., 1., n),
'bb_r_scale': self._interval(20., 4., n),
'bb_rmax_arms': self._interval(30., 5., n),
'bb_spiral_cpow': self._interval(3., 1., n),
'bb_spiral_h_d': self._interval(0.1, 1., n),
}
return defaults
# -*- coding: utf-8 -*-
from jf12_magnetic_field import JF12MagneticField
from jf12_magnetic_field_factory import JF12MagneticFieldFactory
\ No newline at end of file
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field import MagneticField
class JF12MagneticField(MagneticField):
@property
def parameter_list(self):
parameter_list = ['b51_ran_b1', 'b51_ran_b2', 'b51_ran_b3',
'b51_ran_b4', 'b51_ran_b5', 'b51_ran_b6',
'b51_ran_b7', 'b51_ran_b8', 'b51_coh_b1',
'b51_coh_b2', 'b51_coh_b3', 'b51_coh_b4',
'b51_coh_b5', 'b51_coh_b6', 'b51_coh_b7',
'b51_z0_spiral', 'b51_z0_smooth', 'b51_r0_smooth',
'b51_b0_smooth', 'b51_b0_x', 'b51_Xtheta',
'b51_r0_x', 'b51_h_disk', 'b51_Bn', 'b51_Bs',
'b51_z0_halo', 'b51_b_ring', 'b51_b0_interior',
'b51_shift', 'B_analytic_beta']
return parameter_list
def _create_field(self):
raise NotImplementedError
# -*- coding: utf-8 -*-
from imagine.magnetic_fields.magnetic_field.magnetic_field_factory \
import MagneticFieldFactory
from jf12_magnetic_field import JF12MagneticField
class JF12MagneticFieldFactory(MagneticFieldFactory):
@property
def magnetic_field_class(self):
return JF12MagneticField
@property
def _initial_parameter_defaults(self):
defaults = {'b51_ran_b1': 10.8,
'b51_ran_b2': 6.96,
'b51_ran_b3': 9.59,
'b51_ran_b4': 6.96,
'b51_ran_b5': 1.96,
'b51_ran_b6': 16.34,
'b51_ran_b7': 37.29,
'b51_ran_b8': 10.35,
'b51_coh_b1': 0.1,
'b51_coh_b2': 3.,
'b51_coh_b3': -0.9,
'b51_coh_b4': -0.8,
'b51_coh_b5': -2.,
'b51_coh_b6': -4.2,
'b51_coh_b7': 0.,
'b51_z0_spiral': 0.61,
'b51_z0_smooth': 2.84,
'b51_r0_smooth': 10.97,
'b51_b0_smooth': 4.68,
'b51_b0_x': 4.6,
'b51_Xtheta': 49.,
'b51_r0_x': 2.9,
'b51_h_disk': 0.4,
'b51_Bn': 1.4,
'b51_Bs': -1.1,
'b51_z0_halo': 5.3,
'b51_b_ring': 0.1,
'b51_b0_interior': 7.63,
'b51_shift': 0.,
'B_analytic_beta': 1.36}
return defaults
@property
def _initial_variable_to_parameter_mappings(self):
return self._generate_variable_to_parameter_mapping_defaults(n=3)
def _generate_variable_to_parameter_mapping_defaults(self, n):
defaults = {
'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_b3': self._interval(9.59, 1.10, n), # b_3, 1210.7820
'b51_ran_b4': self._interval(6.96, 0.87, n), # b_4 1210.7820
'b51_ran_b5': self._interval(1.96, 1.32, n), # b_5, 1210.7820
'b51_ran_b6': self._interval(16.34, 2.53, n), # b_6, 1210.7820
'b51_ran_b7': self._interval(37.29, 2.39, n), # b_7, 1210.7820
'b51_ran_b8': self._interval(10.35, 4.43, n), # b_8, 1210.7820
'b51_b0_interior': self._interval(7.63, 1.39, n), # b_int, 1210.7820
'b51_z0_spiral': self._positive_interval(0.61, 0.04, n), # z_0^disk, 1210.7820
'b51_b0_smooth': self._interval(4.68, 1.39, n), # B_0, 1210.7820
'b51_r0_smooth': self._positive_interval(10.97, 3.80, n), # r_0, 1210.7820
'b51_z0_smooth': self._positive_interval(2.84, 1.30, n), # z_0, 1210.7820
# beta is missing (1210.7820)
'b51_coh_b1': self._interval(0.1, 1.8, n), # b_1, 1204.3662
'b51_coh_b2': self._interval(3.0, 0.6, n), # b_2, 1204.3662
'b51_coh_b3': self._interval(-0.9, 0.8, n), # b_3, 1204.3662
'b51_coh_b4': self._interval(-0.8, 0.3, n), # b_4, 1204.3662
'b51_coh_b5': self._interval(-2.0, 0.1, n), # b_5, 1204.3662
'b51_coh_b6': self._interval(-4.2, 0.5, n), # b_6, 1204.3662
'b51_coh_b7': self._interval(0.0, 1.8, n), # b_7, 1204.3662
'b51_b_ring': self._interval(0.1, 0.1, n), # b_ring, 1204.3662
'b51_h_disk': self._positive_interval(0.4, 0.03, n), # b_disk, 1204.3662
# w_disk is missing, 1204.3662
# B_n_disk is missing, 1204.3662
'b51_Bs': self._interval(-1.1, 0.1, n), # B_s, 1204.3662
# r_n is missing, 1204.3662
# r_s is missing, 1204.3662
# w_h is missing, 1204.3662
'b51_z0_halo': self._positive_interval(5.3, 1.6, n), # z_0, 1204.3662
'b51_b0_x': self._interval(4.6, 0.3, n), # B_X, 1204.3662
'b51_Xtheta': self._positive_interval(49., 1., n), # Theta_X^0, 1204.3662
# r_x^c is missing, 1204.3662
'b51_r0_x': self._positive_interval(2.9, 0.1, n), # r_x, 1204.3662
# gamma is missing (1204.3662)
'b51_shift': [-2, 0, 2],
'B_analytic_beta': self._interval(1.36, 0.4, n),
}
return defaults
......@@ -31,7 +31,7 @@ class MagneticField(Field):
assert(isinstance(self.domain[2], FieldArray))
self._parameters = {}
for p in self.parameter_list:
for p in self.descriptor_lookup:
self._parameters[p] = np.float(parameters[p])
casted_random_seed = distributed_data_object(
......@@ -48,8 +48,8 @@ class MagneticField(Field):
self.random_seed = casted_random_seed
@property
def parameter_list(self):
return []
def descriptor_lookup(self):
return {}
@property
def parameters(self):
......
......@@ -4,14 +4,18 @@ from imagine.magnetic_fields.magnetic_field import MagneticField
class WMAP3yrMagneticField(MagneticField):
@property
def parameter_list(self):
parameter_list = ['B_field_b0',
'B_field_psi0_deg',
'B_field_psi1_deg',
'B_field_xsi0_deg',
'B_field_RMS_uG']
return parameter_list
def descriptor_lookup(self):
lookup = \
{'b0': ('./Galaxy/MagneticField/Regular/WMAP/b0', 'value'),
'psi0': ('./Galaxy/MagneticField/Regular/WMAP/psi0', 'value'),
'psi1': ('./Galaxy/MagneticField/Regular/WMAP/psi1', 'value'),
'chi0': ('./Galaxy/MagneticField/Regular/WMAP/chi0', 'value'),
'random_rms': ('./Galaxy/MagneticField/Random/Iso/rms', 'value'),
'random_rho': ('./Galaxy/MagneticField/Random/Anisoglob/rho',
'value')}
return lookup
def _create_field(self):
raise NotImplementedError
......@@ -13,13 +13,12 @@ class WMAP3yrMagneticFieldFactory(MagneticFieldFactory):
@property
def _initial_parameter_defaults(self):
defaults = {
'B_field_b0': 6,
'B_field_psi0_deg': 27,
'B_field_psi1_deg': 0.9,
'B_field_xsi0_deg': 25,
'B_field_RMS_uG': 1.0,
}
defaults = {'b0': 6,
'psi0': 27,
'psi1': 0.9,
'chi0': 25,
'random_rms': 1.0,
'random_rho': 0.5}
return defaults
@property
......@@ -28,10 +27,11 @@ class WMAP3yrMagneticFieldFactory(MagneticFieldFactory):
def _generate_variable_to_parameter_mapping_defaults(self, n):
defaults = {
'B_field_b0': self._positive_interval(6.0, 2.0, n), # b0 astro-ph/0603450
'B_field_psi0_deg': self._positive_interval(27.0, 5.0, n), # psi0 astro-ph/0603450
'B_field_psi1_deg': self._positive_interval(0.9, 5.0, n), # psi1 astro-ph/0603450
'B_field_xsi0_deg': self._positive_interval(25, 5.0, n), # xsi0 astro-ph/0603450
'B_field_RMS_uG': self._positive_interval(1.0, 2.0, n)
'b0': self._positive_interval(6.0, 2.0, n), # b0 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
'chi0': self._positive_interval(25, 5.0, n), # xsi0 astro-ph/0603450
'random_rms': self._positive_interval(1.0, 2.0, n),
'random_rho': self._positive_interval(0.5, 1/6., n)
}
return defaults
This diff is collapsed.
<?xml version="1.0"?>
<!-- FULL PARAMETER-SET FOR ALL MODULES -->
<!-- "cue" acts as switches for usage -->
<root>
<!-- final output .fits maps -->
<Output>
<!-- Dispersion Measure -->
<DM cue="0" filename="dm.fits"/>
<!-- Synchrotron Emission -->
<Sync cue="0" filename="sync.fits"/>
<!-- Faraday Depth -->
<Faraday cue="0" filename="fd.fits"/>
</Output>
<!-- INTERACTIVE IN/OUTPUT -->
<Interface>
<!-- RESOLUTION DEFINED IN './Grid/Box' -->
<!-- regular magnetic field -->
<breg_grid read="0" write="0" filename="breg.bin"/>
<!-- turbulent magnetic field -->
<brnd_grid read="0" write="0" filename="brnd.bin"/>
<!-- free electron field -->
<fe_grid read="0" write="0" filename="ymw16.bin"/>
<!-- turbulent free electron field -->
<fernd_grid read="0" write="0" filename="fernd.bin"/>
<!-- cosmic ray electron -->
<cre_grid read="0" write="0" filename="cre.bin"/>
</Interface>
<!-- HAMMURABI GRID -->
<Grid type="3D" ec_frame="0">
<!-- ec_frame offers a local simulation timesaving scheme -->
<SunPosition>
<x value="-8.3"/> <!-- kpc -->
<y value="0"/> <!-- kpc -->
<z value="6"/> <!-- pc -->
</SunPosition>
<Box>
<!-- grid vertex number in each direction -->
<nx value="400"/>
<ny value="400"/>
<nz value="160"/>
<!-- box length in each direction -->
<lx value="40.0"/> <!-- kpc -->
<ly value="40.0"/> <!-- kpc -->
<lz value="8.0"/> <!-- kpc -->
</Box>
<!-- LOS integration -->
<Integration>
<shell value="1"/>
<nside value="64"/>
<!-- maximum radius in earth/galactic centric frame -->
<ec_r_max value="30.0"/> <!-- kpc -->
<gc_r_max value="20.0"/> <!-- kpc -->
<!-- maximum height in galactic centric frame -->
<gc_z_max value="10.0"/> <!-- kpc -->
<!-- radial resolution -->
<ec_r_res value="0.1"/> <!-- kpc -->
<!-- lower limit on galactic latitude -->
<lat_lim value="0."/> <!-- [0,90] -->
</Integration>
</Grid>
<!-- GALAXY SETTINGS -->
<Galaxy>
<!-- MAGNETIC FIELDS -->
<MagneticField>
<!-- regular fields -->
<Regular type="WMAP">
<!-- WMAP3yr -->
<WMAP>
<b0 value="2.0"/>
<psi0 value="27.0"/>
<psi1 value="0.9"/>
<chi0 value="25.0"/>
</WMAP>
<!-- Local testing -->
<Local>
<bd value="5"/>
<l0 value="70"/>
<z0 value="1.0"/>
<bn value="-2"/>
<bs value="2"/>
</Local>
</Regular>
<!-- turbulent fields -->
<Random cue="0" type="Iso" seed="-1">
<!-- isotropic -->
<Iso>
<rms value="1.0"/> <!-- norm at k0 -->
<k0 value="0.5"/> <!-- k0 = 1/(Lambda in kpc) -->
<a0 value="1.7"/> <!-- 5/3, Kolmogrov -->
</Iso>
<!-- global anisotropy -->
<Anisoglob>
<rho value="0.5"/>
</Anisoglob>
<!-- local turbulent -->
<Anisolocal>
<beta value="1.0"/>
</Anisolocal>
<!-- rescaling -->
<Rescal>
<r0 value="8.0"/> <!-- in kpc -->
<z0 value="1.0"/> <!-- in kpc -->
</Rescal>
</Random>
</MagneticField>
<!-- FREE ELECTRON -->
<FreeElectron type="YMW16">
<!-- YMW16 -->
<YMW16>
<Warp>
<R_warp value="8.4"/>
<Gamma_w value="0.14"/>
<R0 value="8.3"/>
</Warp>
<ThickDisk>
<Ad value="2500"/>
<Bd value="15000"/>
<n1 value="0.01132"/>
<H1 value="1673"/>
</ThickDisk>
<ThinDisk>
<A2 value="1200"/>
<B2 value="4000"/>
<n2 value="0.404"/>
<K2 value="1.54"/>
</ThinDisk>
<!-- using HH14 SpiralArms -->
<SpiralArm>
<B2s value="4000"/>
<Ele_arm_0 value="0.135000"/>
<Ele_arm_1 value="0.129000"/>
<Ele_arm_2 value="0.103000"/>
<Ele_arm_3 value="0.116000"/>
<Ele_arm_4 value="0.005700"/>
<Wid_arm_0 value="300"/>
<Wid_arm_1 value="500"/>
<Wid_arm_2 value="300"/>
<Wid_arm_3 value="500"/>
<Wid_arm_4 value="300"/>
<Aa value="11680"/>
<Ka value="5.015"/>
<ncn value="2.4"/>
<wcn value="8.2"/>
<thetacn value="109"/>
<nsg value="0.626"/>
<wsg value="20"/>
<thetasg value="75.8"/>
</SpiralArm>
<GalCenter>
<ngc value="6.2"/>
<Agc value="160"/>
<Hgc value="35"/>
</GalCenter>
<GumNebula>
<ngn value="1.84"/>
<Wgn value="15.1"/>
<Agn value="125.8"/>
<Kgn value="1.4"/>
</GumNebula>
<LocalBubble>
<J_LB value="0.480"/>
<nlb1 value="1.094"/>
<detlb1 value="28.4"/>
<wlb1 value="14.2"/>
<hlb1 value="112.9"/>
<thetalb1 value="195.4"/>
<nlb2 value="2.33"/>
<detlb2 value="14.7"/>
<wlb2 value="15.6"/>
<hlb2 value="43.6"/>
<thetalb2 value="278.2"/>
</LocalBubble>
<LoopI>
<nLI value="1.907"/>
<RLI value="80.0"/>
<WLI value="15.0"/>
<detthetaLI value="30.0"/>
<thetaLI value="40.0"/>
</LoopI>
</YMW16>
<!-- turbulent free electron -->