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

Update versioning for all spaces

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