Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
615ff81a
Commit
615ff81a
authored
Nov 11, 2017
by
Martin Reinecke
Browse files
tweaks
parent
0db9e4a6
Pipeline
#21398
failed with stage
in 3 minutes and 53 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/wiener_filter_via_curvature.py
View file @
615ff81a
...
...
@@ -44,7 +44,7 @@ if __name__ == "__main__":
np
.
random
.
seed
(
43
)
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k_lengths
))
val
=
ift
.
dobj
.
from_global_data
(
power_spectrum
(
power_space
.
k_lengths
))
)
mock_harmonic
=
ift
.
power_synthesize
(
mock_power
,
real_signal
=
True
)
mock_harmonic
=
mock_harmonic
.
real
mock_signal
=
fft
(
mock_harmonic
)
...
...
demos/wiener_filter_via_hamiltonian.py
View file @
615ff81a
...
...
@@ -50,14 +50,15 @@ if __name__ == "__main__":
S
=
ift
.
create_power_operator
(
h_space
,
power_spectrum
=
p_spec
)
# Drawing a sample sh from the prior distribution in harmonic space
sp
=
ift
.
Field
(
p_space
,
val
=
p_spec
(
p_space
.
k_lengths
))
sp
=
ift
.
Field
(
p_space
,
ift
.
dobj
.
from_global_data
(
p_spec
(
p_space
.
k_lengths
))
)
sh
=
ift
.
power_synthesize
(
sp
,
real_signal
=
True
)
ss
=
fft
.
adjoint_times
(
sh
)
# Choosing the measurement instrument
# Instrument = ift.FFTSmoothingOperator(s_space, sigma=0.05)
diag
=
ift
.
Field
.
ones
(
s_space
)
diag
.
val
[
20
:
80
,
20
:
80
]
=
0
diag
=
np
.
ones
(
s_space
.
shape
)
diag
[
20
:
80
,
20
:
80
]
=
0
diag
=
ift
.
Field
(
s_space
,
ift
.
dobj
.
from_global_data
(
diag
))
Instrument
=
ift
.
DiagonalOperator
(
diag
)
# Adding a harmonic transformation to the instrument
...
...
nifty/data_objects/distributed_do.py
View file @
615ff81a
...
...
@@ -17,7 +17,7 @@ def shareRange(nwork, nshares, myshare):
hi
=
lo
+
nbase
+
(
1
if
myshare
<
additional
else
0
)
return
lo
,
hi
def
get_
locshape
(
shape
,
distaxis
):
def
loc
al_
shape
(
shape
,
distaxis
):
if
len
(
shape
)
==
0
:
distaxis
=
-
1
if
distaxis
==-
1
:
...
...
@@ -25,8 +25,6 @@ def get_locshape(shape, distaxis):
shape2
=
list
(
shape
)
shape2
[
distaxis
]
=
shareSize
(
shape
[
distaxis
],
ntask
,
rank
)
return
tuple
(
shape2
)
def
local_shape
(
shape
,
distaxis
):
return
get_locshape
(
shape
,
distaxis
)
class
data_object
(
object
):
def
__init__
(
self
,
shape
,
data
,
distaxis
):
...
...
@@ -35,7 +33,7 @@ class data_object(object):
if
len
(
self
.
_shape
)
==
0
:
distaxis
=
-
1
self
.
_distaxis
=
distaxis
lshape
=
get_
locshape
(
self
.
_shape
,
self
.
_distaxis
)
lshape
=
loc
al_
shape
(
self
.
_shape
,
self
.
_distaxis
)
self
.
_data
=
data
def
sanity_checks
(
self
):
...
...
@@ -123,6 +121,14 @@ class data_object(object):
def
sum
(
self
,
axis
=
None
):
return
self
.
_contraction_helper
(
"sum"
,
MPI
.
SUM
,
axis
)
# FIXME: to be improved!
def
mean
(
self
):
return
self
.
sum
()
/
self
.
size
def
std
(
self
):
return
np
.
sqrt
(
self
.
var
())
def
var
(
self
):
return
(
abs
(
self
-
self
.
mean
())
**
2
).
mean
()
def
_binary_helper
(
self
,
other
,
op
):
a
=
self
if
isinstance
(
other
,
data_object
):
...
...
@@ -173,6 +179,9 @@ class data_object(object):
def
__rdiv__
(
self
,
other
):
return
self
.
_binary_helper
(
other
,
op
=
'__rdiv__'
)
def
__idiv__
(
self
,
other
):
return
self
.
_binary_helper
(
other
,
op
=
'__idiv__'
)
def
__truediv__
(
self
,
other
):
return
self
.
_binary_helper
(
other
,
op
=
'__truediv__'
)
...
...
@@ -214,19 +223,19 @@ class data_object(object):
def
full
(
shape
,
fill_value
,
dtype
=
None
,
distaxis
=
0
):
return
data_object
(
shape
,
np
.
full
(
get_
locshape
(
shape
,
distaxis
),
fill_value
,
dtype
),
distaxis
)
return
data_object
(
shape
,
np
.
full
(
loc
al_
shape
(
shape
,
distaxis
),
fill_value
,
dtype
),
distaxis
)
def
empty
(
shape
,
dtype
=
None
,
distaxis
=
0
):
return
data_object
(
shape
,
np
.
empty
(
get_
locshape
(
shape
,
distaxis
),
dtype
),
distaxis
)
return
data_object
(
shape
,
np
.
empty
(
loc
al_
shape
(
shape
,
distaxis
),
dtype
),
distaxis
)
def
zeros
(
shape
,
dtype
=
None
,
distaxis
=
0
):
return
data_object
(
shape
,
np
.
zeros
(
get_
locshape
(
shape
,
distaxis
),
dtype
),
distaxis
)
return
data_object
(
shape
,
np
.
zeros
(
loc
al_
shape
(
shape
,
distaxis
),
dtype
),
distaxis
)
def
ones
(
shape
,
dtype
=
None
,
distaxis
=
0
):
return
data_object
(
shape
,
np
.
ones
(
get_
locshape
(
shape
,
distaxis
),
dtype
),
distaxis
)
return
data_object
(
shape
,
np
.
ones
(
loc
al_
shape
(
shape
,
distaxis
),
dtype
),
distaxis
)
def
empty_like
(
a
,
dtype
=
None
):
...
...
@@ -277,9 +286,9 @@ def from_object(object, dtype=None, copy=True):
def
from_random
(
random_type
,
shape
,
dtype
=
np
.
float64
,
distaxis
=
0
,
**
kwargs
):
generator_function
=
getattr
(
Random
,
random_type
)
lshape
=
get_
locshape
(
shape
,
distaxis
)
return
data_object
(
shape
,
generator_function
(
dtype
=
dtype
,
shape
=
lshape
,
**
kwargs
),
distaxis
=
distaxis
)
#
lshape = loc
al_
shape(shape, distaxis)
#
return data_object(shape, generator_function(dtype=dtype, shape=lshape, **kwargs), distaxis=distaxis)
return
from_global_data
(
generator_function
(
dtype
=
dtype
,
shape
=
shape
,
**
kwargs
),
distaxis
=
distaxis
)
def
local_data
(
arr
):
return
arr
.
_data
...
...
@@ -368,8 +377,8 @@ def redistribute (arr, dist=None, nodist=None):
ssz
=
np
.
empty
(
ntask
,
dtype
=
np
.
int
)
rsz
=
np
.
empty
(
ntask
,
dtype
=
np
.
int
)
for
i
in
range
(
ntask
):
ssz
[
i
]
=
slabsize
*
tmp
.
shape
[
1
]
*
shareSize
(
arr
.
shape
[
dist
],
ntask
,
i
)
rsz
[
i
]
=
slabsize
*
shareSize
(
arr
.
shape
[
dist
],
ntask
,
rank
)
*
shareSize
(
arr
.
shape
[
arr
.
_distaxis
],
ntask
,
i
)
ssz
[
i
]
=
shareSize
(
arr
.
shape
[
dist
],
ntask
,
i
)
*
tmp
.
shape
[
1
]
*
slabsize
rsz
[
i
]
=
shareSize
(
arr
.
shape
[
dist
],
ntask
,
rank
)
*
shareSize
(
arr
.
shape
[
arr
.
_distaxis
],
ntask
,
i
)
*
slabsize
sdisp
=
np
.
empty
(
ntask
,
dtype
=
np
.
int
)
rdisp
=
np
.
empty
(
ntask
,
dtype
=
np
.
int
)
sdisp
[
0
]
=
0
...
...
@@ -377,7 +386,7 @@ def redistribute (arr, dist=None, nodist=None):
sdisp
[
1
:]
=
np
.
cumsum
(
ssz
[:
-
1
])
rdisp
[
1
:]
=
np
.
cumsum
(
rsz
[:
-
1
])
tmp
=
tmp
.
flatten
()
out
=
np
.
empty
(
np
.
prod
(
get_
locshape
(
arr
.
shape
,
dist
)),
dtype
=
arr
.
dtype
)
out
=
np
.
empty
(
np
.
prod
(
loc
al_
shape
(
arr
.
shape
,
dist
)),
dtype
=
arr
.
dtype
)
s_msg
=
[
tmp
,
(
ssz
,
sdisp
),
MPI
.
BYTE
]
r_msg
=
[
out
,
(
rsz
,
rdisp
),
MPI
.
BYTE
]
comm
.
Alltoallv
(
s_msg
,
r_msg
)
...
...
nifty/operators/power_projection_operator.py
View file @
615ff81a
...
...
@@ -77,7 +77,7 @@ class PowerProjectionOperator(LinearOperator):
oarr
=
oarr
.
reshape
(
self
.
_target
.
shape
)
res
=
Field
(
self
.
_target
,
dobj
.
from_global_data
(
oarr
))
else
:
oarr
=
oarr
.
reshape
(
dobj
.
get_
locshape
(
self
.
_target
.
shape
,
dobj
.
distaxis
(
x
.
val
)))
oarr
=
oarr
.
reshape
(
dobj
.
loc
al_
shape
(
self
.
_target
.
shape
,
dobj
.
distaxis
(
x
.
val
)))
res
=
Field
(
self
.
_target
,
dobj
.
from_local_data
(
self
.
_target
.
shape
,
oarr
,
dobj
.
default_distaxis
()))
return
res
.
weight
(
-
1
,
spaces
=
self
.
_space
)
...
...
nifty/plotting/plot.py
View file @
615ff81a
from
__future__
import
division
import
numpy
as
np
from
..
import
Field
,
RGSpace
,
HPSpace
,
GLSpace
,
PowerSpace
from
..
import
Field
,
RGSpace
,
HPSpace
,
GLSpace
,
PowerSpace
,
dobj
import
os
# relevant properties:
...
...
@@ -45,6 +45,8 @@ def _find_closest(A, target):
def
_makeplot
(
name
):
import
matplotlib.pyplot
as
plt
if
dobj
.
rank
!=
0
:
return
if
name
is
None
:
plt
.
show
()
return
...
...
@@ -185,7 +187,7 @@ def plot(f, **kwargs):
dy
=
dom
.
distances
[
1
]
xc
=
np
.
arange
(
nx
,
dtype
=
np
.
float64
)
*
dx
yc
=
np
.
arange
(
ny
,
dtype
=
np
.
float64
)
*
dy
im
=
ax
.
imshow
(
f
.
val
,
extent
=
[
xc
[
0
],
xc
[
-
1
],
yc
[
0
],
yc
[
-
1
]],
im
=
ax
.
imshow
(
dobj
.
to_global_data
(
f
.
val
)
,
extent
=
[
xc
[
0
],
xc
[
-
1
],
yc
[
0
],
yc
[
-
1
]],
vmin
=
kwargs
.
get
(
"zmin"
),
vmax
=
kwargs
.
get
(
"zmax"
),
cmap
=
cmap
,
origin
=
"lower"
)
# from mpl_toolkits.axes_grid1 import make_axes_locatable
...
...
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