Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Convert Veeco Wyko NT9100 ASC format
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Plougonven Erwan
Convert Veeco Wyko NT9100 ASC format
Commits
ef786487
Commit
ef786487
authored
11 months ago
by
Plougonven Erwan
Browse files
Options
Downloads
Patches
Plain Diff
The code.
parent
cb8bc0bf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Convert_Wyko_ASCII.py
+104
-0
104 additions, 0 deletions
Convert_Wyko_ASCII.py
with
104 additions
and
0 deletions
Convert_Wyko_ASCII.py
0 → 100644
+
104
−
0
View file @
ef786487
__author__
=
"
Erwan Plougonven
"
import
os
import
sys
import
re
import
numpy
as
np
from
scipy.ndimage
import
median_filter
def
main
():
input_file
=
"
particle 2 a.asc
"
output_file_h
=
"
particle2a_height.am
"
output_file_i
=
"
particle2a_intensity.am
"
dims
,
hfld
,
ifld
=
extract_Wyko_ASCII_data
(
input_file
)
# Some spikes in height field raw data, removed with median filter
hfld
=
median_filter
(
hfld
,
footprint
=
np
.
array
([[
0
,
1
,
0
],[
1
,
1
,
1
],[
0
,
1
,
0
]]))
create_Avizo_ASCII
(
dims
,
hfld
,
output_file_h
)
create_Avizo_ASCII
(
dims
,
ifld
,
output_file_i
)
##########################
### Internal functions ###
##########################
def
extract_Wyko_ASCII_data
(
input_file
):
allLines
=
[
line
.
rstrip
(
'
\r\n
'
)
for
line
in
open
(
input_file
)]
# if len(line)>0]
dataFormatKey
=
"
Wyko ASCII Data File Format
"
if
dataFormatKey
not
in
allLines
[
0
]:
print
(
"
File
"
+
input_file
+
"
does not appear to be Wyko ASCII file. Exiting.
"
)
sys
.
exit
(
"
Wrong file format. Header of file
"
+
input_file
+
"
is:
\"
"
+
allLines
[
0
]
+
"
\"
. Was looking for:
\"
"
+
dataFormatKey
+
"
\"
.
"
)
codes
=
[
int
(
i
)
for
i
in
allLines
[
0
][
len
(
dataFormatKey
):].
split
()]
# First number is "Array format, 0 for standard, 2 for XYZ Triplet, Real".
nbPixelsKey
=
[
"
X Size
"
,
"
Y Size
"
]
dims
=
[
int
(
allLines
[
x
+
1
][
len
(
nbPixelsKey
[
x
]):])
for
x
in
[
0
,
1
]]
# Find last line of header
endHeaderLine
=
r
"
OPD
"
for
i
,
line
in
enumerate
(
allLines
):
if
re
.
match
(
endHeaderLine
+
"
[^\w]
"
,
line
):
#print(line)
sepChar
=
line
[
len
(
endHeaderLine
)]
break
data
=
allLines
[
i
+
1
:]
startIntensityLine
=
r
"
Intensity
"
# There are two data sections
for
i
,
line
in
enumerate
(
data
):
if
re
.
match
(
startIntensityLine
,
line
):
#print(line)
break
data_H
=
data
[
0
:
i
]
data_I
=
data
[
i
+
1
:]
def
parse_data
(
datalines
):
arr
=
np
.
full
(
dims
,
np
.
nan
)
if
codes
[
0
]
==
0
:
#print("Array Format: Standard")
for
j
,
line
in
enumerate
(
datalines
):
lineElems
=
line
[:
-
1
].
split
(
sepChar
)
# One too many separators at EOL
arr
[
j
,:]
=
[
x
if
x
else
np
.
nan
for
x
in
lineElems
]
if
codes
[
0
]
==
2
:
#print("Array Format: XYZ Triplet, Real")
for
j
in
range
(
0
,
dims
[
0
]):
for
i
in
range
(
0
,
dims
[
1
]):
nums
=
[
float
(
x
)
for
x
in
datalines
[
j
*
dims
[
1
]
+
i
].
split
()]
if
(
len
(
nums
)
==
3
):
arr
[
j
,
i
]
=
nums
[
2
]
np
.
nan_to_num
(
arr
,
copy
=
False
,
nan
=
np
.
nanmean
(
arr
))
arr
=
np
.
transpose
(
arr
)
return
arr
height_field
=
parse_data
(
data_H
)
intensity_field
=
parse_data
(
data_I
)
return
[
dims
,
height_field
,
intensity_field
]
def
create_Avizo_ASCII
(
dims
,
fld
,
output_file
):
outputfile_header
=
"""
# Avizo 3D ASCII 2.0
define Lattice {X} {Y} 1
Parameters {{
Content
"
{X}x{Y}x1 float, uniform coordinates
"
,
BoundingBox 0 {BBx} 0 {BBy} 0 0.1,
CoordType
"
uniform
"
}}
Lattice {{ float Data }} @1
# Data section follows
@1
"""
.
format
(
X
=
dims
[
0
],
Y
=
dims
[
1
],
BBx
=
dims
[
0
]
-
1
,
BBy
=
dims
[
1
]
-
1
)
ofh
=
open
(
output_file
,
'
w
'
)
ofh
.
write
(
outputfile_header
)
np
.
savetxt
(
ofh
,
fld
,
fmt
=
"
%f
"
,
delimiter
=
'
'
)
ofh
.
close
()
if
__name__
==
'
__main__
'
:
main
()
# Defined this way so that user-defined parameters are at the beginning of the file.
\ No newline at end of file
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