Commit 66c00558 authored by Martin Reinecke's avatar Martin Reinecke

cleanup

parent 9d6729d2
...@@ -20,13 +20,12 @@ from __future__ import division ...@@ -20,13 +20,12 @@ from __future__ import division
import abc import abc
from .nifty_meta import NiftyMeta from .nifty_meta import NiftyMeta
from keepers import Loggable,\ from keepers import Loggable
Versionable
from future.utils import with_metaclass from future.utils import with_metaclass
class DomainObject(with_metaclass( class DomainObject(with_metaclass(
NiftyMeta, type('NewBase', (Versionable, Loggable, object), {}))): NiftyMeta, type('NewBase', (Loggable, object), {}))):
"""The abstract class that can be used as a domain for a field. """The abstract class that can be used as a domain for a field.
This holds all the information and functionality a field needs to know This holds all the information and functionality a field needs to know
...@@ -224,13 +223,3 @@ class DomainObject(with_metaclass( ...@@ -224,13 +223,3 @@ class DomainObject(with_metaclass(
""" """
return x return x
# ---Serialization---
def _to_hdf5(self, hdf5_group):
return None
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
result = cls()
return result
...@@ -23,8 +23,7 @@ from builtins import range ...@@ -23,8 +23,7 @@ from builtins import range
import ast import ast
import numpy as np import numpy as np
from keepers import Versionable,\ from keepers import Loggable
Loggable
from .domain_object import DomainObject from .domain_object import DomainObject
...@@ -35,7 +34,7 @@ from .random import Random ...@@ -35,7 +34,7 @@ from .random import Random
from functools import reduce from functools import reduce
class Field(Loggable, Versionable, object): class Field(Loggable, object):
""" The discrete representation of a continuous field over multiple spaces. """ The discrete representation of a continuous field over multiple spaces.
In NIFTY, Fields are used to store data arrays and carry all the needed In NIFTY, Fields are used to store data arrays and carry all the needed
...@@ -1444,47 +1443,6 @@ class Field(Loggable, Versionable, object): ...@@ -1444,47 +1443,6 @@ class Field(Loggable, Versionable, object):
"\n - min.,max. = " + str(minmax) + \ "\n - min.,max. = " + str(minmax) + \
"\n - mean = " + str(mean) "\n - mean = " + str(mean)
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group.attrs['dtype'] = self.dtype.name
hdf5_group.attrs['domain_axes'] = str(self.domain_axes)
hdf5_group['num_domain'] = len(self.domain)
if self._val is None:
ret_dict = {}
else:
ret_dict = {'val': self.val}
for i in range(len(self.domain)):
ret_dict['s_' + str(i)] = self.domain[i]
return ret_dict
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
# create empty field
new_field = EmptyField()
# reset class
new_field.__class__ = cls
# set values
temp_domain = []
for i in range(hdf5_group['num_domain'][()]):
temp_domain.append(repository.get('s_' + str(i), hdf5_group))
new_field.domain = tuple(temp_domain)
new_field.domain_axes = ast.literal_eval(
hdf5_group.attrs['domain_axes'])
try:
new_field._val = repository.get('val', hdf5_group)
except(KeyError):
new_field._val = None
new_field.dtype = np.dtype(hdf5_group.attrs['dtype'])
return new_field
class EmptyField(Field): class EmptyField(Field):
def __init__(self): def __init__(self):
......
...@@ -39,14 +39,3 @@ class FieldArray(FieldType): ...@@ -39,14 +39,3 @@ class FieldArray(FieldType):
@property @property
def dim(self): def dim(self):
return reduce(lambda x, y: x*y, self.shape) return reduce(lambda x, y: x*y, self.shape)
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['shape'] = self.shape
return None
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
result = cls(shape=hdf5_group['shape'][:])
return result
...@@ -20,15 +20,14 @@ from builtins import str ...@@ -20,15 +20,14 @@ from builtins import str
import abc import abc
from ...nifty_meta import NiftyMeta from ...nifty_meta import NiftyMeta
from keepers import Loggable,\ from keepers import Loggable
Versionable
from ...field import Field from ...field import Field
from ... import nifty_utilities as utilities from ... import nifty_utilities as utilities
from future.utils import with_metaclass from future.utils import with_metaclass
class LinearOperator(with_metaclass( class LinearOperator(with_metaclass(
NiftyMeta, type('NewBase', (Versionable, Loggable, object), {}))): NiftyMeta, type('NewBase', (Loggable, object), {}))):
"""NIFTY base class for linear operators. """NIFTY base class for linear operators.
The base NIFTY operator class is an abstract class from which The base NIFTY operator class is an abstract class from which
......
...@@ -180,20 +180,3 @@ class GLSpace(Space): ...@@ -180,20 +180,3 @@ class GLSpace(Space):
if nlon < 1: if nlon < 1:
raise ValueError("nlon must be a positive number.") raise ValueError("nlon must be a positive number.")
return nlon return nlon
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['nlat'] = self.nlat
hdf5_group['nlon'] = self.nlon
return None
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
result = cls(
nlat=hdf5_group['nlat'][()],
nlon=hdf5_group['nlon'][()],
)
return result
...@@ -139,16 +139,3 @@ class HPSpace(Space): ...@@ -139,16 +139,3 @@ class HPSpace(Space):
if nside < 1: if nside < 1:
raise ValueError("nside must be >=1.") raise ValueError("nside must be >=1.")
return nside return nside
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['nside'] = self.nside
return None
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
result = cls(
nside=hdf5_group['nside'][()],
)
return result
...@@ -187,16 +187,3 @@ class LMSpace(Space): ...@@ -187,16 +187,3 @@ class LMSpace(Space):
if lmax < 0: if lmax < 0:
raise ValueError("lmax must be >=0.") raise ValueError("lmax must be >=0.")
return lmax return lmax
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['lmax'] = self.lmax
return None
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
result = cls(
lmax=hdf5_group['lmax'][()],
)
return result
...@@ -277,18 +277,3 @@ class PowerSpace(Space): ...@@ -277,18 +277,3 @@ class PowerSpace(Space):
"""Degeneracy factor of the individual k-vectors. """Degeneracy factor of the individual k-vectors.
""" """
return self._rho return self._rho
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group.attrs['binbounds'] = str(self._binbounds)
return {
'harmonic_partner': self.harmonic_partner,
}
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
hp = repository.get('harmonic_partner', hdf5_group)
bb = ast.literal_eval(hdf5_group.attrs['binbounds'])
return PowerSpace(hp, binbounds=bb)
...@@ -252,21 +252,3 @@ class RGSpace(Space): ...@@ -252,21 +252,3 @@ class RGSpace(Space):
temp = np.empty(len(self.shape), dtype=np.float64) temp = np.empty(len(self.shape), dtype=np.float64)
temp[:] = distances temp[:] = distances
return tuple(temp) return tuple(temp)
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['shape'] = self.shape
hdf5_group['distances'] = self.distances
hdf5_group['harmonic'] = self.harmonic
return None
@classmethod
def _from_hdf5(cls, hdf5_group, repository):
result = cls(
shape=hdf5_group['shape'][:],
distances=hdf5_group['distances'][:],
harmonic=hdf5_group['harmonic'][()],
)
return result
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