diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0b24817..6cb0245 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -31,7 +31,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} diff --git a/.github/workflows/DocCleanup.yml b/.github/workflows/DocCleanup.yml index c694061..32498cb 100644 --- a/.github/workflows/DocCleanup.yml +++ b/.github/workflows/DocCleanup.yml @@ -16,7 +16,7 @@ jobs: contents: write steps: - name: Checkout gh-pages branch - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: ref: gh-pages - name: Delete preview and history + push changes diff --git a/.github/workflows/DocNav.yml b/.github/workflows/DocNav.yml index 7a76a76..cc516c0 100644 --- a/.github/workflows/DocNav.yml +++ b/.github/workflows/DocNav.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout gh-pages branch - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: ref: gh-pages @@ -25,7 +25,7 @@ jobs: uses: TuringLang/actions/DocsNav@main with: doc-path: "." - navbar-url: "https://raw.githubusercontent.com/JuliaSpacePhysics/actions/refs/heads/main/Navbar.html" + navbar-url: "https://raw.githubusercontent.com/JuliaSpacePhysics/juliaspacephysics.github.io/refs/heads/main/ecosystem/Navbar.html" - name: Commit and push changes run: | diff --git a/src/SpaceDataModel.jl b/src/SpaceDataModel.jl index 431dbd5..3d92304 100644 --- a/src/SpaceDataModel.jl +++ b/src/SpaceDataModel.jl @@ -26,7 +26,9 @@ include("coord.jl") include("workload.jl") # Interface -name(v) = @getfield v :name getmeta(v, "name", "") +name(v) = @getfield v :name meta_name(meta(v)) +meta_name(nt::NamedTuple) = get(nt, :name, "") +meta_name(meta) = get(meta, "name", "") """ getmeta(x) @@ -41,16 +43,19 @@ getmeta(x) = @getfield x (:meta, :metadata) NoMetadata() Get metadata value associated with object `x` for key `key`, or `default` if `key` is not present. """ -getmeta(x, key, default=nothing) = get(meta(x), key, default) +getmeta(x, key, default = nothing) = get(meta(x), key, default) meta(x) = getmeta(x) # not exported (to be removed) -units(v) = @get(v, "units", nothing) +function units(v) + m = getmeta(v) + return m isa NamedTuple ? get(m, :units, nothing) : get(m, "units", nothing) +end times(v) = @getfield v (:times, :time) function unit(v) us = units(v) - allequal(us) ? only(us) : error("Units are not equal: $us") + return allequal(us) ? only(us) : error("Units are not equal: $us") end """ @@ -88,8 +93,8 @@ Update metadata for object `x` for key `key` to have value `value` and return `x function setmeta end function setmeta(x, args::Pair...; kw...) - return @set x.metadata=_merge(meta(x), Dict(args...), kw) + return @set x.metadata = _merge(meta(x), Dict(args...), kw) end -setmeta(x, dict::AbstractDict) = @set x.metadata=_merge(meta(x), dict) +setmeta(x, dict::AbstractDict) = @set x.metadata = _merge(meta(x), dict) -end \ No newline at end of file +end diff --git a/src/product.jl b/src/product.jl index 77f9f0f..ea83ffb 100644 --- a/src/product.jl +++ b/src/product.jl @@ -26,7 +26,7 @@ func(p::Product) = p.transformation # Allow chaining of transformations with multiple products ∘(g::AbstractProduct, f::AbstractProduct) = @set g.transformation = func(g) ∘ func(f) -function set(p::Product; name=nothing, data=nothing, transformation=nothing, metadata=nothing, kwargs...) +function set(p::AbstractProduct; name=nothing, data=nothing, transformation=nothing, metadata=nothing, kwargs...) !isnothing(name) && (p = @set p.name = name) !isnothing(data) && (p = @set p.data = data) !isnothing(transformation) && (p = @set p.transformation = transformation) diff --git a/src/show.jl b/src/show.jl index c5df310..e4ba298 100644 --- a/src/show.jl +++ b/src/show.jl @@ -1,4 +1,5 @@ _isdefault(v) = false +_isdefault(::NoMetadata) = true _isdefault(v::AbstractDict) = isempty(v) _isdefault(v::Tuple) = isempty(v) diff --git a/src/variable.jl b/src/variable.jl index f7be082..cf622a5 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -40,7 +40,7 @@ function Base.show(io::IO, var::T) where {T <: AbstractDataVariable} print_name(io, var) print(io, " [") time = times(var) - isnothing(time) || print(io, _timerange_str(time), ",") + isnothing(time) || isempty(time) || print(io, _timerange_str(time), ",") u = units(var) isnothing(u) || print(io, " Units: ", u, ",") print(io, " Size: ", size(var)) @@ -58,7 +58,7 @@ function Base.show(io::IO, m::MIME"text/plain", var::T) where {T <: AbstractData print_name(io, var) println(io) time = times(var) - isnothing(time) || println(io, " ", _timerange_str(time)) + isnothing(time) || isempty(time) || println(io, " ", _timerange_str(time)) u = units(var) isnothing(u) || println(io, " Units: ", u) println(io, " Size: ", size(var)) diff --git a/src/workload.jl b/src/workload.jl index c5f1075..5694b3d 100644 --- a/src/workload.jl +++ b/src/workload.jl @@ -2,11 +2,13 @@ function workload() io = IOContext(IOBuffer(), :color => true) var1 = [1, 2, 3] var2 = (4, 5, 6) - var = DataVariable([1, 2, 3], Dict()) + var = DataVariable([1, 2, 3], Dict("name" => "var")) + var2 = DataVariable([1, 2, 3], (; name = "var2")) dataset = DataSet("Dataset Name", [var1, var2]) project = Project(name = "Project Name", abbreviation = "Proj", links = "links") instrument = Instrument(name = "Instrument Name") show(io, MIME"text/plain"(), var) + show(io, MIME"text/plain"(), var2) show(io, MIME"text/plain"(), dataset) show(io, MIME"text/plain"(), project) push!(project, instrument, dataset)