public void plotDeriv(EPRPlotView pw) { LineSeries se = new LineSeries { ItemsSource = BPUtil.getDataPoints(this.getX(), this.getDerivative()), Title = "Derivative" }; pw.Model.Series.Add(se); pw.InvalidatePlot(); pw.rescale(); }
private void DerivButton_Click(object sender, RoutedEventArgs e) { EPRPlotView pw = this.getActivePlotView(); if (!this.getActiveSpectrum().showDeriv) { this.getActiveSpectrum().showDeriv = true; this.DerivButton.Foreground = Brushes.SaddleBrown; this.getActiveSpectrum().plotDeriv(pw); } else { var test = pw.Model.Series.Where(s => s.Title.Contains("Derivative")); if (test.Count() != 0) { pw.Model.Series.Remove(test.First()); } this.getActiveSpectrum().showDeriv = false; pw.InvalidatePlot(); pw.rescale(); this.DerivButton.Foreground = Brushes.Black; } }
private void IntButton_Click(object sender, RoutedEventArgs e) { EPRPlotView pw = this.getActivePlotView(); if (!this.getActiveSpectrum().showInt) { this.getActiveSpectrum().showInt = true; this.IntButton.Foreground = Brushes.Magenta; this.getActiveSpectrum().plotInt(pw); } else { var test = pw.Model.Series.Where(s => s.Title.Contains("Integral")); if (test.Count() != 0) { pw.Model.Series.Remove(test.First()); } this.getActiveSpectrum().showInt = false; pw.InvalidatePlot(); pw.rescale(); this.IntButton.Foreground = Brushes.Black; } }
private void SubmitButton_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; btn.IsEnabled = false; //remove existing sim var test = plotView.Model.Series.Where(s => s.Title.Contains("Simulation")); if (test.Count() != 0) { plotView.Model.Series.Remove(test.First()); } this.ExpTBlock.Text = "Experimental Data: \nFrequency: " + exp.frequency + " GHz \nRange: " + this.spc.getX().First() + " - " + this.spc.getX().Last() + " mT\nResolution: " + this.spc.getX().Length + " Points\nTemperature: " + this.exp.Temperature + " K"; NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; double Spin = getSpin(); double[] g = Array.ConvertAll(TB_gVal.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture)); double[] A = new double[] { }; if (TB_HFCoup.Text.Length != 0) { A = Array.ConvertAll(TB_HFCoup.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture)); } double[] D = new double[] { }; if (TB_ZFS.Text.Length != 0) { D = Array.ConvertAll(TB_ZFS.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture)); } string[] Nucs = new string[] { }; if (TB_Nucs.Text.Length != 0) { Nucs = TB_Nucs.Text.Split(','); } int[] N = new int[] { }; if (TB_NucsN.Text.Length != 0) { N = Array.ConvertAll(TB_NucsN.Text.Split(','), i => Convert.ToInt32(i, CultureInfo.InvariantCulture)); } this.ExpTBlock.Text += "\n\nSimulation Parameters:\nSpin: " + Spin + "\ng-Values: " + String.Join(",", g.Select(p => p.ToString(nfi)).ToArray()); this.ExpTBlock.Text += "\nNucs: " + String.Join(",", Nucs.Select(p => p.ToString(nfi)).ToArray()); this.ExpTBlock.Text += "\nA: " + String.Join(",", A.Select(p => p.ToString(nfi)).ToArray()); double lw = 0; double[] gStrain = new double[] { }; if (Spin <= 0.5) { lw = Convert.ToDouble(TB_lw.Text, nfi); this.ExpTBlock.Text += "\nn: " + TB_NucsN.Text + "\nlw: " + lw; } else { if (TB_lw.Text.Length != 0) { this.ExpTBlock.Text += "\nD: " + String.Join(",", D.Select(p => p.ToString(nfi)).ToArray()); gStrain = Array.ConvertAll(TB_lw.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture)); this.ExpTBlock.Text += "\ngStrain: " + String.Join(",", gStrain.Select(p => p.ToString(nfi)).ToArray()); } } string additional = ""; if (ToggleAdditional.IsChecked == true) { additional = TB_Additional.Text; this.ExpTBlock.Text += "\nAddtional Parameters: \n" + additional; } Sys sys; //garlic mode if (Spin <= 0.5) { sys = new Sys(Spin, g, A, Nucs, N, lw, additional); Task.Factory.StartNew(() => { double[] y = AddSim(sys, this.exp, spc); Dispatcher.Invoke(() => { LineSeries se = new LineSeries { ItemsSource = BPUtil.getDataPoints(spc.getX(), y), Title = "Simulation" }; plotView.Model.Series.Add(se); plotView.InvalidatePlot(); plotView.rescale(); btn.IsEnabled = true; }); }); this.ExpTBlock.Text += "\nMode is garlic"; } //pepper mode else { sys = new Sys(Spin, g, D, A, gStrain, Nucs, additional); Task.Factory.StartNew(() => { double[] y = AddSim(sys, this.exp, spc); Dispatcher.Invoke(() => { LineSeries se = new LineSeries { ItemsSource = BPUtil.getDataPoints(spc.getX(), y), Title = "Simulation" }; plotView.Model.Series.Add(se); plotView.InvalidatePlot(); plotView.rescale(); btn.IsEnabled = true; }); }); this.ExpTBlock.Text += "\nMode is pepper"; } //save sim-File string filename = spc.fileName + ".sim"; using (StreamWriter sw = File.CreateText(filename)) { JsonSerializer json = new JsonSerializer(); json.Serialize(sw, sys); this.ExpTBlock.Text += "\n\nParameters saved to " + filename; } }
public PlottableEPRSpectrum plotEPR(EPRPlotView plotView) { PlotModel pm = new PlotModel(); pm.IsLegendVisible = true; pm.LegendPosition = LegendPosition.RightTop; pm.DefaultFontSize = 14; pm.LegendFontSize = 14; LineSeries se = new LineSeries { ItemsSource = BPUtil.getDataPoints(getX(), getY()), Title = this.getTitle() }; LinearAxis x = new LinearAxis { Position = AxisPosition.Bottom, Title = "B/" + unit }; pm.PlotAreaBorderThickness = new OxyThickness(1.5); x.MajorGridlineThickness = 1.5; x.MinorGridlineThickness = 1.5; x.AbsoluteMaximum = getX().Last(); x.AbsoluteMinimum = getX().First(); LinearAxis y = new LinearAxis { Position = AxisPosition.Left }; y.IsAxisVisible = false; LinkedAxis g = new LinkedAxis(x, calcG, calcB); g.Position = AxisPosition.Top; g.Title = "g"; g.MajorGridlineThickness = 1.5; g.MinorGridlineThickness = 1.5; pm.Series.Add(se); pm.Axes.Add(x); pm.Axes.Add(y); pm.Axes.Add(g); //rescale y.AbsoluteMaximum = getY().Max() + getY().Max() * 0.1; y.AbsoluteMinimum = getY().Min() + getY().Min() * 0.1; //full zoom out on y scale y.Zoom(y.AbsoluteMinimum, y.AbsoluteMaximum); plotView.InvalidatePlot(); //sync bool isc = false; x.AxisChanged += (s, e) => { if (isc) { return; } isc = true; g.Zoom(calcG(x.ActualMinimum), calcG(x.ActualMaximum)); pm.InvalidatePlot(false); isc = false; }; g.AxisChanged += (s, e) => { if (isc) { return; } isc = true; x.Zoom(calcB(g.ActualMinimum), calcB(g.ActualMaximum)); pm.InvalidatePlot(false); isc = false; }; pm.MouseDown += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseDown(s, e); pm.MouseMove += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseMove(s, e); pm.MouseUp += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseUp(s, e); plotView.Model = pm; plotView.spc = this; return(this); }