示例#1
0
        public async Task FitSingleProfile(FittingProfile profile)
        {
            var d_data = WideScan.GetRestrictedData(profile.RangeBegin, profile.RangeEnd).Differentiate(_differentialWindow);

            var fitting_results = new FittingProfile.FittingResult();

            // キーはサイクル数.
            EqualIntervalData target_data = new EqualIntervalData();

            // 1.まず,フィッティングの計算を行う.
            {
                #region  固定参照スペクトルを取得する。(一時的にコメントアウト中)

                /*
                 * List<decimal> fixed_data = new List<decimal>();
                 * if (FixedSpectra.Count > 0)
                 * {
                 *      var v_data = await FixedSpectra.ForEachAsync(
                 *              async sp => await sp.GetShiftedDataAsync(d_data.Parameter, 3), 10);
                 *
                 *      for (int j = 0; j < v_data.First().Count; j++)
                 *      {
                 *              fixed_data.Add(v_data.Sum(one => one[j]));
                 *      }
                 * }
                 */
                #endregion

                /// フィッティング対象となるデータ。すなわち、もとのデータからFixされた分を差し引いたデータ。
                //var target_data = fixed_data.Count > 0 ? data.Substract(fixed_data) : data;
                // なんだけど、とりあえずはFixedを考慮しない。
                target_data = d_data.Data;

                //fitting_tasks.Add(i, profile.FitOneCycle(i, target_data[i], d_data.Parameter));
                fitting_results = profile.FitOneCycle(-1, target_data, d_data.Parameter);
            }

            // 2.その後に,チャート出力を行う?

            Gnuplot charts = await Output(d_data.Parameter, profile, target_data, fitting_results);


            // pltファイルも出力してみる。
            using (var writer = new StreamWriter(GetCsvFileName(profile.Name, -1) + ".plt"))
            {
                await charts.OutputPltFileAsync(writer);
            }
            // チャートを描画する。
            await charts.Draw();
        }
示例#2
0
        /// <summary>
        /// 具体的なチャートの設定を行います.
        /// </summary>
        /// <param name="cycle"></param>
        /// <param name="result"></param>
        /// <param name="profile"></param>
        /// <param name="outputConvolution"></param>
        /// <returns></returns>
        public Gnuplot ConfigureChart(FittingProfile.FittingResult result, FittingProfile profile, bool outputConvolution, int cycle = -1)
        {
            string chart_ext = string.Empty;

            switch (FittingCondition.ChartFormat)
            {
            case ChartFormat.Png:
                chart_ext = ".png";
                break;

            case ChartFormat.Svg:
                chart_ext = ".svg";
                break;
            }

            var chart_destination = Path.Combine(FittingCondition.OutputDestination, $"{profile.Name}{(cycle >= 0 ? string.Format("_{0}", cycle) : string.Empty)}{chart_ext}");

            #region チャート設定
            var gnuplot = new Gnuplot
            {
                Format      = FittingCondition.ChartFormat,
                Width       = 800,
                Height      = 600,
                FontScale   = 1.6,
                Destination = chart_destination,
                XTitle      = "Kinetic Energy / eV",
                YTitle      = "dN(E)/dE",
                Title       = (cycle >= 0 ? $"Cycle {cycle} , " : string.Empty) + $"Shift {result.Shift} eV"
            };

            var source_csv = GetCsvFileName(profile.Name, cycle);

            gnuplot.DataSeries.Add(new LineChartSeries
            {
                SourceFile = source_csv,
                XColumn    = 1,
                YColumn    = 2,
                Title      = "data",
                Style      = new LineChartSeriesStyle(LineChartStyle.Lines)
                {
                    Style = new LinePointStyle
                    {
                        LineColor = "#FF0000",
                        LineWidth = 3,
                    }
                }
            });

            var reference_names = profile.ReferenceSpectra.Select(r => r.Name).ToList();
            for (int j = 0; j < reference_names.Count; j++)
            {
                gnuplot.DataSeries.Add(new LineChartSeries
                {
                    SourceFile = source_csv,
                    XColumn    = 1,
                    YColumn    = j + 3,
                    Title      = $"{result.Gains[j].ToString("f3")} * {reference_names[j]}",
                    Style      = new LineChartSeriesStyle(LineChartStyle.Lines)
                    {
                        Style = new LinePointStyle
                        {
                            LineColorIndex = j,
                            LineWidth      = 2,
                        }
                    }
                });
            }

            if (outputConvolution)
            {
                gnuplot.DataSeries.Add(new LineChartSeries
                {
                    SourceFile = source_csv,
                    XColumn    = 1,
                    YColumn    = reference_names.Count + 3,
                    Title      = "Convolution",
                    Style      = new LineChartSeriesStyle(LineChartStyle.Lines)
                    {
                        Style = new LinePointStyle
                        {
                            LineColor = "#0000FF",
                            LineWidth = 3,
                        }
                    }
                });
            }
            #endregion

            gnuplot.PreConfigureAxis();

            return(gnuplot);
        }