Esempio n. 1
0
		/// <summary>
		/// Shows the dialog in which the user can select options for the 2D Fourier transformation, and then executes the Fourier transformation
		/// The result is stored in a newly created data table in the same folder as the source data table.
		/// </summary>
		/// <param name="table">The table containing the data to transform.</param>
		/// <param name="selectedDataRows">The selected data rows of the table. (A value of <c>null</c> can be provided here).</param>
		/// <param name="selectedDataColumns">The selected data columns of the table. (A value of <c>null</c> can be provided here).</param>
		/// <param name="selectedPropertyColumns">The selected property columns of the table. (A value of <c>null</c> can be provided here).</param>
		public static void ShowRealFourierTransformation2DDialog(DataTable table, IAscendingIntegerCollection selectedDataRows, IAscendingIntegerCollection selectedDataColumns, IAscendingIntegerCollection selectedPropertyColumns)
		{
			DataTableMatrixProxy proxy = null;
			RealFourierTransformation2DOptions options = null;

			try
			{
				proxy = new DataTableMatrixProxy(table, selectedDataRows, selectedDataColumns, selectedPropertyColumns);

				options = null != _lastUsedOptions ? (RealFourierTransformation2DOptions)_lastUsedOptions.Clone() : new RealFourierTransformation2DOptions();

				double rowIncrementValue; string rowIncrementMessage;
				proxy.TryGetRowHeaderIncrement(out rowIncrementValue, out rowIncrementMessage);
				double columnIncrementValue; string columnIncrementMessage;
				proxy.TryGetColumnHeaderIncrement(out columnIncrementValue, out columnIncrementMessage);

				options.IsUserDefinedRowIncrementValue = false;
				options.RowIncrementValue = rowIncrementValue;
				options.RowIncrementMessage = rowIncrementMessage;

				options.IsUserDefinedColumnIncrementValue = false;
				options.ColumnIncrementValue = columnIncrementValue;
				options.ColumnIncrementMessage = columnIncrementMessage;
			}
			catch (Exception ex)
			{
				Current.Gui.ErrorMessageBox(string.Format("{0}\r\nDetails:\r\n{1}", ex.Message, ex.ToString()), "Error in preparation of Fourier transformation");
				return;
			}

			if (!Current.Gui.ShowDialog(ref options, "Choose fourier transform options", false))
				return;

			_lastUsedOptions = options;

			try
			{
				var resultTable = new DataTable { Name = string.Format("{0}Fourier{1} of {2}", table.Folder, options.OutputKind, table.ShortName) };
				ExecuteFouriertransformation2D(proxy, options, resultTable);

				// Create a DataSource
				Altaxo.Worksheet.Commands.Analysis.FourierTransformation2DDataSource dataSource = new FourierTransformation2DDataSource(proxy, options, new Altaxo.Data.DataSourceImportOptions());
				resultTable.DataSource = dataSource;

				Current.ProjectService.OpenOrCreateWorksheetForTable(resultTable);
			}
			catch (Exception ex)
			{
				Current.Gui.ErrorMessageBox(string.Format("{0}\r\nDetails:\r\n{1}", ex.Message, ex.ToString()), "Error in execution of Fourier transformation");
				return;
			}
		}
Esempio n. 2
0
		/// <summary>
		/// Executes a two dimensional Fourier transformation.
		/// </summary>
		/// <param name="matrixProxy">The proxy containing the matrix data that should be transformed, as well as the row header column and column header column that can be used to determine the spacing between adjacent rows and columns.</param>
		/// <param name="options">The options for the Fourier transformation.</param>
		/// <param name="destinationTable">The destination table that is used to store the Fourier transformed values.</param>
		/// <exception cref="System.NotImplementedException">Data pretreatment has an order which is not implemented yet.</exception>
		public static void ExecuteFouriertransformation2D(DataTableMatrixProxy matrixProxy, RealFourierTransformation2DOptions options, DataTable destinationTable)
		{
			// preparation step

			if (!options.IsUserDefinedRowIncrementValue)
			{
				double rowIncrementValue; string rowIncrementMessage;
				matrixProxy.TryGetRowHeaderIncrement(out rowIncrementValue, out rowIncrementMessage);
				options.RowIncrementValue = rowIncrementValue;
				options.RowIncrementMessage = rowIncrementMessage;
			}

			if (!options.IsUserDefinedColumnIncrementValue)
			{
				double columnIncrementValue; string columnIncrementMessage;
				matrixProxy.TryGetColumnHeaderIncrement(out columnIncrementValue, out columnIncrementMessage);
				options.ColumnIncrementValue = columnIncrementValue;
				options.ColumnIncrementMessage = columnIncrementMessage;
			}

			var matrix = matrixProxy.GetMatrix((r, c) => new Altaxo.Calc.LinearAlgebra.DoubleMatrixInArray1DRowMajorRepresentation(r, c));

			var fft = new Altaxo.Calc.Fourier.RealFourierTransformation2D(matrix, true);
			fft.ColumnSpacing = options.RowIncrementValue;
			fft.RowSpacing = options.ColumnIncrementValue;

			if (options.DataPretreatmentCorrectionOrder.HasValue)
			{
				switch (options.DataPretreatmentCorrectionOrder.Value)
				{
					case 0:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveZeroOrderFromMatrixIgnoringInvalidElements;
						break;

					case 1:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveFirstOrderFromMatrixIgnoringInvalidElements;
						break;

					case 2:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveSecondOrderFromMatrixIgnoringInvalidElements;
						break;

					case 3:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveThirdOrderFromMatrixIgnoringInvalidElements;
						break;

					default:
						throw new NotImplementedException(string.Format("Regression of order {0} is not implemented yet", options.DataPretreatmentCorrectionOrder.Value));
				}
			}

			if (options.ReplacementValueForNaNMatrixElements.HasValue)
				Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNElementsWith(matrix, options.ReplacementValueForNaNMatrixElements.Value);
			if (options.ReplacementValueForInfiniteMatrixElements.HasValue)
				Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNAndInfiniteElementsWith(matrix, options.ReplacementValueForInfiniteMatrixElements.Value);

			if (options.FourierWindow != null)
			{
				fft.DataPretreatment += options.FourierWindow.Apply;
			}

			fft.Execute();

			IMatrix resultMatrix;
			IROVector rowFrequencies;
			IROVector columnFrequencies;

			if (options.CenterResult)
				fft.GetResultCentered(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);
			else
				fft.GetResult(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);

			var matTableConverter = new Altaxo.Data.MatrixToDataTableConverter(resultMatrix, destinationTable);

			if (options.OutputFrequencyHeaderColumns)
			{
				matTableConverter.AddMatrixRowHeaderData(rowFrequencies, string.IsNullOrEmpty(options.FrequencyRowHeaderColumnName) ? "RowFrequencies" : options.FrequencyRowHeaderColumnName);
				matTableConverter.AddMatrixColumnHeaderData(columnFrequencies, string.IsNullOrEmpty(options.FrequencyColumnHeaderColumnName) ? "ColumnFrequencies" : options.FrequencyColumnHeaderColumnName);
			}

			if (options.OutputPeriodHeaderColumns)
			{
				matTableConverter.AddMatrixRowHeaderData(VectorMath.Divide(1, rowFrequencies), string.IsNullOrEmpty(options.PeriodRowHeaderColumnName) ? "RowPeriods" : options.PeriodRowHeaderColumnName);
				matTableConverter.AddMatrixColumnHeaderData(VectorMath.Divide(1, columnFrequencies), string.IsNullOrEmpty(options.PeriodColumnHeaderColumnName) ? "ColumnPeriods" : options.PeriodColumnHeaderColumnName);
			}

			matTableConverter.Execute();
		}