1-
21"""
32An array-like object that represents a HAPI variable.
43
@@ -8,27 +7,35 @@ An array-like object that represents a HAPI variable.
87- `time`: The time axis (use `times(x)` to access).
98- `meta`: The metadata (use `meta(x)` to access).
109"""
11- struct HAPIVariable{T, N, A <: AbstractArray{T, N} , Tt <: AbstractVector } <: AbstractDataVariable{T, N}
10+ struct HAPIVariable{T, N, A <: AbstractArray{T, N} , Tt <: AbstractVector , M <: AbstractDict } <: AbstractDataVariable{T, N}
1211 data:: A
1312 time:: Tt
14- meta:: Dict
13+ meta:: M
1514end
1615
1716"""
1817A thin wrapper over NamedTuple for HAPI variables that shares the same time axis.
1918"""
20- struct HAPIVariables{NT <: NamedTuple , D <: Dict , S, DS}
19+ struct HAPIVariables{NT <: NamedTuple , D <: AbstractDict , S, DS}
2120 nt:: NT
2221 meta:: D
2322 server:: S
2423 dataset:: DS
24+ uri:: URI
2525end
2626
2727@inline Base. parent (x:: HAPIVariables ) = getfield (x, :nt )
2828times (x:: HAPIVariables ) = times (first (parent (x)))
2929server (x:: HAPIVariables ) = getfield (x, :server )
3030dataset (x:: HAPIVariables ) = getfield (x, :dataset )
31- id (x:: HAPIVariables ) = id (server (x)) * " /" * dataset (x)
31+ function id (x:: HAPIVariables )
32+ s = server (x)
33+ if s isa Server
34+ return id (s) * " /" * dataset (x)
35+ else
36+ return s * " /info?id=" * dataset (x)
37+ end
38+ end
3239Base. propertynames (x:: HAPIVariables ) = propertynames (parent (x))
3340Base. getproperty (x:: HAPIVariables , s:: Symbol ) = getproperty (parent (x), s)
3441Base. length (x:: HAPIVariables ) = length (parent (x))
@@ -38,12 +45,13 @@ Base.getindex(x::HAPIVariables, i) = getindex(parent(x), i)
3845Base. show (io:: IO , x:: HAPIVariables ) = show (io, parent (x))
3946function Base. show (io:: IO , m:: MIME"text/plain" , var:: HAPIVariables )
4047 print (io, " HAPIVariables: " )
41- printstyled (io, id (var), color= 209 )
48+ printstyled (io, id (var), color = 209 )
49+ print (io, " (" , getfield (var, :uri ), " )" )
4250 foreach (var) do v
4351 print (io, " \n " )
4452 show (io, v)
4553 end
46- if (mt = meta (var)) != = nothing
54+ return if (mt = meta (var)) != = nothing
4755 print (io, " \n Metadata - " )
4856 show (io, m, mt)
4957 end
96104
97105Construct a `HAPIVariable` object from a JSON-parsed Dict `d` (containing parameters) at index `i`.
98106"""
99- function HAPIVariable (d:: Dict , i:: Integer )
107+ function HAPIVariable (d:: AbstractDict , i:: Integer )
100108 data = d[" data" ]
101109 param = d[" parameters" ][i + 1 ]
102110 time = @. DateTime (getindex (data, 1 ), DEFAULT_DATE_FORMAT)
103111 values = getindex .(data, i + 1 )
104112 return HAPIVariable (values, time, param)
105113end
106114
107- HAPIVariable (d:: Dict , meta, i:: Integer ) = HAPIVariable (d, i)
115+ HAPIVariable (d:: AbstractDict , meta, i:: Integer ) = HAPIVariable (d, i)
108116
109117columns (var:: HAPIVariable ) = meta (var)[" columns" ]
110118colsize (var:: HAPIVariable ) = colsize (meta (var))
0 commit comments