Exemple #1
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();
        }
    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();
    }
Exemple #3
0
        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);
            }
        }
Exemple #4
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();
            }
        }
        /// <summary>
        /// Tries to get the uniform spacing value of a vector.
        /// </summary>
        /// <param name="headerVector">The vector to investigate.</param>
        /// <param name="rowOrColumn">Contains either "row" or "column" to include in the diagnostic error message.</param>
        /// <param name="spacingValue">If the function is successful, contains the uniform spacing value.</param>
        /// <param name="errorMessage">If the function is not successful, contains a diagnostic error message.</param>
        /// <returns><c>True</c> if the function was successful, otherwise <c>False</c>.</returns>
        public static bool TryGetRowOrColumnSpacing(IReadOnlyList <double> headerVector, string rowOrColumn, out double spacingValue, out string errorMessage)
        {
            var spacing = new Calc.LinearAlgebra.VectorSpacingEvaluator(headerVector);

            if (!spacing.IsStrictlyMonotonicIncreasing)
            {
                errorMessage = string.Format("The values of the {0} header vector are not monotonically increasing. Thus {0} spacing could not be evaluated.", rowOrColumn);
                spacingValue = double.NaN;
                return(false);
            }

            if (!spacing.IsStrictlyEquallySpaced)
            {
                errorMessage = string.Format("The values of the {0} header vector are not strictly equally spaced. The relative deviation is {1}. Thus {0} spacing could not be evaluated.", rowOrColumn, spacing.RelativeSpaceDeviation);
                spacingValue = spacing.SpaceMeanValue;
                return(false);
            }

            errorMessage = null;
            spacingValue = spacing.SpaceMeanValue;
            return(true);
        }
Exemple #6
0
		public static void SavitzkyGolay(SavitzkyGolayParameters parameters, Altaxo.Data.DataColumn yCol, Altaxo.Data.DataColumn xCol)
		{
			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)
				{
					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;
			}

			Calc.Regression.SavitzkyGolay 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();
			}
		}
		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;
		}
		/// <summary>
		/// Tries to get the uniform spacing value of a vector.
		/// </summary>
		/// <param name="headerVector">The vector to investigate.</param>
		/// <param name="rowOrColumn">Contains either "row" or "column" to include in the diagnostic error message.</param>
		/// <param name="spacingValue">If the function is successful, contains the uniform spacing value.</param>
		/// <param name="errorMessage">If the function is not successful, contains a diagnostic error message.</param>
		/// <returns><c>True</c> if the function was successful, otherwise <c>False</c>.</returns>
		public static bool TryGetRowOrColumnSpacing(IROVector headerVector, string rowOrColumn, out double spacingValue, out string errorMessage)
		{
			var spacing = new Calc.LinearAlgebra.VectorSpacingEvaluator(headerVector);

			if (!spacing.IsStrictlyMonotonicIncreasing)
			{
				errorMessage = string.Format("The values of the {0} header vector are not monotonically increasing. Thus {0} spacing could not be evaluated.", rowOrColumn);
				spacingValue = double.NaN;
				return false;
			}

			if (!spacing.IsStrictlyEquallySpaced)
			{
				errorMessage = string.Format("The values of the {0} header vector are not strictly equally spaced. The relative deviation is {1}. Thus {0} spacing could not be evaluated.", rowOrColumn, spacing.RelativeSpaceDeviation);
				spacingValue = spacing.SpaceMeanValue;
				return false;
			}

			errorMessage = null;
			spacingValue = spacing.SpaceMeanValue;
			return true;
		}