Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
9dc01f33
Commit
9dc01f33
authored
Nov 15, 2016
by
Jait Dixit
Browse files
WIP: Add versioning functionality to spaces
parent
5af4d1da
Changes
5
Hide whitespace changes
Inline
Side-by-side
nifty/probing/__init__.py
View file @
9dc01f33
# -*- coding: utf-8 -*-
from
prober
import
Prober
from
operator_prober
import
OperatorProber
from
diagonal_prober
import
*
from
trace_prober
import
*
nifty/spaces/gl_space/gl_space.py
View file @
9dc01f33
from
__future__
import
division
import
pickle
import
itertools
import
numpy
as
np
import
d2o
from
d2o
import
STRATEGIES
as
DISTRIBUTION_STRATEGIES
from
keepers
import
Versionable
from
nifty.spaces.space
import
Space
from
nifty.config
import
nifty_configuration
as
gc
,
\
...
...
@@ -16,7 +19,7 @@ gl = gdi.get('libsharp_wrapper_gl')
GL_DISTRIBUTION_STRATEGIES
=
DISTRIBUTION_STRATEGIES
[
'global'
]
class
GLSpace
(
Space
):
class
GLSpace
(
Versionable
,
Space
):
"""
.. __
.. / /
...
...
@@ -69,6 +72,8 @@ class GLSpace(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'
)):
...
...
@@ -208,3 +213,17 @@ class GLSpace(Space):
self
.
logger
.
warn
(
"nlon was set to an unrecommended value: "
"nlon <> 2*nlat-1."
)
return
nlon
# ---Serialization---
def
_to_hdf5
(
self
,
hdf5_group
):
hdf5_group
[
'serialized'
]
=
[
pickle
.
dumps
(
getattr
(
self
,
item
))
for
item
in
self
.
_serializable
]
return
None
@
classmethod
def
_from_hdf5
(
cls
,
hdf5_group
,
loopback_get
):
result
=
cls
(
*
[
pickle
.
loads
(
item
)
for
item
in
hdf5_group
[
'serialized'
]])
return
result
nifty/spaces/hp_space/hp_space.py
View file @
9dc01f33
...
...
@@ -33,9 +33,12 @@
"""
from
__future__
import
division
import
pickle
import
numpy
as
np
import
d2o
from
keepers
import
Versionable
from
nifty.spaces.space
import
Space
from
nifty.config
import
nifty_configuration
as
gc
,
\
...
...
@@ -44,7 +47,7 @@ from nifty.config import nifty_configuration as gc, \
hp
=
gdi
.
get
(
'healpy'
)
class
HPSpace
(
Space
):
class
HPSpace
(
Versionable
,
Space
):
"""
.. __
.. / /
...
...
@@ -94,6 +97,8 @@ class HPSpace(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'
)):
...
...
@@ -203,3 +208,17 @@ class HPSpace(Space):
raise
ValueError
(
"nside must be positive and a multiple of 2."
)
return
nside
# ---Serialization---
def
_to_hdf5
(
self
,
hdf5_group
):
hdf5_group
[
'serialized'
]
=
[
pickle
.
dumps
(
getattr
(
self
,
item
))
for
item
in
self
.
_serializable
]
return
None
@
classmethod
def
_from_hdf5
(
cls
,
hdf5_group
,
loopback_get
):
result
=
cls
(
*
[
pickle
.
loads
(
item
)
for
item
in
hdf5_group
[
'serialized'
]])
return
result
nifty/spaces/power_space/power_space.py
View file @
9dc01f33
# -*- coding: utf-8 -*-
import
pickle
import
numpy
as
np
from
keepers
import
Versionable
import
d2o
from
power_index_factory
import
PowerIndexFactory
...
...
@@ -11,13 +14,16 @@ from nifty.spaces.rg_space import RGSpace
from
nifty.nifty_utilities
import
cast_axis_to_tuple
class
PowerSpace
(
Space
):
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
,
log
=
False
,
nbin
=
None
,
binbounds
=
None
,
power_index
=
None
,
dtype
=
np
.
dtype
(
'float'
)):
super
(
PowerSpace
,
self
).
__init__
(
dtype
)
...
...
@@ -32,12 +38,13 @@ class PowerSpace(Space):
"harmonic_domain must be a harmonic space."
)
self
.
_harmonic_domain
=
harmonic_domain
power_index
=
PowerIndexFactory
.
get_power_index
(
domain
=
self
.
harmonic_domain
,
distribution_strategy
=
distribution_strategy
,
log
=
log
,
nbin
=
nbin
,
binbounds
=
binbounds
)
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
)
config
=
power_index
[
'config'
]
self
.
_log
=
config
[
'log'
]
...
...
@@ -154,3 +161,42 @@ class PowerSpace(Space):
@
property
def
k_array
(
self
):
return
self
.
_k_array
# ---Serialization---
def
_to_hdf5
(
self
,
hdf5_group
):
hdf5_group
[
'serialized'
]
=
[
pickle
.
dumps
(
getattr
(
self
,
item
))
for
item
in
self
.
_serializable
]
return
{
'harmonic_domain'
:
self
.
harmonic_domain
,
'pindex'
:
self
.
pindex
,
'k_array'
:
self
.
k_array
}
@
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
nifty/spaces/rg_space/rg_space.py
View file @
9dc01f33
...
...
@@ -33,15 +33,19 @@
"""
from
__future__
import
division
import
pickle
import
numpy
as
np
from
keepers
import
Versionable
from
d2o
import
distributed_data_object
,
\
STRATEGIES
as
DISTRIBUTION_STRATEGIES
from
nifty.spaces.space
import
Space
class
RGSpace
(
Space
):
class
RGSpace
(
Versionable
,
Space
):
"""
.. _____ _______
.. / __/ / _ /
...
...
@@ -103,6 +107,8 @@ class RGSpace(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
,
...
...
@@ -320,3 +326,17 @@ class RGSpace(Space):
temp
=
np
.
empty
(
len
(
self
.
shape
),
dtype
=
bool
)
temp
[:]
=
zerocenter
return
tuple
(
temp
)
# ---Serialization---
def
_to_hdf5
(
self
,
hdf5_group
):
hdf5_group
[
'serialized'
]
=
[
pickle
.
dumps
(
getattr
(
self
,
item
))
for
item
in
self
.
_serializable
]
return
None
@
classmethod
def
_from_hdf5
(
cls
,
hdf5_group
,
loopback_get
):
result
=
cls
(
*
[
pickle
.
loads
(
item
)
for
item
in
hdf5_group
[
'serialized'
]])
return
result
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment