Skip to content

Commit

Permalink
Merge pull request #5 from ModiaSim/Branch_v0.4.0
Browse files Browse the repository at this point in the history
Branch v0.4.0
  • Loading branch information
MartinOtter authored Aug 4, 2022
2 parents ebd63e6 + 758bc1f commit 73b3205
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SignalTables"
uuid = "3201582d-3078-4276-ba5d-0a1254d79d7c"
authors = ["[email protected] <[email protected]>"]
version = "0.3.5"
version = "0.4.0"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

Package [SignalTables](https://github.com/ModiaSim/SignalTables.jl) (see [docu](https://modiasim.github.io/SignalTables.jl/stable/index.html))
provides abstract and concrete types and functions for *signal tables*.
A *signal table* is basically a table where the table columns can be multi-dimensional arrays with attributes.
Typically, simulation results, reference signals, table-based input signals, measurement data,
look-up tables can be represented by a signal table.

A *signal table* is an *ordered dictionary* of *signals* with string keys that supports the
[Abstract Signal Table Interface](https://modiasim.github.io/SignalTables.jl/stable/Internal/AbstractSignalTableInterface.html).
A *signal* can be defined in two forms:
A *signal table* is an *ordered dictionary* of *signals* with string keys. A *signal* can be defined in the following forms:

- As [Var](https://modiasim.github.io/SignalTables.jl/stable/Functions/Signals.html#SignalTables.Var) *dictionary* that has a required *values* key representing a *signal array* of any element type as function of the independent signal(s) (or is the k-th independent signal). A *signal array* is a *multi-dimensional array* with indices `[i1,i2,...,j1,j2,...]` to hold variable elements `[j1,j2,...]` at the `[i1,i2,...]` independent signal(s). If an element of a signal array is *not defined*, it has a value of *missing*.
- As [Par](https://modiasim.github.io/SignalTables.jl/stable/Functions/Signals.html#SignalTables.Par) *dictionary* that has an optional *value* key representing a constant of any type.
- As [Var](https://modiasim.github.io/SignalTables.jl/stable/Functions/Signals.html#SignalTables.Var) *dictionary* that has a required *values* key
(or an *alias* key) representing a *signal array* of any element type as function of the independent signal(s) (or is the k-th independent signal). A *signal array* is a *multi-dimensional array* with indices `[i1,i2,...,j1,j2,...]` to hold variable elements `[j1,j2,...]` at the `[i1,i2,...]` independent signal(s). If an element of a signal array is *not defined*, it has a value of *missing*.
- As [Par](https://modiasim.github.io/SignalTables.jl/stable/Functions/Signals.html#SignalTables.Par) *dictionary* that has a required *value* key (or and *alias* key) representing a constant of any type.
- As [Map](https://modiasim.github.io/SignalTables.jl/stable/Functions/Signals.html#SignalTables.Map) *dictionary* that has no required keys and collects attributes/meta-data that are associated with a Var, Par, Map, or signal table dictionary.

In both dictionaries, additional attributes can be stored, for example *unit*, *info*, *variability* (continuous, clocked, ...), *alias*, *interpolation*,
In all these dictionaries, additional attributes can be stored, for example *unit*, *info*, *variability* (continuous, clocked, ...), *interpolation*,
*extrapolation*, and user-defined attributes.

This logical view is directly mapped to Julia data structures, but can be also mapped to data structures in other
Expand All @@ -33,19 +34,18 @@ t = 0.0:0.1:0.5
sigTable = SignalTable(
"time" => Var(values= t, unit="s", independent=true),
"load.r" => Var(values= [sin.(t) cos.(t) sin.(t)], unit="m"),
"motor.angle" => Var(values= sin.(t), unit="rad", state=true),
"motor.w" => Var(values= cos.(t), unit="rad/s", integral="motor.angle"),
"motor.angle" => Var(values= sin.(t), unit="rad", state=true, der="motor.w"),
"motor.w" => Var(values= cos.(t), unit="rad/s"),
"motor.w_ref" => Var(values= 0.9*[sin.(t) cos.(t)], unit = ["rad", "1/s"],
info="Reference angle and speed"),
"wm" => Var(alias = "motor.w"),
"ref.clock" => Var(values= [true, missing, missing, true, missing, missing],
variability="clock"),
"motor.w_c" => Var(values= [0.8, missing, missing, 1.5, missing, missing],
variability="clocked", clock="ref.clock"),

"motor.inertia"=> Par(value = 0.02f0, unit="kg*m/s^2"),
"motor.data" => Par(value = "resources/motorMap.json"),
"attributes" => Par(info = "This is a test signal table")
"attributes" => Map(experiment=Map(stoptime=0.5, interval=0.01))
)

phi_m_sig = getSignal( sigTable, "motor.angle") # = Var(values=..., unit=..., ...)
Expand All @@ -62,17 +62,17 @@ Command `showInfo` generates the following output:
```julia
name unit size eltypeOrType kind attributes
───────────────────────────────────────────────────────────────────────────────────────────────────────
time "s" (6,) Float64 Var independent=true
load.r "m" (6,3) Float64 Var
motor.angle "rad" (6,) Float64 Var state=true, der="motor.w"
motor.w "rad/s" (6,) Float64 Var
motor.w_ref ["rad", "1/s"] (6,2) Float64 Var info="Reference angle and speed"
wm "rad/s" (6,) Float64 Var alias="motor.w"
ref.clock (6,) Union{Missing,Bool} Var variability="clock"
motor.w_c (6,) Union{Missing,Float64} Var variability="clocked", clock="ref.clock"
motor.inertia "kg*m/s^2" () Float32 Par
motor.data String Par
attributes Par info="This is a test signal table"
time "s" [6] Float64 Var independent=true
load.r "m" [6,3] Float64 Var
motor.angle "rad" [6] Float64 Var state=true, der="motor.w"
motor.w "rad/s" [6] Float64 Var
motor.w_ref ["rad", "1/s"] [6,2] Float64 Var info="Reference angle and speed"
wm "rad/s" [6] Float64 Var alias="motor.w"
ref.clock [6] Union{Missing,Bool} Var variability="clock"
motor.w_c [6] Union{Missing,Float64} Var variability="clocked", clock="ref.clock"
motor.inertia "kg*m/s^2" Float32 Par
motor.data String Par
attributes Map experiment=Map(stoptime=0.5, interval=0.01)
```

The various Julia FileIO functions can be directly used to save a signal table
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/examples/fileIO/VariousTypes_compact.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_class":"SignalTable","_classVersion":"0.3.5","time":{"_class":"Var","values":[0.0,0.1,0.2,0.3,0.4,0.5],"unit":"s","independent":true},"load.r":{"_class":"Var","values":{"_class":"Array","eltype":"Float64","size":[6,3],"layout":"column-major","values":[0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203,1.0,0.9950041652780258,0.9800665778412416,0.955336489125606,0.9210609940028851,0.8775825618903728,0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203]},"unit":"m"},"motor.angle":{"_class":"Var","values":[0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203],"unit":"rad","state":true,"der":"motor.w"},"motor.w":{"_class":"Var","values":[1.0,0.9950041652780258,0.9800665778412416,0.955336489125606,0.9210609940028851,0.8775825618903728],"unit":"rad/s","state":true,"start":{"_class":"Number","unit":"rad*s^-1","type":"Float64","value":1.0}},"motor.w_ref":{"_class":"Var","values":{"_class":"Array","eltype":"Float64","size":[6,2],"layout":"column-major","values":[0.0,0.08985007498214534,0.1788023977155551,0.2659681859952056,0.35047650807778546,0.4314829847437827,0.9,0.8955037487502232,0.8820599200571175,0.8598028402130454,0.8289548946025966,0.7898243057013355]},"unit":["rad","1/s"],"info":"Reference angle and speed"},"wm":{"_class":"Var","unit":"rad/s","state":true,"start":{"_class":"Number","unit":"rad*s^-1","type":"Float64","value":1.0},"alias":"motor.w"},"ref.clock":{"_class":"Var","values":{"_class":"Array","eltype":"Union{Missing, Bool}","size":[6],"layout":"column-major","values":[true,null,null,true,null,null]},"variability":"clock"},"motor.w_c":{"_class":"Var","values":{"_class":"Array","eltype":"Union{Missing, Float64}","size":[6],"layout":"column-major","values":[0.6,null,null,0.8,null,null]},"variability":"clocked","clock":"ref.clock"},"motor.inertia":{"_class":"Par","value":{"_class":"Number","type":"Float32","value":0.02},"unit":"kg*m/s^2"},"motor.data":{"_class":"Par","value":"resources/motorMap.json"},"attributes":{"_class":"Par","info":"This is a test signal table"}}
{"_class":"SignalTable","_classVersion":"0.3.6","time":{"_class":"Var","values":[0.0,0.1,0.2,0.3,0.4,0.5],"unit":"s","independent":true},"load.r":{"_class":"Var","values":{"_class":"Array","eltype":"Float64","size":[6,3],"layout":"column-major","values":[0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203,1.0,0.9950041652780258,0.9800665778412416,0.955336489125606,0.9210609940028851,0.8775825618903728,0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203]},"unit":"m"},"motor.angle":{"_class":"Var","values":[0.0,0.09983341664682815,0.19866933079506122,0.29552020666133955,0.3894183423086505,0.479425538604203],"unit":"rad","state":true,"der":"motor.w"},"motor.w":{"_class":"Var","values":[1.0,0.9950041652780258,0.9800665778412416,0.955336489125606,0.9210609940028851,0.8775825618903728],"unit":"rad/s","state":true,"start":{"_class":"Number","unit":"rad*s^-1","type":"Float64","value":1.0}},"motor.w_ref":{"_class":"Var","values":{"_class":"Array","eltype":"Float64","size":[6,2],"layout":"column-major","values":[0.0,0.08985007498214534,0.1788023977155551,0.2659681859952056,0.35047650807778546,0.4314829847437827,0.9,0.8955037487502232,0.8820599200571175,0.8598028402130454,0.8289548946025966,0.7898243057013355]},"unit":["rad","1/s"],"info":"Reference angle and speed"},"wm":{"_class":"Var","unit":"rad/s","state":true,"start":{"_class":"Number","unit":"rad*s^-1","type":"Float64","value":1.0},"alias":"motor.w"},"ref.clock":{"_class":"Var","values":{"_class":"Array","eltype":"Union{Missing, Bool}","size":[6],"layout":"column-major","values":[true,null,null,true,null,null]},"variability":"clock"},"motor.w_c":{"_class":"Var","values":{"_class":"Array","eltype":"Union{Missing, Float64}","size":[6],"layout":"column-major","values":[0.6,null,null,0.8,null,null]},"variability":"clocked","clock":"ref.clock"},"motor.inertia":{"_class":"Par","value":{"_class":"Number","type":"Float32","value":0.02},"unit":"kg*m/s^2"},"motor.data":{"_class":"Par","value":"resources/motorMap.json"},"attributes":{"_class":"Map","experiment":{"_class":"Map","stoptime":0.5,"interval":0.01}}}
10 changes: 7 additions & 3 deletions docs/resources/examples/fileIO/VariousTypes_prettyPrint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_class": "SignalTable",
"_classVersion": "0.3.5",
"_classVersion": "0.3.6",
"time": {
"_class": "Var",
"values": [
Expand Down Expand Up @@ -178,7 +178,11 @@
"value": "resources/motorMap.json"
},
"attributes": {
"_class": "Par",
"info": "This is a test signal table"
"_class": "Map",
"experiment": {
"_class": "Map",
"stoptime": 0.5,
"interval": 0.01
}
}
}
7 changes: 4 additions & 3 deletions docs/src/Functions/OverviewOfFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Note, *FileIO* functions (e.g. JSON, HDF5) can be directly used, see [FileIO Exa
| [`Par`](@ref) | Returns a parameter signal definition in form of a dictionary. |
| [`isVar`](@ref) | Returns true, if signal is a [`Var`](@ref). |
| [`isPar`](@ref) | Returns true, if signal is a [`Par`](@ref). |
| [`isSignal`](@ref) | Returns true, if signal is a [`Var`](@ref) or a [`Par`](@ref). |
| [`showSignal`](@ref) | Prints a [`Var`](@ref)(...) or [`Par`](@ref)(...) signal to io. |
| [`isMap`](@ref) | Returns true, if signal is a [`Map`](@ref). |
| [`isSignal`](@ref) | Returns true, if signal is a [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref). |
| [`showSignal`](@ref) | Prints a [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref) signal to io. |
| [`eltypeOrType`](@ref) | Returns eltype(..) of AbstractArray or otherwise typeof(..). |
| [`quantity`](@ref) | Returns `Unitful.Quantity` from numberType and numberUnit, e.g. `quantity(Float64,u"m/s")` |
| [`unitAsParseableString`](@ref) | Returns the unit as a String that can be parsed with `Unitful.uparse`, e.g. "m*s^-1" |
Expand All @@ -42,7 +43,7 @@ Note, *FileIO* functions (e.g. JSON, HDF5) can be directly used, see [FileIO Exa
| [`getIndependentSignalNames`](@ref) | Returns the names of the independent signals. |
| [`getSignalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
| [`hasSignal`](@ref) | Returns `true` if a signal is present in a signal table. |
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref). |
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref). |
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value keys. |
| [`getIndependentSignalsSize`](@ref) | Returns the lengths of the independent signals as Dims. |
| [`getValues`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table. |
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Functions/SignalTables.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The functions below operate on a *signal table* that implements the [Abstract Si
| [`getIndependentSignalNames`](@ref)| Returns the names of the independent signals. |
| [`getSignalNames`](@ref) | Returns a string vector of the signal names that are present in a signal table. |
| [`hasSignal`](@ref) | Returns `true` if a signal is present in a signal table. |
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref) or as [`Par`](@ref). |
| [`getSignal`](@ref) | Returns signal from a signal table as [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref). |
| [`getSignalInfo`](@ref) | Returns signal with :\_typeof, :\_size keys instead of :values/:value keys. |
| [`getIndependentSignalsSize`](@ref)| Returns the lengths of the independent signals as Dims. |
| [`getValues`](@ref) | Returns the *values* of a [`Var`](@ref) signal from a signal table. |
Expand Down
10 changes: 7 additions & 3 deletions docs/src/Functions/Signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ The functions below operate on *signals*.
|:--------------------------------|:-------------------------------------------------------------------------------------------|
| [`Var`](@ref) | Returns a variable signal definition in form of a dictionary. |
| [`Par`](@ref) | Returns a parameter signal definition in form of a dictionary. |
| [`Map`](@ref) | Returns an attribute signal definition in form of a dictionary. |
| [`isVar`](@ref) | Returns true, if signal is a [`Var`](@ref). |
| [`isPar`](@ref) | Returns true, if signal is a [`Par`](@ref). |
| [`isSignal`](@ref) | Returns true, if signal is a [`Var`](@ref) or a [`Par`](@ref). |
| [`showSignal`](@ref) | Prints a [`Var`](@ref)(...) or [`Par`](@ref)(...) signal to io. |
| [`eltypeOrType`](@ref) | Returns eltype of an array (but without Missing) and otherwise returns typeof. | |
| [`isMap`](@ref) | Returns true, if signal is a [`Map`](@ref). |
| [`isSignal`](@ref) | Returns true, if signal is a [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref). |
| [`showSignal`](@ref) | Prints a [`Var`](@ref), [`Par`](@ref) or [`Map`](@ref) signal to io. |
| [`eltypeOrType`](@ref) | Returns eltype of an array (but without Missing) and otherwise returns typeof. |
| [`quantity`](@ref) | Returns `Unitful.Quantity` from numberType and numberUnit, e.g. `quantity(Float64,u"m/s")` |
| [`unitAsParseableString`](@ref) | Returns the unit as a String that can be parsed with `Unitful.uparse`, e.g. "m*s^-1" |

```@docs
Var
Par
Map
isVar
isPar
isMap
isSignal
showSignal
eltypeOrType
Expand Down
Loading

0 comments on commit 73b3205

Please sign in to comment.