public override double[] Calculate(IReadOnlyList <double> raw, ArgsCorrection args) { object[] inputs = { raw }; object[] parameters = args.Parameters; return(Arr.Instance.RunScriptDoubleV(_script, inputs, parameters).ToArray()); }
internal FrmEditConfigurationCorrection(Core core, ArgsCorrection def, bool readOnly, Peak previewPeak) { this.InitializeComponent(); UiControls.SetIcon(this); this._lblPreviewTitle.BackColor = UiControls.PreviewBackColour; this._lblPreviewTitle.ForeColor = UiControls.PreviewForeColour; this._flpPreviewButtons.BackColor = UiControls.PreviewBackColour; this._flpPreviewButtons.ForeColor = UiControls.PreviewForeColour; this._core = core; this._readOnly = readOnly; this._selectedPeak = previewPeak; // Charts this._chartOrig = new ChartHelperForPeaks(null, this._core, this.panel1); this._chartChanged = new ChartHelperForPeaks(null, this._core, this.panel2); // Choicelists this._ecbFilter = DataSet.ForObsFilter(core).CreateComboBox(this._lstFilter, this._btnFilter, EditableComboBox.EFlags.IncludeAll); this._ecbMethod = DataSet.ForTrendAndCorrectionAlgorithms(core).CreateComboBox(this._lstMethod, this._btnNewStatistic, EditableComboBox.EFlags.None); this._ecbTypes = DataSet.ForGroups(this._core).CreateComboBox(this._lstTypes, this._btnEditTypes, EditableComboBox.EFlags.None); this._ecbSource = DataSet.ForMatrixProviders(this._core).CreateComboBox(this._lstSource, this._btnSource, EditableComboBox.EFlags.None); // Buttons this.GenerateTypeButtons(); // Default if (def != null) { this._txtName.Text = def.OverrideDisplayName; this._txtParameters.Text = AlgoParameterCollection.ParamsToReversableString(def.Parameters, core); this._ecbMethod.SelectedItem = def.GetAlgorithmOrNull(); this._comments = def.Comment; if (def.IsUsingTrend) { this._radBatch.Checked = def.Mode == ECorrectionMode.Batch; this._radType.Checked = def.Mode == ECorrectionMode.Control; this._radDivide.Checked = def.Method == ECorrectionMethod.Divide; this._radSubtract.Checked = def.Method == ECorrectionMethod.Subtract; this._ecbTypes.SelectedItem = def.ControlGroup; this._ecbFilter.SelectedItem = def.Constraint; } } this.CheckAndChange(); if (readOnly) { UiControls.MakeReadOnly(this, this._tlpPreview); } }
internal static ArgsCorrection Show(Form owner, Core core, ArgsCorrection def, bool readOnly) { using (FrmEditConfigurationCorrection frm = new FrmEditConfigurationCorrection(core, def, readOnly, FrmMain.SearchForSelectedPeak(owner))) { if (UiControls.ShowWithDim(owner, frm) == DialogResult.OK) { return(frm.GetSelection()); } return(null); } }
void CheckAndChange() { AlgoBase trend = (AlgoBase)this._ecbMethod.SelectedItem; bool paramsVisible = trend != null && trend.Parameters.HasCustomisableParams; this._lblParams.Visible = paramsVisible; this._txtParameters.Visible = paramsVisible; this._btnEditParameters.Visible = paramsVisible; this._lblParams.Text = paramsVisible ? trend.Parameters.ParamNames() : "Parameters"; bool usingTrend = trend is TrendBase; bool correctorVisible = usingTrend; this._lblCorrector.Visible = correctorVisible; this.tableLayoutPanel3.Visible = correctorVisible; this._lstTypes.Visible = correctorVisible && this._radType.Checked; this._btnEditTypes.Visible = correctorVisible; this._btnBatchInfo2.Visible = correctorVisible; bool filterVisible = correctorVisible && this._radBatch.Checked; this._lblSepFilter.Visible = filterVisible; this._lblAVec.Visible = filterVisible; this._ecbFilter.Visible = filterVisible; bool operatorVisible = correctorVisible && ((this._radType.Checked && this._ecbTypes.HasSelection) || this._radBatch.Checked); this._lblCorrector2.Visible = operatorVisible; this.tableLayoutPanel4.Visible = operatorVisible; bool readyToGo = (usingTrend && operatorVisible && (this._radDivide.Checked || this._radSubtract.Checked)) || (!usingTrend); ArgsCorrection sel = this.GetSelection(); this._txtName.Watermark = sel != null ? sel.DefaultDisplayName : Resx.Texts.default_name; bool valid = sel != null; this._tlpPreview.Visible = valid; this._btnOk.Enabled = valid; this._flpGroupButtons.Visible = (!usingTrend || this._radType.Checked); this._flpBatchButtons.Visible = (usingTrend && this._radBatch.Checked); if (valid) { this.GeneratePreview(sel); } }
public override double[] Calculate(IReadOnlyList <double> raw, ArgsCorrection args) { double c = (double)args.Parameters[0]; double[] result = new double[raw.Count]; for (int index = 0; index < result.Length; index++) { double v = raw[index]; if (double.IsNaN(v) || double.IsInfinity(v)) { result[index] = c; } else { result[index] = v; } } return(result); }
/// <summary> /// Generates the preview image. /// </summary> /// <param name="sel">Correction to generate the preview for</param> private void GeneratePreview(ArgsCorrection sel) { // No error unless otherwise this._lnkError.Visible = false; // No selection, no preview if (sel == null) { this.SetPreviewError("Nothing to preview", null); return; } // No peak, no preview if (this._selectedPeak == null) { this.SetPreviewError("No peak selected", null); return; } // Title this._lblPreviewTitle.Text = "Preview (" + this._selectedPeak.DisplayName + ")"; // Get source matrix IntensityMatrix source = sel.SourceProvider?.Provide; if (source == null) { this.SetPreviewError(StrRes.NoPreview, StrRes.MissingSourceDetails(sel)); return; } // Get vectors Vector original = source.Find(this._selectedPeak); Vector trend; Vector corrected; ConfigurationCorrection temp = new ConfigurationCorrection() { Args = sel }; try { IReadOnlyList <ObservationInfo> order; double[] trendData = temp.ExtractTrend(this._core, original.Values, out order); trend = (trendData != null) ? new Vector(trendData, original.Header, order.Select(z => new IntensityMatrix.ColumnHeader(z)).ToArray()) : null; corrected = new Vector(temp.Calculate(this._core, original.Values), original.Header, original.ColHeaders); } catch (Exception ex) { this._chartOrig.Plot(null); this._chartChanged.Plot(null); this._lnkError.Text = StrRes.PreviewError; this._lnkError.Tag = ex.ToString(); this._lnkError.Visible = true; return; } // Special flag for batch ordering bool isBatchMode; if (sel.IsUsingTrend) { isBatchMode = sel.Mode == ECorrectionMode.Batch; } else { isBatchMode = false; } // Create displays StylisedPeak oldDisplay = new StylisedPeak(this._selectedPeak) { OverrideDefaultOptions = new StylisedPeakOptions(this._core) { ShowAcqisition = isBatchMode, ViewBatches = this._vBatches, ViewGroups = this._vTypes, ConditionsSideBySide = true, ShowPoints = true, ShowTrend = sel.IsUsingTrend, ShowRanges = false, }, ForceTrend = trend }; StylisedPeak newDisplay = new StylisedPeak(this._selectedPeak) { OverrideDefaultOptions = oldDisplay.OverrideDefaultOptions.Clone(), ForceObservations = corrected }; newDisplay.OverrideDefaultOptions.ShowTrend = false; // Draw it! this._chartOrig.Plot(oldDisplay); this._chartChanged.Plot(newDisplay); }
private ArgsCorrection GetSelection() { this._checker.Clear(); IMatrixProvider source = this._ecbSource.SelectedItem; this._checker.Check(this._ecbSource.ComboBox, source != null, "Select a source"); // Algo AlgoBase algo = this._ecbMethod.SelectedItem; // Params object[] parameters; if (algo != null) { string error; parameters = algo.Parameters.TryStringToParams(this._core, this._txtParameters.Text, out error); this._checker.Check(this._txtParameters, parameters != null, error ?? "error"); } else { parameters = null; this._checker.Check(this._ecbMethod.ComboBox, false, "Select a correction method"); } if (algo is TrendBase) { // Method ECorrectionMethod met; if (this._radSubtract.Checked) { met = ECorrectionMethod.Subtract; } else if (this._radDivide.Checked) { met = ECorrectionMethod.Divide; } else { this._checker.Check(this._radSubtract, false, "Select a method"); this._checker.Check(this._radDivide, false, "Select a method"); met = default(ECorrectionMethod); } // Mode ECorrectionMode mode; GroupInfo controlGroup; ObsFilter filter; if (this._radBatch.Checked) { mode = ECorrectionMode.Batch; controlGroup = null; this._checker.Check(this._ecbFilter.ComboBox, this._ecbFilter.HasSelection, "Select a filter"); filter = this._ecbFilter.SelectedItem; } else if (this._radType.Checked) { mode = ECorrectionMode.Control; controlGroup = this._ecbTypes.SelectedItem; filter = null; } else { this._checker.Check(this._radBatch, false, "Select a mode"); this._checker.Check(this._radType, false, "Select a mode"); controlGroup = default(GroupInfo); filter = default(ObsFilter); mode = default(ECorrectionMode); } if (this._checker.HasErrors) { return(null); } ArgsCorrection args = new ArgsCorrection(((TrendBase)algo).Id, source, parameters, mode, met, controlGroup, filter) { OverrideDisplayName = this._txtName.Text, Comment = this._comments }; return(args); } else if (algo is CorrectionBase) { if (this._checker.HasErrors) { return(null); } ArgsCorrection args = new ArgsCorrection(((CorrectionBase)algo).Id, source, parameters, ECorrectionMode.None, ECorrectionMethod.None, null, null) { OverrideDisplayName = this._txtName.Text, Comment = this._comments }; return(args); } else { return(null); } }