Skip to content

Commit

Permalink
Support more fields, add github conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
jaakkor2 committed Oct 25, 2024
1 parent a947558 commit 42b0a19
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
40 changes: 40 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI
on:
push:
branches:
- master
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
fail-fast: false
matrix:
version:
- '1.10'
- 'pre'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
31 changes: 31 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: "3"
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WykoOPDReader"
uuid = "6da23c8c-444c-4310-aaa6-9150b66cb193"
authors = ["Jaakko Ruohio <jaakkor2@gmail.com>"]
version = "0.1.0"
version = "0.1.1"

[compat]
julia = "1.10"
Expand Down
5 changes: 3 additions & 2 deletions src/WykoOPDReader.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
WykoOPDReader
Reader for WYKO data sets (.opd) implemented in Julia.
Reader for WYKO OPD data sets (.opd) implemented in Julia.
Exports `readopd`.
"""
module WykoOPDReader

export readopd
export readopd, prepplot

include("reader.jl")
include("util.jl")

end
102 changes: 92 additions & 10 deletions src/reader.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
readopd(fn)
Read Wyko data set from file `fn`.
Read Wyko OPD data set from file `fn`.
# Example
Expand All @@ -10,14 +10,17 @@ using WykoOPDReader
fn = joinpath(pathof(WykoOPDReader), "..", "..", "test", "demo.opd")
data = readopd(fn)
# data to plot
z = data["RAW_DATA"] * (haskey(data, "Wavelength") ? data["Wavelength"]/1000 : 1.0)
(; x, y, colormap, nan_color) = prepplot(data)
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)
ax = Axis(fig[1,1], aspect = DataAspect())
hm = heatmap!(ax, x, y, z; colormap, nan_color)
hm.inspector_label = (plot, index, position) -> "\$(x[index[1]]) \$(y[index[2]]) \$(position[3])"
Colorbar(fig[1,2], hm, width = Relative(1/10))
DataInspector()
```
"""
function readopd(fn)
Expand All @@ -33,22 +36,26 @@ function readopd(fn)
push!(entries, readentry(io))
end
for i = 2:n_entries
(; name, type, len) = entries[i]
(; name, type, len, dunno) = entries[i]
# name == "" || @show name, type, len, dunno, "OPP"
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
elseif type == 6
push!(data, name => readint(io, len))
elseif entries[i].type == 7
elseif type in [7,8] # 7=Float32, 8=Float64
push!(data, name => readfloat(io, len))
elseif type == 15
push!(data, name => read15(io, len))
else
@show "This is unknown: ", name, type, len
@show "This is unknown: ", name, type, len, dunno
end
end
close(io)
data = replaceshortkeys(data)
return data
end

Expand Down Expand Up @@ -76,3 +83,78 @@ 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]

function read15(io, n)
readnext(io)
end

function readnext(io)
type = read(io, 1)[1]
if type == 1 # bool?
reinterpret(Bool, read(io, 1)[1])
elseif type == 6
reinterpret(Int32, read(io, 4))[1]
elseif type == 10
reinterpret(Int64, read(io, 8))[1]
elseif type == 12
reinterpret(Float32, read(io, 4))[1]
elseif type == 13
reinterpret(Float64, read(io, 8))[1]
elseif type == 14
len = reinterpret(Int32, read(io, 4))[1]
s1 = String(read(io, len))
read(io, 1)
n = read(io, 1)[1]
v1 = read(io, n)
s1, v1
elseif type == 21 # TimeStamp
read(io, 1)
reinterpret(Int64, read(io, 8)) # ANSI Date (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.)
elseif type == 66
len = reinterpret(Int32, read(io, 4))[1]
s1 = String(read(io, len))
lenbytes = read(io, 1)[1]
len = reinterpret(lenbytes == 1 ? UInt8 : UInt16, read(io, lenbytes))[1]
len = reinterpret(Int32, read(io, 4))[1]
s2 = String(read(io, len))
s1, s2
else
lenbytes = read(io, 1)[1]
len = reinterpret(lenbytes == 1 ? UInt8 : UInt16, read(io, lenbytes))[1]
if type == 18
String(read(io, len))
elseif type == 19
v = reinterpret(Float64, read(io, 8))[1]
len1 = reinterpret(Int32, read(io, 4))[1]
s1 = String(read(io, len1))
len2 = reinterpret(Int32, read(io, 4))[1]
s2 = String(read(io, len2))
sc = reinterpret(Float64, read(io, 8))[1]
read(io, len - 8 - 4 - len1 - 4 - len2 - 8) # TODO some bytes unprocessed
v, s1, s2, sc
elseif type == 125
res = Dict{String,Any}()
while true
len1 = reinterpret(Int32, read(io, 4))[1]
if len1 == 0
read(io, 3)
break
end
s1 = String(read(io, len1))
v1 = readnext(io)
push!(res, s1 => v1)
end
res
else
@show "$type unhandled, please add code"
read(io, len)
end
end
end

function replaceshortkeys(data)
key_short2long = "\xcaxtendedKe\xfds"
haskey(data, key_short2long) || return data
map = data[key_short2long]
Dict((haskey(map, k) ? map[k] : k) => v for (k,v) in data if k != key_short2long)
end
11 changes: 11 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function prepplot(data)
k = findfirst(x->isa(x, Matrix), data)
x = range(0, stop = size(data[k], 1))
y = range(0, stop = size(data[k], 2))
x = x * data["Pixel_size"] * 1000 # µm
y = y * data["Pixel_size"] * data["Aspect"] * 1000 # µm
colormap = [:NavyBlue, :royalblue3, :LightGreen, :Red]
nan_color = :black
return (; x, y, colormap, nan_color)
end

0 comments on commit 42b0a19

Please sign in to comment.