Commit 107300e3 authored by Theo Steininger's avatar Theo Steininger

Updated magnetic field structure.

parent 537ff73f
# -*- coding: utf-8 -*-
from magnetic_field_factory import MagneticFieldFactory
from magnetic_field import MagneticField
from constant_field_factory import ConstantFieldFactory
from jf12_factory import JF12Factory
from magnetic_field import MagneticField, \
MagneticFieldFactory
from constant_magnetic_field import ConstantMagneticField, \
ConstantMagneticFieldFactory
from jf12_magnetic_field import JF12MagneticField, \
JF12MagneticFieldFactory
# -*- coding: utf-8 -*-
import numpy as np
from magnetic_field_factory import MagneticFieldFactory
class ConstantFieldFactory(MagneticFieldFactory):
@property
def descriptor(self):
return 'CONSTANT_FIELD'
@staticmethod
def _create_array(self):
result_array = np.empty(tuple(self.resolution) + (3,))
result_array[:, :, :] = [self.parameters['b_x'],
self.parameters['b_y'],
self.parameters['b_z']]
return result_array
def _initialize_parameter_defaults(self):
self._parameter_defaults = {'b_x': 0,
'b_y': 0,
'b_z': 0}
def _initialize_variable_to_parameter_mappings(self):
self._variable_to_parameter_mappings = {'b_x': [-np.inf, 0, np.inf],
'b_y': [-np.inf, 0, np.inf],
'b_z': [-np.inf, 0, np.inf]}
# -*- coding: utf-8 -*-
from constant_magnetic_field import ConstantMagneticField
from constant_magnetic_field_factory import ConstantMagneticFieldFactory
\ No newline at end of file
# -*- coding: utf-8 -*-
import numpy as np
from nifty import RGSpace, Field, FieldArray
from imagine.magnetic_fields.magnetic_field import MagneticField
class ConstantMagneticField(MagneticField):
@property
def parameter_list(self):
parameter_list = ['b_x', 'b_y', 'b_z']
return parameter_list
def _create_field(self):
distances = np.array(self.box_dimensions)/np.array(self.resolution)
space = RGSpace(shape=self.resolution,
distances=distances)
field_array = FieldArray(shape=(3,), dtype=np.float)
result_field = Field(domain=space, field_type=field_array)
result_field.val[:, :, :, 0] = self.parameters['b_x']
result_field.val[:, :, :, 1] = self.parameters['b_y']
result_field.val[:, :, :, 2] = self.parameters['b_z']
return result_field
# -*- coding: utf-8 -*-
import numpy as np
from imagine.magnetic_fields.magnetic_field.magnetic_field_factory \
import MagneticFieldFactory
from constant_magnetic_field import ConstantMagneticField
class ConstantMagneticFieldFactory(MagneticFieldFactory):
@property
def magnetic_field_class(self):
return ConstantMagneticField
@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': [-np.inf, 0, np.inf],
'b_y': [-np.inf, 0, np.inf],
'b_z': [-np.inf, 0, np.inf]}
# -*- 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_reg_b0', 'b51_shift']
return parameter_list
def _create_field(self):
raise NotImplementedError
# -*- coding: utf-8 -*-
from magnetic_field_factory import MagneticFieldFactory
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
class JF12Factory(MagneticFieldFactory):
@property
def descriptor(self):
result_descriptor = super(JF12Factory, self).descriptor
result_descriptor += ['JF12']
return result_descriptor
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.0,
'b51_coh_b3': -0.9,
'b51_coh_b4': -0.8,
'b51_coh_b5': -2.0,
'b51_coh_b6': -4.2,
'b51_coh_b7': 0.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_reg_b0': 0,
'b51_shift': 0}
return defaults
def _initialize_parameter_defaults(self):
self._parameter_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.0,
'b51_coh_b3': -0.9,
'b51_coh_b4': -0.8,
'b51_coh_b5': -2.0,
'b51_coh_b6': -4.2,
'b51_coh_b7': 0.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_reg_b0': 0,
'b51_shift': 0}
@property
def _initial_variable_to_parameter_mappings(self):
return self._generate_variable_to_parameter_mapping_defaults(n=3)
def _initialize_variable_to_parameter_mappings(self, n=3):
self._variable_to_parameter_mappings = {
def _generate_variable_to_parameter_mapping_defaults(self, n):
defaults = {
'b51_ran_b1': self._interval(10.8, 2.33, n),
'b51_ran_b2': self._interval(6.96, 1.58, n),
'b51_ran_b3': self._interval(9.59, 1.10, n),
......@@ -75,5 +82,4 @@ class JF12Factory(MagneticFieldFactory):
'b51_reg_b0': [0, 10, 1],
'b51_shift': [0, 10, 1],
}
return defaults
# -*- coding: utf-8 -*-
from magnetic_field import MagneticField
from magnetic_field_factory import MagneticFieldFactory
# -*- coding: utf-8 -*-
import types
import numpy as np
from keepers import Loggable
class MagneticField(Loggable, object):
def __init__(self, box_dimensions, resolution, descriptor,
parameters={}, create_array=None):
def __init__(self, box_dimensions, resolution, parameters):
self._box_dimensions = np.empty(3)
self._box_dimensions[:] = box_dimensions
self._box_dimensions = tuple(self._box_dimensions)
self._resolution = np.empty(3)
self._resolution[:] = resolution
self._descriptor = descriptor
self._resolution = tuple(self._resolution)
self._parameters = {}
for (key, value) in parameters.items():
self._parameters[str(key)] = np.float(value)
for p in self.parameter_list:
self._parameters[p] = np.float(parameters[p])
self._array = None
if create_array is not None:
self._create_array = types.MethodType(create_array, self)
@property
def parameter_list(self):
return []
@property
def parameters(self):
return self._parameters
@property
def field(self):
if self._field is None:
self._field = self._create_field()
return self._field
def _create_field(self):
raise NotImplementedError
@property
def box_dimensions(self):
return self._box_dimensions
......@@ -40,12 +48,3 @@ class MagneticField(Loggable, object):
@property
def descriptor(self):
return self._descriptor
@property
def array(self):
if self._array is None:
self._array = self._create_array()
return self._array
def _create_array(self):
raise NotImplementedError
# -*- coding: utf-8 -*-
import abc
import numpy as np
from keepers import Loggable
......@@ -15,18 +14,21 @@ class MagneticFieldFactory(Loggable, object):
def __init__(self, box_dimensions, resolution):
self.box_dimensions = box_dimensions
self.resolution = resolution
self._initialize_parameter_defaults()
self._initialize_variable_to_parameter_mappings()
self._parameter_defaults = self._initial_parameter_defaults
self._variable_to_parameter_mappings = \
self._initial_variable_to_parameter_mappings
@abc.abstractproperty
def descriptor(self):
return []
@property
def magnetic_field_class(self):
return MagneticField
def _initialize_parameter_defaults(self):
self._parameter_defaults = {}
@property
def _initial_parameter_defaults(self):
return {}
def _initialize_variable_to_parameter_mappings(self):
self._variable_to_parameter_mapping = {}
@property
def _initial_variable_to_parameter_mappings(self):
return {}
@staticmethod
def _interval(mean, sigma, n):
......@@ -88,11 +90,9 @@ class MagneticFieldFactory(Loggable, object):
work_parameters = self.parameter_defaults.copy()
work_parameters.update(mapped_variables)
result_magnetic_field = MagneticField(
result_magnetic_field = self.magnetic_field_class(
box_dimensions=self.box_dimensions,
resolution=self.resolution,
descriptor=self.descriptor,
parameters=work_parameters,
create_array=self._create_array)
parameters=work_parameters)
return result_magnetic_field
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