Commit 6c2df0f6 authored by Jait Dixit's avatar Jait Dixit

Update versioning for all spaces

parent 9dc01f33
......@@ -72,8 +72,6 @@ class GLSpace(Versionable, Space):
An array containing the pixel sizes.
"""
_serializable = ('nlat', 'nlon', 'dtype')
# ---Overwritten properties and methods---
def __init__(self, nlat=2, nlon=None, dtype=np.dtype('float')):
......@@ -217,13 +215,18 @@ class GLSpace(Versionable, Space):
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['serialized'] = [
pickle.dumps(getattr(self, item)) for item in self._serializable
]
hdf5_group['nlat'] = self.nlat
hdf5_group['nlon'] = self.nlon
hdf5_group['dtype'] = pickle.dumps(self.dtype)
return None
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
result = cls(
*[pickle.loads(item) for item in hdf5_group['serialized']])
nlat=hdf5_group['nlat'][()],
nlon=hdf5_group['nlon'][()],
dtype=pickle.loads(hdf5_group['dtype'][()])
)
return result
......@@ -97,8 +97,6 @@ class HPSpace(Versionable, Space):
An array with one element containing the pixel size.
"""
_serializable = ('nside', 'dtype')
# ---Overwritten properties and methods---
def __init__(self, nside=2, dtype=np.dtype('float')):
......@@ -212,13 +210,14 @@ class HPSpace(Versionable, Space):
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['serialized'] = [
pickle.dumps(getattr(self, item)) for item in self._serializable
]
hdf5_group['nside'] = self.nside
hdf5_group['dtype'] = pickle.dumps(self.dtype)
return None
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
result = cls(
*[pickle.loads(item) for item in hdf5_group['serialized']])
nside=hdf5_group['nside'][()],
dtype=pickle.loads(hdf5_group['dtype'][()])
)
return result
from __future__ import division
import pickle
import numpy as np
from keepers import Versionable
from nifty.spaces.space import Space
from nifty.config import nifty_configuration as gc,\
......@@ -15,7 +18,7 @@ gl = gdi.get('libsharp_wrapper_gl')
hp = gdi.get('healpy')
class LMSpace(Space):
class LMSpace(Versionable, Space):
"""
.. __
.. / /
......@@ -180,3 +183,18 @@ class LMSpace(Space):
if (lmax % 2 == 0) and (lmax > 2):
self.logger.warn("Unrecommended parameter (lmax <> 2*n+1).")
return lmax
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['lmax'] = self.lmax
hdf5_group['dtype'] = pickle.dumps(self.dtype)
return None
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
result = cls(
lmax=hdf5_group['lmax'][()],
dtype=pickle.loads(hdf5_group['dtype'][()])
)
return result
......@@ -16,14 +16,11 @@ from nifty.nifty_utilities import cast_axis_to_tuple
class PowerSpace(Versionable, Space):
_serializable = ('log', 'nbin', 'binbounds', 'kindex', 'rho',
'pundex', 'dtype')
# ---Overwritten properties and methods---
def __init__(self, harmonic_domain=RGSpace((1,)),
distribution_strategy='not',
log=False, nbin=None, binbounds=None, power_index=None,
log=False, nbin=None, binbounds=None,
dtype=np.dtype('float')):
super(PowerSpace, self).__init__(dtype)
......@@ -38,13 +35,12 @@ class PowerSpace(Versionable, Space):
"harmonic_domain must be a harmonic space.")
self._harmonic_domain = harmonic_domain
if power_index is None:
power_index = PowerIndexFactory.get_power_index(
domain=self.harmonic_domain,
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
power_index = PowerIndexFactory.get_power_index(
domain=self.harmonic_domain,
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
config = power_index['config']
self._log = config['log']
......@@ -165,9 +161,13 @@ class PowerSpace(Versionable, Space):
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['serialized'] = [
pickle.dumps(getattr(self, item)) for item in self._serializable
]
hdf5_group['log'] = self.log
hdf5_group['nbin'] = pickle.dumps(self.nbin)
hdf5_group['binbounds'] = pickle.dumps(self.binbounds)
hdf5_group['kindex'] = self.kindex
hdf5_group['rho'] = self.rho
hdf5_group['pundex'] = self.pundex
hdf5_group['dtype'] = pickle.dumps(self.dtype)
return {
'harmonic_domain': self.harmonic_domain,
......@@ -177,26 +177,26 @@ class PowerSpace(Versionable, Space):
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
deserialized =\
[pickle.loads(item) for item in hdf5_group['serialized']]
dtype = deserialized[6]
harmonic_domain = loopback_get('harmonic_domain')
power_index = {
'config': {
'log': deserialized[0], 'nbin': deserialized[1],
'binbounds': deserialized[2]
},
'pindex': loopback_get('pindex'),
'kindex': deserialized[3],
'rho': deserialized[4],
'pundex': deserialized[5],
'k_array': loopback_get('k_array')
}
result = cls(
harmonic_domain=harmonic_domain,
power_index=power_index,
dtype=dtype
)
return result
# make an empty PowerSpace object
new_ps = EmptyPowerSpace()
# reset class
new_ps.__class__ = cls
# set all values
new_ps.dtype = pickle.loads(hdf5_group['dtype'][()])
new_ps._harmonic_domain = loopback_get('harmonic_domain')
new_ps._log = hdf5_group['log'][()]
new_ps._nbin = pickle.loads(hdf5_group['nbin'][()])
new_ps._binbounds = pickle.loads(hdf5_group['binbounds'][()])
new_ps._pindex = loopback_get('pindex')
new_ps._kindex = hdf5_group['kindex'][:]
new_ps._rho = hdf5_group['rho'][:]
new_ps._pundex = hdf5_group['pundex'][:]
new_ps._k_array = loopback_get('k_array')
return new_ps
class EmptyPowerSpace(PowerSpace):
def __init__(self):
pass
......@@ -107,8 +107,6 @@ class RGSpace(Versionable, Space):
Whether or not the grid represents a Fourier basis.
"""
_serializable = ('shape', 'zerocenter', 'distances', 'harmonic', 'dtype')
# ---Overwritten properties and methods---
def __init__(self, shape=(1,), zerocenter=False, distances=None,
......@@ -247,7 +245,6 @@ class RGSpace(Versionable, Space):
# prepare the distributed_data_object
nkdict = distributed_data_object(
global_shape=shape,
dtype=np.float128,
distribution_strategy=distribution_strategy)
if distribution_strategy in DISTRIBUTION_STRATEGIES['slicing']:
......@@ -330,13 +327,21 @@ class RGSpace(Versionable, Space):
# ---Serialization---
def _to_hdf5(self, hdf5_group):
hdf5_group['serialized'] = [
pickle.dumps(getattr(self, item)) for item in self._serializable
]
hdf5_group['shape'] = self.shape
hdf5_group['zerocenter'] = self.zerocenter
hdf5_group['distances'] = self.distances
hdf5_group['harmonic'] = self.harmonic
hdf5_group['dtype'] = pickle.dumps(self.dtype)
return None
@classmethod
def _from_hdf5(cls, hdf5_group, loopback_get):
result = cls(
*[pickle.loads(item) for item in hdf5_group['serialized']])
shape=hdf5_group['shape'][:],
zerocenter=hdf5_group['zerocenter'][:],
distances=hdf5_group['distances'][:],
harmonic=hdf5_group['harmonic'][()],
dtype=pickle.loads(hdf5_group['dtype'][()])
)
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