private IEnumerable <IFoundPeak> FindIntervalPeaks(float intervalStart, float intervalEnd, IList <int> identifiedIndices) { int startIndex = Times.BinarySearch(intervalStart); if (startIndex < 0) { startIndex = Math.Max(0, ~startIndex - 1); } int endIndex = Times.BinarySearch(intervalEnd); if (endIndex < 0) { endIndex = Math.Min(Times.Count - 1, ~endIndex); } if (endIndex <= startIndex) { yield break; } var times = Times.Skip(startIndex).Take(endIndex - startIndex + 1).ToArray(); var intensities = Intensities.Skip(startIndex).Take(endIndex - startIndex + 1).ToArray(); var subIdentifiedIndices = identifiedIndices.Select(index => index - startIndex).ToArray(); var subFinder = Crawdads.NewCrawdadPeakFinder(); subFinder.SetChromatogram(times, intensities); foreach (var peak in subFinder.CalcPeaks(MAX_PEAKS, subIdentifiedIndices)) { yield return(Finder.GetPeak(peak.StartIndex + startIndex, peak.EndIndex + startIndex)); } }
public int IndexAtOrBefore(DateTime time, out bool exact) { exact = false; var sidx = Times.BinarySearch(time); if (sidx < 0) { sidx = ~sidx - 1; } else { exact = true; } return(sidx); }
/// <summary> /// inserts a new point into the time series. /// if the datetime already has a value, then it either replaces it /// or throws an exception /// </summary> /// <param name="time">time at which value is to be inserted</param> /// <param name="value">value to be inserted</param> /// <param name="forceOverwrite">determines whether exception is thrown when point alread exists</param> public void InsertInMiddle(DateTime time, T value, bool forceOverwrite) { if (Count == 0) { Add(time, value, forceOverwrite); return; } var sidx = Times.BinarySearch(time); if (sidx >= 0) // got a match { if (forceOverwrite) { Values[sidx] = value; return; } throw new ApplicationException("Cannot insert over the top of an existing point."); } var i0 = ~sidx - 1; // the index of the time before the searched time if (i0 == -1) // it goes at the front { Values.Insert(0, value); Times.Insert(0, time); } else if (i0 == Count - 1) // it goes at the end { Add(time, value, forceOverwrite); } else // it goes in the middle somewhere { Values.Insert(i0 + 1, value); Times.Insert(i0 + 1, time); } }