Skip to content

Commit

Permalink
- adding comment to PlotGain
Browse files Browse the repository at this point in the history
- GainSchedIdentifer now fills out dataset.Y_sim
  • Loading branch information
Steinar Elgsæter committed Oct 2, 2024
1 parent 71b2bd4 commit 8c95fc4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
14 changes: 7 additions & 7 deletions Dynamic/Identification/GainSchedIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ public static GainSchedParameters IdentifyGainsForGivenThresholds(UnitDataSet da
dataSetCopy.IndicesToIgnore = null;
}





// final gain:above the highest threshold
ret.LinearGains = linearGains;
ret.Fitting = new FittingInfo();
Expand All @@ -202,22 +198,26 @@ public static GainSchedParameters IdentifyGainsForGivenThresholds(UnitDataSet da
if(warningNotEnoughExitationBetweenAllThresholds)
ret.AddWarning(GainSchedIdentWarnings.InsufficientExcitationBetweenEachThresholdToBeCertainOfGains);


// simulate the model and determine the optimal bias term:
{
var gsIdentModel = new GainSchedModel(ret, "ident_model");
var identModelSim = new PlantSimulator(new List<ISimulatableModel> { gsIdentModel });

var inputDataIdent = new TimeSeriesDataSet();
inputDataIdent.Add(identModelSim.AddExternalSignal(gsIdentModel, SignalType.External_U, (int)INDEX.FIRST), dataSet.U.GetColumn(0));// todo row 0 is not general
inputDataIdent.CreateTimestamps(dataSet.GetTimeBase());
var isOk = identModelSim.Simulate(inputDataIdent, out TimeSeriesDataSet identModelSimData);

var simY_nobias = identModelSimData.GetValues(gsIdentModel.ID, SignalType.Output_Y);
var measY = dataSet.Y_meas;
var estBias = vec.Mean(vec.Subtract(measY, simY_nobias));
if (estBias.HasValue)
{
ret.Bias = estBias.Value;
dataSet.Y_sim = vec.Add(simY_nobias, ret.Bias);
}
else
{
dataSet.Y_sim = simY_nobias;
}
}
return ret;
}
Expand Down
9 changes: 5 additions & 4 deletions TimeSeriesAnalysis.Tests/Tests/GainSchedIdentifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void GainEstOnly_CorrectGainsReturned(int ver, int expectedNumWarnings)
Assert.IsTrue(gsParams.Fitting.WasAbleToIdentify);
Assert.AreEqual(expectedNumWarnings, gsParams.GetWarningList().Count());


// simulate the gains-scheduled model:(TODO: this shoudl be done automatically )
var gsIdentModel = new GainSchedModel(gsParams, "ident_model");
var inputDataIdent = new TimeSeriesDataSet();
Expand All @@ -131,14 +130,18 @@ public void GainEstOnly_CorrectGainsReturned(int ver, int expectedNumWarnings)
Shared.EnablePlots();
Plot.FromList(new List<double[]> {
dataSet.Y_meas,
identModelSimData.GetValues(gsIdentModel.ID, SignalType.Output_Y),
dataSet.Y_sim, // identModelSimData.GetValues(gsIdentModel.ID, SignalType.Output_Y),
dataSet.U.GetColumn(0) },
new List<string> { "y1=y_meas", "y1=y_ident", "y3=u1" },
timeBase_s,
"GainEstOnly_CorrectGainsReturned");

GainSchedModel gsModel = new GainSchedModel(gsParams,"ident_model");
gsModel.SetOutputID("y_meas");
gsModel.SetInputIDs((new List<string> { "u_1" }).ToArray());
GainSchedModel referenceModel = new GainSchedModel(refParams,"ref_model");
referenceModel.SetInputIDs(gsModel.GetModelInputIDs());
referenceModel.SetOutputID(gsModel.GetOutputID());

PlotGain.Plot(gsModel, referenceModel);
Shared.DisablePlots();
Expand All @@ -148,8 +151,6 @@ public void GainEstOnly_CorrectGainsReturned(int ver, int expectedNumWarnings)
{
DiffLessThan(refParams.LinearGains[i][0], gsParams.LinearGains[i][0], gainTolerancePrc,i);
}


}

private void DiffLessThan(double trueVal, double testVal, double tolerancePrc,int index)
Expand Down
2 changes: 1 addition & 1 deletion TimeSeriesAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RepositoryUrl>https://github.com/equinor/TimeSeriesAnalysis.git</RepositoryUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<Version>1.3.13</Version>
<Version>1.3.14</Version>
<Company>Equinor</Company>
<Authors>Equinor</Authors>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
7 changes: 3 additions & 4 deletions Utility/PlotGain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void Plot(UnitModel model1, UnitModel model2 = null, double[] uMin
/// <param name="model2">optional seond model to be compared in the plots</param>
/// <param name="uMin">optional umin array over which to plot gain plots</param>

Check warning on line 110 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

XML comment has a param tag for 'uMin', but there is no parameter by that name

Check warning on line 110 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

XML comment has a param tag for 'uMin', but there is no parameter by that name

Check warning on line 110 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has a param tag for 'uMin', but there is no parameter by that name

Check warning on line 110 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has a param tag for 'uMin', but there is no parameter by that name
/// <param name="uMax">optional umax aray over which to plot gain plots</param>

Check warning on line 111 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

XML comment has a param tag for 'uMax', but there is no parameter by that name

Check warning on line 111 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

XML comment has a param tag for 'uMax', but there is no parameter by that name

Check warning on line 111 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has a param tag for 'uMax', but there is no parameter by that name

Check warning on line 111 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has a param tag for 'uMax', but there is no parameter by that name
public static void Plot(GainSchedModel model1, GainSchedModel model2 = null)
public static void Plot(GainSchedModel model1, GainSchedModel model2 = null, string comment= null)

Check warning on line 112 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

Parameter 'comment' has no matching param tag in the XML comment for 'PlotGain.Plot(GainSchedModel, GainSchedModel, string)' (but other parameters do)

Check warning on line 112 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Tests

Parameter 'comment' has no matching param tag in the XML comment for 'PlotGain.Plot(GainSchedModel, GainSchedModel, string)' (but other parameters do)

Check warning on line 112 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

Parameter 'comment' has no matching param tag in the XML comment for 'PlotGain.Plot(GainSchedModel, GainSchedModel, string)' (but other parameters do)

Check warning on line 112 in Utility/PlotGain.cs

View workflow job for this annotation

GitHub Actions / Build

Parameter 'comment' has no matching param tag in the XML comment for 'PlotGain.Plot(GainSchedModel, GainSchedModel, string)' (but other parameters do)
{
// TODO: could also plot the uminfit/umaxfit if applicable
//double[] uMinFit = model.modelParameters.FittingSpecs.U_min_fit;
Expand Down Expand Up @@ -147,7 +147,6 @@ public static void Plot(GainSchedModel model1, GainSchedModel model2 = null)
}
tables_m1 = CreateXYTablesFromGainSchedModel(model1, model1Name, inputIdx, uMin, uMax);


/*if (uMin != null && uMax != null)
{
tables_m1 = CreateXYTablesFromModel(model1, model1Name, inputIdx, uMin, uMax);
Expand All @@ -170,7 +169,7 @@ public static void Plot(GainSchedModel model1, GainSchedModel model2 = null)

if (model2 == null)
{
PlotXY.FromTables(tables_m1, outputId + "_" + inputSignalID + "_gains");
PlotXY.FromTables(tables_m1, outputId + "_" + inputSignalID + "_gains", comment);
return;
}
//////////////////////////////////
Expand Down Expand Up @@ -200,7 +199,7 @@ public static void Plot(GainSchedModel model1, GainSchedModel model2 = null)
var plotTables = new List<XYTable>();
plotTables.AddRange(tables_m1);
plotTables.AddRange(tables_m2);
PlotXY.FromTables(plotTables, outputId + "_" + inputSignalID + "_gains");
PlotXY.FromTables(plotTables, outputId + "_" + inputSignalID + "_gains", comment);
}
}

Expand Down
16 changes: 11 additions & 5 deletions Utility/PlotXY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ private static string GetCodeFromType(XYlineType type)
/// <summary>
/// Make an xy-plot from a list of XYTable entries
/// </summary>
/// <param name="tables"></param>
/// <param name="caseName"></param>
/// <param name="comment"></param>
/// <param name="doStartChrome"></param>
/// <param name="tables">List of XYtables containing the data to be plotted</param>
/// <param name="caseName">a unique string that is used to keep the data separate from all other simultanously created plots</param>
/// <param name="comment">a string that is added to the top of the plot (often, a user-friendly name of the output)</param>
/// <param name="doStartChrome">if true then a chrome window will be opened (by default this is true)</param>
/// <returns></returns>
public static string FromTables(List<XYTable> tables, string caseName, string comment = null,
bool doStartChrome = true)
Expand All @@ -83,11 +83,17 @@ public static string FromTables(List<XYTable> tables, string caseName, string co
{
plotURL += "casename:" + caseName;
}
if (comment != null)
{
if (!plotURL.EndsWith(";"))
plotURL += ";";

plotURL += "comment:" + comment;
}
if (doStartChrome)
{
Plot.Start(chromePath, command + plotURL, out bool returnVal);
}

return plotURL;
}

Expand Down

0 comments on commit 8c95fc4

Please sign in to comment.