示例#1
0
 /// <summary>
 /// This function searches for patterns like aaa=bbb in the items of the text column. If it finds such a item, it creates a column named aaa
 /// and stores the value bbb at the same position in it as in the text column.
 /// </summary>
 /// <param name="col">The column where to search for the patterns described above.</param>
 /// <param name="store">The column collection where to store the newly created columns of properties.</param>
 public static void ExtractPropertiesFromColumn(Altaxo.Data.DataColumn col, Altaxo.Data.DataColumnCollection store)
 {
     for (int nRow = 0; nRow < col.Count; nRow++)
     {
         ExtractPropertiesFromString(col[nRow].ToString(), store, nRow);
     }
 }
示例#2
0
        public static void Interpolation(Altaxo.Data.DataColumn xCol, Altaxo.Data.DataColumn yCol,
                                         Calc.Interpolation.IInterpolationFunction interpolInstance, IReadOnlyList <double> samplePoints,
                                         Altaxo.Data.DataColumn xRes, Altaxo.Data.DataColumn yRes)
        {
            int rows = Math.Min(xCol.Count, yCol.Count);
            var yVec = DataColumnWrapper.ToROVector((INumericColumn)yCol, rows);
            var xVec = DataColumnWrapper.ToROVector((INumericColumn)xCol, rows);

            interpolInstance.Interpolate(xVec, yVec);

            using (var suspendToken_xRes = xRes.SuspendGetToken())
            {
                using (var suspendToken_yRes = yRes.SuspendGetToken())
                {
                    for (int i = 0; i < samplePoints.Count; i++)
                    {
                        //double r = i / (double)(parameters.NumberOfPoints - 1);
                        //double x = parameters.XOrg * (1 - r) + parameters.XEnd * (r);
                        double x = samplePoints[i];
                        double y = interpolInstance.GetYOfX(x);
                        xRes[i] = x;
                        yRes[i] = y;
                    }
                    suspendToken_yRes.Resume();
                }
                suspendToken_xRes.Resume();
            }
        }
示例#3
0
        public static void SavitzkyGolayFiltering(WorksheetController ctrl)
        {
            if (ctrl.SelectedDataColumns.Count == 0)
            {
                return;
            }

            object paramobject = new SavitzkyGolayParameters();

            if (!Current.Gui.ShowDialog(ref paramobject, "Savitzky-Golay parameters"))
            {
                return;
            }

            SavitzkyGolayParameters parameters = (SavitzkyGolayParameters)paramobject;

            Altaxo.Data.DataColumn yCol = ctrl.Doc.DataColumns[ctrl.SelectedDataColumns[0]];
            Altaxo.Data.DataColumn xCol = ctrl.Doc.DataColumns.FindXColumnOf(yCol);

            double spacing = 1;

            if (xCol is Data.INumericColumn)
            {
                Calc.LinearAlgebra.VectorSpacingEvaluator calcspace = new Calc.LinearAlgebra.VectorSpacingEvaluator(Calc.LinearAlgebra.DataColumnWrapper.ToROVector(xCol));
                if (!calcspace.HasValidSpaces || calcspace.HasInvalidSpaces)
                {
                    Current.Gui.ErrorMessageBox(string.Format("The x-column {0} contains invalid spaces (is not equally spaced)", xCol.Name));
                    return;
                }
                if (calcspace.RelativeSpaceDeviation > 1E-2)
                {
                    System.Windows.Forms.DialogResult dlgresult =
                        System.Windows.Forms.MessageBox.Show(Current.MainWindow,
                                                             string.Format("The x-column {0} is not equally spaced, the deviation is {1}, the mean spacing is {2}. Continue anyway?", xCol.Name, calcspace.RelativeSpaceDeviation, calcspace.SpaceMeanValue),
                                                             "Continue?", System.Windows.Forms.MessageBoxButtons.YesNo,
                                                             System.Windows.Forms.MessageBoxIcon.Question,
                                                             System.Windows.Forms.MessageBoxDefaultButton.Button1);

                    if (dlgresult == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }

                spacing = calcspace.SpaceMeanValue;
            }

            Calc.Regression.SavitzkyGolay filter = new SavitzkyGolay(parameters);

            yCol.Suspend();
            filter.Apply(DataColumnWrapper.ToROVectorCopy(yCol), DataColumnWrapper.ToVector(yCol));

            if (parameters.DerivativeOrder > 0)
            {
                double factor = Math.Pow(1 / spacing, parameters.DerivativeOrder) * Calc.GammaRelated.Fac(parameters.DerivativeOrder);
                yCol.Data = yCol * factor;
            }

            yCol.Resume();
        }
示例#4
0
        /// <summary>
        /// Maps each data column of the source table to a corresponding data columns of the destination table.
        /// The matching is based on the index (order) and on the currently selected columns of the destination table.
        /// Attention: The match here does <b>not</b> mean that the two columns are data compatible to each other!
        /// </summary>
        /// <param name="desttable">The destination table.</param>
        /// <param name="selectedDestColumns">The currently selected columns of the destination table.</param>
        /// <param name="sourcetable">The source table.</param>
        /// <returns>An array of columns. Each column of the array is a data column in the destination table, which
        /// matches (by index) the data column in the source table.</returns>
        /// <remarks>
        /// 1.) Since the returned columns are part of the DataColumns collection of the destination table, you must not
        /// use these for inserting i.e. in other tables.
        /// 2.) The match is based on the index and the selected columns of the destination table. The rules are as follows: if there is
        /// no selection, the first column of the destination table matches the first column of the source table, and so forth.
        /// If there is a column selection, the first selected column of the destination table matches the first column of the source table,
        /// the second selected column of the destination table matches the second column of the source table. If more source columns than selected columns in the destination
        /// table exists, the match is done 1:1 after the last selected column of the destination table. If there is no further column in the destination
        /// table to match, new columns are created in the destination table.
        /// </remarks>
        static protected Altaxo.Data.DataColumn[] MapOrCreateDataColumns(Altaxo.Data.DataTable desttable, IAscendingIntegerCollection selectedDestColumns, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataColumn[] columnmap = new Altaxo.Data.DataColumn[sourcetable.DataColumns.ColumnCount];
            int nDestCol = -1;

            for (int nCol = 0; nCol < sourcetable.DataColumns.ColumnCount; nCol++)
            {
                nDestCol = nCol < selectedDestColumns.Count ? selectedDestColumns[nCol] : nDestCol + 1;

                string name  = sourcetable.DataColumns.GetColumnName(nCol);
                int    group = sourcetable.DataColumns.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind = sourcetable.DataColumns.GetColumnKind(nCol);

                if (nDestCol < desttable.DataColumns.ColumnCount)
                {
                    columnmap[nCol] = desttable.DataColumns[nDestCol];
                }
                else
                {
                    columnmap[nCol] = (DataColumn)Activator.CreateInstance(sourcetable.DataColumns[nCol].GetType());
                    desttable.DataColumns.Add(columnmap[nCol], name, kind, group);
                }
            }
            return(columnmap);
        }
示例#5
0
        public static void Interpolation(IWorksheetController ctrl, InterpolationParameters parameters)
        {
            var _columnToGroupNumber = new Dictionary <DataColumn, int>();

            for (int nSel = 0; nSel < ctrl.SelectedDataColumns.Count; nSel++)
            {
                Altaxo.Data.DataColumn yCol = ctrl.DataTable.DataColumns[ctrl.SelectedDataColumns[nSel]];
                Altaxo.Data.DataColumn xCol = ctrl.DataTable.DataColumns.FindXColumnOf(yCol);

                if (!(yCol is INumericColumn))
                {
                    Current.Gui.ErrorMessageBox("The selected column is not numeric!");
                    return;
                }
                if (!(xCol is INumericColumn))
                {
                    Current.Gui.ErrorMessageBox("The x-column of the selected column is not numeric!");
                    return;
                }

                var xRes = new DoubleColumn();
                var yRes = new DoubleColumn();
                if (!_columnToGroupNumber.TryGetValue(xCol, out var newgroup))
                {
                    newgroup = ctrl.DataTable.DataColumns.GetUnusedColumnGroupNumber();
                    ctrl.DataTable.DataColumns.Add(xRes, xCol.Name + ".I", ColumnKind.X, newgroup);
                    _columnToGroupNumber.Add(xCol, newgroup);
                }
                ctrl.DataTable.DataColumns.Add(yRes, yCol.Name + ".I", ColumnKind.V, newgroup);

                Interpolation(xCol, yCol, parameters, xRes, yRes);
            }
        }
		public static string DetermineXIncrement(DataColumn yColumnToTransform, out double xIncrement)
		{
			xIncrement = 1;
			var coll = DataColumnCollection.GetParentDataColumnCollectionOf(yColumnToTransform);

			if (null == coll)
				return "Can't find parent collection of provided data column to transform";

			var xColD = coll.FindXColumnOf(yColumnToTransform);
			if (null == xColD)
				return "Can't find x-column of provided data column to transform";

			var xCol = xColD as DoubleColumn;
			if (null == xCol)
				return "X-column of provided data column to transform is not a numeric column";

			var spacing = new Calc.LinearAlgebra.VectorSpacingEvaluator(xCol.ToROVector());
			if (!spacing.IsStrictlyMonotonicIncreasing)
				return "X-column of provided column to transform is not monotonically increasing";

			xIncrement = spacing.SpaceMeanValue;

			if (!spacing.IsStrictlyEquallySpaced)
				return "X-Column is not strictly equally spaced, the relative deviation is " + spacing.RelativeSpaceDeviation.ToString();
			else
				return null;
		}
 static int GetNumberOfY(Altaxo.Data.DataTable table)
 {
     Altaxo.Data.DataColumn col = table.DataColumns[GetYLoad_ColumnName(0, 0)];
     if (col == null)
     {
         NotFound(GetYLoad_ColumnName(0, 0));
     }
     return(col.Count);
 }
示例#8
0
 /// <summary>
 /// Extracts the property values of the selected property columns.
 /// </summary>
 /// <param name="ctrl">The controller that controls the table.</param>
 public static void ExtractPropertyValues(IWorksheetController ctrl)
 {
     for (int i = 0; i < ctrl.SelectedPropertyColumns.Count; i++)
     {
         Altaxo.Data.DataColumn col = ctrl.DataTable.PropCols[ctrl.SelectedPropertyColumns[i]];
         ExtractPropertiesFromColumn(col, ctrl.DataTable.PropCols);
     }
     ctrl.ClearAllSelections();
 }
 static int GetNumberOfFactors(Altaxo.Data.DataTable table)
 {
     Altaxo.Data.DataColumn col = table.DataColumns[GetCrossProduct_ColumnName(0)];
     if (col == null)
     {
         NotFound(GetCrossProduct_ColumnName(0));
     }
     return(col.Count);
 }
示例#10
0
 public static void Interpolation(Altaxo.Data.DataColumn xCol, Altaxo.Data.DataColumn yCol,
                                  InterpolationParameters parameters,
                                  Altaxo.Data.DataColumn xRes, Altaxo.Data.DataColumn yRes)
 {
     Interpolation(
         xCol, yCol,
         parameters.InterpolationInstance,
         VectorMath.CreateEquidistantSequenceByStartEndLength(parameters.XOrg, parameters.XEnd, parameters.NumberOfPoints),
         xRes, yRes);
 }
示例#11
0
        public static void Interpolation(WorksheetController ctrl)
        {
            if (ctrl.SelectedDataColumns.Count == 0)
            {
                return;
            }

            object paramobject = new InterpolationParameters();

            if (!Current.Gui.ShowDialog(ref paramobject, "Interpolation"))
            {
                return;
            }

            InterpolationParameters parameters = (InterpolationParameters)paramobject;


            Altaxo.Data.DataColumn yCol = ctrl.Doc.DataColumns[ctrl.SelectedDataColumns[0]];
            Altaxo.Data.DataColumn xCol = ctrl.Doc.DataColumns.FindXColumnOf(yCol);

            if (!(yCol is INumericColumn))
            {
                Current.Gui.ErrorMessageBox("The selected column is not numeric!");
                return;
            }
            if (!(xCol is INumericColumn))
            {
                Current.Gui.ErrorMessageBox("The x-column of the selected column is not numeric!");
                return;
            }

            int       rows = Math.Min(xCol.Count, yCol.Count);
            IROVector yVec = DataColumnWrapper.ToROVector((INumericColumn)yCol, rows);
            IROVector xVec = DataColumnWrapper.ToROVector((INumericColumn)xCol, rows);

            parameters.InterpolationInstance.Interpolate(xVec, yVec);

            DoubleColumn xRes = new DoubleColumn();
            DoubleColumn yRes = new DoubleColumn();

            for (int i = 0; i < parameters.NumberOfPoints; i++)
            {
                double r = i / (double)(parameters.NumberOfPoints - 1);
                double x = parameters.XOrg * (1 - r) + parameters.XEnd * (r);
                double y = ((IInterpolationFunction)parameters.InterpolationInstance).GetYOfX(x);
                xRes[i] = x;
                yRes[i] = y;
            }

            int newgroup = ctrl.DataTable.DataColumns.GetUnusedColumnGroupNumber();

            ctrl.DataTable.DataColumns.Add(xRes, xCol.Name + ".I", ColumnKind.X, newgroup);
            ctrl.DataTable.DataColumns.Add(yRes, yCol.Name + ".I", ColumnKind.V, newgroup);
        }
示例#12
0
        /// <summary>
        /// Plots the cross PRESS value into a provided layer.
        /// </summary>
        /// <param name="table">The table of PLS output data.</param>
        /// <param name="layer">The layer to plot into.</param>
        public static void PlotCrossPRESSValue(Altaxo.Data.DataTable table, XYPlotLayer layer)
        {
            Altaxo.Data.DataColumn ycol = table[WorksheetAnalysis.GetCrossPRESSValue_ColumnName()];
            Altaxo.Data.DataColumn xcol = table[WorksheetAnalysis.GetNumberOfFactors_ColumnName()];

            XYColumnPlotData       pa = new XYColumnPlotData(xcol, ycol);
            G2DPlotStyleCollection ps = new G2DPlotStyleCollection(LineScatterPlotStyleKind.LineAndScatter);

            layer.PlotItems.Add(new XYColumnPlotItem(pa, ps));

            layer.DefaultXAxisTitleString = "Number of factors";
            layer.DefaultYAxisTitleString = "Cross PRESS value";
        }
示例#13
0
        /// <summary>
        /// This plots a label plot into the provided layer.
        /// </summary>
        /// <param name="layer">The layer to plot into.</param>
        /// <param name="xcol">The x column.</param>
        /// <param name="ycol">The y column.</param>
        /// <param name="labelcol">The label column.</param>
        public static void PlotOnlyLabel(XYPlotLayer layer, Altaxo.Data.DataColumn xcol, Altaxo.Data.DataColumn ycol, Altaxo.Data.DataColumn labelcol)
        {
            XYColumnPlotData pa = new XYColumnPlotData(xcol, ycol);

            G2DPlotStyleCollection ps         = new G2DPlotStyleCollection(LineScatterPlotStyleKind.Empty);
            LabelPlotStyle         labelStyle = new LabelPlotStyle(labelcol);

            labelStyle.FontSize        = 10;
            labelStyle.BackgroundStyle = new FilledRectangle(System.Drawing.Color.LightCyan);
            ps.Add(labelStyle);

            layer.PlotItems.Add(new XYColumnPlotItem(pa, ps));
        }
示例#14
0
        /// <summary>
        /// Pastes data from a table (usually deserialized table from the clipboard) into a worksheet, which has
        /// currently selected columns. The number of selected columns has to match the number of columns of the source table.
        /// </summary>
        /// <param name="dg">The worksheet to paste into.</param>
        /// <param name="sourcetable">The table which contains the data to paste into the worksheet.</param>
        /// <remarks>The operation is defined as follows: if the is no ro selection, the data are inserted beginning at row[0] of the destination table.
        /// If there is a row selection, the data are inserted in the selected rows, and then in the rows after the last selected rows.
        /// No exception is thrown if a column type does not match the corresponding source column type.
        /// The columns to paste into do not change their name, kind or group number. But property columns in the source table
        /// are pasted into the destination table.</remarks>
        protected static void PasteFromTableColumnsToSelectedColumns(GUI.WorksheetController dg, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataTable desttable = dg.DataTable;

            Altaxo.Data.DataColumn[] propertycolumnmap = MapOrCreatePropertyColumns(desttable, sourcetable);

            // use the selected columns, then use the following columns, then add columns
            int nDestCol = -1;

            for (int nSrcCol = 0; nSrcCol < sourcetable.DataColumns.ColumnCount; nSrcCol++)
            {
                nDestCol = nSrcCol < dg.SelectedDataColumns.Count ? dg.SelectedDataColumns[nSrcCol] : nDestCol + 1;
                Altaxo.Data.DataColumn destcolumn;
                if (nDestCol < desttable.DataColumns.ColumnCount)
                {
                    destcolumn = desttable.DataColumns[nDestCol];
                }
                else
                {
                    string name  = sourcetable.DataColumns.GetColumnName(nSrcCol);
                    int    group = sourcetable.DataColumns.GetColumnGroup(nSrcCol);
                    Altaxo.Data.ColumnKind kind = sourcetable.DataColumns.GetColumnKind(nSrcCol);
                    destcolumn = (Altaxo.Data.DataColumn)Activator.CreateInstance(sourcetable.DataColumns[nSrcCol].GetType());
                    desttable.DataColumns.Add(destcolumn, name, kind, group);
                }

                // now fill the data into that column
                Altaxo.Data.DataColumn sourcecolumn = sourcetable.DataColumns[nSrcCol];

                try
                {
                    int nDestRow = -1;
                    for (int nSrcRow = 0; nSrcRow < sourcetable.DataColumns.RowCount; nSrcRow++)
                    {
                        nDestRow             = nSrcRow < dg.SelectedDataRows.Count ? dg.SelectedDataRows[nSrcRow] : nDestRow + 1;
                        destcolumn[nDestRow] = sourcecolumn[nSrcRow];
                    }
                }
                catch (Exception)
                {
                }


                // also fill in the property values
                int nDestColumnIndex = desttable.DataColumns.GetColumnNumber(destcolumn);
                FillRow(propertycolumnmap, nDestColumnIndex, sourcetable.PropCols, nSrcCol);
            } // for all data columns
        }
        public ColumnScriptController(Altaxo.Data.DataTable dataTable, Altaxo.Data.DataColumn dataColumn, ColumnScript columnScript)
        {
            this.m_DataTable  = dataTable;
            this.m_DataColumn = dataColumn;



            if (null != columnScript)
            {
                this.m_ColumnScript = (ColumnScript)columnScript.Clone();
            }
            else
            {
                this.m_ColumnScript = new ColumnScript();
            }



            if (null == m_ColumnScript.ForFrom)
            {
                m_ColumnScript.ForFrom = "0";
            }
            if (null == m_ColumnScript.ForCondition)
            {
                m_ColumnScript.ForCondition = "<";
            }
            if (null == m_ColumnScript.ForEnd)
            {
                m_ColumnScript.ForEnd = "col.RowCount";
            }
            if (null == m_ColumnScript.ForInc)
            {
                m_ColumnScript.ForInc = "++";
            }
            if (null == m_ColumnScript.ScriptBody)
            {
                m_ColumnScript.ScriptBody = "";
            }



            SetElements(true);
        }
示例#16
0
        /// <summary>
        /// Pastes data from a table (usually deserialized table from the clipboard) into a worksheet, which has
        /// no current selections. This means that the data are appended to the end of the worksheet.
        /// </summary>
        /// <param name="dg">The worksheet to paste into.</param>
        /// <param name="sourcetable">The table which contains the data to paste into the worksheet.</param>
        protected static void PasteFromTableToUnselected(GUI.WorksheetController dg, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataTable    desttable         = dg.DataTable;
            Altaxo.Data.DataColumn[] propertycolumnmap = MapOrCreatePropertyColumns(desttable, sourcetable);

            // add first the data columns to the end of the table
            for (int nCol = 0; nCol < sourcetable.DataColumns.ColumnCount; nCol++)
            {
                string name  = sourcetable.DataColumns.GetColumnName(nCol);
                int    group = sourcetable.DataColumns.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind       = sourcetable.DataColumns.GetColumnKind(nCol);
                Altaxo.Data.DataColumn destcolumn = (Altaxo.Data.DataColumn)sourcetable.DataColumns[nCol].Clone();
                desttable.DataColumns.Add(destcolumn, name, kind, group);

                // also fill in the property values
                int nDestColumnIndex = desttable.DataColumns.GetColumnNumber(destcolumn);
                FillRow(propertycolumnmap, nDestColumnIndex, sourcetable.PropCols, nCol);
            } // for all data columns
        }
示例#17
0
        /// <summary>
        /// Converts a data item to a string.
        /// </summary>
        /// <param name="col">The data column.</param>
        /// <param name="index">Index of the item in the data column, which should be converted.</param>
        /// <returns>The converted item as string.</returns>
        public string DataItemToString(Altaxo.Data.DataColumn col, int index)
        {
            if (col.IsElementEmpty(index))
            {
                return(string.Empty);
            }

            string result;

            if (_typeConverters.TryGetValue(col.GetType(), out var func))
            {
                result = func(col[index]);
            }
            else
            {
                result = DefaultTextConverter(col[index]);
            }

            return(result.Replace(SeparatorChar, SubstituteForSeparatorChar));
        }
示例#18
0
        public static void SavitzkyGolayFiltering(IWorksheetController ctrl)
        {
            if (ctrl.SelectedDataColumns.Count == 0)
            {
                return;
            }

            object paramobject = new SavitzkyGolayParameters();

            if (!Current.Gui.ShowDialog(ref paramobject, "Savitzky-Golay parameters"))
            {
                return;
            }

            var parameters = (SavitzkyGolayParameters)paramobject;

            Altaxo.Data.DataColumn yCol = ctrl.DataTable.DataColumns[ctrl.SelectedDataColumns[0]];
            Altaxo.Data.DataColumn xCol = ctrl.DataTable.DataColumns.FindXColumnOf(yCol);

            SavitzkyGolay(parameters, yCol, xCol);
        }
示例#19
0
		/// <summary>
		/// Merges two tables by corresponding x-columns.
		/// </summary>
		/// <param name="masterTable">Master table. Values from the slave table will be recalculated to fit the x-values of the master table.</param>
		/// <param name="masterXColumn">The master x-column of the master table.</param>
		/// <param name="slaveTable">The table providing the data for merging into the master table.</param>
		/// <param name="slaveXColumn">The x column of the slave table.</param>
		/// <param name="columnsToMerge">Indices of that columns of the slave table that should be merged into the master table.</param>
		/// <param name="createNewTable">If true, a new table is created as a clone of the master table. The data from the slave table are then merged into that clone. If false,
		/// the data are directly merged into the master table.</param>
		/// <returns>If <c>createNewTable</c> is true, then the newly created table. If false, then the provided master table where the data are merge to.</returns>
		public static DataTable MergeTable(
			this DataTable masterTable, DataColumn masterXColumn,
			DataTable slaveTable, DataColumn slaveXColumn,
			Altaxo.Collections.IAscendingIntegerCollection columnsToMerge,
			bool createNewTable)
		{
			DataTable destinationTable;
			if (createNewTable)
				destinationTable = (DataTable)masterTable.Clone();
			else
				destinationTable = masterTable;

			// create a fractional index column with the same length than the master table
			// that points into the slave table

			DoubleColumn fractIndex = GetFractionalIndex(masterXColumn, slaveXColumn);

			MergeTable(masterTable, fractIndex, slaveTable, columnsToMerge);

			return destinationTable;
		}
示例#20
0
        public override void Run(Altaxo.Gui.Worksheet.Viewing.WorksheetController ctrl)
        {
            Altaxo.Data.DataTable dataTable = ctrl.DataTable;
            if (ctrl.SelectedPropertyColumns.Count == 0)
            {
                return;
            }
            m_Column = dataTable.PropertyColumns[ctrl.SelectedPropertyColumns[0]];

            dataTable.PropertyColumns.ColumnScripts.TryGetValue(m_Column, out var script);
            if (script == null)
            {
                script = new PropertyColumnScript();
            }

            object[] args = new object[] { script, new ScriptExecutionHandler(EhScriptExecution) };
            if (Current.Gui.ShowDialog(args, "PropertyColumnScript of " + m_Column.Name))
            {
                dataTable.PropCols.ColumnScripts[m_Column] = (IColumnScriptText)args[0];
            }
            m_Column = null;
        }
    public void TenEmptyColumns()
    {
      DataColumnCollection d = new DataColumnCollection();

      DataColumn[] cols = new DataColumn[10];
      for(int i=0;i<10;i++)
      {
        cols[i] = new DoubleColumn();
        d.Add(cols[i]);
      }

      Assert.AreEqual(10, d.ColumnCount);
      Assert.AreEqual(0, d.RowCount);
      Assert.AreEqual(false, d.IsDirty);
      Assert.AreEqual(false, d.IsSuspended);

      Assert.AreEqual("A", d.GetColumnName(0));
      Assert.AreEqual("A", d[0].Name);

      Assert.AreEqual("J", d.GetColumnName(9));
      Assert.AreEqual("J", d[9].Name);


      // Test index to column resolution
      for(int i=0;i<10;i++)
        Assert.AreEqual(cols[i], d[i]);

      // test name to column resolution

      for(int i=0;i<10;i++)
      {
        char name = (char)('A'+i);
        Assert.AreEqual(cols[i], d[name.ToString()],"Column to name resolution of col " + name.ToString());
      }
      // test column to number resolution
      for(int i=0;i<10;i++)
        Assert.AreEqual(i, d.GetColumnNumber(cols[i]));

    }
示例#22
0
        public static void SavitzkyGolay(SavitzkyGolayParameters parameters, Altaxo.Data.DataColumn yCol, Altaxo.Data.DataColumn xCol)
        {
            double spacing = 1;

            if (xCol is Data.INumericColumn)
            {
                var calcspace = new Calc.LinearAlgebra.VectorSpacingEvaluator(Calc.LinearAlgebra.DataColumnWrapper.ToROVector(xCol));
                if (!calcspace.HasValidSpaces || calcspace.HasInvalidSpaces)
                {
                    Current.Gui.ErrorMessageBox(string.Format("The x-column {0} contains invalid spaces (is not equally spaced)", xCol.Name));
                    return;
                }
                if (calcspace.RelativeSpaceDeviation > 1E-2)
                {
                    if (!Current.Gui.YesNoMessageBox(
                            string.Format("The x-column {0} is not equally spaced, the deviation is {1}, the mean spacing is {2}. Continue anyway?", xCol.Name, calcspace.RelativeSpaceDeviation, calcspace.SpaceMeanValue),
                            "Continue?", true))
                    {
                        return;
                    }
                }

                spacing = calcspace.SpaceMeanValue;
            }

            var filter = new SavitzkyGolay(parameters);

            using (var suspendToken = yCol.SuspendGetToken())
            {
                filter.Apply(DataColumnWrapper.ToROVectorCopy(yCol), DataColumnWrapper.ToVector(yCol));

                if (parameters.DerivativeOrder > 0)
                {
                    double factor = Math.Pow(1 / spacing, parameters.DerivativeOrder) * Calc.GammaRelated.Fac(parameters.DerivativeOrder);
                    yCol.Data = yCol * factor;
                }
                suspendToken.Dispose();
            }
        }
示例#23
0
        /// <summary>
        /// Maps each property column of the source table to a corresponding property columns of the destination table. If no matching property
        /// column can be found in the destination table, a new matching property column is added to the destination table.
        /// </summary>
        /// <param name="desttable">The destination table.</param>
        /// <param name="sourcetable">The source table.</param>
        /// <returns>An array of columns. Each column of the array is a property column in the destination table, which
        /// matches the property column in the source table by index.</returns>
        /// <remarks>
        /// 1.) Since the returned columns are part of the PropCols collection of the destination table, you must not
        /// use these for inserting i.e. in other tables.
        /// 2.) The match is based on the names _and_ the types of the property columns. If there is no match,
        /// a new property column of the same type as in the source table and with a reasonable name is created.
        /// Therefore each mapped property column has the same type as its counterpart in the source table.
        /// </remarks>
        static protected Altaxo.Data.DataColumn[] MapOrCreatePropertyColumns(Altaxo.Data.DataTable desttable, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataColumn[] columnmap = new Altaxo.Data.DataColumn[sourcetable.PropCols.ColumnCount];
            for (int nCol = 0; nCol < sourcetable.PropCols.ColumnCount; nCol++)
            {
                string name  = sourcetable.PropCols.GetColumnName(nCol);
                int    group = sourcetable.PropCols.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind = sourcetable.PropCols.GetColumnKind(nCol);

                // if a property column with the same name and kind exist - use that one - else create a new one
                if (desttable.PropCols.ContainsColumn(name) && desttable.PropCols[name].GetType() == sourcetable.PropCols[nCol].GetType())
                {
                    columnmap[nCol] = desttable.PropCols[name];
                }
                else
                {
                    // the prop col must be empty - we will add the data later
                    columnmap[nCol] = (DataColumn)Activator.CreateInstance(sourcetable.PropCols[nCol].GetType());
                    desttable.PropCols.Add(columnmap[nCol], name, kind, group);
                }
            }
            return(columnmap);
        }
示例#24
0
        /// <summary>
        /// Maps each data column of the source table to a corresponding data row (!) of the destination table.
        /// The matching is based on the index (order) and on the currently selected columns of the destination table.
        /// Attention: The match here does <b>not</b> mean that the data of destination columns and source rows are compatible to each other!
        /// </summary>
        /// <param name="desttable">The destination table.</param>
        /// <param name="selectedDestColumns">The currently selected columns of the destination table.</param>
        /// <param name="sourcetable">The source table.</param>
        /// <returns>An array of columns. Each column of the array is a data column in the destination table, which
        /// matches (by index) the data row (!) in the source table with the same index.</returns>
        /// <remarks>
        /// 1.) Since the returned columns are part of the DataColumns collection of the destination table, you must not
        /// use these for inserting i.e. in other tables.
        /// 2.) The match is based on the index and the selected columns of the destination table. The rules are as follows: if there is
        /// no selection, the first column of the destination table matches the first row of the source table, and so forth.
        /// If there is a column selection, the first selected column of the destination table matches the first row of the source table,
        /// the second selected column of the destination table matches the second row of the source table. If there are more source rows than selected columns in the destination
        /// table exists, the match is done 1:1 after the last selected column of the destination table. If there is no further column in the destination
        /// table to match, new columns are created in the destination table. The type of the newly created columns in the destination table is
        /// the same as the first column of the source table in this case.
        /// </remarks>
        static protected Altaxo.Data.DataColumn[] MapOrCreateDataColumnsToRows(Altaxo.Data.DataTable desttable, IAscendingIntegerCollection selectedDestColumns, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataColumn[] columnmap = new Altaxo.Data.DataColumn[sourcetable.DataColumns.RowCount];
            int nDestCol = -1;
            int group    = 0;

            for (int nCol = 0; nCol < sourcetable.DataColumns.RowCount; nCol++)
            {
                nDestCol = nCol < selectedDestColumns.Count ? selectedDestColumns[nCol] : nDestCol + 1;

                if (nDestCol < desttable.DataColumns.ColumnCount)
                {
                    group           = desttable.DataColumns.GetColumnGroup(nDestCol); // we preserve the group of the last existing column for creation of new columns
                    columnmap[nCol] = desttable.DataColumns[nDestCol];
                }
                else
                {
                    columnmap[nCol] = (DataColumn)Activator.CreateInstance(sourcetable.DataColumns[0].GetType());
                    desttable.DataColumns.Add(columnmap[nCol], desttable.DataColumns.FindNewColumnName(), ColumnKind.V, group);
                }
            }
            return(columnmap);
        }
示例#25
0
		public override bool vop_Multiplication(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				c3 = this * (Altaxo.Data.DoubleColumn)c2;
				return true;
			}
			c3 = null;
			return false;
		}
示例#26
0
		public override bool vop_Multiplication_Rev(DataColumn c2, out DataColumn c3)
		{
			return vop_Multiplication(c2, out c3);
		}
示例#27
0
 public static void SavitzkyGolay(SavitzkyGolayParameters parameters, Altaxo.Data.DataColumn yCol)
 {
     SavitzkyGolay(parameters, yCol, null);
 }
示例#28
0
		public override bool vop_ShiftRight_Rev(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				Altaxo.Data.DoubleColumn c1 = this;
				DoubleColumn c22 = (DoubleColumn)c2;
				int len = c1.Count < c2.Count ? c1.Count : c2.Count;
				Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
				for (int i = 0; i < len; i++)
				{
					c33._data[i] = ((long)c22._data[i]) >> ((int)c1._data[i]);
				}
				c33._count = len;
				c3 = c33;
				return true;
			}
			c3 = null;
			return false;
		}
示例#29
0
		/// <summary>
		/// Gets the fractional index for merging of two tables.
		/// </summary>
		/// <param name="masterColumn">X-column of the master table.</param>
		/// <param name="slaveColumn">X-column of the slave table.</param>
		/// <returns>Array of fractional indices. Each item points into the slaveTable to the value that should be included in the master column at the item's index.</returns>
		public static DoubleColumn GetFractionalIndex(DataColumn masterColumn, DataColumn slaveColumn)
		{
			if (masterColumn is DateTimeColumn && slaveColumn is DateTimeColumn)
				return GetFractionalIndex((DateTimeColumn)masterColumn, (DateTimeColumn)slaveColumn);

			if (masterColumn is INumericColumn && slaveColumn is INumericColumn)
				return GetFractionalIndex((INumericColumn)masterColumn, (INumericColumn)slaveColumn);

			throw new ArgumentException(string.Format("Unable to create fractional index from columns of type {0} and {1}", masterColumn.GetType(), slaveColumn.GetType()));
		}
示例#30
0
        public static DataColumn GetAltaxoColumnFromOriginDataFormat(COLDATAFORMAT originColDataFormat)
        {
            // create a column
            Altaxo.Data.DataColumn destCol = null;

            switch (originColDataFormat)
            {
            case COLDATAFORMAT.DF_BYTE:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_CHAR:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_COMPLEX:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_DATE:
                destCol = new Altaxo.Data.DateTimeColumn();
                break;

            case COLDATAFORMAT.DF_DOUBLE:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_FLOAT:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_LONG:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_SHORT:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_TEXT:
                destCol = new Altaxo.Data.TextColumn();
                break;

            case COLDATAFORMAT.DF_TEXT_NUMERIC:
                destCol = new Altaxo.Data.TextColumn();
                break;

            case COLDATAFORMAT.DF_TIME:
                destCol = new Altaxo.Data.DateTimeColumn();
                break;

            case COLDATAFORMAT.DF_ULONG:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            case COLDATAFORMAT.DF_USHORT:
                destCol = new Altaxo.Data.DoubleColumn();
                break;

            default:
                destCol = new Altaxo.Data.TextColumn();
                break;
            }
            return(destCol);
        }
示例#31
0
		public override bool vop_Plus(out DataColumn c3)
		{
			c3 = +this;
			return true;
		}
示例#32
0
		public override bool vop_Division_Rev(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				c3 = (Altaxo.Data.DoubleColumn)c2 / this;
				return true;
			}
			c3 = null;
			return false;
		}
示例#33
0
        public static void StatisticsOnRows(
            Altaxo.AltaxoDocument mainDocument,
            Altaxo.Data.DataTable srctable,
            IAscendingIntegerCollection selectedColumns,
            IAscendingIntegerCollection selectedRows
            )
        {
            bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count);
            int  numcols             = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount;

            if (numcols == 0)
            {
                return; // nothing selected
            }
            bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count);
            int  numrows          = bUseSelectedRows ? selectedRows.Count : srctable.DataColumns.RowCount;

            if (numrows == 0)
            {
                return;
            }

            Altaxo.Data.DataTable table = new Altaxo.Data.DataTable();
            // add a text column and some double columns
            // note: statistics is only possible for numeric columns since
            // otherwise in one column doubles and i.e. dates are mixed, which is not possible

            // 1st column is the mean, and holds the sum during the calculation
            Data.DoubleColumn c1 = new Data.DoubleColumn();

            // 2rd column is the standard deviation, and holds the square sum during calculation
            Data.DoubleColumn c2 = new Data.DoubleColumn();

            // 3th column is the standard e (N)
            Data.DoubleColumn c3 = new Data.DoubleColumn();

            // 4th column is the sum
            Data.DoubleColumn c4 = new Data.DoubleColumn();

            // 5th column is the number of items for statistics
            Data.DoubleColumn c5 = new Data.DoubleColumn();

            table.DataColumns.Add(c1, "Mean");
            table.DataColumns.Add(c2, "sd");
            table.DataColumns.Add(c3, "se");
            table.DataColumns.Add(c4, "Sum");
            table.DataColumns.Add(c5, "N");

            table.Suspend();


            // first fill the cols c1, c2, c5 with zeros because we want to sum up
            for (int i = 0; i < numrows; i++)
            {
                c1[i] = 0;
                c2[i] = 0;
                c5[i] = 0;
            }


            for (int si = 0; si < numcols; si++)
            {
                Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si];
                if (!(col is Altaxo.Data.INumericColumn))
                {
                    continue;
                }

                // now do the statistics
                Data.INumericColumn ncol = (Data.INumericColumn)col;
                for (int i = 0; i < numrows; i++)
                {
                    double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i];
                    if (Double.IsNaN(val))
                    {
                        continue;
                    }

                    c1[i] += val;
                    c2[i] += val * val;
                    c5[i] += 1;
                }
            } // for all selected columns


            // now calculate the statistics
            for (int i = 0; i < numrows; i++)
            {
                // now fill a new row in the worksheet
                double NN     = c5[i];
                double sum    = c1[i];
                double sumsqr = c2[i];
                if (NN > 0)
                {
                    double mean    = c1[i] / NN;
                    double ymy0sqr = sumsqr - sum * sum / NN;
                    if (ymy0sqr < 0)
                    {
                        ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero
                    }
                    double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0;
                    double se = sd / Math.Sqrt(NN);

                    c1[i] = mean; // mean
                    c2[i] = sd;
                    c3[i] = se;
                    c4[i] = sum;
                    c5[i] = NN;
                }
            } // for all rows

            // if a table was created, we add the table to the data set and
            // create a worksheet
            if (null != table)
            {
                table.Resume();
                mainDocument.DataTableCollection.Add(table);
                // create a new worksheet without any columns
                Current.ProjectService.CreateNewWorksheet(table);
            }
        }
示例#34
0
		public override bool vop_GreaterOrEqual(AltaxoVariant c2, out DataColumn c3)
		{
			if (((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
			{
				double c22 = (double)c2;
				c3 = this >= c22;
				return true;
			}
			c3 = null;
			return false;
		}
示例#35
0
        public static void StatisticsOnColumns(
            Altaxo.AltaxoDocument mainDocument,
            Altaxo.Data.DataTable srctable,
            IAscendingIntegerCollection selectedColumns,
            IAscendingIntegerCollection selectedRows
            )
        {
            bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count);
            int  numcols             = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount;

            bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count);

            if (numcols == 0)
            {
                return;                  // nothing selected
            }
            Data.DataTable table = null; // the created table


            // add a text column and some double columns
            // note: statistics is only possible for numeric columns since
            // otherwise in one column doubles and i.e. dates are mixed, which is not possible

            // 1st column is the name of the column of which the statistics is made
            Data.TextColumn colCol = new Data.TextColumn();

            // 2nd column is the mean
            Data.DoubleColumn colMean = new Data.DoubleColumn();

            // 3rd column is the standard deviation
            Data.DoubleColumn colSd = new Data.DoubleColumn();

            // 4th column is the standard e (N)
            Data.DoubleColumn colSe = new Data.DoubleColumn();

            // 5th column is the sum
            Data.DoubleColumn colSum = new Data.DoubleColumn();

            // 6th column is the number of items for statistics
            Data.DoubleColumn colN = new Data.DoubleColumn();

            int currRow = 0;

            for (int si = 0; si < numcols; si++)
            {
                Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si];
                if (!(col is Altaxo.Data.INumericColumn))
                {
                    continue;
                }

                int rows = bUseSelectedRows ? selectedRows.Count : srctable.DataColumns.RowCount;
                if (rows == 0)
                {
                    continue;
                }

                // now do the statistics
                Data.INumericColumn ncol = (Data.INumericColumn)col;
                double sum    = 0;
                double sumsqr = 0;
                int    NN     = 0;
                for (int i = 0; i < rows; i++)
                {
                    double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i];
                    if (Double.IsNaN(val))
                    {
                        continue;
                    }

                    NN++;
                    sum    += val;
                    sumsqr += (val * val);
                }
                // now fill a new row in the worksheet

                if (NN > 0)
                {
                    double mean    = sum / NN;
                    double ymy0sqr = sumsqr - sum * sum / NN;
                    if (ymy0sqr < 0)
                    {
                        ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero
                    }
                    double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0;
                    double se = sd / Math.Sqrt(NN);

                    colCol[currRow]  = col.Name;
                    colMean[currRow] = mean; // mean
                    colSd[currRow]   = sd;
                    colSe[currRow]   = se;
                    colSum[currRow]  = sum;
                    colN[currRow]    = NN;
                    currRow++; // for the next column
                }
            } // for all selected columns


            if (currRow != 0)
            {
                table = new Altaxo.Data.DataTable("Statistics of " + srctable.Name);
                table.DataColumns.Add(colCol, "Col", Altaxo.Data.ColumnKind.X);

                // new : add a copy of all property columns; can be usefull
                for (int i = 0; i < srctable.PropertyColumnCount; i++)
                {
                    DataColumn originalColumn = srctable.PropertyColumns[i];
                    DataColumn clonedColumn   = (DataColumn)originalColumn.Clone();
                    clonedColumn.Clear();
                    for (int si = 0; si < numcols; si++)
                    {
                        int idx = bUseSelectedColumns ? selectedColumns[si] : si;
                        clonedColumn[si] = originalColumn[idx];
                    }
                    table.DataColumns.Add(clonedColumn, srctable.PropertyColumns.GetColumnName(i), srctable.PropertyColumns.GetColumnKind(i), srctable.PropertyColumns.GetColumnGroup(i));
                }

                table.DataColumns.Add(colMean, "Mean");
                table.DataColumns.Add(colSd, "Sd");
                table.DataColumns.Add(colSe, "Se");
                table.DataColumns.Add(colSum, "Sum");
                table.DataColumns.Add(colN, "N");

                mainDocument.DataTableCollection.Add(table);
                // create a new worksheet without any columns
                Current.ProjectService.CreateNewWorksheet(table);
            }
        }
		private NGTreeNode FindColumnNode(NGTreeNode tableNode, DataColumn column)
		{
			NGTreeNode result = null;
			foreach (NGTreeNode node in tableNode.Nodes)
			{
				if (object.ReferenceEquals(node.Tag, column))
				{
					return node;
				}
				else if (node.HasChilds)
				{
					result = FindColumnNode(node, column);
					if (null != result)
						return result;
				}
			}

			return null;
		}
示例#37
0
		public override bool vop_ShiftRight_Rev(AltaxoVariant c2, out DataColumn c3)
		{
			if (((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
			{
				DoubleColumn c1 = this;
				int len = c1._count;
				Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
				long c22 = (long)(double)c2;
				for (int i = 0; i < len; i++)
					c33._data[i] = c22 >> ((int)c1._data[i]);
				c33._count = len;
				c3 = c33;
				return true;
			}
			c3 = null;
			return false;
		}
示例#38
0
		public override bool vop_Multiplication(AltaxoVariant c2, out DataColumn c3)
		{
			if (((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
			{
				double c22 = (double)c2;
				c3 = this * c22;
				return true;
			}
			c3 = null;
			return false;
		}
示例#39
0
		public override bool vop_Minus(out DataColumn c3)
		{
			c3 = -this;
			return true;
		}
示例#40
0
		public override bool vop_Multiplication_Rev(AltaxoVariant c2, out DataColumn c3)
		{
			return vop_Multiplication(c2, out c3);
		}
示例#41
0
 public override bool vop_Increment(out DataColumn c3)
 {
   int len = this.m_Count;
   Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
   for(int i=0;i<len;i++)
   {
     c33.m_Array[i] = this.m_Array[i]+1;
   }
   c33.m_Count = len;
   c3=c33;
   return true;
 }
示例#42
0
		public override bool vop_Division_Rev(AltaxoVariant c2, out DataColumn c3)
		{
			if (((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
			{
				double c22 = (double)c2;
				c3 = c22 / this;
				return true;
			}
			c3 = null;
			return false;
		}
		public static void ShowRealFourierTransformDialog(DataColumn ycolumnToTransform)
		{
			var options = new RealFourierTransformOptions() { ColumnToTransform = ycolumnToTransform };

			double xIncrementValue;
			options.XIncrementMessage = DetermineXIncrement(ycolumnToTransform, out xIncrementValue);
			options.XIncrementValue = xIncrementValue;

			if (Current.Gui.ShowDialog(ref options, "Choose fourier transform options", false))
			{
				RealFourierTransform(options);
			}
		}
示例#44
0
        /// <summary>
        /// Retrieves the data columns from an Origin table.
        /// </summary>
        /// <param name="wks">The Origin worksheet to retrieve the data from.</param>
        /// <returns>The data columns with the data from the Origin worksheet.</returns>
        public static Altaxo.Data.DataColumnCollection GetDataColumns(this Origin.Worksheet wks)
        {
            var culture = Current.PropertyService.GetValue(Altaxo.Settings.CultureSettings.PropertyKeyDocumentCulture, Altaxo.Main.Services.RuntimePropertyKind.UserAndApplicationAndBuiltin).Culture;

            int nCols = wks.Cols;

            var result = new Altaxo.Data.DataColumnCollection();

            for (int c = 0; c < nCols; c++)
            {
                var srcCol = wks.Columns[c];

                Altaxo.Data.DataColumn destCol = GetAltaxoColumnFromOriginDataFormat(srcCol.DataFormat);

                int groupNumber = -1;

                var altaxoColumnKind = OriginToAltaxoColumnKind(srcCol.Type);

                if (altaxoColumnKind == Altaxo.Data.ColumnKind.X)
                {
                    groupNumber++;
                }

                if (destCol is DoubleColumn)
                {
                    var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
                    (destCol as DoubleColumn).Array = (double[])data;
                }
                else if (destCol is DateTimeColumn)
                {
                    var          data            = (double[])srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
                    const double refDateAsDouble = 2451910; // this is the number of days in julian calendar belonging to the date below...
                    var          refDate         = DateTime.Parse("2001-01-01", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal);
                    for (int i = data.Length - 1; i >= 0; --i)
                    {
                        destCol[i] = refDate.AddDays(data[i] - refDateAsDouble);
                    }
                }
                else if (destCol is TextColumn && srcCol.DataFormat == COLDATAFORMAT.DF_TEXT_NUMERIC)
                {
                    var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_VARIANT, 0, -1, 0);

                    var destColNum = new Altaxo.Data.DoubleColumn();

                    object[] oarr;
                    if (null != (oarr = data as object[]))
                    {
                        int numberOfNums    = 0;
                        int numberOfObjects = 0;
                        for (int i = 0; i < oarr.Length; ++i)
                        {
                            if (oarr[i] is double)
                            {
                                destColNum[i] = (double)oarr[i];
                                ++numberOfNums;
                            }
                            if (oarr[i] != null)
                            {
                                destCol[i] = string.Format(culture, "{0}", oarr[i]);
                                ++numberOfObjects;
                            }
                        }
                        // if the column consist mostly of numerics, then exchange it with destcol
                        if (numberOfNums >= 0.99 * numberOfObjects || numberOfNums >= numberOfObjects - 2)
                        {
                            destCol = destColNum;
                        }
                    }
                }
                else if (destCol is TextColumn)
                {
                    var      data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_TEXT, 0, -1, 0);
                    string[] sarr;
                    object[] oarr;

                    if (null != (sarr = data as string[]))
                    {
                        (destCol as TextColumn).Array = sarr;
                    }
                    else if (null != (oarr = data as object[]))
                    {
                        for (int i = 0; i < oarr.Length; ++i)
                        {
                            if (null != oarr[i])
                            {
                                destCol[i] = string.Format(culture, "{0}", oarr[i]);
                            }
                            else
                            {
                                destCol[i] = null;
                            }
                        }
                    }
                }

                result.Add(destCol, (!string.IsNullOrEmpty(srcCol.LongName) ? srcCol.LongName : srcCol.Name), altaxoColumnKind, Math.Max(0, groupNumber));
            }

            return(result);
        }
示例#45
0
        public static List <IGPlotItem> CreatePlotItems(DataTable table, IAscendingIntegerCollection selectedColumns, G2DPlotStyleCollection templatePlotStyle)
        {
            int len        = selectedColumns.Count;
            int numColumns = table.DataColumnCount;

            List <IGPlotItem>          result = new List <IGPlotItem>();
            ErrorBarPlotStyle          unpairedPositiveError = null;
            ErrorBarPlotStyle          unpairedNegativeError = null;
            AscendingIntegerCollection processedColumns      = new AscendingIntegerCollection();

            int idx;

            for (int sci = 0; sci < len; sci++)
            {
                idx = selectedColumns[sci];
                if (processedColumns.Contains(idx))
                {
                    continue;
                }
                else
                {
                    processedColumns.Add(idx);
                }

                Altaxo.Data.DataColumn ycol = table[idx];
                Altaxo.Data.DataColumn xcol = table.DataColumns.FindXColumnOf(ycol);
                XYColumnPlotData       pa;
                if (null != xcol)
                {
                    pa = new XYColumnPlotData(xcol, ycol);
                }
                else
                {
                    pa = new XYColumnPlotData(new Altaxo.Data.IndexerColumn(), ycol);
                }

                G2DPlotStyleCollection ps = templatePlotStyle != null? (G2DPlotStyleCollection)templatePlotStyle.Clone() : new G2DPlotStyleCollection();

                bool foundMoreColumns = true;
                for (idx = idx + 1; foundMoreColumns && idx < numColumns; idx++)
                {
                    DataColumn col = table.DataColumns[idx];
                    switch (table.DataColumns.GetColumnKind(idx))
                    {
                    case ColumnKind.Label:
                        LabelPlotStyle labelStyle = new LabelPlotStyle(col);
                        ps.Insert(0, labelStyle);
                        break;

                    case ColumnKind.Err:
                        ErrorBarPlotStyle errStyle = new ErrorBarPlotStyle();
                        errStyle.PositiveErrorColumn = col as INumericColumn;
                        errStyle.NegativeErrorColumn = col as INumericColumn;
                        ps.Add(errStyle);
                        break;

                    case ColumnKind.pErr:
                        if (null != unpairedNegativeError)
                        {
                            unpairedNegativeError.PositiveErrorColumn = col as INumericColumn;;
                            unpairedNegativeError = null;
                        }
                        else
                        {
                            unpairedPositiveError = new ErrorBarPlotStyle();
                            unpairedPositiveError.PositiveErrorColumn = col as INumericColumn;
                            ps.Add(unpairedPositiveError);
                        }
                        break;

                    case ColumnKind.mErr:
                        if (null != unpairedPositiveError)
                        {
                            unpairedPositiveError.NegativeErrorColumn = col as INumericColumn;
                            unpairedPositiveError = null;
                        }
                        else
                        {
                            unpairedNegativeError = new ErrorBarPlotStyle();
                            unpairedNegativeError.NegativeErrorColumn = col as INumericColumn;
                            ps.Add(unpairedNegativeError);
                        }
                        break;

                    default:
                        foundMoreColumns = false;
                        break;
                    }

                    if (foundMoreColumns)
                    {
                        processedColumns.Add(idx);
                    }
                }

                result.Add(new XYColumnPlotItem(pa, ps));
            }

            return(result);
        }
示例#46
0
 public override bool vop_ShiftLeft(DataColumn c2, out DataColumn c3)
 {
   if(c2 is Altaxo.Data.DoubleColumn)
   {
     Altaxo.Data.DoubleColumn c1=this;
     Altaxo.Data.DoubleColumn c22 = (DoubleColumn)c2;
     int len = c1.Count<c2.Count ? c1.Count : c2.Count;
     Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
     for(int i=0;i<len;i++)
     {
       c33.m_Array[i] = ((long)c1.m_Array[i]) << ((int)c22.m_Array[i]);
     }
     c33.m_Count=len;
     c3=c33;
     return true;
   }
   c3=null;
   return false;
 }
示例#47
0
 public override bool vop_ShiftRight(AltaxoVariant c2, out DataColumn c3)
 {
   if(((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
   {
     DoubleColumn c1=this;
     int len = c1.m_Count;
     Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
     int c22 = (int)(double)c2;
     for(int i=0;i<len;i++)
       c33.m_Array[i] = ((long)c1.m_Array[i]) >> c22;
     c33.m_Count = len;
     c3=c33;
     return true;
   }
   c3=null;
   return false;
 }
示例#48
0
		public override bool vop_Not(out DataColumn c3)
		{
			c3 = !this;
			return true;
		}
示例#49
0
		public override bool vop_ShiftLeft(AltaxoVariant c2, out DataColumn c3)
		{
			if (((AltaxoVariant)c2).IsType(AltaxoVariant.Content.VDouble))
			{
				int c22 = (int)(double)c2;
				c3 = this << c22;
				return true;
			}
			c3 = null;
			return false;
		}
示例#50
0
		public override bool vop_Complement(out DataColumn c3)
		{
			c3 = ~this;
			return true;
		}
示例#51
0
		public override bool vop_Decrement(out DataColumn c3)
		{
			int len = this._count;
			Altaxo.Data.DoubleColumn c33 = new Altaxo.Data.DoubleColumn(len);
			for (int i = 0; i < len; i++)
			{
				c33._data[i] = this._data[i] - 1;
			}
			c33._count = len;
			c3 = c33;
			return true;
		}
示例#52
0
        /// <summary>
        /// Imports a couple of SPC files into a table. The spectra are added as columns to the table. If the x column
        /// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
        /// </summary>
        /// <param name="filenames">An array of filenames to import.</param>
        /// <param name="table">The table the spectra should be imported to.</param>
        /// <returns>Null if no error occurs, or an error description.</returns>
        public static string ImportSpcFiles(string[] filenames, Altaxo.Data.DataTable table)
        {
            Altaxo.Data.DoubleColumn xcol = null;
            double[] xvalues, yvalues;
            System.Text.StringBuilder errorList = new System.Text.StringBuilder();
            int lastColumnGroup = 0;

            if (table.DataColumns.ColumnCount > 0)
            {
                lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount - 1);
                Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
                if (xColumnOfRightMost is Altaxo.Data.DoubleColumn)
                {
                    xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
                }
            }

            foreach (string filename in filenames)
            {
                string error = ToArrays(filename, out xvalues, out yvalues);
                if (null != error)
                {
                    errorList.Append(error);
                    continue;
                }

                bool bMatchsXColumn = false;

                // first look if our default xcolumn matches the xvalues
                if (null != xcol)
                {
                    bMatchsXColumn = ValuesMatch(xvalues, xcol);
                }

                // if no match, then consider all xcolumns from right to left, maybe some fits
                if (!bMatchsXColumn)
                {
                    for (int ncol = table.DataColumns.ColumnCount - 1; ncol >= 0; ncol--)
                    {
                        if ((ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
                            (table.DataColumns[ncol] is DoubleColumn) &&
                            (ValuesMatch(xvalues, (DoubleColumn)table.DataColumns[ncol]))
                            )
                        {
                            xcol            = (DoubleColumn)table.DataColumns[ncol];
                            lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
                            bMatchsXColumn  = true;
                            break;
                        }
                    }
                }

                // create a new x column if the last one does not match
                if (!bMatchsXColumn)
                {
                    xcol = new Altaxo.Data.DoubleColumn();
                    xcol.CopyDataFrom(xvalues);
                    lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
                    table.DataColumns.Add(xcol, "SPC X values", Altaxo.Data.ColumnKind.X, lastColumnGroup);
                }

                // now add the y-values
                Altaxo.Data.DoubleColumn ycol = new Altaxo.Data.DoubleColumn();
                ycol.CopyDataFrom(yvalues);
                table.DataColumns.Add(ycol,
                                      table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
                                      Altaxo.Data.ColumnKind.V,
                                      lastColumnGroup);

                // add also a property column named "FilePath" if not existing so far
                if (!table.PropCols.ContainsColumn("FilePath"))
                {
                    table.PropCols.Add(new Altaxo.Data.TextColumn(), "FilePath");
                }

                // now set the file name property cell
                if (table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
                {
                    table.PropCols["FilePath"][table.DataColumns.GetColumnNumber(ycol)] = filename;
                }
            } // foreache file

            return(errorList.Length == 0 ? null : errorList.ToString());
        }
示例#53
0
		public override bool vop_Addition_Rev(DataColumn c2, out DataColumn c3)
		{
			return vop_Addition(c2, out c3);
		}
示例#54
0
		public override bool vop_Greater(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				c3 = this > (Altaxo.Data.DoubleColumn)c2;
				return true;
			}
			c3 = null;
			return false;
		}
示例#55
0
		/// <summary>
		/// Decomposes a column into repeat units by analysing the values of the column with increasing index.
		/// If a column value is repeated, the current range is finalized and a new range is started. At the end,
		/// a list of index ranges is returned. Inside each range the column values are guaranteed to be unique.
		/// </summary>
		/// <param name="col">Column to decompose.</param>
		/// <returns>List of integer ranges. Inside a single range the column values are ensured to be unique.</returns>
		public static List<AltaxoVariant> Decompose(DataColumn col)
		{
			var result = new List<AltaxoVariant>();
			var alreadyIn = new HashSet<AltaxoVariant>();
			for (int i = 0; i < col.Count; i++)
			{
				var item = col[i];
				if (!alreadyIn.Contains(item))
				{
					result.Add(item);
					alreadyIn.Add(item);
				}
			}
			return result;
		}
		public void EhView_AfterSelectNode(NGTreeNode node)
		{
			if (node.Tag is DataColumn)
				_selectedColumn = (DataColumn)node.Tag;
			else
				_selectedColumn = null;
		}
示例#57
0
		public override bool vop_LesserOrEqual(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				c3 = this <= (Altaxo.Data.DoubleColumn)c2;
				return true;
			}
			c3 = null;
			return false;
		}
示例#58
0
		public override bool vop_GreaterOrEqual_Rev(DataColumn c2, out DataColumn c3)
		{
			if (c2 is Altaxo.Data.DoubleColumn)
			{
				c3 = (Altaxo.Data.DoubleColumn)c2 >= this;
				return true;
			}
			c3 = null;
			return false;
		}
示例#59
0
        /// <summary>
        /// Imports a couple of JCAMP files into a table. The spectra are added as columns to the (one and only) table. If the x column
        /// of the rightmost column does not match the x-data of the spectra, a new x-column is also created.
        /// </summary>
        /// <param name="filenames">An array of filenames to import.</param>
        /// <param name="table">The table the spectra should be imported to.</param>
        /// <returns>Null if no error occurs, or an error description.</returns>
        public static string ImportJcampFiles(string[] filenames, Altaxo.Data.DataTable table)
        {
            DoubleColumn xcol = null;
            DoubleColumn xvalues, yvalues;
            var          errorList       = new System.Text.StringBuilder();
            int          lastColumnGroup = 0;

            if (table.DataColumns.ColumnCount > 0)
            {
                lastColumnGroup = table.DataColumns.GetColumnGroup(table.DataColumns.ColumnCount - 1);
                Altaxo.Data.DataColumn xColumnOfRightMost = table.DataColumns.FindXColumnOfGroup(lastColumnGroup);
                if (xColumnOfRightMost is Altaxo.Data.DoubleColumn)
                {
                    xcol = (Altaxo.Data.DoubleColumn)xColumnOfRightMost;
                }
            }

            foreach (string filename in filenames)
            {
                var    stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                string error  = ToDataTable(stream, out var localTable);
                stream.Close();

                if (null != error)
                {
                    errorList.Append(error);
                    continue;
                }
                if (localTable.DataColumns.RowCount == 0)
                {
                    continue;
                }
                xvalues = (DoubleColumn)localTable[0];
                yvalues = (DoubleColumn)localTable[1];

                // Add the necessary property columns
                for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
                {
                    string name = localTable.PropCols.GetColumnName(i);
                    if (!table.PropCols.ContainsColumn(name))
                    {
                        table.PropCols.Add((DataColumn)localTable.PropCols[i].Clone(), name, localTable.PropCols.GetColumnKind(i));
                    }
                }

                bool bMatchsXColumn = false;

                // first look if our default xcolumn matches the xvalues
                if (null != xcol)
                {
                    bMatchsXColumn = ValuesMatch(xvalues, xcol);
                }

                // if no match, then consider all xcolumns from right to left, maybe some fits
                if (!bMatchsXColumn)
                {
                    for (int ncol = table.DataColumns.ColumnCount - 1; ncol >= 0; ncol--)
                    {
                        if ((ColumnKind.X == table.DataColumns.GetColumnKind(ncol)) &&
                            (table.DataColumns[ncol] is DoubleColumn) &&
                            (ValuesMatch(xvalues, (DoubleColumn)table.DataColumns[ncol]))
                            )
                        {
                            xcol            = (DoubleColumn)table.DataColumns[ncol];
                            lastColumnGroup = table.DataColumns.GetColumnGroup(xcol);
                            bMatchsXColumn  = true;
                            break;
                        }
                    }
                }

                // create a new x column if the last one does not match
                if (!bMatchsXColumn)
                {
                    xcol = new Altaxo.Data.DoubleColumn();
                    xcol.CopyDataFrom(xvalues);
                    lastColumnGroup = table.DataColumns.GetUnusedColumnGroupNumber();
                    table.DataColumns.Add(xcol, "X", Altaxo.Data.ColumnKind.X, lastColumnGroup);
                }

                // now add the y-values
                var ycol = new Altaxo.Data.DoubleColumn();
                ycol.CopyDataFrom(yvalues);
                table.DataColumns.Add(ycol,
                                      table.DataColumns.FindUniqueColumnName(System.IO.Path.GetFileNameWithoutExtension(filename)),
                                      Altaxo.Data.ColumnKind.V,
                                      lastColumnGroup);

                // add also a property column named "FilePath" if not existing so far
                if (!table.PropCols.ContainsColumn("FilePath"))
                {
                    table.PropCols.Add(new Altaxo.Data.TextColumn(), "FilePath");
                }

                // now set the file name property cell
                int yColumnNumber = table.DataColumns.GetColumnNumber(ycol);
                if (table.PropCols["FilePath"] is Altaxo.Data.TextColumn)
                {
                    table.PropCols["FilePath"][yColumnNumber] = filename;
                }

                // set the other property columns
                for (int i = 0; i < localTable.PropCols.ColumnCount; i++)
                {
                    string name = localTable.PropCols.GetColumnName(i);
                    table.PropCols[name][yColumnNumber] = localTable.PropCols[i][1];
                }
            } // foreache file

            return(errorList.Length == 0 ? null : errorList.ToString());
        }