void RefreshSelectedPeakGraph() { Part_Plotter.Children.Remove(m_selectedPeakGraph); m_selectedPeakGraph = null; var peakInfo = this.ViewModel.CurrentDataItem?.SelectedPeakInfo; if (peakInfo != null) { PeakInfo[] point = new PeakInfo[] { peakInfo.PeakInfo }; EnumerableDataSource <PeakInfo> locatedPeaksDS = new EnumerableDataSource <PeakInfo>(point); locatedPeaksDS.SetXMapping((item) => item.Pos.X); locatedPeaksDS.SetYMapping((item) => item.Pos.Y); locatedPeaksDS.AddMapping(PeaksMarker.DataContextProperty, (peakInfoItem) => peakInfoItem); m_selectedPeakGraph = new ElementMarkerPointsGraph(locatedPeaksDS) { Marker = new SelectedPeaksMarker() { Size = 10, Pen = new Pen(Brushes.BlanchedAlmond, 1), Fill = Brushes.Transparent, ContextMenu = this.TryFindResource("PeakMarkerContextMenu") as ContextMenu } }; Part_Plotter.Children.Add(m_selectedPeakGraph); OrderGraphs(); } }
public PeakInfo[] getSampleArray(IPeakProvider peakProvider, int sampleCount) { PeakInfo[] samples = new PeakInfo[sampleCount]; for (int i = 0; i < sampleCount; i++) { samples[i] = peakProvider.GetNextPeak(); } return(samples); }
void generatePeaksSolver(string filename) { SortedDictionary <int, PeakInfo> thesePeaks = findPeaksSPAM(filename); foreach (KeyValuePair <int, PeakInfo> peak in thesePeaks) { int centerPixel = peak.Key; PeakInfo pi = peak.Value; // grab one half-width's worth pixels to either side of centroid if (centerPixel < gaussianHalfWidth || centerPixel + gaussianHalfWidth >= pixels) { logger.display("Warning: can't create {0}-pixel gaussian on peak centered at {1}", gaussianHalfWidth * 2 + 1, centerPixel); continue; // leave SPAM resolution } // determine initial guesses double guessIntensity = spectra[filename][centerPixel]; double guessWavelength = pi.wavelength; double guessWidth = 1.0; // MZ: in Excel this converged fine (don't use zero) double guessBaseline = 0.0; // MZ: in Excel this worked fine GaussianSolver solver = new GaussianSolver(guessIntensity, guessWavelength, guessWidth, guessBaseline); // Load the peak's local spectrum into the Solver. // // Note: the choice of which peaks to load into the Solver is significant in // the Guassian curve generated, and therefore the calculated FWHM. We could: // // 1. Simply hard-code a half-width of 'n' pixels (fast, deterministic, simple, but may // not reach all the way to the true baseline and therefore understates resolution). // 2. Do something clever like stop where slope crosses 0.5 or 0. // // For now, just let user pick a half-width. // for (int i = 0; i < gaussianHalfWidth * 2 + 1; i++) { int pixel = centerPixel - gaussianHalfWidth + i; solver.addPoint(wavelengths[pixel], spectra[filename][pixel]); } double resolution = solver.computeFWHM(); if (resolution < pi.fwhm * 2) { logger.display("replacing SPAM fwhm {0:f4} with gaussian {1:f4}", pi.fwhm, resolution); pi.fwhm = resolution; } else { logger.display("NOT replacing SPAM fwhm {0:f4} with gaussian {1:f4} (something seems wonky)", pi.fwhm, resolution); } } peaks.Add(filename, thesePeaks); }
public PeakInfo[] getSamplePeakArray(string file, int desiredSamples) { PeakInfo[] samples = new PeakInfo[desiredSamples]; MaxPeakProvider mpp = new MaxPeakProvider(); using (var reader = new AudioFileReader(file)) { int bytesPerSample = (reader.WaveFormat.BitsPerSample / 8); var sc = reader.Length / (bytesPerSample); var samplesPerPixel = (int)(sc / desiredSamples); //var gapSize = settings.PixelsPerPeak + settings.SpacerPixels; mpp.Init(reader, samplesPerPixel); samples = getSampleArray(mpp, desiredSamples); } return(samples); }
internal void RemovePeak(PeakInfo peakInfo) { if (peakInfo == null) { return; } if (!this.DataItem.IsAnalyzed || this.DataItem.LocatedPeaks == null) { return; } var locatedPeaks = this.DataItem.LocatedPeaks.ToList(); locatedPeaks.Remove(peakInfo); this.DataItem.LocatedPeaks = locatedPeaks.ToArray(); }
private void AddPeak(object sender, EventArgs e) { if (string.IsNullOrEmpty(PPMShift.Text)) { return; } PeakInfo peak = new PeakInfo(); peak.Shift = float.Parse(PPMShift.Text); peak.Coupling = string.IsNullOrEmpty(Coupling.Text) ? "None" : Coupling.Text; peak.Type = (PeakType)SignalType.SelectedIndex; if ((int)peak.Type == -1) { peak.Type = (PeakType)SignalType.Items.IndexOf(SignalType.Text); } if ((int)peak.Type == -1) { return; } peak.HydrogenCount = int.Parse(HydrogenCount.Text); peak.Description = Description.Text; if (peak.Shift == 0.00f || peak.HydrogenCount == 0) { return; } PeakView.AddObject(peak); PeakView.Sort(0); SignalType.SelectedIndex = 0; SignalType.Text = String.Empty; PPMShift.Clear(); HydrogenCount.Clear(); Description.Clear(); Coupling.Clear(); }
internal int?GetNearestStimulusIndex(PeakInfo peakInfo) { int?nearestStimulusStart = null; if (peakInfo == null || !this.DataItem.IsAnalyzed) { return(nearestStimulusStart); } int distMin = int.MaxValue; for (int i = 0; i < this.DataItem.Sweeps.Length; i++) { var dist = Math.Abs(this.DataItem.Sweeps[i].StimulusInfo.StartSample - peakInfo.Sample); if (dist < distMin) { distMin = dist; nearestStimulusStart = i; } } return(nearestStimulusStart); }
internal void RemovePeak(PeakInfo peakInfo) { this.CurrentDataItem?.RemovePeak(peakInfo); }
private void RemovePeakCommand_Executed(PeakInfo peakInfo) { this.ViewModel.RemovePeak(peakInfo); }
internal int?GetNearestStimulusIndex(PeakInfo peakInfo) { return(peakInfo != null?GetNearestStimulusIndex(peakInfo.Pos.X) : null); }