private string[] GetLegendLabels(PlotDataType datatype)
        {
            string solverString = null;
            OpticalProperties opticalProperties = null;
            string modelString = null;
            ForwardSolverType forwardSolver;

            switch (datatype)
            {
                case PlotDataType.Simulated:
                    solverString = "\nSimulated:";
                    opticalProperties = MeasuredOpticalPropertyVM.GetOpticalProperties();
                    forwardSolver = MeasuredForwardSolverTypeOptionVM.SelectedValue;
                    break;
                case PlotDataType.Calculated:
                    solverString = "\nCalculated:";
                    opticalProperties = ResultOpticalPropertyVM.GetOpticalProperties();
                    forwardSolver = MeasuredForwardSolverTypeOptionVM.SelectedValue;
                    break;
                case PlotDataType.Guess:
                    solverString = "\nGuess:";
                    opticalProperties = InitialGuessOpticalPropertyVM.GetOpticalProperties();
                    forwardSolver = InverseForwardSolverTypeOptionVM.SelectedValue;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("datatype");
            }
            var opString = "\rμa=" + opticalProperties.Mua.ToString("F4") + " \rμs'=" + opticalProperties.Musp.ToString("F4");

            switch (forwardSolver)
            {
                case ForwardSolverType.DistributedGaussianSourceSDA:
                case ForwardSolverType.DistributedPointSourceSDA:
                case ForwardSolverType.PointSourceSDA:
                    modelString = "\rModel - SDA";
                    break;
                case ForwardSolverType.MonteCarlo:
                    modelString = "\rModel - scaled MC";
                    break;
                case ForwardSolverType.Nurbs:
                    modelString = "\rModel - nurbs";
                    break;
                case ForwardSolverType.TwoLayerSDA:
                    modelString = "\rModel - 2 layer SDA";
                    break;
            }
            
            if (_allRangeVMs.Length > 1)
            {
                var isWavelengthPlot = _allRangeVMs.Any(vm => vm.AxisType == IndependentVariableAxis.Wavelength);
                var secondaryRangeVM = isWavelengthPlot
                    ? _allRangeVMs.Where(vm => vm.AxisType != IndependentVariableAxis.Wavelength).First()
                    : _allRangeVMs.Where(vm => vm.AxisType != IndependentVariableAxis.Time && vm.AxisType != IndependentVariableAxis.Ft).First();

                string[] secondaryAxesStrings = secondaryRangeVM.Values.Select(value => "\r" + secondaryRangeVM.AxisType.GetInternationalizedString() + " = " + value.ToString()).ToArray();
                return secondaryAxesStrings.Select(sas => solverString + modelString + sas + (isWavelengthPlot ? "\r(spectral μa,μs')" : opString)).ToArray();
            }

            return new []{ solverString + modelString + opString };
        }
示例#2
0
        /// <summary>
        /// Get the data based off the selected data type.
        /// </summary>
        /// <param name="ePlotDataType">Selected data type.</param>
        /// <param name="cnn">SQLite connection.</param>
        /// <param name="maxNumEnsembles">Max number of ensembles to display.</param>
        /// <param name="selectedPlotType">Selected Plot type.</param>
        /// <returns>The selected for each ensemble and bin.</returns>
        private PlotData GetData(SQLiteConnection cnn, int maxNumEnsembles, PlotDataType selectedPlotType, int minIndex = 0, int maxIndex = 0)
        {
            //StatusProgressMax = TotalNumEnsembles;
            StatusProgress = 0;
            _backupBtEast  = DbDataHelper.BAD_VELOCITY;
            _backupBtNorth = DbDataHelper.BAD_VELOCITY;

            // Get the data to plot
            return(QueryDataFromDb(cnn, selectedPlotType, minIndex, maxIndex));
        }
示例#3
0
        /// <summary>
        /// Query the project database for the data to plot.
        /// </summary>
        /// <param name="cnn">SQLite connection.</param>
        /// <param name="selectedPlotType">Selected Plot Type.</param>
        /// <param name="minIndex">Minimum index.</param>
        /// <param name="maxIndex">Maximum index.</param>
        /// <returns></returns>
        private PlotData QueryDataFromDb(SQLiteConnection cnn, PlotDataType selectedPlotType, int minIndex = 0, int maxIndex = 0)
        {
            // Get the dataset column name
            string datasetColumnName = "EarthVelocityDS";

            switch (selectedPlotType)
            {
            case PlotDataType.Magnitude:
                datasetColumnName = "EarthVelocityDS";              // Velocity vectors from Earth Velocity
                break;

            case PlotDataType.Direction:
                datasetColumnName = "EarthVelocityDS";              // Velocity vectors from Earth Velocity
                break;

            case PlotDataType.Amplitude:
                datasetColumnName = "AmplitudeDS";                  // Amplitude data
                break;

            default:
                datasetColumnName = "EarthVelocityDS";
                break;
            }

            // Get the number of ensembles
            int numEnsembles = GetNumEnsembles(cnn, string.Format("SELECT COUNT(*) FROM tblEnsemble WHERE ({0} IS NOT NULL) {1} {2};",
                                                                  datasetColumnName,
                                                                  GenerateQueryFileList(),
                                                                  GenerateQuerySubsystemList()));

            // Update the progress bar
            StatusProgressMax = numEnsembles;

            // If min and max are used, set the limit and offset
            LimitOffset lo = CalcLimitOffset(numEnsembles, minIndex, maxIndex);

            numEnsembles = lo.Limit;

            // Get data
            string query = string.Format("SELECT ID,EnsembleNum,DateTime,EnsembleDS,AncillaryDS,BottomTrackDS,{0} FROM tblEnsemble WHERE ({1} IS NOT NULL) {2} {3} LIMIT {4} OFFSET {5};",
                                         datasetColumnName,
                                         datasetColumnName,
                                         GenerateQueryFileList(),
                                         GenerateQuerySubsystemList(),
                                         lo.Limit,
                                         lo.Offset);

            // Return the data to plot
            return(GetDataFromDb(cnn, numEnsembles, query, selectedPlotType));
        }
示例#4
0
        /// <summary>
        /// Load the project.  Use the selected min and max index to select the ensemble range to display.
        /// </summary>
        /// <param name="fileName">Project file path.</param>
        /// <param name="minIndex">Minimum Ensemble index.</param>
        /// <param name="maxIndex">Maximum Ensemble index.</param>
        public override void LoadProject(string fileName, int minIndex = 0, int maxIndex = 0)
        {
            // Load the base calls
            base.LoadProject(fileName, minIndex, maxIndex);

            // Selected Plot Type
            _SelectedPlotType = PlotDataType.Magnitude;
            NotifyOfPropertyChange(() => SelectedPlotType);
            _IsMagnitude = true;
            NotifyOfPropertyChange(() => IsMagnitude);

            // Draw the plot
            DrawPlot(fileName, _SelectedPlotType, minIndex, maxIndex);
        }
示例#5
0
        /// <summary>
        /// Select which parser to use based off the selected plot.
        /// </summary>
        /// <param name="reader">Reader holds a single row (ensemble).</param>
        /// <param name="selectedPlotType">Selected Plot Type.</param>
        /// <returns>Data selected for the row.</returns>
        private double[] ParseData(DbDataReader reader, PlotDataType selectedPlotType)
        {
            switch (selectedPlotType)
            {
            case PlotDataType.Magnitude:
                return(ParseMagData(reader));

            case PlotDataType.Direction:
                return(ParseDirData(reader));

            case PlotDataType.Amplitude:
                return(ParseAmpData(reader));

            default:
                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Replot the data based off a settings chage
        /// </summary>
        /// <param name="eplotDataType"></param>
        public void ReplotData(PlotDataType eplotDataType)
        {
            switch (eplotDataType)
            {
            case PlotDataType.Magnitude:
                _SelectedPlotType = PlotDataType.Magnitude;
                NotifyOfPropertyChange(() => SelectedPlotType);
                IsAmplitude = false;
                IsDirection = false;
                SetMinMaxColorAxis(0, 2);
                Plot.Title = "Water Magnitude";
                break;

            case PlotDataType.Direction:
                _SelectedPlotType = PlotDataType.Direction;
                NotifyOfPropertyChange(() => SelectedPlotType);
                IsAmplitude = false;
                IsMagnitude = false;
                SetMinMaxColorAxis(0, 360);
                Plot.Title = "Water Direction";
                break;

            case PlotDataType.Amplitude:
                _SelectedPlotType = PlotDataType.Amplitude;
                NotifyOfPropertyChange(() => SelectedPlotType);
                IsMagnitude = false;
                IsDirection = false;
                SetMinMaxColorAxis(0, 120);
                Plot.Title = "Amplitude";
                break;

            default:
                break;
            }

            // Replot the data
            if (!string.IsNullOrEmpty(ProjectFilePath))
            {
                DrawPlot(ProjectFilePath, eplotDataType);
            }
        }
示例#7
0
        /// <summary>
        /// Draw the plot based off the settings.
        /// </summary>
        /// <param name="fileName">File name of the project.</param>
        /// <param name="selectedPlotType">Selected plot type.</param>
        /// <param name="minIndex">Minimum index to draw.</param>
        /// <param name="maxIndex">Maximum index to draw.</param>
        protected async void DrawPlot(string fileName, PlotDataType selectedPlotType, int minIndex = 0, int maxIndex = 0)
        {
            // Data to get from the project
            PlotData data = null;

            // Verify a file was given
            if (!string.IsNullOrEmpty(fileName))
            {
                // Verify the file exist
                if (File.Exists(fileName))
                {
                    // Create data Source string
                    string dataSource = string.Format("Data Source={0};Version=3;", fileName);

                    try
                    {
                        // Create a new database connection:
                        using (SQLiteConnection sqlite_conn = new SQLiteConnection(dataSource))
                        {
                            // Open the connection:
                            sqlite_conn.Open();

                            // Get total number of ensembles in the project
                            // Run as a task to allow the UI to be updated
                            // Use await to keep the sqlite connection open
                            await Task.Run(() => TotalNumEnsembles = GetNumEnsembles(sqlite_conn));

                            // If this is the first time loading
                            // show the entire plot
                            if (_firstLoad)
                            {
                                _firstLoad = false;
                                minIndex   = 1;
                                maxIndex   = TotalNumEnsembles;

                                // Set the Bin size and blank
                                SetBinSizeAndBlank(sqlite_conn);
                            }

                            // Get the magnitude data
                            // Run as a task to allow the UI to be updated
                            // Use await to keep the sqlite connection open
                            await Task.Run(() => data = GetData(sqlite_conn, TotalNumEnsembles, selectedPlotType, minIndex, maxIndex));

                            // Close connection
                            sqlite_conn.Close();
                        }
                    }
                    catch (SQLiteException e)
                    {
                        Debug.WriteLine("Error using database", e);
                        return;
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Error using database", e);
                        return;
                    }

                    // If there is no data, do not plot
                    if (data != null)
                    {
                        // Update status
                        StatusMsg = "Drawing Plot";

                        // Plot the Profile data from the project
                        await Task.Run(() => PlotProfileData(data.ProfileData));

                        // Plot the Bottom Track data from the project
                        await Task.Run(() => PlotBtSeries(data.BottomTrackData));

                        // Reset the axis to set the meters axis
                        await Task.Run(() => Plot.ResetAllAxes());
                    }
                    else
                    {
                        StatusMsg = "No data to plot";
                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Get the data from the project DB.
        /// </summary>
        /// <param name="cnn">Database connection.</param>
        /// <param name="numEnsembles">Number of ensembles.</param>
        /// <param name="query">Query string to retreive the data.</param>
        /// <param name="selectedPlotType">Selected Plot Type.</param>
        /// <returns>Magnitude data in (NumEns X NumBin) format.</returns>
        private PlotData GetDataFromDb(SQLiteConnection cnn, int numEnsembles, string query, PlotDataType selectedPlotType)
        {
            // Init list
            PlotData   result   = new PlotData();
            AreaSeries btSeries = CreateBtSeries();
            int        ensIndex = 0;

            // Ensure a connection was made
            if (cnn == null)
            {
                return(null);
            }

            using (DbCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = query;

                // Get Result
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    // Convert the Earth JSON to an object
                    //Debug.WriteLine(reader["EnsembleNum"]);
                    // Update the status
                    StatusProgress++;
                    StatusMsg = reader["EnsembleNum"].ToString();

                    // Verify there is more data available
                    if (reader == null)
                    {
                        break;
                    }

                    // Ensure we do not exceed the number of ensembles
                    if (ensIndex >= numEnsembles)
                    {
                        break;
                    }

                    // Parse the Bottom Track line if enabled
                    if (IsBottomTrackLine)
                    {
                        // Get Bottom Track Line Data
                        ParseBtData(ref btSeries, reader, ensIndex);
                    }

                    // Parse the data from the db
                    // This will be select which type of data to plot
                    double[] data = ParseData(reader, selectedPlotType);

                    // Verify we have data
                    if (data != null)
                    {
                        // If the array has not be created, created now
                        if (result.ProfileData == null)
                        {
                            // Create the array if this is the first entry
                            // NumEnsembles X NumBins
                            result.ProfileData = new double[numEnsembles, data.Length];
                        }

                        // Add the data to the array
                        for (int x = 0; x < data.Length; x++)
                        {
                            // Verify if the number of bins has changed
                            if (x < result.ProfileData.GetLength(1))
                            {
                                result.ProfileData[ensIndex, x] = data[x];
                            }
                        }

                        ensIndex++;
                    }
                }
            }

            // Set the Bottom Track series
            result.BottomTrackData = btSeries;

            return(result);
        }