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
PETRA III Debian Packages
python-nexusformat
Commits
d2f2e654
Commit
d2f2e654
authored
Oct 10, 2019
by
Jan Kotanski
Browse files
New upstream version 0.4.20
parent
88ed97d7
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
d2f2e654
...
...
@@ -54,3 +54,6 @@ Icon?
# Emacs backup files
*~
# Virtual Studio Code
.vscode
conda-recipe/meta.yaml
View file @
d2f2e654
package
:
name
:
nexusformat
version
:
"
0.4.1
8
"
version
:
"
0.4.1
9
"
source
:
git_url
:
https://github.com/nexpy/nexusformat.git
git_tag
:
v0.4.1
8
git_tag
:
v0.4.1
9
build
:
entry_points
:
...
...
src/nexusformat/_version.py
View file @
d2f2e654
...
...
@@ -20,8 +20,8 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames
=
" (
HEAD -> master,
tag: v0.4.
18
)"
git_full
=
"
b9de7f7dba7e2b4c623aa05f19bee12fbc4ec3a9
"
git_refnames
=
" (tag: v0.4.
20
)"
git_full
=
"
e1e6689b1651b8b7217158528336b80d8f126113
"
keywords
=
{
"refnames"
:
git_refnames
,
"full"
:
git_full
}
return
keywords
...
...
src/nexusformat/nexus/plot.py
View file @
d2f2e654
...
...
@@ -71,7 +71,8 @@ class PylabPlotter(object):
Matplotlib plotter class for NeXus data.
"""
def
plot
(
self
,
data_group
,
fmt
,
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
,
**
opts
):
def
plot
(
self
,
data_group
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
vmin
=
None
,
vmax
=
None
,
**
opts
):
"""
Plot the data entry.
...
...
@@ -159,18 +160,18 @@ class PylabPlotter(object):
y
=
boundaries
(
axes
[
-
2
],
data
.
shape
[
-
2
])
xlabel
,
ylabel
=
label
(
axes
[
-
1
]),
label
(
axes
[
-
2
])
if
not
z
min
:
z
min
=
np
.
nanmin
(
data
[
data
>-
np
.
inf
])
if
not
z
max
:
z
max
=
np
.
nanmax
(
data
[
data
<
np
.
inf
])
if
not
v
min
:
v
min
=
np
.
nanmin
(
data
[
data
>-
np
.
inf
])
if
not
v
max
:
v
max
=
np
.
nanmax
(
data
[
data
<
np
.
inf
])
if
not
image
:
if
log
:
z
min
=
max
(
z
min
,
0.01
)
z
max
=
max
(
z
max
,
0.01
)
opts
[
"norm"
]
=
LogNorm
(
z
min
,
z
max
)
v
min
=
max
(
v
min
,
0.01
)
v
max
=
max
(
v
max
,
0.01
)
opts
[
"norm"
]
=
LogNorm
(
v
min
,
v
max
)
else
:
opts
[
"norm"
]
=
Normalize
(
z
min
,
z
max
)
opts
[
"norm"
]
=
Normalize
(
v
min
,
v
max
)
ax
=
plt
.
gca
()
if
image
:
...
...
src/nexusformat/nexus/tree.py
View file @
d2f2e654
...
...
@@ -28,7 +28,7 @@ data.
Example 1: Loading a NeXus file
-------------------------------
The following commands loads NeXus data from a file, displays (some of) the
contents as a tree, and then accesses individual data items
.
contents as a tree, and then accesses individual data items
>>> from nexusformat import nexus as nx
>>> a=nx.load('sns/data/ARCS_7326.nxs')
...
...
@@ -83,7 +83,7 @@ file. The data are first created as Numpy arrays
>>> z=np.sin(X)*np.sin(Y)
Then, a NeXus data group is created and the data inserted to produce a
NeXus-compliant structure that can be saved to a file
.
NeXus-compliant structure that can be saved to a file
>>> root=nx.NXroot(NXentry())
>>> print root.tree
...
...
@@ -369,7 +369,7 @@ class NXFile(object):
elif
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
name
)):
raise
NeXusError
(
"'%s/' does not exist"
%
os
.
path
.
dirname
(
name
))
elif
mode
==
'w'
or
mode
==
'w-'
or
mode
==
'w5'
:
elif
mode
==
'w'
or
mode
==
'w-'
or
mode
==
'w5'
or
mode
==
'a'
:
if
mode
==
'w5'
:
mode
=
'w'
self
.
_file
=
self
.
h5
.
File
(
name
,
mode
,
**
opts
)
...
...
@@ -892,7 +892,7 @@ def _getvalue(value, dtype=None, shape=None):
_dtype
=
_getdtype
(
dtype
)
if
_dtype
.
kind
==
'S'
:
value
=
text
(
value
).
encode
(
'utf-8'
)
return
np
.
asscalar
(
np
.
array
(
value
,
dtype
=
_dtype
)),
_dtype
,
()
return
np
.
array
(
value
,
dtype
=
_dtype
)
.
item
(
),
_dtype
,
()
except
Exception
:
raise
NeXusError
(
"The value is incompatible with the dtype"
)
else
:
...
...
@@ -909,7 +909,14 @@ def _getvalue(value, dtype=None, shape=None):
else
:
_value
=
np
.
asarray
(
value
)
#convert subclasses of ndarray
else
:
_value
=
np
.
asarray
(
value
)
try
:
_value
=
[
np
.
asarray
(
v
)
for
v
in
value
]
if
len
(
set
([
v
.
shape
for
v
in
_value
]))
>
1
:
raise
NeXusError
(
"Cannot assign an iterable with items of multiple shapes"
)
_value
=
np
.
asarray
(
_value
)
except
TypeError
:
_value
=
np
.
asarray
(
value
)
if
_value
.
dtype
.
kind
==
'S'
or
_value
.
dtype
.
kind
==
'U'
:
_value
=
_value
.
astype
(
string_dtype
)
if
dtype
is
not
None
:
...
...
@@ -927,7 +934,7 @@ def _getvalue(value, dtype=None, shape=None):
except
ValueError
:
raise
NeXusError
(
"The value is incompatible with the shape"
)
if
_value
.
shape
==
():
return
np
.
asscalar
(
_value
),
_value
.
dtype
,
_value
.
shape
return
_value
.
item
(
),
_value
.
dtype
,
_value
.
shape
else
:
return
_value
,
_value
.
dtype
,
_value
.
shape
...
...
@@ -1161,7 +1168,7 @@ class NXattr(object):
else
:
return
[
text
(
value
)
for
value
in
self
.
_value
[()]]
elif
self
.
shape
==
(
1
,):
return
np
.
asscalar
(
self
.
_value
)
return
self
.
_value
.
item
(
)
else
:
return
self
.
_value
...
...
@@ -1967,7 +1974,7 @@ class NXfield(NXobject):
"""
idx
=
convert_index
(
idx
,
self
)
if
len
(
self
)
==
1
:
result
=
self
result
=
self
.
nxvalue
elif
self
.
_value
is
None
:
if
self
.
_uncopied_data
:
self
.
_get_uncopied_data
()
...
...
@@ -2320,8 +2327,10 @@ class NXfield(NXobject):
def
__long__
(
self
):
"""
Casts a scalar field as a long integer
The use of the 'long' function is not valid in Python 3 and no longer useful in Python 2
"""
return
long
(
self
.
nxvalue
)
return
int
(
self
.
nxvalue
)
def
__float__
(
self
):
"""
...
...
@@ -2723,7 +2732,7 @@ class NXfield(NXobject):
else
:
return
[
text
(
value
)
for
value
in
_value
[()]]
elif
self
.
shape
==
(
1
,):
return
np
.
asscalar
(
_value
)
return
_value
.
item
(
)
else
:
return
_value
...
...
@@ -2931,7 +2940,9 @@ class NXfield(NXobject):
@
property
def
maxshape
(
self
):
if
self
.
nxfilemode
:
if
self
.
_maxshape
is
not
None
:
return
self
.
_maxshape
elif
self
.
nxfilemode
:
with
self
.
nxfile
as
f
:
_maxshape
=
f
[
self
.
nxfilepath
].
maxshape
elif
self
.
_memfile
:
...
...
@@ -2992,7 +3003,7 @@ class NXfield(NXobject):
return
False
def
plot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plot data if the signal attribute is defined.
...
...
@@ -3031,7 +3042,8 @@ class NXfield(NXobject):
else
:
signal_path
=
self
.
nxpath
data
.
nxsignal
.
attrs
[
'signal_path'
]
=
signal_path
plotview
.
plot
(
data
,
fmt
,
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
,
**
opts
)
plotview
.
plot
(
data
,
fmt
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
vmin
=
None
,
vmax
=
None
,
**
opts
)
else
:
raise
NeXusError
(
"NXfield not plottable"
)
...
...
@@ -3042,23 +3054,23 @@ class NXfield(NXobject):
self
.
plot
(
fmt
=
fmt
,
over
=
True
,
**
opts
)
def
logplot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plots the data intensity contained within the group on a log scale.
"""
self
.
plot
(
fmt
=
fmt
,
log
=
True
,
xmin
=
xmin
,
xmax
=
xmax
,
ymin
=
ymin
,
ymax
=
ymax
,
z
min
=
z
min
,
z
max
=
z
max
,
**
opts
)
v
min
=
v
min
,
v
max
=
v
max
,
**
opts
)
def
implot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plots the data intensity as an RGB(A) image.
"""
if
self
.
plot_rank
>
2
and
(
self
.
shape
[
-
1
]
==
3
or
self
.
shape
[
-
1
]
==
4
):
self
.
plot
(
fmt
=
fmt
,
image
=
True
,
xmin
=
xmin
,
xmax
=
xmax
,
ymin
=
ymin
,
ymax
=
ymax
,
z
min
=
z
min
,
z
max
=
z
max
,
**
opts
)
v
min
=
v
min
,
v
max
=
v
max
,
**
opts
)
else
:
raise
NeXusError
(
"Invalid shape for RGB(A) image"
)
...
...
@@ -3595,7 +3607,7 @@ class NXgroup(NXobject):
"""
Returns true if a NeXus object with the specified name is in the group.
"""
return
self
.
entries
.
has_key
(
name
)
return
name
in
self
.
entries
def
copy
(
self
):
"""
...
...
@@ -3741,30 +3753,30 @@ class NXgroup(NXobject):
"""
return
self
.
sum
(
axis
,
averaged
=
True
)
def
moment
(
self
,
order
=
1
):
def
moment
(
self
,
order
=
1
,
center
=
None
):
"""
Returns an NXfield containing the moments of the NXdata group
Returns an NXfield containing the
central
moments of the NXdata group
assuming the signal is one-dimensional.
Currently, the first two moments have been defined (order =1 or 2).
"""
if
self
.
nxsignal
is
None
:
signal
,
axes
=
self
.
nxsignal
,
self
.
nxaxes
if
signal
is
None
:
raise
NeXusError
(
"No signal to calculate"
)
elif
len
(
self
.
nx
signal
.
shape
)
>
1
:
elif
len
(
signal
.
shape
)
>
1
:
raise
NeXusError
(
"Operation only possible on one-dimensional signals"
)
elif
order
>
2
:
raise
NeXusError
(
"Higher moments not yet implemented"
)
if
not
hasattr
(
self
,
"nxclass"
):
if
not
hasattr
(
self
,
"nxclass"
):
raise
NeXusError
(
"Operation not allowed for groups of unknown class"
)
y
=
self
.
nxsignal
x
=
centers
(
y
,
self
.
nxaxes
)[
0
]
mean
=
(
y
*
x
).
sum
()
/
y
.
sum
()
y
=
signal
/
signal
.
sum
()
x
=
centers
(
y
,
axes
)[
0
]
if
center
:
c
=
center
else
:
c
=
(
y
*
x
).
sum
()
if
order
==
1
:
return
mean
el
if
order
==
2
:
return
(
(
y
*
x
**
2
).
sum
()
/
y
.
sum
())
-
mean
**
2
return
c
el
se
:
return
(
y
*
(
x
-
c
)
**
order
).
sum
()
def
mean
(
self
):
"""
...
...
@@ -4618,7 +4630,7 @@ class NXdata(NXgroup):
idx
,
axes
=
self
.
slab
(
key
)
removed_axes
=
[]
for
axis
in
axes
:
if
axis
.
shape
==
()
or
axis
.
shape
==
(
1
,):
if
axis
.
shape
==
()
or
axis
.
shape
==
(
0
,)
or
axis
.
shape
==
(
1
,):
removed_axes
.
append
(
axis
)
axes
=
[
ax
for
ax
in
axes
if
ax
not
in
[
rax
for
rax
in
removed_axes
if
rax
is
ax
]]
...
...
@@ -4877,8 +4889,8 @@ class NXdata(NXgroup):
else
:
ind
=
convert_index
(
ind
,
axes
[
i
])
slices
.
append
(
ind
)
if
(
si
gnal
.
shape
[
i
]
<
axes
[
i
].
shape
[
0
]
and
isinstance
(
ind
,
slice
)
and
ind
.
stop
is
not
None
):
if
(
i
si
nstance
(
ind
,
slice
)
and
ind
.
stop
is
not
None
and
signal
.
shape
[
i
]
<
axes
[
i
].
shape
[
0
]
):
ind
=
slice
(
ind
.
start
,
ind
.
stop
+
1
,
ind
.
step
)
axes
[
i
]
=
axes
[
i
][
ind
]
return
tuple
(
slices
),
axes
...
...
@@ -4924,7 +4936,7 @@ class NXdata(NXgroup):
return
None
def
plot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plot data contained within the group.
...
...
@@ -4966,7 +4978,8 @@ class NXdata(NXgroup):
except
ImportError
:
from
.plot
import
plotview
plotview
.
plot
(
self
,
fmt
,
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
,
**
opts
)
plotview
.
plot
(
self
,
fmt
,
xmin
=
xmin
,
xmax
=
xmax
,
ymin
=
ymin
,
ymax
=
ymax
,
vmin
=
vmin
,
vmax
=
vmax
,
**
opts
)
def
oplot
(
self
,
fmt
=
''
,
**
opts
):
"""
...
...
@@ -4975,16 +4988,16 @@ class NXdata(NXgroup):
self
.
plot
(
fmt
=
fmt
,
over
=
True
,
**
opts
)
def
logplot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plots the data intensity contained within the group on a log scale.
"""
self
.
plot
(
fmt
=
fmt
,
log
=
True
,
xmin
=
xmin
,
xmax
=
xmax
,
ymin
=
ymin
,
ymax
=
ymax
,
z
min
=
z
min
,
z
max
=
z
max
,
**
opts
)
v
min
=
v
min
,
v
max
=
v
max
,
**
opts
)
def
implot
(
self
,
fmt
=
''
,
xmin
=
None
,
xmax
=
None
,
ymin
=
None
,
ymax
=
None
,
z
min
=
None
,
z
max
=
None
,
**
opts
):
v
min
=
None
,
v
max
=
None
,
**
opts
):
"""
Plots the data intensity as an image.
"""
...
...
@@ -4992,7 +5005,7 @@ class NXdata(NXgroup):
(
self
.
nxsignal
.
shape
[
-
1
]
==
3
or
self
.
nxsignal
.
shape
[
-
1
]
==
4
)):
self
.
plot
(
fmt
=
fmt
,
image
=
True
,
xmin
=
xmin
,
xmax
=
xmax
,
ymin
=
ymin
,
ymax
=
ymax
,
z
min
=
z
min
,
z
max
=
z
max
,
**
opts
)
v
min
=
v
min
,
v
max
=
v
max
,
**
opts
)
else
:
raise
NeXusError
(
"Invalid shape for RGB(A) image"
)
...
...
src/nexusformat/notebooks/nexusformat.ipynb
View file @
d2f2e654
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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