Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
46021a81
Commit
46021a81
authored
Dec 05, 2019
by
Martin Reinecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renaming
parent
52e58aeb
Pipeline
#64986
passed with stages
in 8 minutes and 31 seconds
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
44 additions
and
44 deletions
+44
-44
demos/bench_gridder.py
demos/bench_gridder.py
+2
-2
demos/find_amplitude_parameters.py
demos/find_amplitude_parameters.py
+3
-3
demos/getting_started_mf.py
demos/getting_started_mf.py
+1
-1
demos/misc/convolution.py
demos/misc/convolution.py
+4
-4
demos/polynomial_fit.py
demos/polynomial_fit.py
+3
-3
nifty6/library/correlated_fields.py
nifty6/library/correlated_fields.py
+12
-12
nifty6/library/gridder.py
nifty6/library/gridder.py
+3
-3
nifty6/operator_spectrum.py
nifty6/operator_spectrum.py
+3
-3
nifty6/plot.py
nifty6/plot.py
+2
-2
nifty6/probing.py
nifty6/probing.py
+2
-2
nifty6/sugar.py
nifty6/sugar.py
+2
-2
test/test_field.py
test/test_field.py
+3
-3
test/test_multi_field.py
test/test_multi_field.py
+2
-2
test/test_operators/test_nft.py
test/test_operators/test_nft.py
+2
-2
No files found.
demos/bench_gridder.py
View file @
46021a81
...
...
@@ -24,11 +24,11 @@ for ii in range(10, 26):
img
=
np
.
random
.
randn
(
nu
*
nv
)
img
=
img
.
reshape
((
nu
,
nv
))
img
=
ift
.
from_global_data
(
uvspace
,
img
)
img
=
ift
.
makeField
(
uvspace
,
img
)
t0
=
time
()
GM
=
ift
.
GridderMaker
(
uvspace
,
eps
=
1e-7
,
uv
=
uv
)
vis
=
ift
.
from_global_data
(
visspace
,
vis
)
vis
=
ift
.
makeField
(
visspace
,
vis
)
op
=
GM
.
getFull
().
adjoint
t1
=
time
()
op
(
img
).
val
...
...
demos/find_amplitude_parameters.py
View file @
46021a81
...
...
@@ -57,7 +57,7 @@ if __name__ == '__main__':
for
_
in
range
(
n_samps
):
fld
=
pspec
(
ift
.
from_random
(
'normal'
,
pspec
.
domain
))
klengths
=
fld
.
domain
[
0
].
k_lengths
ycoord
=
fld
.
to_global_data_rw
()
ycoord
=
fld
.
val
.
copy
()
ycoord
[
0
]
=
ycoord
[
1
]
ax
.
plot
(
klengths
,
ycoord
,
alpha
=
1
)
...
...
@@ -80,7 +80,7 @@ if __name__ == '__main__':
foo
=
[]
for
ax
in
axs
:
pos
=
ift
.
from_random
(
'normal'
,
correlated_field
.
domain
)
fld
=
correlated_field
(
pos
).
to_global_data
()
fld
=
correlated_field
(
pos
).
val
foo
.
append
((
ax
,
fld
))
mi
,
ma
=
np
.
inf
,
-
np
.
inf
for
_
,
fld
in
foo
:
...
...
@@ -106,7 +106,7 @@ if __name__ == '__main__':
flds
=
[]
for
_
in
range
(
n_samps
):
pos
=
ift
.
from_random
(
'normal'
,
correlated_field
.
domain
)
ax
.
plot
(
correlated_field
(
pos
).
to_global_data
()
)
ax
.
plot
(
correlated_field
(
pos
).
val
)
plt
.
savefig
(
'correlated_fields.png'
)
plt
.
close
()
demos/getting_started_mf.py
View file @
46021a81
...
...
@@ -40,7 +40,7 @@ class SingleDomain(ift.LinearOperator):
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
return
ift
.
from_global_data
(
self
.
_tgt
(
mode
),
x
.
val
)
return
ift
.
makeField
(
self
.
_tgt
(
mode
),
x
.
val
)
def
random_los
(
n_los
):
...
...
demos/misc/convolution.py
View file @
46021a81
...
...
@@ -38,11 +38,11 @@ signal_vals = np.zeros(npix, dtype=np.float64)
for
i
in
range
(
0
,
npix
,
npix
//
12
+
27
):
signal_vals
[
i
]
=
500.
signal
=
ift
.
from_global_data
(
domain
,
signal_vals
)
signal
=
ift
.
makeField
(
domain
,
signal_vals
)
delta_vals
=
np
.
zeros
(
npix
,
dtype
=
np
.
float64
)
delta_vals
[
0
]
=
1.0
delta
=
ift
.
from_global_data
(
domain
,
delta_vals
)
delta
=
ift
.
makeField
(
domain
,
delta_vals
)
# Define kernel function
...
...
@@ -58,12 +58,12 @@ domain = ift.RGSpace((100, 100))
signal_vals
=
np
.
zeros
(
domain
.
shape
,
dtype
=
np
.
float64
)
signal_vals
[
35
,
70
]
=
5000.
signal_vals
[
45
,
8
]
=
5000.
signal
=
ift
.
from_global_data
(
domain
,
signal_vals
)
signal
=
ift
.
makeField
(
domain
,
signal_vals
)
# Define delta signal, generate kernel image
delta_vals
=
np
.
zeros
(
domain
.
shape
,
dtype
=
np
.
float64
)
delta_vals
[
0
,
0
]
=
1.0
delta
=
ift
.
from_global_data
(
domain
,
delta_vals
)
delta
=
ift
.
makeField
(
domain
,
delta_vals
)
# Define kernel function
...
...
demos/polynomial_fit.py
View file @
46021a81
...
...
@@ -78,7 +78,7 @@ class PolynomialResponse(ift.LinearOperator):
else
:
# FIXME Can this be optimized?
out
=
self
.
_mat
.
conj
().
T
.
dot
(
val
)
return
ift
.
from_global_data
(
self
.
_tgt
(
mode
),
out
)
return
ift
.
makeField
(
self
.
_tgt
(
mode
),
out
)
# Generate some mock data
...
...
@@ -99,8 +99,8 @@ R = PolynomialResponse(p_space, x)
ift
.
extra
.
consistency_check
(
R
)
d_space
=
R
.
target
d
=
ift
.
from_global_data
(
d_space
,
y
)
N
=
ift
.
DiagonalOperator
(
ift
.
from_global_data
(
d_space
,
var
))
d
=
ift
.
makeField
(
d_space
,
y
)
N
=
ift
.
DiagonalOperator
(
ift
.
makeField
(
d_space
,
var
))
IC
=
ift
.
DeltaEnergyController
(
tol_rel_deltaE
=
1e-12
,
iteration_limit
=
200
)
likelihood
=
ift
.
GaussianEnergy
(
d
,
N
)(
R
)
...
...
nifty6/library/correlated_fields.py
View file @
46021a81
...
...
@@ -33,7 +33,7 @@ from ..operators.linear_operator import LinearOperator
from
..operators.operator
import
Operator
from
..operators.simple_linear_operators
import
ducktape
from
..probing
import
StatCalculator
from
..sugar
import
from_global_data
,
full
,
makeDomain
from
..sugar
import
makeField
,
full
,
makeDomain
def
_reshaper
(
x
,
N
):
...
...
@@ -68,8 +68,8 @@ def _normal(mean, sig, key, N=0):
else
:
domain
=
UnstructuredDomain
(
N
)
mean
,
sig
=
(
_reshaper
(
param
,
N
)
for
param
in
(
mean
,
sig
))
return
Adder
(
from_global_data
(
domain
,
mean
))
@
(
DiagonalOperator
(
from_global_data
(
domain
,
sig
))
@
ducktape
(
domain
,
None
,
key
))
return
Adder
(
makeField
(
domain
,
mean
))
@
(
DiagonalOperator
(
makeField
(
domain
,
sig
))
@
ducktape
(
domain
,
None
,
key
))
def
_log_k_lengths
(
pspace
):
...
...
@@ -144,7 +144,7 @@ class _SlopeRemover(EndomorphicOperator):
res
=
x
.
copy
()
res
[
self
.
_last
]
-=
(
x
*
self
.
_sc
[
self
.
_extender
]).
sum
(
axis
=
self
.
_space
,
keepdims
=
True
)
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
class
_TwoLogIntegrations
(
LinearOperator
):
...
...
@@ -186,7 +186,7 @@ class _TwoLogIntegrations(LinearOperator):
x
[
from_third
]
*=
(
self
.
_log_vol
/
2.
)[
extender_sl
]
x
[
no_border
]
+=
x
[
from_third
]
res
[
second
]
+=
np
.
cumsum
(
x
[
from_third
][
reverse
],
axis
=
axis
)[
reverse
]
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
class
_Normalization
(
Operator
):
...
...
@@ -202,7 +202,7 @@ class _Normalization(Operator):
mode_multiplicity
=
pd
.
adjoint
(
full
(
pd
.
target
,
1.
)).
val
.
copy
()
zero_mode
=
(
slice
(
None
),)
*
self
.
_domain
.
axes
[
space
][
0
]
+
(
0
,)
mode_multiplicity
[
zero_mode
]
=
0
self
.
_mode_multiplicity
=
from_global_data
(
self
.
_domain
,
self
.
_mode_multiplicity
=
makeField
(
self
.
_domain
,
mode_multiplicity
)
self
.
_specsum
=
_SpecialSum
(
self
.
_domain
,
space
)
...
...
@@ -243,7 +243,7 @@ class _Distributor(LinearOperator):
else
:
res
=
np
.
empty
(
self
.
_tgt
(
mode
).
shape
)
res
[
self
.
_dofdex
]
=
x
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
class
_Amplitude
(
Operator
):
...
...
@@ -284,24 +284,24 @@ class _Amplitude(Operator):
# Prepare constant fields
foo
=
np
.
zeros
(
shp
)
foo
[
0
]
=
foo
[
1
]
=
np
.
sqrt
(
_log_vol
(
target
[
space
]))
vflex
=
DiagonalOperator
(
from_global_data
(
dom
[
space
],
foo
),
dom
,
space
)
vflex
=
DiagonalOperator
(
makeField
(
dom
[
space
],
foo
),
dom
,
space
)
foo
=
np
.
zeros
(
shp
,
dtype
=
np
.
float64
)
foo
[
0
]
+=
1
vasp
=
DiagonalOperator
(
from_global_data
(
dom
[
space
],
foo
),
dom
,
space
)
vasp
=
DiagonalOperator
(
makeField
(
dom
[
space
],
foo
),
dom
,
space
)
foo
=
np
.
ones
(
shp
)
foo
[
0
]
=
_log_vol
(
target
[
space
])
**
2
/
12.
shift
=
DiagonalOperator
(
from_global_data
(
dom
[
space
],
foo
),
dom
,
space
)
shift
=
DiagonalOperator
(
makeField
(
dom
[
space
],
foo
),
dom
,
space
)
vslope
=
DiagonalOperator
(
from_global_data
(
target
[
space
],
makeField
(
target
[
space
],
_relative_log_k_lengths
(
target
[
space
])),
target
,
space
)
foo
,
bar
=
[
np
.
zeros
(
target
[
space
].
shape
)
for
_
in
range
(
2
)]
bar
[
1
:]
=
foo
[
0
]
=
totvol
vol0
,
vol1
=
[
DiagonalOperator
(
from_global_data
(
target
[
space
],
aa
),
vol0
,
vol1
=
[
DiagonalOperator
(
makeField
(
target
[
space
],
aa
),
target
,
space
)
for
aa
in
(
foo
,
bar
)]
# Prepare fields for Adder
...
...
nifty6/library/gridder.py
View file @
46021a81
...
...
@@ -21,7 +21,7 @@ from ..domain_tuple import DomainTuple
from
..domains.rg_space
import
RGSpace
from
..domains.unstructured_domain
import
UnstructuredDomain
from
..operators.linear_operator
import
LinearOperator
from
..sugar
import
from_global_data
,
makeDomain
from
..sugar
import
makeField
,
makeDomain
class
GridderMaker
(
object
):
...
...
@@ -85,7 +85,7 @@ class _RestOperator(LinearOperator):
res
=
self
.
_gconf
.
grid2dirty
(
res
)
else
:
res
=
self
.
_gconf
.
dirty2grid
(
res
)
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
class
RadioGridder
(
LinearOperator
):
...
...
@@ -108,4 +108,4 @@ class RadioGridder(LinearOperator):
res
=
nifty_gridder
.
grid2vis
(
self
.
_bl
,
self
.
_gconf
,
self
.
_idx
,
x
.
val
)
res
=
self
.
_bl
.
vis2ms
(
res
,
self
.
_idx
).
reshape
((
-
1
,))
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
nifty6/operator_spectrum.py
View file @
46021a81
...
...
@@ -23,7 +23,7 @@ from .multi_domain import MultiDomain
from
.multi_field
import
MultiField
from
.operators.linear_operator
import
LinearOperator
from
.operators.sandwich_operator
import
SandwichOperator
from
.sugar
import
from_global_data
,
makeDomain
from
.sugar
import
makeField
,
makeDomain
class
_DomRemover
(
LinearOperator
):
...
...
@@ -68,7 +68,7 @@ class _DomRemover(LinearOperator):
res
[
i0
:
i1
]
=
x
[
kk
].
ravel
()
else
:
res
[
kk
]
=
x
[
i0
:
i1
].
reshape
(
dd
.
shape
)
return
from_global_data
(
self
.
_tgt
(
mode
),
res
)
return
makeField
(
self
.
_tgt
(
mode
),
res
)
@
staticmethod
def
_check_float_dtype
(
fld
):
...
...
@@ -137,7 +137,7 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
Ar
=
SandwichOperator
.
make
(
_DomRemover
(
A
.
domain
).
adjoint
,
A
)
M
=
ssl
.
LinearOperator
(
shape
=
2
*
(
size
,),
matvec
=
lambda
x
:
Ar
(
from_global_data
(
Ar
.
domain
,
x
)).
val
)
matvec
=
lambda
x
:
Ar
(
makeField
(
Ar
.
domain
,
x
)).
val
)
f
=
ssl
.
eigsh
if
hermitian
else
ssl
.
eigs
eigs
=
f
(
M
,
k
=
k
,
tol
=
tol
,
return_eigenvectors
=
False
,
which
=
which
)
return
np
.
flip
(
np
.
sort
(
eigs
),
axis
=
0
)
nifty6/plot.py
View file @
46021a81
...
...
@@ -335,8 +335,8 @@ def _plot2D(f, ax, **kwargs):
if
(
not
isinstance
(
dom
[
1
],
RGSpace
))
or
len
(
dom
[
1
].
shape
)
!=
1
:
raise
TypeError
(
"need 1D RGSpace as second domain"
)
if
dom
[
1
].
shape
[
0
]
==
1
:
from
.sugar
import
from_global_data
f
=
from_global_data
(
f
.
domain
[
0
],
f
.
val
[...,
0
])
from
.sugar
import
makeField
f
=
makeField
(
f
.
domain
[
0
],
f
.
val
[...,
0
])
else
:
rgb
=
_rgb_data
(
f
.
val
)
have_rgb
=
True
...
...
nifty6/probing.py
View file @
46021a81
...
...
@@ -18,7 +18,7 @@
from
.multi_field
import
MultiField
from
.operators.endomorphic_operator
import
EndomorphicOperator
from
.operators.operator
import
Operator
from
.sugar
import
from_global_data
,
from_random
from
.sugar
import
makeField
,
from_random
class
StatCalculator
(
object
):
...
...
@@ -146,5 +146,5 @@ def approximation2endo(op, nsamples):
for
kk
in
dct
:
foo
=
dct
[
kk
].
to_global_data_rw
()
foo
[
foo
==
0
]
=
1
dct
[
kk
]
=
from_global_data
(
dct
[
kk
].
domain
,
foo
)
dct
[
kk
]
=
makeField
(
dct
[
kk
].
domain
,
foo
)
return
MultiField
.
from_dict
(
dct
)
nifty6/sugar.py
View file @
46021a81
...
...
@@ -35,7 +35,7 @@ from .plot import Plot
__all__
=
[
'PS_field'
,
'power_analyze'
,
'create_power_operator'
,
'create_harmonic_smoothing_operator'
,
'from_random'
,
'full'
,
'
from_global_data
'
,
'full'
,
'
makeField
'
,
'makeDomain'
,
'sqrt'
,
'exp'
,
'log'
,
'tanh'
,
'sigmoid'
,
'sin'
,
'cos'
,
'tan'
,
'sinh'
,
'cosh'
,
'log10'
,
'absolute'
,
'one_over'
,
'clip'
,
'sinc'
,
"log1p"
,
"expm1"
,
...
...
@@ -280,7 +280,7 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs):
return
Field
.
from_random
(
random_type
,
domain
,
dtype
,
**
kwargs
)
def
from_global_data
(
domain
,
arr
):
def
makeField
(
domain
,
arr
):
"""Convenience function creating Fields/MultiFields from Numpy arrays or
dicts of Numpy arrays.
...
...
test/test_field.py
View file @
46021a81
...
...
@@ -175,14 +175,14 @@ def test_dataconv():
s1
=
ift
.
RGSpace
((
10
,))
ld
=
np
.
arange
(
s1
.
shape
[
0
])
gd
=
np
.
arange
(
s1
.
shape
[
0
])
assert_equal
(
gd
,
ift
.
from_global_data
(
s1
,
gd
).
val
)
assert_equal
(
gd
,
ift
.
makeField
(
s1
,
gd
).
val
)
def
test_cast_domain
():
s1
=
ift
.
RGSpace
((
10
,))
s2
=
ift
.
RGSpace
((
10
,),
distances
=
20.
)
d
=
np
.
arange
(
s1
.
shape
[
0
])
d2
=
ift
.
from_global_data
(
s1
,
d
).
cast_domain
(
s2
).
val
d2
=
ift
.
makeField
(
s1
,
d
).
cast_domain
(
s2
).
val
assert_equal
(
d
,
d2
)
...
...
@@ -207,7 +207,7 @@ def test_trivialities():
assert_equal
(
f1
.
sum
(),
f1
.
sum
(
0
))
assert_equal
(
f1
.
conjugate
().
val
,
ift
.
Field
.
full
(
s1
,
27.
-
3j
).
val
)
f1
=
ift
.
from_global_data
(
s1
,
np
.
arange
(
10
))
f1
=
ift
.
makeField
(
s1
,
np
.
arange
(
10
))
# assert_equal(f1.min(), 0)
# assert_equal(f1.max(), 9)
assert_equal
(
f1
.
prod
(),
0
)
...
...
test/test_multi_field.py
View file @
46021a81
...
...
@@ -37,14 +37,14 @@ def test_func():
def
test_multifield_field_consistency
():
f1
=
ift
.
full
(
dom
,
27
)
f2
=
ift
.
from_global_data
(
dom
[
'd1'
],
f1
[
'd1'
].
val
)
f2
=
ift
.
makeField
(
dom
[
'd1'
],
f1
[
'd1'
].
val
)
assert_equal
(
f1
.
sum
(),
f2
.
sum
())
assert_equal
(
f1
.
size
,
f2
.
size
)
def
test_dataconv
():
f1
=
ift
.
full
(
dom
,
27
)
f2
=
ift
.
from_global_data
(
dom
,
f1
.
to_global_data
())
f2
=
ift
.
makeField
(
dom
,
f1
.
to_global_data
())
for
key
,
val
in
f1
.
items
():
assert_equal
(
val
.
val
,
f2
[
key
].
val
)
if
"d1"
not
in
f2
:
...
...
test/test_operators/test_nft.py
View file @
46021a81
...
...
@@ -44,7 +44,7 @@ def test_gridding(nu, nv, N, eps):
uv
[:,
0
]
=
uv
[:,
0
]
/
dstx
uv
[:,
1
]
=
uv
[:,
1
]
/
dsty
GM
=
ift
.
GridderMaker
(
dom
,
uv
=
uv
,
eps
=
eps
)
vis2
=
ift
.
from_global_data
(
ift
.
UnstructuredDomain
(
vis
.
shape
),
vis
)
vis2
=
ift
.
makeField
(
ift
.
UnstructuredDomain
(
vis
.
shape
),
vis
)
Op
=
GM
.
getFull
()
pynu
=
Op
(
vis2
).
val
...
...
@@ -75,7 +75,7 @@ def test_cartesian():
fld
=
ift
.
from_random
(
'normal'
,
dom
)
arr
=
fld
.
val
fld2
=
ift
.
from_global_data
(
dom
,
np
.
roll
(
arr
,
(
nx
//
2
,
ny
//
2
),
axis
=
(
0
,
1
)))
fld2
=
ift
.
makeField
(
dom
,
np
.
roll
(
arr
,
(
nx
//
2
,
ny
//
2
),
axis
=
(
0
,
1
)))
res
=
op
(
fld2
).
val
.
reshape
(
nx
,
ny
)
fft
=
ift
.
FFTOperator
(
dom
.
get_default_codomain
(),
target
=
dom
).
adjoint
...
...
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