Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/DocCleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/DocNav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:

steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
ref: gh-pages

- name: Insert navbar
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: |
Expand Down
19 changes: 12 additions & 7 deletions src/SpaceDataModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

"""
Expand Down Expand Up @@ -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
end
2 changes: 1 addition & 1 deletion src/product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_isdefault(v) = false
_isdefault(::NoMetadata) = true
_isdefault(v::AbstractDict) = isempty(v)
_isdefault(v::Tuple) = isempty(v)

Expand Down
4 changes: 2 additions & 2 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion src/workload.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down