Esempio n. 1
0
        public static PlotModel CreatePeaks(OxyPalette palette = null, bool includeContours = true, int n = 100)
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues = ArrayBuilder.CreateVector(x0, x1, n);
            var yvalues = ArrayBuilder.CreateVector(y0, y1, n);
            var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel { Title = "Peaks" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = palette ?? OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            model.Series.Add(hms);
            if (includeContours)
            {
                var cs = new ContourSeries
                             {
                                 Color = OxyColors.Black,
                                 FontSize = 0,
                                 ContourLevelStep = 1,
                                 LabelBackground = OxyColors.Undefined,
                                 ColumnCoordinates = yvalues,
                                 RowCoordinates = xvalues,
                                 Data = peaksData
                             };
                model.Series.Add(cs);
            }

            return model;
        }
        public static PlotModel Peaks()
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
               - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
               - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues = ArrayHelper.CreateVector(x0, x1, 0.03);
            var yvalues = ArrayHelper.CreateVector(y0, y1, 0.03);
            var peaksData = ArrayHelper.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel("Peaks");
            model.Axes.Add(new ColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            model.Series.Add(hms);
            var cs = new ContourSeries
                {
                    Color = OxyColors.Black,
                    FontSize = 0,
                    ContourLevelStep = 1,
                    LabelBackground = null,
                    ColumnCoordinates = yvalues,
                    RowCoordinates = xvalues,
                    Data = peaksData
                };
            model.Series.Add(cs);
            return model;
        }
Esempio n. 3
0
        public Heatmap(string title, string xTitle, string yTitle, double[,] data)
            : base(title)
        {
            var model = new PlotModel
            {
                Title = title,
            };

            OxyPalette palette = OxyPalettes.Hot(200);
            var colorAxis = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            model.Axes.Add(colorAxis);

            var xAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title = xTitle
            };
            model.Axes.Add(xAxis);

            var yAxis = new LinearAxis
            {
                Title = yTitle
            };
            model.Axes.Add(yAxis);

            var series = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };
            int width = data.GetLength(0);
            int height = data.GetLength(1);
            series.Data = new double[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    series.Data[i, j] = data[i, j];
                }
            }

            model.Series.Add(series);
            Model = model;
        }
        public static PlotModel ConfusionMatrix()
        {
            // Example provided by Pau Climent Pérez
            // See also http://en.wikipedia.org/wiki/Confusion_matrix
            var data = new double[3, 3];

            data[0, 0] = 1;
            data[1, 1] = 0.8;
            data[1, 2] = 0.2;
            data[2, 2] = 1;

            // I guess this is where the confusion comes from?
            data = data.Transpose();

            string[] cat1 = { "class A", "class B", "class C" };

            var model = new PlotModel { Title = "Confusion Matrix" };

            var palette = OxyPalette.Interpolate(50, OxyColors.White, OxyColors.Black);

            var lca = new LinearColorAxis { Position = AxisPosition.Right, Palette = palette, HighColor = OxyColors.White, LowColor = OxyColors.White };
            model.Axes.Add(lca);

            var axis1 = new CategoryAxis { Position = AxisPosition.Top, Title = "Actual class" };
            axis1.Labels.AddRange(cat1);
            model.Axes.Add(axis1);

            // We invert this axis, so that they look "symmetrical"
            var axis2 = new CategoryAxis { Position = AxisPosition.Left, Title = "Predicted class" };
            axis2.Labels.AddRange(cat1);
            axis2.Angle = -90;
            axis2.StartPosition = 1;
            axis2.EndPosition = 0;

            model.Axes.Add(axis2);

            var hms = new HeatMapSeries
            {
                Data = data,
                Interpolate = false,
                LabelFontSize = 0.25,
                X0 = 0,
                X1 = data.GetLength(1) - 1,
                Y0 = 0,
                Y1 = data.GetLength(0) - 1,
            };

            model.Series.Add(hms);
            return model;
        }
        public static PlotModel HeatMapSeries()
        {
            var model = new PlotModel { Title = "HeatMapSeries" };
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xx = ArrayBuilder.CreateVector(x0, x1, 100);
            var yy = ArrayBuilder.CreateVector(y0, y1, 100);
            var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy);

            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            model.Series.Add(hms);

            return model;
        }
Esempio n. 6
0
        public async Task <PlotModel> PlotTagOnHeatMapPlotModel(PlotModel model, Tag tag, PlotSettingsEventModel settings)
        {
            return(await Task.Run(() =>
            {
                model.Series.Clear();
                var dataPoints = ConvertIntoDataPoints(tag.TimeCoordinates, settings, 1);
                var logPoints = ConvertIntoLogScale(dataPoints, settings, 1);

                var heatMapSeries = new HeatMapSeries
                {
                    X0 = settings.XAxisMinimum,
                    X1 = settings.XAxisMaximum,
                    Y0 = settings.YAxisMinimum,
                    Y1 = settings.YAxisMaximum,
                    Interpolate = true,
                    RenderMethod = HeatMapRenderMethod.Bitmap,
                    Data = logPoints
                };

                model.Series.Add(heatMapSeries);
                return model;
            }));
        }
Esempio n. 7
0
        public void PlotDetector(Detector detector)
        {
            var model = new PlotModel();

            model.PlotType = PlotType.Cartesian;

            var sser = new OxyPlot.Series.HeatMapSeries()
            {
                X0           = detector.MinDetectorPositionMer,
                X1           = detector.MaxDetectorPositionMer,
                Y0           = detector.MinDetectorPositionSag - detector.PixelSize / 2.0,
                Y1           = detector.MaxDetectorPositionSag + detector.PixelSize / 2.0,
                Data         = detector.GetHeatMap(),
                Interpolate  = false,
                RenderMethod = HeatMapRenderMethod.Bitmap
            };

            model.Series.Add(sser);
            model.Axes.Add(new OxyPlot.Axes.LinearAxis {
                Title = "x, [mm]", Position = AxisPosition.Bottom, Maximum = detector.MaxDetectorPositionMer, Minimum = detector.MinDetectorPositionMer
            });
            model.Axes.Add(new OxyPlot.Axes.LinearAxis {
                Title = "y, [mm]", Position = AxisPosition.Left, Maximum = detector.MaxDetectorPositionSag, Minimum = detector.MinDetectorPositionSag
            });
            model.Axes.Add(new OxyPlot.Axes.LinearColorAxis {
                Position = AxisPosition.Right, Palette = OxyPalettes.Gray(1000).Reverse()
            });



            model.Axes[0].AxisChanged += DetectorPlotX_AxisChanged;
            model.Axes[1].AxisChanged += DetectorPlotY_AxisChanged;

            m_Canvas.Model = model;
            m_Canvas.InvalidatePlot(true);
        }
Esempio n. 8
0
        public static PlotModel HeatMapSeriesInterpolationColor()
        {
            var data = new double[2, 3];
            data[0, 0] = 10;
            data[0, 1] = 0;
            data[0, 2] = -10;

            var model = new PlotModel { Title = "HeatMapSeries" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = new OxyPalette(OxyColors.Red, OxyColors.Green, OxyColors.Blue) });

            var hms = new HeatMapSeries
            {
                CoordinateDefinition = HeatMapCoordinateDefinition.Center,
                X0 = 0,
                X1 = 3,
                Y0 = 0,
                Y1 = 2,
                Data = data,
                Interpolate = false,
                LabelFontSize = 0.2
            };
            model.Series.Add(hms);
            return model;
        }
        private async void createPlotModel()
        {
            await Task.Run(() =>
            {
                this.dataTable = DatabaseAccesserEcolog.GetResult(createQuery());
            });
            
            calculateEnergyParameter();
            calculateTimeParameter();

            var plotModel = new PlotModel();
            plotModel.Subtitle = "SemananticLink: " + semantciLink.Semantics + ", Direction: " + direction.Direction;
            plotModel.Title = "Semantic Matrix";

            var linearColorAxis = new LinearColorAxis();
            linearColorAxis.HighColor = OxyColors.Gray;
            linearColorAxis.LowColor = OxyColors.Black;
            linearColorAxis.Position = AxisPosition.Right;
            plotModel.Axes.Add(linearColorAxis);

            var linearAxis1 = new LinearAxis();
            linearAxis1.Title = "Time";
            linearAxis1.Unit = "s";
            linearAxis1.Position = AxisPosition.Bottom;
            plotModel.Axes.Add(linearAxis1);
            var linearAxis2 = new LinearAxis();
            linearAxis2.Title = "Lost Energy";
            linearAxis2.Unit = "kWh";
            plotModel.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries();
            heatMapSeries1.LabelFormatString = "0";
            heatMapSeries1.X0 = minExcludedTime;
            heatMapSeries1.X1 = maxExcludedTime;
            heatMapSeries1.Y0 = minExcludedEnergy;
            heatMapSeries1.Y1 = maxExcludedEnergy;
            heatMapSeries1.LabelFontSize = 0.2;
            heatMapSeries1.Data = new Double[classNumber + 1, classNumber + 1];

            int count = 0; //  for debug

            double preTimeLevel = 0;
            double currentTimeLevel = minExcludedTime;

            for (int i = 0; i < classNumber + 1; i++)
            {
                double preEnergyLevel = 0;
                double currentEnergyLevel = minExcludedEnergy;

                for (int j = 0; j < classNumber + 1; j++)
                {
                    heatMapSeries1.Data[i, j] = dataTable.AsEnumerable()
                        .Where(x => x.Field<double>("SumLostEnergy") > preEnergyLevel)
                        .Where(x => x.Field<double>("SumLostEnergy") <= currentEnergyLevel)
                        .Where(x => x.Field<int>("TIME") > preTimeLevel)
                        .Where(x => x.Field<int>("TIME") <= currentTimeLevel).Count();

                    count += (int)heatMapSeries1.Data[i, j];

                    if (j == 0)
                    {
                        preEnergyLevel = minExcludedEnergy;
                    }
                    else
                    {
                        preEnergyLevel += classWidthEnergy;
                    }

                    currentEnergyLevel += classWidthEnergy;

                }

                if (i == 0)
                {
                    preTimeLevel = minExcludedTime;
                }
                else
                {
                    preTimeLevel += classWidthTime;
                }

                currentTimeLevel += classWidthTime;
            }

            plotModel.Series.Add(heatMapSeries1);

            this.ProgressBarVisibility = System.Windows.Visibility.Collapsed;
            this.PlotModel = plotModel;

        }
Esempio n. 10
0
        public static PlotModel Diagonal2()
        {
            var data = new double[3, 3];
            data[0, 0] = 1;
            data[1, 1] = 1;
            data[2, 2] = 1;

            var model = new PlotModel { Title = "Diagonal (edge defined)" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            // adding half cellwidth/cellheight to bounding box coordinates
            var hms = new HeatMapSeries { CoordinateDefinition = HeatMapCoordinateDefinition.Edge, X0 = 0, X1 = 3, Y0 = 3, Y1 = 0, Data = data, Interpolate = false };
            model.Series.Add(hms);
            return model;
        }
Esempio n. 11
0
        public void TestSimpleCreation()
        {
            var plotModel1 = new PlotModel
            {
                PlotType = PlotType.Cartesian,
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };

            plotModel1.Axes.Add(linearColorAxis1);

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);
            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);
            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0.0,
                X1 = 1.0,
                Y0 = 0.0,
                Y1 = 1.0,
                FontSize = .2,
                Data = new Double[2, 3]
            };
            //heatMapSeries1.LabelFontSize = 0.2;
            heatMapSeries1.Data[0, 0] = 0;
            heatMapSeries1.Data[0, 1] = 10.2;
            heatMapSeries1.Data[0, 2] = 20.4;
            heatMapSeries1.Data[1, 0] = 0.1;
            heatMapSeries1.Data[1, 1] = 0.3;
            heatMapSeries1.Data[1, 2] = 0.2;
            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);

            var xml = new XmlDocument();
            xml.LoadXml(svgString);
            var x = SvgDocument.Open(xml); // Svg.SvgDocument();
            var bmp = x.Draw();
            bmp.Save(GetPath(HEATMAP_RESULTS_FOLDER_BASE + "testbmp.jpg"));

            var encoder = new PngPlotModelEncoder();
            encoder.SaveImage(plotModel1, GetPath(HEATMAP_RESULTS_FOLDER_BASE + "mine.png"));
        }
Esempio n. 12
0
        public void TestLcmsWarpAlignment(string path1, string path2, string svgPath)
        {
            // Convert relative paths to absolute paths
            path1 = GetPath(path1);
            path2 = GetPath(path2);
            svgPath = GetPath(HEATMAP_RESULTS_FOLDER_BASE + svgPath);

            var aligner = new LcmsWarpFeatureAligner();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased);

            var tolerances = new FeatureTolerances
            {
                FragmentationWindowSize = .5,
                Mass = 13,
                DriftTime = .3,
                Net = .01
            };
            var options = new LcmsFeatureFindingOptions(tolerances)
            {
                MaximumNetRange = .002
            };

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee = finder.FindFeatures(aligneeMs, options, null);
            var data = aligner.Align(baseline, alignee);

            var plotModel1 = new PlotModel
            {
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            plotModel1.Axes.Add(linearColorAxis1);

            // linearColorAxis1.

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);

            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };

            var scores = data.heatScores;
            var width = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    heatMapSeries1.Data[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);
            using (var writer = File.CreateText(svgPath + ".svg"))
            {
                writer.Write(svgString);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Creates a simple example heat map from a 2×3 matrix.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="interpolate">Interpolate the HeatMapSeries if set to <c>true</c>.</param>
        /// <returns>A <see cref="PlotModel" />.</returns>
        private static PlotModel CreateExample(string title, bool interpolate)
        {
            var data = new double[2, 3];
            data[0, 0] = 0;
            data[0, 1] = 0.2;
            data[0, 2] = 0.4;
            data[1, 0] = 0.1;
            data[1, 1] = 0.3;
            data[1, 2] = 0.2;

            var model = new PlotModel { Title = "HeatMapSeries", Subtitle = title };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            // adding half cellwidth/cellheight to bounding box coordinates
            var hms = new HeatMapSeries
            {
                CoordinateDefinition = HeatMapCoordinateDefinition.Center,
                X0 = 0.5,
                X1 = 1.5,
                Y0 = 0.5,
                Y1 = 2.5,
                Data = data,
                Interpolate = interpolate,
                LabelFontSize = 0.2
            };
            model.Series.Add(hms);
            return model;
        }
        public static PlotModel LogXNotInterpolated()
        {
            var data = new double[11, 21];

            double k = Math.Pow(2, 0.1);

            for (int i = 0; i < 11; i++)
            {
                for (int j = 0; j < 21; j++)
                {
                    data[i, j] = Math.Pow(k, (double)i) * (double)j / 40.0;
                }
            }

            var model = new PlotModel { Title = "Logarithmic X, discrete rectangles" };
            model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Gray(500), HighColor = OxyColors.White, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = 1.0, X1 = 2.0, Y0 = 0, Y1 = 20, Data = data, Interpolate = false, RenderMethod = HeatMapRenderMethod.Rectangles, LabelFontSize = 0.4 };

            model.Series.Add(hms);
            return model;
        }
        private static PlotModel Create6X4(bool transpose, string title)
        {
            var data = new double[6, 4];

            for (int i = 1; i <= 6; i++)
            {
                for (int j = 1; j <= 4; j++)
                {
                    data[i - 1, j - 1] = i * j;
                }
            }

            var model = new PlotModel { Title = title, Subtitle = "Note the positions of the axes" };

            var xaxis = new LinearAxis { Key = "x", Title = "X", Position = transpose ? AxisPosition.Left : AxisPosition.Bottom };
            var yaxis = new LinearAxis { Key = "y", Title = "Y", Position = transpose ? AxisPosition.Bottom : AxisPosition.Left };

            model.Axes.Add(xaxis);
            model.Axes.Add(yaxis);
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.White, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries { X0 = 1, X1 = 6, Y0 = 1, Y1 = 4, Data = data, Interpolate = true, LabelFontSize = 0.2 };

            hms.XAxisKey = "x";
            hms.YAxisKey = "y";

            model.Series.Add(hms);
            return model;
        }
Esempio n. 16
0
        public static PlotModel Diagonal_6X6()
        {
            var data = new double[6, 6];
            data[0, 0] = 1;
            data[1, 1] = 1;
            data[2, 2] = 1;
            data[3, 3] = 1;
            data[4, 4] = 1;
            data[5, 5] = 1;

            var model = new PlotModel { Title = "Diagonal 6×6" };
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            // note: the coordinates are specifying the centers of the edge cells
            var hms = new HeatMapSeries { X0 = 0, X1 = 5, Y0 = 5, Y1 = 0, Data = data, Interpolate = false };
            model.Series.Add(hms);
            return model;
        }
Esempio n. 17
0
        public static PlotModel TransposedHeatMap()
        {
            int n = 100;

            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
            var xvalues = ArrayBuilder.CreateVector(x0, x1, n);
            var yvalues = ArrayBuilder.CreateVector(y0, y1, n);
            var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);

            var model = new PlotModel { Title = "Normal Heatmap" };

            model.Axes.Add(
                new LinearAxis() { Key = "x_axis", AbsoluteMinimum = x0, AbsoluteMaximum = x1, Position = AxisPosition.Left });

            model.Axes.Add(
                new LinearAxis() { Key = "y_axis", AbsoluteMinimum = y0, AbsoluteMaximum = y1, Position = AxisPosition.Top });

            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });

            var hms = new HeatMapSeries
            {
                X0 = x0,
                X1 = x1,
                Y0 = y0,
                Y1 = y1,
                Data = peaksData,
                XAxisKey = "x_axis",
                YAxisKey = "y_axis"
            };
            model.Series.Add(hms);

            return model;
        }
Esempio n. 18
0
        /// <summary>
        /// Adds a peaks HeatMapSeries to the plot model.
        /// </summary>
        /// <param name="pm">The plot model.</param>
        public void AddPeaks(PlotModel pm)
        {
            double x0 = -3.1;
            double x1 = 3.1;
            double y0 = -3;
            double y1 = 3;
            var xx = ArrayHelper.CreateVector(x0, x1, 100);
            var yy = ArrayHelper.CreateVector(y0, y1, 100);
            var peaksData = ArrayHelper.Evaluate(Functions.Peaks, xx, yy);

            pm.Axes.Add(
                new LinearColorAxis
                    {
                        Position = AxisPosition.Right,
                        Palette = OxyPalettes.Jet(500),
                        HighColor = OxyColors.Gray,
                        LowColor = OxyColors.Black,
                        IsAxisVisible = false
                    });

            var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
            pm.Series.Add(hms);
        }
Esempio n. 19
0
        private void DoReloadModel(string fieldDataFile, bool isWindMap)
        {
            // Create the plot model
            PlotModel model = this.Model;

            model.PlotMargins = new OxyThickness(30, 0, 60, 30);

            model.Axes.Clear();
            model.Series.Clear();
            model.Annotations.Clear();

            string fileTitle = Path.GetFileNameWithoutExtension(fieldDataFile);

            this.FileTitle = fileTitle;

            WeatherDataPalette wdp = WeatherDataPaletteFactory.GetPaletteForDataFile(fieldDataFile);
            bool contours          = wdp.ShowContours;
            bool heatmap           = wdp.ShowHeatmap;
            bool precipitationMap  = false;

            model.Title = string.Format("{0}: {1} [{2}]{3}",
                                        App.ControlPanelModel.SelectedViewport.Name,
                                        App.ControlPanelModel.SelectedDataType.Value,
                                        fileTitle,
                                        App.ControlPanelModel.SelectedDataType.Comments);

            DenseMatrix m = null;

            int minLon = App.ControlPanelModel.SelectedViewport.MinLon.Round();
            int maxLon = App.ControlPanelModel.SelectedViewport.MaxLon.Round();
            int minLat = App.ControlPanelModel.SelectedViewport.MinLat.Round();
            int maxLat = App.ControlPanelModel.SelectedViewport.MaxLat.Round();

            var fieldMatrix = FileSupport.LoadSubMatrixFromFile(fieldDataFile, minLon, maxLon, minLat, maxLat);

            bool interpolate = (fieldMatrix.RowCount < 10);

            if (interpolate)
            {
                fieldMatrix = fieldMatrix.Interpolate();
            }

            float[,] data  = null;
            float[,] data2 = null;

            float actualOffset = 0;

            if (wdp.ShowHeatmap)
            {
                float fOffset = (float)App.ControlPanelModel.Offset / 100;
                float delta   = wdp.MinMax.Delta;

                if (wdp.GetType() == typeof(C_00_Palette))
                {
                    delta = 100;
                }

                actualOffset = delta * fOffset;
            }

            if (wdp.GetType() == typeof(C_00_Palette))
            {
                // It's a map of the precipitation
                precipitationMap = true;

                string t01File = fieldDataFile.Replace("C_00", "T_01");
                string teFile  = fieldDataFile.Replace("C_00", "T_TE");
                string tsFile  = fieldDataFile.Replace("C_00", "T_TS");

                DenseMatrix T01 = FileSupport.LoadSubMatrixFromFile(t01File, minLon, maxLon, minLat, maxLat);
                DenseMatrix TE  = FileSupport.LoadSubMatrixFromFile(teFile, minLon, maxLon, minLat, maxLat);
                DenseMatrix TS  = FileSupport.LoadSubMatrixFromFile(tsFile, minLon, maxLon, minLat, maxLat);
                DenseMatrix C00 = fieldMatrix;

                if (interpolate)
                {
                    T01 = T01.Interpolate();
                    TE  = TE.Interpolate();
                    TS  = TS.Interpolate();
                }

                float sRain         = 0;
                float sSnow         = 300;
                float sSleet        = 600;
                float sFreezingRain = 900;

                data2 = C00.Transpose().ToArray();

                m = DenseMatrix.Create(C00.RowCount, C00.ColumnCount, (r, c) =>
                {
                    float cl = Math.Abs(C00[r, c]) + actualOffset;

                    if (cl <= 0)
                    {
                        cl = 0;
                    }
                    if (cl >= 100)
                    {
                        cl = 100;
                    }


                    float t01 = T01[r, c];
                    float te  = TE[r, c];
                    float ts  = TS[r, c];

                    float precipClThreshold = 10f;
                    float actualPrecipRate  = (cl - precipClThreshold);
                    if (actualPrecipRate >= 0)
                    {
                        return(PrecipTypeComputer <float> .Compute(

                                   // Actual temperatures
                                   te, ts, t01,

                                   // Boundary temperatures as read from simulation parameters
                                   SimulationParameters.Instance,

                                   // Computed precip type: snow
                                   () => (cl + sSnow),

                                   // Computed precip type: rain
                                   () => (cl + sRain),

                                   // Computed precip type: freezing rain
                                   () => (cl + sFreezingRain),

                                   // Computed precip type: sleet
                                   () => (cl + sSleet)
                                   ));
                    }
                    else if (cl > 5)
                    {
                        // Cloudy but without precipitation.
                        return(5);
                    }

                    // Sunny
                    return(0);
                });
            }
            else
            {
                m = DenseMatrix.Create(fieldMatrix.RowCount, fieldMatrix.ColumnCount, (r, c) =>
                                       fieldMatrix[r, c]);

                m.ADD(actualOffset);
            }

            Range <float> minMax      = wdp.MinMax;
            float         lineSpacing = wdp.LineSpacing;

            m    = m.MIN(minMax.Max).MAX(minMax.Min);
            data = m.Transpose().ToArray();

            float step = interpolate ? 0.5f : 1;

            List <float> cols = new List <float>();

            for (float i = minLon; i <= maxLon; i += step)
            {
                cols.Add(i);
            }

            List <float> rows = new List <float>();

            for (float i = maxLat; i >= minLat; i -= step)
            {
                rows.Add(i);
            }


            List <float> levels = new List <float>();

            for (float i = wdp.MinMax.Min; i <= wdp.MinMax.Max; i += wdp.LineSpacing)
            {
                levels.Add(i);
            }

            var pal = OxyPalette.Interpolate(levels.Count, wdp.ColorSteps.ToArray());

            List <OxyColor> lineColors = new List <OxyColor>();

            foreach (OxyColor c in wdp.ColorSteps)
            {
                if (heatmap)
                {
                    switch (wdp.LineColor.ColorMode)
                    {
                    case Views.LineColorMode.FixedColor:
                        lineColors.Add(wdp.LineColor.Color);
                        break;

                    case Views.LineColorMode.Best_Contrast:
                        lineColors.Add(c.Complementary());
                        break;

                    case Views.LineColorMode.Black_And_White:
                    {
                        System.Drawing.Color cw = System.Drawing.Color.FromArgb(c.R, c.G, c.B);
                        float br = cw.GetBrightness();

                        if (br < 0.5f)
                        {
                            lineColors.Add(OxyColors.White);
                        }
                        else
                        {
                            lineColors.Add(OxyColors.Black);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    lineColors.Add(c);
                }
            }

            if (isWindMap)
            {
                this.FileTitle += "_WINDMAP";

                var D = (App.ControlPanelModel.SelectedViewport.MaxLon -
                         App.ControlPanelModel.SelectedViewport.MinLon);

                float hf = 1;
                if (D > 200)
                {
                    hf = 0.45f;
                }
                else if (D > 20)
                {
                    hf = 0.55f;
                }
                else
                {
                    hf = 1;
                }

                float sf = 0.9f * hf;

                DenseMatrix[] gr = fieldMatrix.ToWindComponents();
                float[,] dataX = gr[Direction.X].ToArray();
                float[,] dataY = gr[Direction.Y].ToArray();

                int rowCount = dataX.GetLength(0);
                int colCount = dataX.GetLength(1);

                for (int r = 0; r < rowCount; r++)
                {
                    for (int c = 0; c < colCount; c++)
                    {
                        float x = c + App.ControlPanelModel.SelectedViewport.MinLon;
                        float y = App.ControlPanelModel.SelectedViewport.MaxLat - r;

                        float dx = dataX[r, c];
                        float dy = -dataY[r, c];

                        int mod = (int)Math.Sqrt(dx * dx + dy * dy);

                        LineSeries line = new LineSeries();
                        line.Points.Add(new DataPoint(x, y));
                        line.Points.Add(new DataPoint(x + dx, y + dy));
                        line.StrokeThickness = 1;


                        if (mod < 2)
                        {
                            line.Color           = OxyColors.Green;
                            line.StrokeThickness = 2 * hf;
                        }
                        else if (mod < 5)
                        {
                            line.Color           = OxyColors.Red;
                            line.StrokeThickness = 2.5 * hf;
                        }
                        else
                        {
                            line.Color           = OxyColors.Magenta;
                            line.StrokeThickness = 3 * hf;
                        }

                        model.Series.Add(line);

                        ArrowAnnotation arrow = new ArrowAnnotation();
                        var             edy   = Math.Min(dy, 2);
                        arrow.StartPoint      = new DataPoint(x + sf * dx, y + sf * edy);
                        arrow.EndPoint        = new DataPoint(x + dx, y + edy);
                        arrow.Color           = line.Color;
                        arrow.StrokeThickness = line.StrokeThickness;
                        arrow.HeadWidth       = 1.5 * line.StrokeThickness;
                        arrow.HeadLength      = 3 * line.StrokeThickness;

                        model.Annotations.Add(arrow);

                        //goto MapFeatures;
                    }
                }
            }
            else
            {
                if (heatmap)
                {
                    if (precipitationMap)
                    {
                        HeatMapSeriesEx cloudMapSeries = new HeatMapSeriesEx
                        {
                            Data = data.ToDoubleArray(),
                            X0   = cols[0],
                            X1   = cols[cols.Count - 1],
                            Y0   = rows[0],
                            Y1   = rows[rows.Count - 1],
                        };
                        model.Series.Add(cloudMapSeries);
                    }
                    else
                    {
                        OxyPlot.Series.HeatMapSeries heatmapSeries = new OxyPlot.Series.HeatMapSeries
                        {
                            Data = data.ToDoubleArray(),
                            X0   = cols[0],
                            X1   = cols[cols.Count - 1],
                            Y0   = rows[0],
                            Y1   = rows[rows.Count - 1],
                        };
                        model.Series.Add(heatmapSeries);
                    }
                }

                if (contours)
                {
                    OxyPlot.Series.ContourSeries contour = new OxyPlot.Series.ContourSeries
                    {
                        ColumnCoordinates = cols.ToArray().ToDoubleArray(),
                        RowCoordinates    = rows.ToArray().ToDoubleArray(),
                        ContourLevels     = levels.ToArray().ToDoubleArray(),

                        ContourColors = lineColors.ToArray(), // Same # elements as the levels' array

                        Data = (data2 == null) ? data.ToDoubleArray() : data2.ToDoubleArray(),

                        LabelBackground  = OxyColors.Transparent,
                        ContourLevelStep = wdp.LineSpacing,
                        StrokeThickness  = wdp.LineWidth,
                        FontSize         = 15,
                        FontWeight       = 500,
                    };


                    model.Series.Add(contour);
                }
            }

MapFeatures:

            // Always do this last.
            AddMapFeatures(model, wdp, pal, isWindMap);
        }
Esempio n. 20
0
        public void TestMsFeatureScatterPlot(string path1, string path2, string pngPath)
        {
            // Convert relative paths to absolute paths
            path1 = GetPath(path1);
            path2 = GetPath(path2);
            pngPath = GetPath(pngPath);

            var fiOutput = new FileInfo(pngPath);
            var didirectory = fiOutput.Directory;
            if (didirectory == null)
                throw new DirectoryNotFoundException(pngPath);

            if (!didirectory.Exists)
                didirectory.Create();

            var aligner = new LcmsWarpFeatureAligner();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased);

            var tolerances = new FeatureTolerances
            {
                FragmentationWindowSize = .5,
                Mass = 13,
                DriftTime = .3,
                Net = .01
            };
            var options = new LcmsFeatureFindingOptions(tolerances);
            options.MaximumNetRange = .002;

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee = finder.FindFeatures(aligneeMs, options, null);
            var alignmentResults = aligner.Align(baseline, alignee);

            var plotModel1 = new PlotModel
            {
                Subtitle = "Interpolated, cartesian axes",
                Title = "HeatMapSeries"
            };

            var palette = OxyPalettes.Hot(200);
            var linearColorAxis1 = new LinearColorAxis
            {
                InvalidNumberColor = OxyColors.Gray,
                Position = AxisPosition.Right,
                Palette = palette
            };
            plotModel1.Axes.Add(linearColorAxis1);

            // linearColorAxis1.

            var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom};
            plotModel1.Axes.Add(linearAxis1);

            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries
            {
                X0 = 0,
                X1 = 1,
                Y0 = 0,
                Y1 = 1,
                FontSize = .2
            };

            var scores = alignmentResults.heatScores;
            var width = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];

            var seriesData = heatMapSeries1.Data;
            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    seriesData[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);

            var xml = new XmlDocument();
            xml.LoadXml(svgString);
            var x = SvgDocument.Open(xml); // Svg.SvgDocument();
            var bmp = x.Draw();

            bmp.Save(pngPath);

            var heatmap = HeatmapFactory.CreateAlignedHeatmap(alignmentResults.heatScores);
            var netHistogram = HistogramFactory.CreateHistogram(alignmentResults.netErrorHistogram, "NET Error", "NET Error");
            var massHistogram = HistogramFactory.CreateHistogram(alignmentResults.massErrorHistogram, "Mass Error", "Mass Error (ppm)");

            var baseName = Path.Combine(didirectory.FullName, Path.GetFileNameWithoutExtension(fiOutput.Name));

            var encoder = new SvgEncoder();
            PlotImageUtility.SaveImage(heatmap, baseName + "_heatmap.svg", encoder);
            PlotImageUtility.SaveImage(netHistogram, baseName + "_netHistogram.svg", encoder);
            PlotImageUtility.SaveImage(massHistogram, baseName + "_massHistogram.svg", encoder);
        }
Esempio n. 21
0
        public static PlotModel PlotHeatMap()
        {
            var model = new PlotModel { Title = "FOOBAR" };
            model.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right,
                Palette = OxyPalettes.Jet(500),
                HighColor = OxyColors.Gray,
                LowColor = OxyColors.Black
            });

            var data = new double[,] { { 1, 2 }, { 1, 1 }, { 2, 1 }, { 2, 2 } };

            var hs = new HeatMapSeries
            {
                Background = OxyColors.Red,
                X0 = 0,
                X1 = 2,
                Y0 = 0,
                Y1 = 3,
                Data = data,
            };
            model.Series.Add(hs);
            return model;
        }