Skip to content

Commit b19b663

Browse files
committed
Some improvements
1 parent 3f9af8b commit b19b663

File tree

13 files changed

+188
-154
lines changed

13 files changed

+188
-154
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ in order that no plot package needs to be loaded during the tests:
126126

127127
## Installation
128128

129-
The packages are not yet registered. Once this is done, installation is performed with
130-
131129
```julia
132130
julia> ]add SignalTables
133131
add SignalTablesInterface_PyPlot # if plotting with PyPlot desired
132+
133+
# once registered
134134
add SignalTablesInterface_GLMakie # if plotting with GLMakie desired
135135
add SignalTablesInterface_WGLMakie # if plotting with WGLMakie desired
136136
add SignalTablesInterface_CairoMakie # if plotting with CairoMakie desired

docs/src/Functions/OverviewOfFunctions.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ Note, *FileIO* functions (e.g. JSON, HDF5) can be directly used, see [FileIO Exa
3535
| [`unitAsParseableString`](@ref) | Returns the unit as a String that can be parsed with `Unitful.uparse`, e.g. "m*s^-1" |
3636

3737

38-
| Signal table functions | Description |
39-
|:---------------------------------|:-----------------------------------------------------------------------------------------------|
40-
| [`SignalTable`](@ref) | Returns a new SignalTable dictionary. |
41-
| [`showInfo`](@ref) | Writes info about a signal table to the output stream. |
42-
| [`independentSignalNames`](@ref) | Returns the names of the independent signals. |
43-
| [`signalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
44-
| [`hasSignal`](@ref) | Returns `true` if a signal is present in a signal table. |
45-
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref). |
46-
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value keys. |
47-
| [`getIndependentSignalsSize`](@ref)| Returns the lengths of the independent signals as Dims. |
48-
| [`getValues`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table. |
49-
| [`getValuesWithUnit`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table including its unit. |
50-
| [`getValue`](@ref) | Returns the *value* of a [`Par`](@ref) signal from a signal table. |
51-
| [`getValueWithUnit`](@ref) | Returns the *value* of a [`Par`](@ref) signal from a signal table including its unit. |
52-
| [`getFlattenedSignal`](@ref) | Returns a copy of a signal where the values or the value are *flattened* and converted for use in plots or traditional tables. |
53-
| [`getDefaultHeading`](@ref) | Returns the default heading for a plot. |
54-
| [`signalTableToJSON`](@ref) | Returns a JSON string representation of a [`SignalTable`](@ref) instance |
55-
| [`writeSignalTable`](@ref) | Write a [`SignalTable`](@ref) instance in JSON format on file. |
56-
| [`toSignalTable`](@ref) | Returns a signalTable as instance of [`SignalTable`](@ref). |
57-
| [`signalTableToDataFrame`](@ref) | Returns a signal table as [DataFrame](https://github.com/JuliaData/DataFrames.jl) object. |
38+
| Signal table functions | Description |
39+
|:------------------------------------|:-----------------------------------------------------------------------------------------------|
40+
| [`SignalTable`](@ref) | Returns a new SignalTable dictionary. |
41+
| [`showInfo`](@ref) | Writes info about a signal table to the output stream. |
42+
| [`getIndependentSignalNames`](@ref) | Returns the names of the independent signals. |
43+
| [`getSignalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
44+
| [`hasSignal`](@ref) | Returns `true` if a signal is present in a signal table. |
45+
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref). |
46+
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value keys. |
47+
| [`getIndependentSignalsSize`](@ref) | Returns the lengths of the independent signals as Dims. |
48+
| [`getValues`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table. |
49+
| [`getValuesWithUnit`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table including its unit. |
50+
| [`getValue`](@ref) | Returns the *value* of a [`Par`](@ref) signal from a signal table. |
51+
| [`getValueWithUnit`](@ref) | Returns the *value* of a [`Par`](@ref) signal from a signal table including its unit. |
52+
| [`getFlattenedSignal`](@ref) | Returns a copy of a signal where the values or the value are *flattened* and converted for use in plots or traditional tables. |
53+
| [`getDefaultHeading`](@ref) | Returns the default heading for a plot. |
54+
| [`signalTableToJSON`](@ref) | Returns a JSON string representation of a signal table. |
55+
| [`writeSignalTable`](@ref) | Write a signal table in JSON format on file. |
56+
| [`toSignalTable`](@ref) | Returns a signal table as [`SignalTable`](@ref) object. |
57+
| [`signalTableToDataFrame`](@ref) | Returns a signal table as [DataFrame](https://github.com/JuliaData/DataFrames.jl) object. |
5858

5959

6060
| Plot package functions | Description |

docs/src/Functions/SignalTables.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ The functions below operate on a *signal table* that implements the [Abstract Si
1515
| [`new_signal_table`](@ref) | Returns a new signal table dictionary (= OrderedDict{String,Any}("_class" => :SignalTable)). |
1616
| [`SignalTable`](@ref) | Returns a new instance of type SignalTable. |
1717
| [`showInfo`](@ref) | Writes info about a signal table to the output stream. |
18-
| [`independentSignalNames`](@ref) | Returns the names of the independent signals. |
19-
| [`signalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
18+
| [`getIndependentSignalNames`](@ref)| Returns the names of the independent signals. |
19+
| [`getSignalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
2020
| [`hasSignal`](@ref) | Returns `true` if a signal is present in a signal table. |
2121
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref). |
2222
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value keys. |
@@ -27,18 +27,18 @@ The functions below operate on a *signal table* that implements the [Abstract Si
2727
| [`getValueWithUnit`](@ref) | Returns the *value* of a [`Par`](@ref) signal from a signal table including its unit. |
2828
| [`getFlattenedSignal`](@ref) | Returns a copy of a signal where the values or the value are *flattened* and converted for use in plots or traditional tables. |
2929
| [`getDefaultHeading`](@ref) | Returns the default heading for a plot. |
30-
| [`signalTableToJSON`](@ref) | Returns a JSON string representation of a [`SignalTable`](@ref) instance |
31-
| [`writeSignalTable`](@ref) | Write a [`SignalTable`](@ref) instance in JSON format on file. |
32-
| [`toSignalTable`](@ref) | Returns a signalTable as instance of [`SignalTable`](@ref). |
30+
| [`signalTableToJSON`](@ref) | Returns a JSON string representation of a signal table. |
31+
| [`writeSignalTable`](@ref) | Write a signal table in JSON format on file. |
32+
| [`toSignalTable`](@ref) | Returns a signal table as instance of [`SignalTable`](@ref). |
3333
| [`signalTableToDataFrame`](@ref) | Returns a signal table as [DataFrame](https://github.com/JuliaData/DataFrames.jl) object. |
3434

3535

3636
```@docs
3737
new_signal_table
3838
SignalTable
3939
showInfo
40-
independentSignalNames
41-
signalNames
40+
getIndependentSignalNames
41+
getSignalNames
4242
hasSignal
4343
getSignal
4444
getSignalInfo

docs/src/Internal/AbstractSignalTableInterface.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Functions that are marked as *optional* have a default implementation.
2424

2525
| Abstract functions | Description |
2626
|:-----------------------------------|:----------------------------------------------------------------------------------------|
27-
| [`independentSignalNames`](@ref) | Returns a string vector of the names of the independent signals (*required*). |
28-
| [`signalNames`](@ref) | Returns a string vector of the signal names from a signal table (*required*). |
27+
| [`getIndependentSignalNames`](@ref) | Returns a string vector of the names of the independent signals (*required*). |
28+
| [`getSignalNames`](@ref) | Returns a string vector of the signal names from a signal table (*required*). |
2929
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref) (*required*). |
3030
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value key (*optional*). |
3131
| [`getIndependentSignalsSize`](@ref)| Returns the lengths of the independent signals as Dims. (*optional*). |

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ in order that no plot package needs to be loaded during the tests:
126126

127127
## Installation
128128

129-
The packages are not yet registered. Once this is done, installation is performed with
130-
131129
```julia
132130
julia> ]add SignalTables
133131
add SignalTablesInterface_PyPlot # if plotting with PyPlot desired
132+
133+
# once registered
134134
add SignalTablesInterface_GLMakie # if plotting with GLMakie desired
135135
add SignalTablesInterface_WGLMakie # if plotting with WGLMakie desired
136136
add SignalTablesInterface_CairoMakie # if plotting with CairoMakie desired

src/AbstractSignalTableInterface.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ isSignalTable(obj) = Tables.istable(obj) && Tables.columnaccess(obj)
1515

1616

1717
"""
18-
independentSignalNames(signalTable)::Vector{String}
18+
getIndependentSignalNames(signalTable)::Vector{String}
1919
2020
Returns the names of the independent signals (often: ["time"]) from signalTable.
2121
"""
22-
function independentSignalNames(obj)
22+
function getIndependentSignalNames(obj)
2323
if Tables.istable(obj) && Tables.columnaccess(obj)
2424
return [string(Tables.columnnames(obj)[1])]
2525
else
26-
@error "independentSignalNames(obj) is not supported for typeof(obj) = " * string(typeof(obj))
26+
@error "getIndependentSignalNames(obj) is not supported for typeof(obj) = " * string(typeof(obj))
2727
end
2828
end
2929

3030

3131
"""
32-
signalNames(signalTable)::Vector{String}
32+
getSignalNames(signalTable)::Vector{String}
3333
3434
Returns a string vector of the signal names that are present in signalTable
3535
(including independent signal names).
3636
"""
37-
function signalNames(obj)
37+
function getSignalNames(obj)
3838
if Tables.istable(obj) && Tables.columnaccess(obj)
3939
return string.(Tables.columnnames(obj))
4040
else
41-
@error "signalNames(obj) is not supported for typeof(obj) = " * string(typeof(obj))
41+
@error "getSignalNames(obj) is not supported for typeof(obj) = " * string(typeof(obj))
4242
end
4343
end
4444

@@ -142,7 +142,7 @@ or for two independent signals of length 5 and 7 return (5,7).
142142
"""
143143
function getIndependentSignalsSize(signalTable)::Dims
144144
sigLength = Int[]
145-
for name in independentSignalNames(signalTable)
145+
for name in getIndependentSignalNames(signalTable)
146146
sigSize = getSignalInfo(signalTable,name)[:_size]
147147
if length(sigSize) != 1
148148
error("Independent signal $name has not one dimension but has size = $sigSize")

src/SignalTable.jl

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ end
203203

204204
# Implementation of AbstractSignalTableInterface
205205
isSignalTable(sigTable::SignalTable) = true
206-
independentSignalNames( sigTable::SignalTable) = sigTable.independendentSignalNames
206+
getIndependentSignalNames( sigTable::SignalTable) = sigTable.independendentSignalNames
207207
getIndependentSignalsSize(sigTable::SignalTable) = sigTable.independentSignalsSize
208-
signalNames( sigTable::SignalTable) = setdiff(String.(keys(sigTable)), ["_class"])
208+
getSignalNames( sigTable::SignalTable) = setdiff(String.(keys(sigTable)), ["_class"])
209209
getSignal( sigTable::SignalTable, name::String) = sigTable[name]
210210
hasSignal( sigTable::SignalTable, name::String) = haskey(sigTable, name)
211211

@@ -220,108 +220,6 @@ function getDefaultHeading(sigTable::SignalTable)::String
220220
end
221221

222222

223-
224-
225-
#
226-
# Encoding and decoding Modia signalTables as JSON.
227-
#
228-
# Based on Modia/src/JSONModel.jl developed by Hilding Elmqvist
229-
# License: MIT (expat)
230-
231-
export signalTableToJSON, writeSignalTable
232-
233-
import JSON
234-
235-
const TypesWithoutEncoding = Set(["Float64", "Int64", "Bool", "String", "Symbol"])
236-
237-
appendNames(name1, name2) = name1 == "" ? name2 : name1 * "." * string(name2)
238-
239-
"""
240-
jsigDict = encodeSignalTable(name, element)
241-
242-
Encodes a SignalTable suitable to convert to a JSON string.
243-
"""
244-
function encodeSignalTable(name, element)
245-
if typeof(element) <: SignalTable
246-
jdict = OrderedDict{String,Any}("_class" => "SignalTable")
247-
for (key,val) in element
248-
jdict[key] = encodeSignalTable(appendNames(name,key),val)
249-
end
250-
return jdict
251-
252-
elseif isVar(element)
253-
jdict = OrderedDict{String,Any}("_class" => "Var")
254-
for (key,val) in element
255-
if key != :Var
256-
jdict[string(key)] = encodeSignalTable(appendNames(name,key),val)
257-
end
258-
end
259-
return jdict
260-
261-
elseif isPar(element)
262-
jdict = OrderedDict{String,Any}("_class" => "Par")
263-
for (key,val) in element
264-
if key != :Par
265-
jdict[string(key)] = encodeSignalTable(appendNames(name,key),val)
266-
end
267-
end
268-
return jdict
269-
270-
elseif typeof(element) <: AbstractArray && (elementBaseType(eltype(element)) <: Number || elementBaseType(eltype(element)) <: String)
271-
if ndims(element) == 1 && string(elementBaseType(eltype(element))) in TypesWithoutEncoding
272-
return element
273-
end
274-
jdict = OrderedDict{String,Any}("_class" => "Array",
275-
"eltype" => string(eltype(element)),
276-
"size" => Int[i for i in size(element)],
277-
"values" => reshape(element, length(element)))
278-
return jdict
279-
280-
elseif string(typeof(element)) in TypesWithoutEncoding
281-
return element
282-
283-
elseif typeof(element) <: Number
284-
jdict = OrderedDict{String,Any}("_class" => "Number",
285-
"type" => typeof(element),
286-
"value" => element)
287-
288-
else
289-
@info "$name::$(typeof(element)) is ignored, because mapping to JSON not known"
290-
return nothing
291-
end
292-
end
293-
294-
295-
"""
296-
json = signalTableToJSON(signalTable)
297-
298-
Returns a JSON string representation of signalTable
299-
"""
300-
function signalTableToJSON(signalTable)::String
301-
jsignalTable = encodeSignalTable("", signalTable)
302-
return JSON.json(jsignalTable)
303-
end
304-
305-
306-
"""
307-
writeSignalTable(filename::String, signalTable; indent=2, log=true)
308-
309-
Write signalTable in JSON format on file `filename`.
310-
"""
311-
function writeSignalTable(filename::String, signalTable::AbstractDict; indent=nothing, log=false)::Nothing
312-
file = joinpath(pwd(), filename)
313-
if log
314-
println(" Write signalTable in JSON format on file \"$file\"")
315-
end
316-
jsignalTable = encodeSignalTable("", signalTable)
317-
open(file, "w") do io
318-
JSON.print(io, jsignalTable, indent)
319-
end
320-
return nothing
321-
end
322-
323-
324-
325223
"""
326224
toSignalTable(signalTable)::SignalTable
327225
@@ -332,7 +230,7 @@ function toSignalTable(sigTable)::SignalTable
332230
error("toSignalTable(obj): obj::$(typeof(sigTable)) is no signal table.")
333231
end
334232
sigTable2 = SignalTable()
335-
for name in signalNames(sigTable)
233+
for name in getSignalNames(sigTable)
336234
sigTable2[name] = getSignal(sigTable,name)
337235
end
338236
return sigTable2

0 commit comments

Comments
 (0)