/// <summary> /// Get a chromatogram with properly sorted time values. /// </summary> public void ReleaseChromatogram(byte[] bytesFromDisk, out float[] times, out float[] intensities, out float[] massErrors, out int[] scanIds) { times = Times.ToArray(bytesFromDisk); intensities = Intensities.ToArray(bytesFromDisk); massErrors = MassErrors != null ? MassErrors.ToArray(bytesFromDisk) : null; scanIds = Scans != null ? Scans.ToArray(bytesFromDisk) : null; // Release memory. Times = null; Intensities = null; MassErrors = null; Scans = null; // Make sure times and intensities match in length. if (times.Length != intensities.Length) { throw new InvalidDataException( string.Format(Resources.ChromCollected_ChromCollected_Times__0__and_intensities__1__disagree_in_point_count, times.Length, intensities.Length)); } }
/// <summary> /// Get a chromatogram with properly sorted time values. /// </summary> public void ReleaseChromatogram(byte[] bytesFromDisk, out TimeIntensities timeIntensities) { var times = Times.ToArray(bytesFromDisk); var intensities = Intensities.ToArray(bytesFromDisk); var massErrors = MassErrors != null ? MassErrors.ToArray(bytesFromDisk) : null; var scanIds = Scans != null ? Scans.ToArray(bytesFromDisk) : null; // Make sure times and intensities match in length. if (times.Length != intensities.Length) { throw new InvalidDataException( string.Format(Resources.ChromCollected_ChromCollected_Times__0__and_intensities__1__disagree_in_point_count, times.Length, intensities.Length)); } if (massErrors != null && massErrors.Length != intensities.Length) { throw new InvalidDataException( string.Format(Resources.ChromCollector_ReleaseChromatogram_Intensities___0___and_mass_errors___1___disagree_in_point_count_, intensities.Length, massErrors.Length)); } timeIntensities = new TimeIntensities(times, intensities, massErrors, scanIds); // Release memory. Times = null; Intensities = null; MassErrors = null; Scans = null; }
public void Play() { var songs = from i in Instruments from s in i.Songs where Notes.Any() ? Notes.Contains(s.Note) : true && Octaves.Any() ? Octaves.Contains(s.Octave) : true && Tempos.Any() ? Tempos.Contains(s.Tempo) : true && Intensities.Any() ? Intensities.Contains(s.Intensity) : true && Modes.Any() ? Modes.Contains(s.Mode) : true group s by s.Instrument into grouping select grouping; var songsDict = new Dictionary <string, List <Song> >(); foreach (IGrouping <string, Song> grouping in songs) { var lstSongs = new List <Song>(); foreach (var s in grouping.Take(MaxSongs)) { lstSongs.Add(s); } songsDict.Add(grouping.Key, lstSongs); } foreach (var instrument in songsDict.Keys) { var song = songsDict[instrument].ElementAt(0); song.Play(); songsDict[instrument].RemoveAt(0); } }
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 void FindPeaks(double[] retentionTimes, TimeIntervals timeIntervals, ExplicitRetentionTimeInfo explicitRT) { Finder = Crawdads.NewCrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); if (timeIntervals == null) { RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); } else { var identifiedIndices = TimesToIndices(retentionTimes); var allPeaks = timeIntervals.Intervals.SelectMany(interval => FindIntervalPeaks(interval.Key, interval.Value, identifiedIndices)); RawPeaks = allPeaks.OrderByDescending(peak => Tuple.Create(peak.Identified, peak.Area)) .Take(MAX_PEAKS).ToArray(); } // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray()); // Accept only peaks within the user-provided RT window, if any if (explicitRT != null) { var winLow = (float)(explicitRT.RetentionTime - 0.5 * (explicitRT.RetentionTimeWindow ?? 0)); var winHigh = winLow + (float)(explicitRT.RetentionTimeWindow ?? 0); RawPeaks = RawPeaks.Where(rp => { var t = Times[rp.TimeIndex]; return(winLow <= t && t <= winHigh); }); } }
/// <summary> /// Fill a number of intensity and mass error values for the given chromatogram with zeroes. /// </summary> public void FillZeroes(int chromatogramIndex, int count, BlockWriter writer) { if (MassErrors != null) { MassErrors.FillZeroes(chromatogramIndex, count, writer); } Intensities.FillZeroes(chromatogramIndex, count, writer); }
public void FindPeaks(double[] retentionTimes) { Finder = Crawdads.NewCrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray()); }
private bool Equals(Chromatogram other) { return (PrecursorMz.Equals(other.PrecursorMz) && ProductMz.Equals(other.ProductMz) && Times.SequenceEqual(other.Times) && Intensities.SequenceEqual(other.Intensities) && Color.Equals(other.Color)); }
/// <summary> /// Add intensity and mass error (if needed) to the given chromatogram. /// </summary> public void AddPoint(int chromatogramIndex, float intensity, float?massError, BlockWriter writer) { if (MassErrors != null) { // ReSharper disable once PossibleInvalidOperationException MassErrors.Add(chromatogramIndex, massError.Value, writer); // If massError is required, this won't be null (and if it is, we want to hear about it) } Intensities.Add(chromatogramIndex, intensity, writer); }
public override int GetHashCode() { unchecked { int hashCode = PrecursorMz.GetHashCode(); hashCode = (hashCode * 397) ^ ProductMz.GetHashCode(); hashCode = (hashCode * 397) ^ Times.GetHashCode(); hashCode = (hashCode * 397) ^ Intensities.GetHashCode(); hashCode = (hashCode * 397) ^ Color.GetHashCode(); return(hashCode); } }
/// <summary> /// 计算选择区域的信噪比。即只有设置为Enabled的离子会用于信噪比计算。 /// </summary> public void CalculateSignalToNoise() { if (Intensities == null || !Intensities.Any(m => m.Enabled)) { this._signalToNoise = 0; } else { this._signalToNoise = (from m in Intensities where m.Enabled select m.Intensity).Max() / Noise; } }
public void CalculateStats(double compoundTotalIntensitySum, double edgeNetThresholdMinutes) { // Ambient noise threshold: ignore the "0" values, but sometimes we see ~1 instead of zero. // We generally don't care about the really low intensities anyway. MedianIntensity = Intensities.Where(x => x.Intensity >= 5).Median(x => x.Intensity); MaxIntensityVsMedian = MaxIntensity / MedianIntensity; MaxIntensityNET = (MaxIntensityTime - StartTimeMinutes) / (StopTimeMinutes - StartTimeMinutes); var edgeNetThreshold = (edgeNetThresholdMinutes) / (StopTimeMinutes - StartTimeMinutes); PassesNET = edgeNetThreshold <= MaxIntensityNET && MaxIntensityNET <= 1 - edgeNetThreshold; RatioOfCompoundTotalIntensity = IntensitySum / compoundTotalIntensitySum; }
public void FindPeaks(double[] retentionTimes, bool requireDocNode) { Finder = Crawdads.NewCrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); if (requireDocNode && DocNode == null) { RawPeaks = new IFoundPeak[0]; } else { RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray()); } }
/// <summary> /// Automatic exposure time adaptation. /// Settings: /// 30 % of points in the top 10 % intensities or /// max intensity lower than last saturation level / 5. /// Initial exposure time shall never be exceeded. /// </summary> /// <returns>Was exposure time altered?</returns> private bool ExposureTimeAdaptation() { float exposureTime = ExposureTime; float maxInt = Intensities.Max(); // Lower limit of top X percent. X = 10. float topPercent = 10; float lowTopInt = maxInt * (1 - (topPercent / 100)); // Count percentage of points being in the top X %. int topCount = 0; foreach (var intensity in Intensities) { if (intensity >= lowTopInt) { topCount++; } } // Float topCount, so it can be divided by intensities.Lenght (int). float topPoints = (float)topCount / Intensities.Length * 100; // More than 30 % points in top X % of intensity. if (topPoints > 30) { exposureTime = exposureTime / 2; saturationLevel = maxInt; } // Maximum lower than one fifth of saturation. else if (maxInt < saturationLevel / 5) { exposureTime = exposureTime * 2; } // No problem found. else { return(false); // No change this time. } // Bounds. exposureTime = Math.Min(exposureTime, MaxExposureTime); exposureTime = Math.Max(exposureTime, MinExposureTime); // Default min. ExposureTime = exposureTime; // Finally write to device. return(true); // Exposure time has been changed. }
/// <summary> /// Add an intensity value to the given chromatogram. /// </summary> public void AddIntensity(int chromatogramIndex, float intensity, BlockWriter writer) { Intensities.Add(chromatogramIndex, intensity, writer); }
/// <summary> /// Fill a number of intensity values for the given chromatogram with zeroes. /// </summary> public void FillIntensities(int chromatogramIndex, int count, BlockWriter writer) { Intensities.FillZeroes(chromatogramIndex, count, writer); }
private void AudioMeter_Manager_FastBeat() { Intensities Intensity_Rating = VU_LastIntensity_Rating; if (Audio_Average_Intensity > VU_Intensity_Threshold_MAX) { Intensity_Rating = Intensities.Max; } else if (Audio_Average_Intensity > VU_Intensity_Threshold_HEAVY) { Intensity_Rating = Intensities.Heavy; } else if (Audio_Average_Intensity > VU_Intensity_Threshold_MEDIUM) { Intensity_Rating = Intensities.Medium; } else { Intensity_Rating = Intensities.Light; } bool Intensity_Rating_Changed = (Intensity_Rating != VU_LastIntensity_Rating); if (Intensity_Rating_Changed) { if (VU_Intensity_Hysterisis >= VU_Intensity_Hysterisis_THRESHOLD) { if (VU_Intensity_Hysterisis > 0) { VU_Intensity_Hysterisis_HasReachedZero = false; VU_Intensity_Hysterisis -= 1; } else { VU_Intensity_Hysterisis = 0; VU_Intensity_Hysterisis_HasReachedZero = true; } } else { Intensity_Rating = VU_LastIntensity_Rating; VU_Intensity_Hysterisis += 1; } } else { if (VU_Intensity_Hysterisis > 0) { if (VU_Intensity_Hysterisis_HasReachedZero) { VU_Intensity_Hysterisis = 0; } else { VU_Intensity_Hysterisis -= 1; } } else { VU_Intensity_Hysterisis = 0; VU_Intensity_Hysterisis_HasReachedZero = true; } } if (Intensity_Rating_Changed) { // VU_Intensity_Last_Random_Choice = -1; // VU_Auto_Force_Change_Count = 0; // Note: I don't -think- Smoothing needs to be reset after each // ResetSmoothing (); } else if (VU_Auto_Force_Change_Count > MathUtilities.ConvertRange (Audio_Average_Intensity, 0, 1, VU_Auto_Force_Change_Max_Delay, VU_Auto_Force_Change_Min_Delay)) { // Force a new random pattern to be chosen VU_Intensity_Last_Random_Choice = -1; VU_Auto_Force_Change_Count = 0; // Note: I don't -think- Smoothing needs to be reset after each //ResetSmoothing (); } else { VU_Auto_Force_Change_Count ++; } switch (Intensity_Rating) { case Intensities.Max: if (VU_Intensity_Last_Random_Choice < 0 | VU_Intensity_Last_Random_Choice > 1) VU_Intensity_Last_Random_Choice = Randomizer.RandomProvider.Next (0, 1); switch (VU_Intensity_Last_Random_Choice) { case 0: AudioMeter_Extended_Solid_Color_Strobe (ColorStrobe.SingleRainbow); break; case 1: AudioMeter_Extended_Solid_Color_Strobe (ColorStrobe.SingleWhite); break; default: // Show that something is up - this shouldn't ever happen FillLights_Brightness (255); FillLights_Color (255, 0, 0); break; } break; case Intensities.Heavy: if (VU_Intensity_Last_Random_Choice < 0 | VU_Intensity_Last_Random_Choice > 2) VU_Intensity_Last_Random_Choice = Randomizer.RandomProvider.Next (0, 2); switch (VU_Intensity_Last_Random_Choice) { case 0: AudioMeter_Extended_Solid_Color_Strobe (ColorStrobe.Rainbow); break; case 1: AudioMeter_Extended_Solid_Color_Strobe (ColorStrobe.White); break; case 2: AudioMeter_Extended_Solid_Color_Strobe (ColorStrobe.Hueshift); break; default: // Show that something is up - this shouldn't ever happen FillLights_Brightness (255); FillLights_Color (255, 0, 0); break; } break; case Intensities.Medium: if (VU_Intensity_Last_Random_Choice < 0 | VU_Intensity_Last_Random_Choice > 3) VU_Intensity_Last_Random_Choice = Randomizer.RandomProvider.Next (0, 3); switch (VU_Intensity_Last_Random_Choice) { case 0: AudioMeter_Extended_Moving_Bars (true); break; case 1: AudioMeter_Extended_Hueshift_Beat (); break; case 2: AudioMeter_Extended_Rainbow (true); break; case 3: AudioMeter_Extended_Moving_Bars (false); break; default: // Show that something is up - this shouldn't ever happen FillLights_Brightness (255); FillLights_Color (255, 0, 0); break; } break; case Intensities.Light: if (VU_Intensity_Last_Random_Choice < 0 | VU_Intensity_Last_Random_Choice > 1) VU_Intensity_Last_Random_Choice = Randomizer.RandomProvider.Next (0, 1); switch (VU_Intensity_Last_Random_Choice) { case 0: AudioMeter_Extended_Rainbow (false); break; case 1: AudioMeter_Extended_Hueshift_Beat (); break; default: // Show that something is up - this shouldn't ever happen FillLights_Brightness (255); FillLights_Color (255, 0, 0); break; } break; default: break; } VU_LastIntensity_Rating = Intensity_Rating; }