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
Neel Shah
NIFTy
Commits
3e36985c
Commit
3e36985c
authored
Apr 09, 2020
by
Martin Reinecke
Browse files
merge and conflict fixes
parents
603cd7be
9974ac4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
nifty6/plot.py
View file @
3e36985c
...
@@ -331,14 +331,26 @@ def _plot2D(f, ax, **kwargs):
...
@@ -331,14 +331,26 @@ def _plot2D(f, ax, **kwargs):
# check for multifrequency plotting
# check for multifrequency plotting
have_rgb
=
False
have_rgb
=
False
x_space
=
0
if
len
(
dom
)
==
2
:
if
len
(
dom
)
==
2
:
if
(
not
isinstance
(
dom
[
1
],
RGSpace
))
or
len
(
dom
[
1
].
shape
)
!=
1
:
f_space
=
kwargs
.
pop
(
"freq_space_idx"
,
1
)
raise
TypeError
(
"need 1D RGSpace as second domain"
)
if
not
f_space
in
[
0
,
1
]:
if
dom
[
1
].
shape
[
0
]
==
1
:
raise
ValueError
(
"Invalid frequency space index"
)
if
(
not
isinstance
(
dom
[
f_space
],
RGSpace
))
\
or
len
(
dom
[
f_space
].
shape
)
!=
1
:
raise
TypeError
(
"Need 1D RGSpace as frequency space domain"
)
x_space
=
1
-
f_space
# Only one frequency?
if
dom
[
f_space
].
shape
[
0
]
==
1
:
from
.sugar
import
makeField
from
.sugar
import
makeField
f
=
makeField
(
f
.
target
[
0
],
f
.
val
[...,
0
])
f
=
makeField
(
f
.
target
[
x_space
],
f
.
val
.
squeeze
(
axis
=
dom
.
axes
[
f_space
]))
else
:
else
:
rgb
=
_rgb_data
(
f
.
val
)
val
=
f
.
val
if
f_space
==
0
:
val
=
np
.
moveaxis
(
val
,
0
,
-
1
)
rgb
=
_rgb_data
(
val
)
have_rgb
=
True
have_rgb
=
True
foo
=
kwargs
.
pop
(
"norm"
,
None
)
foo
=
kwargs
.
pop
(
"norm"
,
None
)
...
@@ -350,7 +362,7 @@ def _plot2D(f, ax, **kwargs):
...
@@ -350,7 +362,7 @@ def _plot2D(f, ax, **kwargs):
ax
.
set_title
(
kwargs
.
pop
(
"title"
,
""
))
ax
.
set_title
(
kwargs
.
pop
(
"title"
,
""
))
ax
.
set_xlabel
(
kwargs
.
pop
(
"xlabel"
,
""
))
ax
.
set_xlabel
(
kwargs
.
pop
(
"xlabel"
,
""
))
ax
.
set_ylabel
(
kwargs
.
pop
(
"ylabel"
,
""
))
ax
.
set_ylabel
(
kwargs
.
pop
(
"ylabel"
,
""
))
dom
=
dom
[
0
]
dom
=
dom
[
x_space
]
if
not
have_rgb
:
if
not
have_rgb
:
cmap
=
kwargs
.
pop
(
"colormap"
,
plt
.
rcParams
[
'image.cmap'
])
cmap
=
kwargs
.
pop
(
"colormap"
,
plt
.
rcParams
[
'image.cmap'
])
...
@@ -400,7 +412,7 @@ def _plot2D(f, ax, **kwargs):
...
@@ -400,7 +412,7 @@ def _plot2D(f, ax, **kwargs):
if
have_rgb
:
if
have_rgb
:
plt
.
imshow
(
res
,
origin
=
"lower"
)
plt
.
imshow
(
res
,
origin
=
"lower"
)
else
:
else
:
plt
.
imshow
(
res
,
vmin
=
kwargs
.
get
(
"zmin"
),
vmax
=
kwargs
.
get
(
"zmax"
),
plt
.
imshow
(
res
,
vmin
=
kwargs
.
get
(
"zmin"
),
vmax
=
kwargs
.
get
(
"zmax"
),
norm
=
norm
.
get
(
'norm'
),
cmap
=
cmap
,
origin
=
"lower"
)
cmap
=
cmap
,
origin
=
"lower"
)
plt
.
colorbar
(
orientation
=
"horizontal"
)
plt
.
colorbar
(
orientation
=
"horizontal"
)
return
return
...
@@ -451,6 +463,9 @@ class Plot(object):
...
@@ -451,6 +463,9 @@ class Plot(object):
`PowerSpace`, `HPSpace`, `GLSpace`.
`PowerSpace`, `HPSpace`, `GLSpace`.
If it is a list, all list members must be Fields defined over the
If it is a list, all list members must be Fields defined over the
same one-dimensional `RGSpace` or `PowerSpace`.
same one-dimensional `RGSpace` or `PowerSpace`.
Optional Parameters
-------------------
title: string
title: string
Title of the plot.
Title of the plot.
xlabel: string
xlabel: string
...
@@ -467,6 +482,8 @@ class Plot(object):
...
@@ -467,6 +482,8 @@ class Plot(object):
Annotation string.
Annotation string.
alpha: float or list of floats
alpha: float or list of floats
Transparency value.
Transparency value.
freq_space_idx: int
for multi-frequency plotting: index of frequency space in domain
"""
"""
from
.multi_field
import
MultiField
from
.multi_field
import
MultiField
if
isinstance
(
f
,
MultiField
):
if
isinstance
(
f
,
MultiField
):
...
@@ -527,4 +544,6 @@ class Plot(object):
...
@@ -527,4 +544,6 @@ class Plot(object):
ax
=
fig
.
add_subplot
(
ny
,
nx
,
i
+
1
)
ax
=
fig
.
add_subplot
(
ny
,
nx
,
i
+
1
)
_plot
(
self
.
_plots
[
i
],
ax
,
**
self
.
_kwargs
[
i
])
_plot
(
self
.
_plots
[
i
],
ax
,
**
self
.
_kwargs
[
i
])
fig
.
tight_layout
()
fig
.
tight_layout
()
_makeplot
(
kwargs
.
pop
(
"name"
,
None
),
block
=
kwargs
.
pop
(
"block"
,
True
),
dpi
=
kwargs
.
pop
(
"dpi"
,
None
))
_makeplot
(
kwargs
.
pop
(
"name"
,
None
),
block
=
kwargs
.
pop
(
"block"
,
True
),
dpi
=
kwargs
.
pop
(
"dpi"
,
None
))
test/test_plot.py
View file @
3e36985c
...
@@ -20,6 +20,11 @@ import numpy as np
...
@@ -20,6 +20,11 @@ import numpy as np
import
nifty6
as
ift
import
nifty6
as
ift
from
.common
import
setup_function
,
teardown_function
from
.common
import
setup_function
,
teardown_function
nr
=
0
def
name
():
global
nr
nr
+=
1
return
'plot{}.png'
.
format
(
nr
)
def
test_plots
():
def
test_plots
():
# FIXME Write to temporary folder?
# FIXME Write to temporary folder?
...
@@ -40,14 +45,14 @@ def test_plots():
...
@@ -40,14 +45,14 @@ def test_plots():
plot
=
ift
.
Plot
()
plot
=
ift
.
Plot
()
plot
.
add
(
field_rg1_1
,
title
=
'Single plot'
)
plot
.
add
(
field_rg1_1
,
title
=
'Single plot'
)
plot
.
output
(
name
=
'plot1.png'
)
plot
.
output
(
name
=
name
()
)
plot
=
ift
.
Plot
()
plot
=
ift
.
Plot
()
plot
.
add
(
field_rg2
,
title
=
'2d rg'
)
plot
.
add
(
field_rg2
,
title
=
'2d rg'
)
plot
.
add
([
field_rg1_1
,
field_rg1_2
],
title
=
'list 1d rg'
,
label
=
[
'1'
,
'2'
])
plot
.
add
([
field_rg1_1
,
field_rg1_2
],
title
=
'list 1d rg'
,
label
=
[
'1'
,
'2'
])
plot
.
add
(
field_rg1_2
,
title
=
'1d rg, xmin, ymin'
,
xmin
=
0.5
,
ymin
=
0.
,
plot
.
add
(
field_rg1_2
,
title
=
'1d rg, xmin, ymin'
,
xmin
=
0.5
,
ymin
=
0.
,
xlabel
=
'xmin=0.5'
,
ylabel
=
'ymin=0'
)
xlabel
=
'xmin=0.5'
,
ylabel
=
'ymin=0'
)
plot
.
output
(
title
=
'Three plots'
,
name
=
'plot2.png'
)
plot
.
output
(
title
=
'Three plots'
,
name
=
name
()
)
plot
=
ift
.
Plot
()
plot
=
ift
.
Plot
()
plot
.
add
(
field_hp
,
title
=
'HP planck-color'
,
colormap
=
'Planck-like'
)
plot
.
add
(
field_hp
,
title
=
'HP planck-color'
,
colormap
=
'Planck-like'
)
...
@@ -55,4 +60,20 @@ def test_plots():
...
@@ -55,4 +60,20 @@ def test_plots():
plot
.
add
(
field_ps
)
plot
.
add
(
field_ps
)
plot
.
add
(
field_gl
,
title
=
'GL'
)
plot
.
add
(
field_gl
,
title
=
'GL'
)
plot
.
add
(
field_rg2
,
title
=
'2d rg'
)
plot
.
add
(
field_rg2
,
title
=
'2d rg'
)
plot
.
output
(
nx
=
2
,
ny
=
3
,
title
=
'Five plots'
,
name
=
'plot3.png'
)
plot
.
output
(
nx
=
2
,
ny
=
3
,
title
=
'Five plots'
,
name
=
name
())
def
test_mf_plot
():
x_space
=
ift
.
RGSpace
((
16
,
16
))
f_space
=
ift
.
RGSpace
(
4
)
d1
=
ift
.
SpaceTuple
.
make
([
x_space
,
f_space
])
d2
=
ift
.
SpaceTuple
.
make
([
f_space
,
x_space
])
f1
=
ift
.
from_random
(
'normal'
,
d1
)
f2
=
ift
.
makeField
(
d2
,
np
.
moveaxis
(
f1
.
val
,
-
1
,
0
))
plot
=
ift
.
Plot
()
plot
.
add
(
f1
,
block
=
False
,
title
=
'f_space_idx = 1'
)
plot
.
add
(
f2
,
freq_space_idx
=
0
,
title
=
'f_space_idx = 0'
)
plot
.
output
(
nx
=
2
,
ny
=
1
,
title
=
'MF-Plots, should look identical'
,
name
=
name
())
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