/// <summary> /// Fits the equivalent circuit. /// </summary> /// <param name="circuitModel">The circuit model.</param> /// <param name="fitOptions">The fit options.</param> /// <param name="fitProgress">The fit progress.</param> /// <returns></returns> /// <exception cref="Exception"> /// Wait untill SimpleCurve is finished before detecting peaks /// or /// No impedimetric readings available in parent SimpleMeasurement /// or /// The circuit model must be defined /// </exception> public async Task <FitResult> FitEquivalentCircuit(CircuitModel circuitModel, FitOptionsCircuit fitOptions = null, FitProgress fitProgress = null) { if (!IsFinished) { throw new Exception("Wait untill SimpleCurve is finished before detecting peaks"); } if (_simpleMeasurement.Measurement.nEISdata == 0) { throw new Exception("No impedimetric readings available in parent SimpleMeasurement"); } if (circuitModel == null) { throw new Exception("The circuit model must be defined"); } if (fitOptions == null) { fitOptions = new FitOptionsCircuit(); fitOptions.Model = circuitModel; fitOptions.RawData = _simpleMeasurement.Measurement.EISdata[0]; } FitAlgorithm fit = FitAlgorithm.FromAlgorithm(fitOptions); return(await fit.ApplyFitCircuitAsync(fitProgress)); }
/// <summary> /// Fits the equivalent circuit. /// </summary> /// <param name="cdc">The circuit descriptor code (CDC) defining the circuit.</param> /// <param name="initialParameters">The initial parameters.</param> /// <param name="fitOptions">The fit options.</param> /// <param name="fitProgress">The fit progress.</param> /// <returns></returns> /// <exception cref="Exception"> /// Wait untill SimpleCurve is finished before detecting peaks /// or /// No impedimetric readings available in parent SimpleMeasurement /// </exception> /// <exception cref="ArgumentNullException">The circuit descriptor code (cdc) must be specified</exception> /// <exception cref="ArgumentException"> /// Invalid circuit descriptor code (cdc) /// or /// The amount of parameters in the model does not match the number of parameters specified in the initial parameter array /// </exception> public async Task <FitResult> FitEquivalentCircuit(string cdc, double[] initialParameters = null, FitOptionsCircuit fitOptions = null, FitProgress fitProgress = null) { if (!IsFinished) { throw new Exception("Wait untill SimpleCurve is finished before fitting equivalent circuits"); } if (_simpleMeasurement.Measurement.nEISdata == 0) { throw new Exception("No impedimetric readings available in parent SimpleMeasurement"); } if (string.IsNullOrEmpty(cdc)) { throw new ArgumentNullException("The circuit descriptor code (cdc) must be specified"); } CircuitModel circuitModel = new CircuitModel(); circuitModel.SetEISdata(_simpleMeasurement.Measurement.EISdata[0]); //Sets reference to measured data try { circuitModel.SetCircuit(cdc); //Sets the circuit defined in the CDC code string, in this case a Randles circuit } catch { throw new ArgumentException("Invalid circuit descriptor code (cdc)"); } if (initialParameters != null) { if (circuitModel.InitialParameters.Count != initialParameters.Length) { throw new ArgumentException("The amount of parameters in the model does not match the number of parameters specified in the initial parameter array"); } circuitModel.SetInitialParameters(initialParameters); } return(await FitEquivalentCircuit(circuitModel, fitOptions, fitProgress)); }