コード例 #1
0
        /// <summary>
        /// Try to get a common data table and a group number from all columns (here we don't rely on <see cref="DataTable"/> and GroupNumber of this document).
        /// </summary>
        /// <param name="columns">The columns to consider. <see cref="ITransformedReadableColumn"/> will be stripped to get the underlying data column.</param>
        /// <param name="dataTableIsNotUniform">If the columns gives different result for their underlying data table, the result here will be true.</param>
        /// <param name="commonDataTable">If the previous parameter results in false, this is the common data table of all columns. If the previous parameter is true, this is the first underlying data table that could be deduced from the columns. The result is null if no underlying table could be deduced from the columns.</param>
        /// <param name="groupNumberIsNotUniform">If the columns gives different result for their group number, the result here will be true.</param>
        /// <param name="commonGroupNumber">If the previous parameter results in false, this is the common group number of all columns. If the previous parameter results in true, this is the first group number that could be deduced from the columns. The result is null if no group number could be deduced from the columns.</param>
        public static void GetCommonDataTableAndGroupNumberFromColumns(this IEnumerable <IReadableColumn> columns, out bool dataTableIsNotUniform, out DataTable commonDataTable, out bool groupNumberIsNotUniform, out int?commonGroupNumber)
        {
            dataTableIsNotUniform   = false;
            groupNumberIsNotUniform = false;
            commonDataTable         = null;
            commonGroupNumber       = null;

            foreach (var col in columns)
            {
                IReadableColumn underlyingColumn = col;

                while (underlyingColumn is ITransformedReadableColumn)
                {
                    underlyingColumn = (underlyingColumn as ITransformedReadableColumn).UnderlyingReadableColumn;
                }

                if (underlyingColumn is DataColumn)
                {
                    var colColl     = DataColumnCollection.GetParentDataColumnCollectionOf((DataColumn)underlyingColumn);
                    var dataTable   = DataTable.GetParentDataTableOf(colColl);
                    int?groupNumber = colColl?.GetColumnGroup((DataColumn)underlyingColumn);

                    if (null != dataTable)
                    {
                        if (null == commonDataTable)
                        {
                            commonDataTable = dataTable;
                        }
                        else if (!object.ReferenceEquals(commonDataTable, dataTable))
                        {
                            dataTableIsNotUniform = true;
                        }
                    }

                    if (null != groupNumber)
                    {
                        if (null == commonGroupNumber)
                        {
                            commonGroupNumber = groupNumber;
                        }
                        else if (!(commonGroupNumber == groupNumber))
                        {
                            groupNumberIsNotUniform = true;
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static void RealFourierTransform(RealFourierTransformOptions options)
        {
            var yCol   = options.ColumnToTransform;
            int fftLen = yCol.Count;

            double[] resultCol = new double[fftLen];
            for (int i = 0; i < resultCol.Length; ++i)
            {
                resultCol[i] = yCol[i];
            }

            var transform = new Calc.Fourier.RealFourierTransform(fftLen);

            transform.Transform(resultCol, Calc.Fourier.FourierDirection.Forward);

            var wrapper = new Calc.Fourier.RealFFTResultWrapper(resultCol);

            DataTable outputTable = null;

            switch (options.OutputPlacement)
            {
            case RealFourierTransformOutputPlacement.CreateInNewWorksheet:
                outputTable = new DataTable
                {
                    Name = "Real FFT results"
                };
                Current.Project.DataTableCollection.Add(outputTable);
                Current.ProjectService.OpenOrCreateWorksheetForTable(outputTable);
                break;

            case RealFourierTransformOutputPlacement.CreateInSameWorksheet:
                outputTable = DataTable.GetParentDataTableOf(yCol);
                if (null == outputTable)
                {
                    throw new ArgumentException("Provided y-column does not belong to a data table.");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("Unkown  enum value: " + options.OutputPlacement.ToString());
            }

            // create the x-Column first
            var freqCol = new DoubleColumn
            {
                AssignVector = wrapper.FrequenciesFromXIncrement(options.XIncrementValue)
            };
            int outputGroup = outputTable.DataColumns.GetUnusedColumnGroupNumber();

            outputTable.DataColumns.Add(freqCol, "Frequency", ColumnKind.X, outputGroup);

            // now create the other output cols
            if (options.Output.HasFlag(RealFourierTransformOutput.Re))
            {
                var col = new DoubleColumn
                {
                    AssignVector = wrapper.RealPart
                };
                outputTable.DataColumns.Add(col, "Re", ColumnKind.V, outputGroup);
            }

            if (options.Output.HasFlag(RealFourierTransformOutput.Im))
            {
                var col = new DoubleColumn
                {
                    AssignVector = wrapper.ImaginaryPart
                };
                outputTable.DataColumns.Add(col, "Im", ColumnKind.V, outputGroup);
            }

            if (options.Output.HasFlag(RealFourierTransformOutput.Abs))
            {
                var col = new DoubleColumn
                {
                    AssignVector = wrapper.Amplitude
                };
                outputTable.DataColumns.Add(col, "Abs", ColumnKind.V, outputGroup);
            }

            if (options.Output.HasFlag(RealFourierTransformOutput.Phase))
            {
                var col = new DoubleColumn
                {
                    AssignVector = wrapper.Phase
                };
                outputTable.DataColumns.Add(col, "Phase", ColumnKind.V, outputGroup);
            }

            if (options.Output.HasFlag(RealFourierTransformOutput.Power))
            {
                var col = new DoubleColumn
                {
                    AssignVector = wrapper.Amplitude
                };
                col.Data = col * col;
                outputTable.DataColumns.Add(col, "Power", ColumnKind.V, outputGroup);
            }
        }