Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
empyre
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dieter Weber
empyre
Commits
8d8fafaa
Commit
8d8fafaa
authored
7 years ago
by
Jan Caron
Browse files
Options
Downloads
Plain Diff
Merge branch 'Fix_OVF_Reader' into 'master'
Fix ovf reader See merge request !6
parents
ab034725
b8e6c191
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyramid/file_io/io_vectordata.py
+33
-19
33 additions, 19 deletions
pyramid/file_io/io_vectordata.py
with
33 additions
and
19 deletions
pyramid/file_io/io_vectordata.py
+
33
−
19
View file @
8d8fafaa
...
...
@@ -74,16 +74,23 @@ def _load_from_llg(filename, a):
def
_load_from_ovf
(
filename
,
a
):
_log
.
debug
(
'
Calling load_from_ovf
'
)
with
open
(
filename
,
'
rb
'
)
as
mag_file
:
assert
mag_file
.
readline
().
startswith
(
b
'
# OOMMF
'
)
# Make sure file has .ovf-format!
# TODO: Also handle OOMF 1.0? See later TODOs...
line
=
mag_file
.
readline
()
assert
line
.
startswith
(
b
'
# OOMMF
'
)
# File has OVF format!
read_header
,
read_data
=
False
,
False
header
=
{}
header
=
{
'
version
'
:
line
.
split
()[
-
1
].
decode
(
'
utf-8
'
)
}
x_mag
,
y_mag
,
z_mag
=
[],
[],
[]
data_mode
=
''
for
line
in
mag_fil
e
:
data_mode
=
None
while
Tru
e
:
# Read in additional info:
if
not
read_header
and
not
read_data
:
line
=
mag_file
.
readline
()
if
line
==
b
''
:
break
# End of file is reached!
if
line
.
startswith
(
b
'
# Segment count
'
):
assert
int
(
line
.
split
()[
3
])
==
1
,
'
Only one vector field can be read at time!
'
header
[
'
segment_count
'
]
=
int
(
line
.
split
()[
-
1
])
# TODO: currently new segments overwrite last ones. read more than one? return
# TODO: navigation axis (segment count > 1) if implemented in HyperSpy reader!
elif
line
.
startswith
(
b
'
# Begin: Header
'
):
read_header
=
True
elif
line
.
startswith
(
b
'
# Begin: Data
'
):
...
...
@@ -93,8 +100,9 @@ def _load_from_ovf(filename, a):
'
Data mode {} is currently not supported by this reader!
'
.
format
(
data_mode
)
assert
header
.
get
(
'
meshtype
'
)
==
'
rectangular
'
,
\
'
Only rectangular grids can be currently read!
'
# Read in header:
elif
read_header
:
# Read header:
# Read header line by line:
elif
read_header
:
line
=
mag_file
.
readline
()
if
line
.
startswith
(
b
'
# End: Header
'
):
# Header is done:
read_header
=
False
continue
...
...
@@ -105,15 +113,18 @@ def _load_from_ovf(filename, a):
if
len
(
line_list
)
<=
1
:
# Just '#' or empty line:
continue
key
,
value
=
line_list
[
1
].
strip
(
'
:
'
),
'
'
.
join
(
line_list
[
2
:])
if
key
not
in
header
:
# Add new key, value pair:
if
key
not
in
header
:
# Add new key, value pair
if not existant
:
header
[
key
]
=
value
elif
key
==
'
Desc
'
:
# Can go over several lines:
header
[
'
Desc
'
]
=
'
'
.
join
([
header
[
'
Desc
'
],
value
])
# Read in data:
# TODO: Make it work for both text and binary! Put into HyperSpy?
# TODO: http://math.nist.gov/oommf/doc/userguide11b2/userguide/vectorfieldformat.html
# TODO: http://math.nist.gov/oommf/doc/userguide12a5/userguide/OVF_2.0_format.html
# TODO: 1.0 and 2.0 DIFFER (little and big endian in binary data -.-)
elif
read_data
:
# Currently in a data block:
if
data_mode
in
[
'
text
'
,
'
Text
'
]:
# Read data as text:
if
data_mode
in
[
'
text
'
,
'
Text
'
]:
# Read data as text, line by line:
line
=
mag_file
.
readline
()
if
line
.
startswith
(
b
'
# End: Data
'
):
# Header is done:
read_data
=
False
else
:
...
...
@@ -121,18 +132,20 @@ def _load_from_ovf(filename, a):
x_mag
.
append
(
x
)
y_mag
.
append
(
y
)
z_mag
.
append
(
z
)
elif
'
Binary
'
in
data_mode
:
elif
'
Binary
'
in
data_mode
:
# Read data as binary, all bytes at the same time:
count
=
int
(
data_mode
.
split
()[
-
1
])
dtype
=
'
>f{}
'
.
format
(
count
)
if
header
[
'
version
'
]
==
'
1.0
'
:
# Big endian:
dtype
=
'
>f{}
'
.
format
(
count
)
elif
header
[
'
version
'
]
==
'
2.0
'
:
# Little endian:
dtype
=
'
<f{}
'
.
format
(
count
)
dim
=
(
int
(
header
[
'
znodes
'
]),
int
(
header
[
'
ynodes
'
]),
int
(
header
[
'
xnodes
'
]))
test
=
np
.
fromfile
(
mag_file
,
dtype
=
'
<f4
'
,
count
=
count
*
2
+
1
)
test
=
np
.
fromfile
(
mag_file
,
dtype
=
dtype
,
count
=
1
)
if
count
==
4
:
# Binary 4:
assert
test
==
'
1234567
89
.0
'
,
'
Wrong test bytes!
'
if
count
==
8
:
# Binary
4
:
assert
test
==
'
123456789012345.0
'
,
'
Wrong test bytes!
'
assert
test
==
1234567.0
,
'
Wrong test bytes!
'
el
if
count
==
8
:
# Binary
8
:
assert
test
==
123456789012345.0
,
'
Wrong test bytes!
'
data
=
np
.
fromfile
(
mag_file
,
dtype
=
dtype
,
count
=
3
*
np
.
prod
(
dim
))
data
.
reshape
((
3
,)
+
dim
)
x_mag
,
y_mag
,
z_mag
=
data
x_mag
,
y_mag
,
z_mag
=
data
[
0
::
3
],
data
[
1
::
3
],
data
[
2
::
3
]
read_data
=
False
# Stop reading data and search for new Segments (if any).
# Format after reading:
dim
=
(
int
(
header
[
'
znodes
'
]),
int
(
header
[
'
ynodes
'
]),
int
(
header
[
'
xnodes
'
]))
...
...
@@ -141,8 +154,9 @@ def _load_from_ovf(filename, a):
z_mag
=
np
.
asarray
(
z_mag
).
reshape
(
dim
)
field
=
np
.
asarray
((
x_mag
,
y_mag
,
z_mag
))
*
float
(
header
.
get
(
'
valuemultiplier
'
,
1
))
if
a
is
None
:
assert
header
.
get
(
'
xstepsize
'
)
==
header
.
get
(
'
ystepsize
'
)
==
header
.
get
(
'
zstepsize
'
),
\
'
Grid spacing is not equidistant!
'
# TODO: If transferred to HyperSpy, this has to stay in Pyramid reader!
if
header
.
get
(
'
xstepsize
'
)
==
header
.
get
(
'
ystepsize
'
)
==
header
.
get
(
'
zstepsize
'
):
_log
.
warning
(
'
Grid spacing is not equal in x, y and z (x will be used)!
'
)
a
=
float
(
header
.
get
(
'
xstepsize
'
,
1.
))
meshunit
=
header
.
get
(
'
meshunit
'
,
'
nm
'
)
a
*=
{
'
m
'
:
1e9
,
'
mm
'
:
1e6
,
'
µm
'
:
1e3
,
'
nm
'
:
1
}[
meshunit
]
# Conversion to nm
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment