/// <summary> /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false. /// If the script object exists, the Execute function of this script object is called. /// </summary> /// <param name="myTable">The data table this script is working on.</param> /// <returns>True if executed without exceptions, otherwise false.</returns> /// <remarks>If exceptions were thrown during execution, the exception messages are stored /// inside the column script and can be recalled by the Errors property.</remarks> public bool Execute(Altaxo.Data.DataTable myTable) { if (null == m_ScriptObject) { m_Errors = new string[1] { "Script Object is null" }; return(false); } DataTable clonedTable = (DataTable)myTable.Clone(); clonedTable.DataColumns.RemoveRowsAll(); Altaxo.Collections.AscendingIntegerCollection rowsToCopy = new Altaxo.Collections.AscendingIntegerCollection(); int len = myTable.DataRowCount; try { Altaxo.Calc.ExtractTableValuesExeBase scriptObject = (Altaxo.Calc.ExtractTableValuesExeBase)m_ScriptObject; for (int i = 0; i < len; i++) { if (scriptObject.IsRowIncluded(myTable, i)) { rowsToCopy.Add(i); } } } catch (Exception ex) { m_Errors = new string[1]; m_Errors[0] = ex.ToString(); return(false); } for (int i = myTable.DataColumns.ColumnCount - 1; i >= 0; i--) { for (int j = rowsToCopy.Count - 1; j >= 0; j--) { clonedTable.DataColumns[i][j] = myTable.DataColumns[i][rowsToCopy[j]]; } } Current.Project.DataTableCollection.Add(clonedTable); Current.ProjectService.OpenOrCreateWorksheetForTable(clonedTable); return(true); }
/// <summary> /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false. /// If the script object exists, the Execute function of this script object is called. /// </summary> /// <param name="myTable">The data table this script is working on.</param> /// <returns>True if executed without exceptions, otherwise false.</returns> /// <remarks>If exceptions were thrown during execution, the exception messages are stored /// inside the column script and can be recalled by the Errors property.</remarks> public bool Execute(Altaxo.Data.DataTable myTable) { if (null == _scriptObject) { _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, "Script Object is null")); return(false); } var clonedTable = (DataTable)myTable.Clone(); clonedTable.DataColumns.RemoveRowsAll(); var rowsToCopy = new Altaxo.Collections.AscendingIntegerCollection(); int len = myTable.DataRowCount; try { var scriptObject = (Altaxo.Calc.ExtractTableValuesExeBase)_scriptObject; for (int i = 0; i < len; i++) { if (scriptObject.IsRowIncluded(myTable, i)) { rowsToCopy.Add(i); } } } catch (Exception ex) { _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, ex.ToString())); return(false); } for (int i = myTable.DataColumns.ColumnCount - 1; i >= 0; i--) { for (int j = rowsToCopy.Count - 1; j >= 0; j--) { clonedTable.DataColumns[i][j] = myTable.DataColumns[i][rowsToCopy[j]]; } } Current.Project.DataTableCollection.Add(clonedTable); Current.ProjectService.OpenOrCreateWorksheetForTable(clonedTable); return(true); }
/// <summary> /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false. /// If the script object exists, the Execute function of this script object is called. /// </summary> /// <param name="myTable">The data table this script is working on.</param> /// <returns>True if executed without exceptions, otherwise false.</returns> /// <remarks>If exceptions were thrown during execution, the exception messages are stored /// inside the column script and can be recalled by the Errors property.</remarks> public bool Execute(Altaxo.Data.DataTable myTable) { if (null == _scriptObject) { _errors = new string[1] { "Script Object is null" }; return false; } DataTable clonedTable = (DataTable)myTable.Clone(); clonedTable.DataColumns.RemoveRowsAll(); Altaxo.Collections.AscendingIntegerCollection rowsToCopy = new Altaxo.Collections.AscendingIntegerCollection(); int len = myTable.DataRowCount; try { Altaxo.Calc.ExtractTableValuesExeBase scriptObject = (Altaxo.Calc.ExtractTableValuesExeBase)_scriptObject; for (int i = 0; i < len; i++) { if (scriptObject.IsRowIncluded(myTable, i)) rowsToCopy.Add(i); } } catch (Exception ex) { _errors = new string[1]; _errors[0] = ex.ToString(); return false; } for (int i = myTable.DataColumns.ColumnCount - 1; i >= 0; i--) { for (int j = rowsToCopy.Count - 1; j >= 0; j--) { clonedTable.DataColumns[i][j] = myTable.DataColumns[i][rowsToCopy[j]]; } } Current.Project.DataTableCollection.Add(clonedTable); Current.ProjectService.OpenOrCreateWorksheetForTable(clonedTable); return true; }
/// <summary> /// Exports a table to a PLS2CalibrationSet /// </summary> /// <param name="table">The table where the calibration model is stored.</param> /// <param name="calibrationSet"></param> public static void Export( DataTable table, out PCRCalibrationModel calibrationSet) { int numberOfX = GetNumberOfX(table); int numberOfY = GetNumberOfY(table); int numberOfFactors = GetNumberOfFactors(table); int numberOfMeasurements = GetNumberOfMeasurements(table); calibrationSet = new PCRCalibrationModel(); calibrationSet.NumberOfX = numberOfX; calibrationSet.NumberOfY = numberOfY; calibrationSet.NumberOfFactors = numberOfFactors; MultivariatePreprocessingModel preprocessSet = new MultivariatePreprocessingModel(); MultivariateContentMemento plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo != null) preprocessSet.PreprocessOptions = plsMemo.SpectralPreprocessing; calibrationSet.SetPreprocessingModel(preprocessSet); Altaxo.Collections.AscendingIntegerCollection sel = new Altaxo.Collections.AscendingIntegerCollection(); Altaxo.Data.DataColumn col; col = table.DataColumns.TryGetColumn(GetXOfX_ColumnName()); if (col == null || !(col is INumericColumn)) NotFound(GetXOfX_ColumnName()); preprocessSet.XOfX = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector((INumericColumn)col, numberOfX); col = table.DataColumns.TryGetColumn(GetXMean_ColumnName()); if (col == null) NotFound(GetXMean_ColumnName()); preprocessSet.XMean = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); col = table.DataColumns.TryGetColumn(GetXScale_ColumnName()); if (col == null) NotFound(GetXScale_ColumnName()); preprocessSet.XScale = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYMean_ColumnName()); if (col == null) NotFound(GetYMean_ColumnName()); sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YMean = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYScale_ColumnName()); if (col == null) NotFound(GetYScale_ColumnName()); sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YScale = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXScore_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XScores = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXLoad_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XLoads = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfX); sel.Clear(); for (int i = 0; i < numberOfY; i++) { string colname = GetYLoad_ColumnName(i); col = table.DataColumns.TryGetColumn(colname); if (col == null) NotFound(colname); sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.YLoads = DataTableWrapper.ToROColumnMatrix(table.DataColumns, sel, numberOfMeasurements); sel.Clear(); col = table.DataColumns.TryGetColumn(GetCrossProduct_ColumnName()); if (col == null) NotFound(GetCrossProduct_ColumnName()); calibrationSet.CrossProduct = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfFactors); }
/// <summary> /// Exports a table to a PLS2CalibrationSet /// </summary> /// <param name="table">The table where the calibration model is stored.</param> /// <param name="calibrationSet"></param> public static void Export( DataTable table, out PLS1CalibrationModel calibrationSet) { int numberOfX = GetNumberOfX(table); int numberOfY = GetNumberOfY(table); int numberOfFactors = GetNumberOfFactors(table); calibrationSet = new PLS1CalibrationModel { NumberOfX = numberOfX, NumberOfY = numberOfY, NumberOfFactors = numberOfFactors }; var preprocessSet = new MultivariatePreprocessingModel(); var plsMemo = table.GetTableProperty("Content") as MultivariateContentMemento; if (plsMemo != null) { preprocessSet.PreprocessOptions = plsMemo.SpectralPreprocessing; } calibrationSet.SetPreprocessingModel(preprocessSet); var sel = new Altaxo.Collections.AscendingIntegerCollection(); Altaxo.Data.DataColumn col; col = table.DataColumns.TryGetColumn(GetXOfX_ColumnName()); if (col == null || !(col is INumericColumn)) { NotFound(GetXOfX_ColumnName()); } preprocessSet.XOfX = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector((INumericColumn)col, numberOfX); col = table.DataColumns.TryGetColumn(GetXMean_ColumnName()); if (col == null) { NotFound(GetXMean_ColumnName()); } preprocessSet.XMean = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); col = table.DataColumns.TryGetColumn(GetXScale_ColumnName()); if (col == null) { NotFound(GetXScale_ColumnName()); } preprocessSet.XScale = Altaxo.Calc.LinearAlgebra.DataColumnWrapper.ToROVector(col, numberOfX); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYMean_ColumnName()); if (col == null) { NotFound(GetYMean_ColumnName()); } sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YMean = DataColumnWrapper.ToROVector(col, numberOfY); sel.Clear(); col = table.DataColumns.TryGetColumn(GetYScale_ColumnName()); if (col == null) { NotFound(GetYScale_ColumnName()); } sel.Add(table.DataColumns.GetColumnNumber(col)); preprocessSet.YScale = DataColumnWrapper.ToROVector(col, numberOfY); for (int yn = 0; yn < numberOfY; yn++) { sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXWeight_ColumnName(yn, i); col = table.DataColumns.TryGetColumn(colname); if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XWeights[yn] = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfX); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetXLoad_ColumnName(yn, i); col = table.DataColumns.TryGetColumn(colname); if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.XLoads[yn] = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfX); sel.Clear(); for (int i = 0; i < numberOfFactors; i++) { string colname = GetYLoad_ColumnName(yn, i); col = table.DataColumns.TryGetColumn(colname); if (col == null) { NotFound(colname); } sel.Add(table.DataColumns.GetColumnNumber(col)); } calibrationSet.YLoads[yn] = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfY); sel.Clear(); col = table.DataColumns.TryGetColumn(GetCrossProduct_ColumnName(yn)); if (col == null) { NotFound(GetCrossProduct_ColumnName()); } sel.Add(table.DataColumns.GetColumnNumber(col)); calibrationSet.CrossProduct[yn] = DataTableWrapper.ToRORowMatrix(table.DataColumns, sel, numberOfFactors); } }