-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = "WykoOPDReader" | ||
uuid = "6da23c8c-444c-4310-aaa6-9150b66cb193" | ||
authors = ["Jaakko Ruohio <jaakkor2@gmail.com>"] | ||
version = "0.1.0" | ||
|
||
[compat] | ||
julia = "1.10" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# WykoOPDReader | ||
|
||
[![Build Status](https://github.com/jaakkor2/WykoOPDReader.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/jaakkor2/WykoOPDReader.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
|
||
Reader for Wyko profilometer datasets (.opd) written in Julia language. | ||
|
||
```julia | ||
using WykoOPDReader | ||
data = readopd("profile.opd") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
WykoOPDReader | ||
Reader for WYKO data sets (.opd) implemented in Julia. | ||
Exports `readopd`. | ||
""" | ||
module WykoOPDReader | ||
|
||
export readopd | ||
|
||
include("reader.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
readopd(fn) | ||
Read Wyko data set from file `fn`. | ||
# Example | ||
```julia | ||
using WykoOPDReader | ||
fn = joinpath(pathof(WykoOPDReader), "..", "..", "test", "demo.opd") | ||
data = readopd(fn) | ||
using GLMakie | ||
colormap = [:NavyBlue, :royalblue3, :LightGreen, :Red] | ||
nan_color = :black | ||
autolimitaspect = data["Aspect"] | ||
fig = Figure() | ||
ax = Axis(fig[1,1]; autolimitaspect) | ||
hm = heatmap!(ax, data["RAW_DATA"]; colormap, nan_color) | ||
Colorbar(fig[1,2], hm, width = Relative(1/10)) | ||
``` | ||
""" | ||
function readopd(fn) | ||
io = open(fn, "r") | ||
magic = read(io, 2) | ||
magic == [0x01, 0x00] || error("not .opd file?") | ||
|
||
entries = [] | ||
data = Dict{String, Any}() | ||
push!(entries, readentry(io)) | ||
n_entries = entries[1].len ÷ 24 | ||
for i = 2:n_entries | ||
push!(entries, readentry(io)) | ||
end | ||
for i = 2:n_entries | ||
(; name, type, len) = entries[i] | ||
if name == "" | ||
continue | ||
elseif type == 3 | ||
push!(data, name => readimage(io)) | ||
elseif type == 5 | ||
push!(data, name => readstring(io, len)) | ||
elseif entries[i].type == 6 | ||
push!(data, name => readint(io, len)) | ||
elseif entries[i].type == 7 | ||
push!(data, name => readfloat(io, len)) | ||
else | ||
@show "This is unknown: ", name, type, len | ||
end | ||
end | ||
close(io) | ||
return data | ||
end | ||
|
||
function readentry(io) | ||
name = rstrip(String(read(io, 16)), '\0') | ||
type = reinterpret(UInt16, read(io, 2))[1] | ||
len = reinterpret(UInt32, read(io, 4))[1] | ||
dunno = reinterpret(UInt16, read(io, 2))[1] | ||
(; name, type, len, dunno) | ||
end | ||
|
||
function readimage(io) | ||
width, height, bytewidth = Int.(reinterpret(Int16, read(io, 6))) | ||
data = read(io, width * height * bytewidth) | ||
T = bytewidth == 4 ? Float32 : bytewidth == 2 ? Int16 : UInt8 | ||
data = reinterpret(T, data) | ||
data = reshape(data, (height, width)) | ||
if !(T <: Integer) | ||
data[data .>= floatmax(T) / 2] .= NaN | ||
end | ||
data = rotr90(data, 1) | ||
data = reverse(data, dims = 2) | ||
end | ||
|
||
readstring(io, n) = rstrip(String(read(io, n)), '\0') | ||
readfloat(io, n) = reinterpret(n == 4 ? Float32 : Float64, read(io, n))[1] | ||
readint(io, n) = reinterpret(n == 4 ? Int32 : n == 2 ? Int16 : Int8, read(io, n))[1] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using WykoOPDReader | ||
using Test | ||
|
||
@testset "WykoOPDReader.jl" begin | ||
data = readopd("demo.opd") | ||
@test data["Pixel_size"] == 0.01f0 | ||
@test data["Aspect"] == 1.5 | ||
@test data["RAW_DATA"] == Float32[ | ||
-3.0 -3.0 -3.0 -3.0 | ||
-2.0 2.0 14.0 1.0 | ||
-1.0 2.0 3.0 2.0 | ||
0.0 2.0 2.0 2.0 | ||
1.0 2.0 2.0 2.0] | ||
|
||
data = readopd("raw_integer.opd") | ||
@test data["Title"] == "WykoOPDReader.jl" | ||
@test data["Note"] == "Julia" | ||
@test data["Mult"] == 32000 | ||
@test data["RAW_DATA"] == Int16[ | ||
0 128 | ||
192 319 | ||
-448 -703] | ||
end |