Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added KZ spectrum smoothing and tests #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

avcarr2
Copy link
Contributor

@avcarr2 avcarr2 commented May 19, 2022

My new deconvolution algorithm idea relies on high quality smoothing of the data. I implemented the Kolmogorov-Zurbenko filter, directly porting to C# most of the C code written originally for R found here: https://github.com/cran/kza/blob/master/src/kz.c.

This is a re-do of my previous commit that included some changes that I didn't want to include in this pull request.

Copy link
Contributor

@trishorts trishorts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tidy up those spots and we're good to go

double[] smoothedIntArray = KZ1D(YArray, window, iterations);
if(smoothedIntArray.Length < YArray.Length)
{
throw new ArgumentException("output length is unequal to input length");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change this to an mzlib exception with a message. add a unit test for that exception to make sure it happens and to make sure the message is correct. this gets passed to metamorpheus and are really helpful

/// Algorithm employed is the Kolmogorov-Zurbenko algorithm originally written in C for R:
/// https://github.com/cran/kza/blob/master/src/kz.c
/// </summary>
public double[,] SmoothSpectrumKZ(int window, int iterations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use an informative name for window and have variable explanations for window and iterations before the method with recommendations.

/// </summary>
/// <param name="x"></param><summary>double array (double[]) of the intensity values.</summary>
/// <param name="window"></param><summary>The window size over which to perform the filtering.</summary>
/// <param name="iterations"></param><summary>The number of smoothering iterations to perform.</summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smoothering?

/// <summary>
/// Computes the moving average for a given window. Used in conjuction with the KZ1D method.
/// </summary>
/// <param name="v"></param><summary>The source data array.</summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use more informative variable names here for v and w at least

}
if (z == 0)
{
return double.NaN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cover this with a unit test

@avcarr2 avcarr2 changed the title Added KZ spectrum smoothing and tests [WIP] Added KZ spectrum smoothing and tests Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants