ScalarInterpolationFileTest ​
Tests time-based interpolation using data from a CSV file.
This component reads data from a specified CSV file and performs linear interpolation, using the current simulation time as the input. The interpolated value is made available through the output variable y. The component utilizes a dataset structure that identifies dependent and independent variables from the CSV file, allowing for flexible time-series data interpolation.
Usage ​
BlockComponents.ScalarInterpolationFileTest()
Parameters: ​
| Name | Description | Units | Default value |
|---|---|---|---|
filepath | Dataset configuration specifying the CSV file path and variable mappings | – | "dyad://BlockComponents/data/interp_square_data.csv" |
independent_var | – | "ts" | |
dependent_var | – | "data" |
Variables ​
| Name | Description | Units |
|---|---|---|
y | Output variable that holds the interpolated value | – |
Behavior ​
Behavior of this component cannot be rendered because it includes path variables.
Source ​
dyad
"""
Tests time-based interpolation using data from a CSV file.
This component reads data from a specified CSV file and performs linear interpolation, using the
current simulation time as the input. The interpolated value is made available through the output
variable `y`. The component utilizes a dataset structure that identifies dependent and independent
variables from the CSV file, allowing for flexible time-series data interpolation.
"""
test component ScalarInterpolationFileTest
"Interpolation object that performs the actual interpolation calculation"
interp = ScalarInterpolation(interpolation_type = "LinearInterpolation", filepath = filepath, independent_var = independent_var, dependent_var = dependent_var) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 100, "x2": 260, "y2": 200, "rot": 0}
}
}
}
"Dataset configuration specifying the CSV file path and variable mappings"
structural parameter filepath::String = "dyad://BlockComponents/data/interp_square_data.csv"
structural parameter independent_var::String = "ts"
structural parameter dependent_var::String = "data"
"Output variable that holds the interpolated value"
variable y::Real
relations
interp.u = time
interp.y = y
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 0.1, "expect": {"signals": ["y"]}}},
"doc": {"behavior": false}
}
}
endFlattened Source
dyad
"""
Tests time-based interpolation using data from a CSV file.
This component reads data from a specified CSV file and performs linear interpolation, using the
current simulation time as the input. The interpolated value is made available through the output
variable `y`. The component utilizes a dataset structure that identifies dependent and independent
variables from the CSV file, allowing for flexible time-series data interpolation.
"""
test component ScalarInterpolationFileTest
"Interpolation object that performs the actual interpolation calculation"
interp = ScalarInterpolation(interpolation_type = "LinearInterpolation", filepath = filepath, independent_var = independent_var, dependent_var = dependent_var) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 100, "x2": 260, "y2": 200, "rot": 0}
}
}
}
"Dataset configuration specifying the CSV file path and variable mappings"
structural parameter filepath::String = "dyad://BlockComponents/data/interp_square_data.csv"
structural parameter independent_var::String = "ts"
structural parameter dependent_var::String = "data"
"Output variable that holds the interpolated value"
variable y::Real
relations
interp.u = time
interp.y = y
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 0.1, "expect": {"signals": ["y"]}}},
"doc": {"behavior": false}
}
}
endTest Cases ​
julia
using BlockComponents
using DyadInterface: TransientAnalysis, rebuild_sol
using ModelingToolkit: toggle_namespacing, get_defaults, @named
using CSV, DataFrames, Plots
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")<< @setup-block not executed in draft mode >>Test Case case1 ​
julia
@named model_case1 = ScalarInterpolationFileTest()
model_case1 = toggle_namespacing(model_case1, false)
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = "auto", start = 0e+0, stop = 1e-1, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.y])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "ScalarInterpolationFileTest_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.y], width=2, label="Actual value of y")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of y")
end<< @setup-block not executed in draft mode >>julia
plt<< @example-block not executed in draft mode >>Related ​
Examples
Experiments
Analyses
Tests