From f284778fc56842752d7d522a268a63304bb94bd0 Mon Sep 17 00:00:00 2001 From: Jeff Fessler Date: Sun, 12 May 2024 23:04:00 -0400 Subject: [PATCH] Illustrate `mid3` with xticks in documentation (#50) * Show mid3 * Module docstring * Avoid duplicate @isplot * Standardize make.jl * Standardize yml --- .github/workflows/CompatHelper.yml | 40 +++++++++++++++++++++++++----- .github/workflows/SpellCheck.yml | 13 ++++++++++ .github/workflows/TagBot.yml | 2 ++ docs/lit/examples/1-examples.jl | 29 +++++++++++++++++++--- docs/lit/examples/2-yflip.jl | 3 ++- docs/make.jl | 10 ++++---- src/MIRTjim.jl | 5 +++- test/isplot.jl | 6 +++-- test/runtests.jl | 4 --- 9 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/SpellCheck.yml diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 8d8c7bb..e4ee926 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -1,20 +1,48 @@ name: CompatHelper + on: schedule: - cron: 0 0 * * 0 # weekly workflow_dispatch: - +permissions: + contents: write + pull-requests: write jobs: CompatHelper: runs-on: ubuntu-latest steps: - - name: Pkg.add("CompatHelper") - run: julia -e 'using Pkg; Pkg.add("CompatHelper")' - - name: CompatHelper.main() + - name: Check if Julia is already available in the PATH + id: julia_in_path + run: which julia + continue-on-error: true + - name: Install Julia, but only if it is not already available in the PATH + uses: julia-actions/setup-julia@latest + with: + version: '1' + # arch: ${{ runner.arch }} + if: steps.julia_in_path.outcome != 'success' + - name: "Add the General registry via Git" + run: | + import Pkg + ENV["JULIA_PKG_SERVER"] = "" + Pkg.Registry.add("General") + shell: julia --color=yes {0} + - name: "Install CompatHelper" + run: | + import Pkg + name = "CompatHelper" + uuid = "aa819f21-2bde-4658-8897-bab36330d9b7" + version = "3" + Pkg.add(; name, uuid, version) + shell: julia --color=yes {0} + - name: "Run CompatHelper" + run: | + import CompatHelper + CompatHelper.main() + shell: julia --color=yes {0} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} # need ssh - run: julia -e 'using CompatHelper; CompatHelper.main()' + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} # based on: # https://github.com/JuliaRegistries/CompatHelper.jl diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml new file mode 100644 index 0000000..c344f6d --- /dev/null +++ b/.github/workflows/SpellCheck.yml @@ -0,0 +1,13 @@ +name: Spell Check + +on: [pull_request] + +jobs: + typos-check: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v4 + - name: Check spelling + uses: crate-ci/typos@master diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index f49313b..6d2efc1 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -1,9 +1,11 @@ name: TagBot + on: issue_comment: types: - created workflow_dispatch: + jobs: TagBot: if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' diff --git a/docs/lit/examples/1-examples.jl b/docs/lit/examples/1-examples.jl index 2752308..96884a0 100644 --- a/docs/lit/examples/1-examples.jl +++ b/docs/lit/examples/1-examples.jl @@ -12,7 +12,7 @@ This page illustrates the Julia package # Packages needed here. -using MIRTjim: jim, prompt +using MIRTjim: jim, prompt, mid3 using AxisArrays: AxisArray using ColorTypes: RGB using OffsetArrays: OffsetArray @@ -71,7 +71,7 @@ jim(zo, "OffsetArray example") =# f3 = reshape(1:(9*7*6), (9, 7, 6)) -jim(f3, "3D") +jim(f3, "3D"; size=(600, 300)) # One can specify how many images per row or column for such a mosaic. @@ -80,7 +80,28 @@ x11 = reshape(1:(5*6*11), (5, 6, 11)) jim(x11, "nrow=3"; nrow=3) # -jim(x11, "ncol=6"; ncol=6) +jim(x11, "ncol=6"; ncol=6, size=(600, 200)) + + +#= +## Central slices with `mid3` +The `mid3` function shows the central x-y, y-z, and x-z slices +[(axial, coronal, sagittal) planes](https://en.wikipedia.org/wiki/Anatomical_plane). +Making useful `xticks` and `yticks` in this case takes some fiddling. +=# +x,y,z = -20:20, -10:10, 1:30 +xc = reshape(x, :, 1, 1) +yc = reshape(y, 1, :, 1) +zc = reshape(z, 1, 1, :) +rx = reshape(range(2, 19, length(z)), size(zc)) +ry = reshape(range(2, 9, length(z)), size(zc)) +cone = @. abs2(xc / rx) + abs2(yc / ry) < 1 +jim(mid3(cone); color=:cividis, title="mid3") +xticks = ([1, length(x), length(x)+length(z)], + ["$(x[begin])", "$(x[end]), $(z[begin])", "$(z[end])"]) +yticks = ([1, length(y), length(y)+length(z)], + ["$(y[begin])", "$(y[end]), $(z[begin])", "$(z[end])"]) +Plots.plot!(;xticks , yticks) #= @@ -115,7 +136,7 @@ jim(x, y, zu, "units" ; x = range(-2,2,201) * 1u"m" y = range(-1.2,1.2,150) * 1u"m" # Δy ≢ Δx z = @. sqrt(x^2 + (y')^2) ≤ 1u"m" -jim(x, y, z, "Axis units with unequal spacing"; color=:cividis) +jim(x, y, z, "Axis units with unequal spacing"; color=:cividis, size=(600,350)) #= diff --git a/docs/lit/examples/2-yflip.jl b/docs/lit/examples/2-yflip.jl index 3352482..f5c3849 100644 --- a/docs/lit/examples/2-yflip.jl +++ b/docs/lit/examples/2-yflip.jl @@ -37,7 +37,8 @@ This is a typical convention in "image processing" of digital images that lack any physical coordinates for their axes. =# -ji = (args...; kwargs...) -> jim(args...; kwargs..., prompt=false) +ji = (args...; kwargs...) -> + jim(args...; size=(700,400), kwargs..., prompt=false) jim( ji(i1, "2D default"), ji(i1, yflip=false, "2D yflip=false"), diff --git a/docs/make.jl b/docs/make.jl index f81b272..35b4ea4 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,8 +2,8 @@ execute = isempty(ARGS) || ARGS[1] == "run" org, reps = :JeffFessler, :MIRTjim eval(:(using $reps)) -using Documenter -using Literate +import Documenter +import Literate # https://juliadocs.github.io/Documenter.jl/stable/man/syntax/#@example-block ENV["GKSwstype"] = "100" @@ -23,7 +23,7 @@ binder_root_url = repo = eval(:($reps)) -DocMeta.setdocmeta!(repo, :DocTestSetup, :(using $reps); recursive=true) +Documenter.DocMeta.setdocmeta!(repo, :DocTestSetup, :(using $reps); recursive=true) # preprocessing inc1 = "include(\"../../../inc/reproduce.jl\")" @@ -77,7 +77,7 @@ format = Documenter.HTML(; assets = ["assets/custom.css"], ) -makedocs(; +Documenter.makedocs(; modules = [repo], authors = "Jeff Fessler and contributors", sitename = "$repo.jl", @@ -90,7 +90,7 @@ makedocs(; ) if isci - deploydocs(; + Documenter.deploydocs(; repo = "github.com/$base", devbranch = "main", devurl = "dev", diff --git a/src/MIRTjim.jl b/src/MIRTjim.jl index 79d500e..dde3d30 100644 --- a/src/MIRTjim.jl +++ b/src/MIRTjim.jl @@ -1,6 +1,9 @@ """ Module `MIRTjim` exports the "jiffy image display" method `jim`, -and the two helper methods `caller_name` and `prompt`. +and the helper methods: +- `caller_name` +- `mid3` +- `prompt` """ module MIRTjim diff --git a/test/isplot.jl b/test/isplot.jl index 979e58e..9f13d8b 100644 --- a/test/isplot.jl +++ b/test/isplot.jl @@ -1,6 +1,8 @@ using Plots using Test: @test -macro isplot(ex) # @isplot macro to streamline tests - :(@test $(esc(ex)) isa Plots.Plot) +if !isdefined(Main, Symbol("@isplot")) + macro isplot(ex) # @isplot macro to streamline tests + :(@test $(esc(ex)) isa Plots.Plot) + end end diff --git a/test/runtests.jl b/test/runtests.jl index a460dbe..1e20fd7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,10 +5,6 @@ using MIRTjim ENV["GKSwstype"] = "100" -macro isplot(ex) # @isplot macro to streamline tests - :(@test $(esc(ex)) isa Plots.Plot) -end - @testset "MIRTjim" begin include("jim.jl")