InterpolationFileTest
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
InterpolationFileTest()
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
dataset | Dataset configuration specifying the CSV file path and variable mappings | – | DyadDataset("data/interp_square_data.csv", dependent_vars=["data"], independent_var="ts") |
Variables
Name | Description | Units |
---|---|---|
y | Output variable that holds the interpolated value | – |
Behavior
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 InterpolationFileTest
# Interpolation object that performs the actual interpolation calculation
interp = Interpolation(interpolation_type=LinearInterpolation, dataset=dataset)
# Dataset configuration specifying the CSV file path and variable mappings
structural parameter dataset::DyadDataset = DyadDataset("data/interp_square_data.csv", dependent_vars=["data"], independent_var="ts")
# Output variable that holds the interpolated value
variable y::Real
relations
interp.u = time
interp.y = y
metadata {"Dyad": {"tests": {"case1": {"stop": 0.1, "expect": {"signals": ["y"]}}}}}
end
Flattened 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 InterpolationFileTest
# Interpolation object that performs the actual interpolation calculation
interp = Interpolation(interpolation_type=LinearInterpolation, dataset=dataset)
# Dataset configuration specifying the CSV file path and variable mappings
structural parameter dataset::DyadDataset = DyadDataset("data/interp_square_data.csv", dependent_vars=["data"], independent_var="ts")
# Output variable that holds the interpolated value
variable y::Real
relations
interp.u = time
interp.y = y
metadata {"Dyad": {"tests": {"case1": {"stop": 0.1, "expect": {"signals": ["y"]}}}}}
end
Test Cases
This is setup code, that must be run before each test case.
julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
Test Case case1
julia
@mtkbuild model_case1 = InterpolationFileTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 0.1))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 1st order linear
t: 2-element Vector{Float64}:
0.0
0.1
u: 2-element Vector{Vector{Float64}}:
[]
[]
julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.y])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "InterpolationFileTest_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
plt
Related
Examples
Experiments
Analyses
Tests