Commit 2e6c5343 authored by Theo Steininger's avatar Theo Steininger
Browse files

Added likelihood to Sample class.

parent ef11cbe0
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import simplejson as json import simplejson as json
import numpy as np
from keepers import Loggable,\ from keepers import Loggable,\
Versionable Versionable
...@@ -10,10 +12,13 @@ from imagine.magnetic_fields import MagneticField ...@@ -10,10 +12,13 @@ from imagine.magnetic_fields import MagneticField
class Sample(Loggable, Versionable, object): class Sample(Loggable, Versionable, object):
def __init__(self): def __init__(self, variables=None, magnetic_field=None, observables=None,
self._variables = None likelihood=None, total_likelihood=None):
self._magnetic_field = None self.variables = variables
self._observables = None self.magnetic_field = magnetic_field
self.observables = observables
self.likelihood = likelihood
self.total_likelihood = total_likelihood
@property @property
def variables(self): def variables(self):
...@@ -50,10 +55,36 @@ class Sample(Loggable, Versionable, object): ...@@ -50,10 +55,36 @@ class Sample(Loggable, Versionable, object):
parsed_observables[key] = value parsed_observables[key] = value
self._observables = parsed_observables self._observables = parsed_observables
@property
def likelihood(self):
return self._likelihood
@likelihood.setter
def likelihood(self, likelihood):
if np.isscalar(likelihood):
likelihood = (likelihood, )
else:
likelihood = tuple(likelihood)
self._likelihood = likelihood
@property
def total_likelihood(self):
return self._total_likelihood
@total_likelihood.setter
def total_likelihood(self, total_likelihood):
self._total_likelihood = np.float(total_likelihood)
def _to_hdf5(self, hdf5_group): def _to_hdf5(self, hdf5_group):
if self._variables is not None: if self._variables is not None:
hdf5_group.attrs['variables'] = json.dumps(self._variables) hdf5_group.attrs['variables'] = json.dumps(self._variables)
if self._likelihood is not None:
hdf5_group['likelihood'] = self._likelihood
if self._total_likelihood is not None:
hdf5_group.attrs['total_likelihood'] = self._total_likelihood
return_dict = {} return_dict = {}
if self._magnetic_field is not None: if self._magnetic_field is not None:
return_dict['magnetic_field'] = self._magnetic_field return_dict['magnetic_field'] = self._magnetic_field
...@@ -74,6 +105,16 @@ class Sample(Loggable, Versionable, object): ...@@ -74,6 +105,16 @@ class Sample(Loggable, Versionable, object):
except(KeyError): except(KeyError):
pass pass
try:
new_sample._likelihood = tuple(hdf5_group['likelihood'])
except(KeyError):
pass
try:
new_sample._total_likelihood = hdf5_group.attrs['total_likelihood']
except(KeyError):
pass
try: try:
magnetic_field = repository.get('magnetic_field', hdf5_group) magnetic_field = repository.get('magnetic_field', hdf5_group)
new_sample._magnetic_field = magnetic_field new_sample._magnetic_field = 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