public string Plot(IPlotParameters plotParameters) { var parameters = (SpectralPlotParameters)plotParameters; var xyPoints = new List <Point>(); foreach (var wv in parameters.Wavelengths) { switch (parameters.SpectralPlotType) { case SpectralPlotType.Mua: xyPoints.Add(new Point(wv, parameters.Tissue.GetMua(wv))); break; case SpectralPlotType.Musp: xyPoints.Add(new Point(wv, parameters.Tissue.GetMusp(wv))); break; } } var plotData = new PlotData { Data = xyPoints, Label = parameters.TissueType }; var plot = new Plots { Id = "Spectral" + parameters.SpectralPlotType, PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = parameters.TissueType + " " + parameters.PlotName }); return(JsonConvert.SerializeObject(plot)); }
public string GetPlot(PlotType plotType, IPlotParameters plotParameters) { switch (plotType) { case PlotType.SolutionDomain: var plotSolutionDomainResultsService = _serviceProvider.GetService <PlotSolutionDomainResultsService>(); return(plotSolutionDomainResultsService.Plot((SolutionDomainPlotParameters)plotParameters)); case PlotType.Spectral: var plotSpectralResultsService = _serviceProvider.GetService <PlotSpectralResultsService>(); return(plotSpectralResultsService.Plot((SpectralPlotParameters)plotParameters)); default: return(null); } }
public string Plot(IPlotParameters plotParameters) { var msg = ""; var parameters = (SolutionDomainPlotParameters)plotParameters; var fs = parameters.ForwardSolverType; var op = parameters.OpticalProperties; var xAxis = parameters.XAxis; var noise = parameters.NoiseValue; var independentAxis = parameters.IndependentAxes.Label; var independentValue = parameters.IndependentAxes.Value; var independentValues = xAxis.AsEnumerable().ToArray(); try { IEnumerable <double> doubleResults; IEnumerable <Complex> complexResults; double[] xs; IEnumerable <Point> xyPoints, xyPointsReal, xyPointsImaginary; PlotData plotData, plotDataReal, plotDataImaginary; Plots plot; switch (parameters.SolutionDomain) { case SolutionDomainType.ROfRho: doubleResults = ROfRho(fs, op, xAxis, noise); xs = independentValues; xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfRho" }; plot = new Plots { Id = "ROfRho", Detector = "R(ρ)", Legend = "R(ρ)", XAxis = "ρ", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp }); msg = JsonConvert.SerializeObject(plot); break; case SolutionDomainType.ROfRhoAndTime: if (independentAxis == "t") { var time = independentValue; doubleResults = ROfRhoAndTime(fs, op, xAxis, time, noise); xs = independentValues; xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfRhoAndTime" }; plot = new Plots { Id = "ROfRhoAndTimeFixedTime", Detector = "R(ρ,time)", Legend = "R(ρ,time)", XAxis = "ρ", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " t=" + time }); msg = JsonConvert.SerializeObject(plot); } else { var rho = independentValue; doubleResults = ROfRhoAndTime(fs, op, rho, xAxis, noise); xs = independentValues.ToArray(); // the Skip(1) is giving inverse problems xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfRhoAndTime" }; plot = new Plots { Id = "ROfRhoAndTimeFixedRho", Detector = "R(ρ,time)", Legend = "R(ρ,time)", XAxis = "Time", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ρ=" + rho }); msg = JsonConvert.SerializeObject(plot); } break; case SolutionDomainType.ROfRhoAndFt: if (independentAxis == "ft") { var rho = xAxis; var ft = independentValue; complexResults = ROfRhoAndFt(fs, op, rho, ft, noise).ToArray(); xs = independentValues; xyPointsReal = xs.Zip(complexResults, (x, y) => new Point(x, y.Real)); xyPointsImaginary = xs.Zip(complexResults, (x, y) => new Point(x, y.Imaginary)); plotDataReal = new PlotData { Data = xyPointsReal, Label = "ROfRhoAndFt" }; plotDataImaginary = new PlotData { Data = xyPointsImaginary, Label = "ROfRhoAndFt" }; plot = new Plots { Id = "ROfRhoAndFtFixedFt", Detector = "R(ρ,ft)", Legend = "R(ρ,ft)", XAxis = "ρ", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotDataReal.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ft=" + ft + "(real)" }); plot.PlotList.Add(new PlotDataJson { Data = plotDataImaginary.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ft=" + ft + "(imag)" }); msg = JsonConvert.SerializeObject(plot); } else { var rho = independentValue; complexResults = ROfRhoAndFt(fs, op, rho, xAxis, noise).ToArray(); xs = independentValues; xyPointsReal = xs.Zip(complexResults, (x, y) => new Point(x, y.Real)); xyPointsImaginary = xs.Zip(complexResults, (x, y) => new Point(x, y.Imaginary)); var realPlot = new PlotData { Data = xyPointsReal, Label = "ROfRhoAndFt" }; var imagPlot = new PlotData { Data = xyPointsImaginary, Label = "ROfRhoAndFt" }; var rhoPlot = new Plots { Id = "ROfRhoAndFtFixedRho", Detector = "R(ρ,ft)", Legend = "R(ρ,ft)", XAxis = "ft", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; rhoPlot.PlotList.Add(new PlotDataJson { Data = realPlot.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ρ=" + rho + "(real)" }); rhoPlot.PlotList.Add(new PlotDataJson { Data = imagPlot.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ρ=" + rho + "(imag)" }); msg = JsonConvert.SerializeObject(rhoPlot); } break; case SolutionDomainType.ROfFx: doubleResults = ROfFx(fs, op, xAxis, noise); xs = independentValues; xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfFx" }; plot = new Plots { Id = "ROfFx", Detector = "R(fx)", Legend = "R(fx)", XAxis = "fx", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp }); msg = JsonConvert.SerializeObject(plot); break; case SolutionDomainType.ROfFxAndTime: if (independentAxis == "t") { var time = independentValue; doubleResults = ROfFxAndTime(fs, op, xAxis, time, noise); xs = independentValues; xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfFxAndTime" }; plot = new Plots { Id = "ROfFxAndTimeFixedTime", Detector = "R(fx,time)", Legend = "R(fx,time)", XAxis = "fx", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " t=" + time }); msg = JsonConvert.SerializeObject(plot); } else { var fx = independentValue; doubleResults = ROfFxAndTime(fs, op, fx, xAxis, noise); xs = independentValues; xyPoints = xs.Zip(doubleResults, (x, y) => new Point(x, y)); plotData = new PlotData { Data = xyPoints, Label = "ROfFxAndTime" }; plot = new Plots { Id = "ROfFxAndTimeFixedFx", Detector = "R(fx,time)", Legend = "R(fx,time)", XAxis = "Time", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ρ=" + fx }); msg = JsonConvert.SerializeObject(plot); } break; case SolutionDomainType.ROfFxAndFt: if (independentAxis == "ft") { var ft = independentValue; complexResults = ROfFxAndFt(fs, op, xAxis, ft, noise).ToArray(); xs = independentValues; xyPointsReal = xs.Zip(complexResults, (x, y) => new Point(x, y.Real)); xyPointsImaginary = xs.Zip(complexResults, (x, y) => new Point(x, y.Imaginary)); plotDataReal = new PlotData { Data = xyPointsReal, Label = "ROfFxAndFt" }; plotDataImaginary = new PlotData { Data = xyPointsImaginary, Label = "ROfFxAndFt" }; plot = new Plots { Id = "ROfFxAndFtFixedFt", Detector = "R(fx,ft)", Legend = "R(fx,ft)", XAxis = "fx", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotDataReal.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ft=" + ft + "(real)" }); plot.PlotList.Add(new PlotDataJson { Data = plotDataImaginary.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " ft=" + ft + "(imag)" }); msg = JsonConvert.SerializeObject(plot); } else { var fx = independentValue; complexResults = ROfFxAndFt(fs, op, fx, xAxis, noise).ToArray(); xs = independentValues; xyPointsReal = xs.Zip(complexResults, (x, y) => new Point(x, y.Real)); xyPointsImaginary = xs.Zip(complexResults, (x, y) => new Point(x, y.Imaginary)); plotDataReal = new PlotData { Data = xyPointsReal, Label = "ROfFxAndFt" }; plotDataImaginary = new PlotData { Data = xyPointsImaginary, Label = "ROfFxAndFt" }; plot = new Plots { Id = "ROfFxAndFtFixedFx", Detector = "R(fx,ft)", Legend = "R(fx,ft)", XAxis = "ft", YAxis = "Reflectance", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotDataReal.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " fx=" + fx + "(real)" }); plot.PlotList.Add(new PlotDataJson { Data = plotDataImaginary.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = fs + " μa=" + op.Mua + " μs'=" + op.Musp + " fx=" + fx + "(imag)" }); msg = JsonConvert.SerializeObject(plot); } break; } return(msg); } catch (Exception e) { _logger.LogError("An error occurred: {Message}", e.Message); throw; } }
public string Plot(IPlotParameters plotParameters) { var parameters = (SolutionDomainPlotParameters)plotParameters; var fs = parameters.ForwardSolverType; var op = parameters.OpticalProperties; var independentValue = parameters.IndependentAxes.Value; var independentValues = parameters.XAxis.AsEnumerable().ToArray(); try { Plots plot; var parametersInOrder = _parameterTools.GetParametersInOrder( _parameterTools.GetOpticalPropertiesObject(parameters.OpticalProperties), plotParameters.XAxis.AsEnumerable().ToArray(), parameters.SolutionDomain, parameters.IndependentAxes.Label, parameters.IndependentAxes.Value); var parametersInOrderObject = parametersInOrder.Values.ToArray(); var reflectance = parameters.NoiseValue > 0 ? ComputationFactory.ComputeReflectance(fs, parameters.SolutionDomain, parameters.ModelAnalysis, parametersInOrderObject).AddNoise(parameters.NoiseValue) : ComputationFactory.ComputeReflectance(fs, parameters.SolutionDomain, parameters.ModelAnalysis, parametersInOrderObject); var isComplex = ComputationFactory.IsComplexSolver(parameters.SolutionDomain); var hasIndependentAxis = parameters.SolutionDomain != SolutionDomainType.ROfFx && parameters.SolutionDomain != SolutionDomainType.ROfRho; if (!isComplex) { var xyPoints = independentValues.Zip(reflectance, (x, y) => new Point(x, y)); var plotData = new PlotData { Data = xyPoints, Label = parameters.SolutionDomain.ToString() }; plot = new Plots { Id = hasIndependentAxis ? $"{parameters.SolutionDomain.ToString()}Fixed{parameters.IndependentAxes.Label}" : $"{parameters.SolutionDomain.ToString()}", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotData.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = hasIndependentAxis ? $"{fs} μa={op.Mua} μs'={op.Musp} {parameters.IndependentAxes.Label}={parameters.IndependentAxes.Value}" : $"{fs} μa={op.Mua} μs'={op.Musp}" }); } else { var offset = reflectance.Length / 2; IEnumerable <ComplexPoint> xyPointsComplex = independentValues.Zip(reflectance, (x, y) => new ComplexPoint(x, new Complex(y, reflectance[Array.IndexOf(reflectance, y) + offset]))).ToArray(); var xyPointsReal = xyPointsComplex.Select(item => new Point(item.X, item.Y.Real)); var xyPointsImaginary = xyPointsComplex.Select(item => new Point(item.X, item.Y.Imaginary)); var plotDataReal = new PlotData { Data = xyPointsReal, Label = parameters.SolutionDomain.ToString() }; var plotDataImaginary = new PlotData { Data = xyPointsImaginary, Label = parameters.SolutionDomain.ToString() }; plot = new Plots { Id = $"{parameters.SolutionDomain.ToString()}Fixed{parameters.IndependentAxes.Label}", PlotList = new List <PlotDataJson>() }; plot.PlotList.Add(new PlotDataJson { Data = plotDataReal.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = $"{fs} μa={op.Mua} μs'={op.Musp} {parameters.IndependentAxes.Label}={independentValue}(real)" }); plot.PlotList.Add(new PlotDataJson { Data = plotDataImaginary.Data.Select(item => new List <double> { item.X, item.Y }).ToList(), Label = $"{fs} μa={op.Mua} μs'={op.Musp} {parameters.IndependentAxes.Label}={independentValue}(imag)" }); } var msg = JsonConvert.SerializeObject(plot); return(msg); } catch (Exception e) { _logger.LogError("An error occurred: {Message}", e.Message); throw; } }