private void OnParamsChanged(object sender, EventArgs e)
        {
            if (_allowEvents)
            {
                bool showContours = false;

                if (chkShowContours.IsEnabled)
                {
                    showContours = chkShowContours.IsChecked.GetValueOrDefault();
                }

                string             dataType = App.ControlPanelModel.SelectedDataType.Name;
                WeatherDataPalette wdp      = WeatherDataPaletteFactory.GetPaletteForDataType(dataType);
                if (wdp != null)
                {
                    wdp.ShowContours = showContours;
                    wdp.LineWidth    = (float)cmbLineWidth.SelectedValue;
                    wdp.LineSpacing  = (float)cmbLevelSpacing.SelectedValue;

                    Range <float> range = new Range <float>(nudMinValue.Value.GetValueOrDefault(), nudMaxValue.Value.GetValueOrDefault());

                    wdp.MinMax.Min = range.Min;
                    wdp.MinMax.Max = range.Max;

                    wdp.LineColor = (LineColor)cmbLineColor.SelectedItem;
                }

                App.ControlPanelModel.FirePropertyChanged("PaletteParams");
            }
        }
Пример #2
0
        void ControlPanelModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            try
            {
                SimDateTime snapshot = App.ControlPanelModel.SelectedSnapshot;
                string      folder   = SimulationData.DataFolder;
                if (string.IsNullOrEmpty(App.ControlPanelModel.SelectedCategory) == false)
                {
                    folder = System.IO.Path.Combine(SimulationData.DataFolder, App.ControlPanelModel.SelectedCategory);
                }

                string fieldDataFileName = string.Format("{0}_MAP_{1}.thd",
                                                         App.ControlPanelModel.SelectedDataType.Name,
                                                         snapshot.Title);

                string             fieldDataFile = System.IO.Path.Combine(folder, fieldDataFileName);
                WeatherDataPalette wdp           = WeatherDataPaletteFactory.GetPaletteForDataFile(fieldDataFile);

                Type baseDataType = null;
                switch (e.PropertyName)
                {
                case "SelectedDataType":
                {
                    if (wdp.GetType().IsSubclassOf(typeof(TemperaturePalette)))
                    {
                        baseDataType = typeof(TemperaturePalette);
                    }
                    else if (wdp.GetType().IsSubclassOf(typeof(PressurePalette)))
                    {
                        baseDataType = typeof(PressurePalette);
                    }
                    else if (wdp.GetType().IsSubclassOf(typeof(HumidityPalette)))
                    {
                        baseDataType = typeof(HumidityPalette);
                    }
                    else
                    {
                        baseDataType = wdp.GetType();
                    }
                }
                break;

                default:
                    break;
                }

                this.sliderPrecipOffset.IsEnabled  = wdp.ShowHeatmap;
                this.sliderPrecipOffset.Visibility = wdp.ShowHeatmap ? Visibility.Visible : Visibility.Hidden;
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }
        private void LoadPaletteDefaultParams()
        {
            string             dataType = App.ControlPanelModel.SelectedDataType.Name;
            WeatherDataPalette wdp      = WeatherDataPaletteFactory.GetPaletteForDataType(dataType);

            if (wdp != null)
            {
                chkShowContours.IsEnabled = wdp.AcceptsContourLines;
                chkShowContours.IsChecked = wdp.ShowContours;

                var offsetSize = 0.5f * wdp.MinMax.Delta;

                nudMinValue.Minimum = wdp.MinMax.Min - offsetSize;
                nudMinValue.Maximum = wdp.MinMax.Min + offsetSize;
                nudMinValue.Value   = wdp.MinMax.Min;

                nudMaxValue.Minimum = wdp.MinMax.Max - offsetSize;
                nudMaxValue.Maximum = wdp.MinMax.Max + offsetSize;
                nudMaxValue.Value   = wdp.MinMax.Max;

                if (cmbLineWidth.Items.Contains(wdp.LineWidth) == false)
                {
                    cmbLineWidth.Items.Add(wdp.LineWidth);
                }
                cmbLineWidth.SelectedValue = wdp.LineWidth;

                if (cmbLevelSpacing.Items.Contains(wdp.LineSpacing) == false)
                {
                    cmbLevelSpacing.Items.Add(wdp.LineSpacing);
                }
                cmbLevelSpacing.SelectedValue = wdp.LineSpacing;

                if (cmbLineColor.Items.Contains(wdp.LineColor) == false)
                {
                    cmbLineColor.Items.Add(wdp.LineColor);
                }
                cmbLineColor.SelectedValue = wdp.LineColor;
            }
        }
Пример #4
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);
        }