Esempio n. 1
0
 public TestTrace()
 {
     TestSpecList = new List <TestTraceSpec>();
     IsTest       = true;
     DivCount     = 10;
     XAxisInfo    = new XAxisInfo();
     ResultData   = new XYDataArr();
 }
Esempio n. 2
0
        /// <summary>
        /// Save the plot, along with any defined annotations, to a png file
        /// </summary>
        /// <param name="pngFilePath">Output file path</param>
        /// <param name="width">PNG file width, in pixels</param>
        /// <param name="height">PNG file height, in pixels</param>
        /// <param name="resolution">Image resolution, in dots per inch</param>
        /// <remarks></remarks>
        public override void SaveToPNG(string pngFilePath, int width, int height, int resolution)
        {
            if (string.IsNullOrWhiteSpace(pngFilePath))
            {
                throw new ArgumentException("PNG file path cannot be blank", nameof(pngFilePath));
            }

            var exportFile = new FileInfo(Path.ChangeExtension(pngFilePath, null) + "_TmpExportData.txt");

            try
            {
                using (var writer = new StreamWriter(new FileStream(exportFile.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
                {
                    // Plot options: set of square brackets with semicolon separated key/value pairs
                    writer.WriteLine("[" + GetPlotOptions() + "]");

                    // Column names
                    writer.WriteLine("Charge\t" + XAxisInfo.Title + "\t" + YAxisInfo.Title + "\t" + ZAxisInfo.Title);

                    // Column options: semicolon separated key/value pairs for each column, e.g.
                    //
                    var additionalOptions = new List <string> {
                        "MarkerSize=" + MarkerSize
                    };

                    if (ColorScaleMinIntensity > 0 || ColorScaleMaxIntensity > 0)
                    {
                        additionalOptions.Add("ColorScaleMinIntensity=" + ColorScaleMinIntensity);
                        additionalOptions.Add("ColorScaleMaxIntensity=" + ColorScaleMaxIntensity);
                    }
                    writer.WriteLine(XAxisInfo.GetOptions() + "\t" + YAxisInfo.GetOptions() + "\t" + ZAxisInfo.GetOptions(additionalOptions));

                    var charges = PointsByCharge.Keys.ToList();
                    charges.Sort();

                    // Data, by charge state
                    foreach (var charge in charges)
                    {
                        foreach (var dataPoint in PointsByCharge[charge])
                        {
                            writer.WriteLine(charge + "\t" + dataPoint.X + "\t" + dataPoint.Y + "\t" + dataPoint.Value);
                        }
                    }
                }

                if (DeleteTempFiles)
                {
                    exportFile.Delete();
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error exporting data in SaveToPNG", ex);
                return;
            }

            if (string.IsNullOrWhiteSpace(PythonPath) && !FindPython())
            {
                OnErrorEvent("Cannot export plot data for PNG creation; Python not found");
                return;
            }

            try
            {
                var args = "";

                var cmdLine = string.Format("{0} {1} {2}", PythonPath, PRISM.clsPathUtils.PossiblyQuotePath(exportFile.FullName), args);

                Console.WriteLine("ToDo: generate 3D plot with " + cmdLine);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error creating 3D plot with Python using " + exportFile.Name, ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Save the plot, along with any defined annotations, to a png file
        /// </summary>
        /// <param name="pngFile">Output PNG file</param>
        /// <param name="width">PNG file width, in pixels</param>
        /// <param name="height">PNG file height, in pixels</param>
        /// <param name="resolution">Image resolution, in dots per inch</param>
        /// <remarks></remarks>
        public override bool SaveToPNG(FileInfo pngFile, int width, int height, int resolution)
        {
            if (pngFile == null)
            {
                throw new ArgumentNullException(nameof(pngFile), "PNG file instance cannot be blank");
            }

            var exportFile = new FileInfo(Path.ChangeExtension(pngFile.FullName, null) + TMP_FILE_SUFFIX + ".txt");

            try
            {
                using (var writer = new StreamWriter(new FileStream(exportFile.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
                {
                    // Plot options: set of square brackets with semicolon separated key/value pairs
                    writer.WriteLine("[" + GetPlotOptions() + "]");

                    // Column options: semicolon separated key/value pairs for each column, with options for each column separated by a tab
                    // Note: these options aren't actually used by the Python plotting library

                    // Example XAxis options: Autoscale=true;StringFormat=#,##0;MinorGridlineThickness=1
                    // Example YAxis options: Autoscale=true;StringFormat=#,##0;MinorGridlineThickness=1
                    // Example ZAxis options: Autoscale=true;StringFormat=#,##0;MinorGridlineThickness=1;MarkerSize=0.6;ColorScaleMinIntensity=400.3625;ColorScaleMaxIntensity=9152594

                    var additionalZAxisOptions = new List <string> {
                        "MarkerSize=" + MarkerSize
                    };

                    if (ColorScaleMinIntensity > 0 || ColorScaleMaxIntensity > 0)
                    {
                        additionalZAxisOptions.Add("ColorScaleMinIntensity=" + ColorScaleMinIntensity);
                        additionalZAxisOptions.Add("ColorScaleMaxIntensity=" + ColorScaleMaxIntensity);
                    }
                    writer.WriteLine(XAxisInfo.GetOptions() + "\t" + YAxisInfo.GetOptions() + "\t" + ZAxisInfo.GetOptions(additionalZAxisOptions));

                    var charges = PointsByCharge.Keys.ToList();
                    charges.Sort();

                    var includeCharge = charges.Count > 1;

                    // Column names
                    if (includeCharge)
                    {
                        writer.WriteLine(XAxisInfo.Title + "\t" + YAxisInfo.Title + "\t" + ZAxisInfo.Title + "\t" + "Charge");
                    }
                    else
                    {
                        writer.WriteLine(XAxisInfo.Title + "\t" + YAxisInfo.Title + "\t" + ZAxisInfo.Title);
                    }

                    // Data, by charge state
                    foreach (var charge in charges)
                    {
                        foreach (var dataPoint in PointsByCharge[charge])
                        {
                            if (includeCharge)
                            {
                                writer.WriteLine(dataPoint.X + "\t" + dataPoint.Y + "\t" + dataPoint.Value + "\t" + charge);
                            }
                            else
                            {
                                writer.WriteLine(dataPoint.X + "\t" + dataPoint.Y + "\t" + dataPoint.Value);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error exporting data in SaveToPNG", ex);
                return(false);
            }

            if (string.IsNullOrWhiteSpace(PythonPath) && !PythonInstalled)
            {
                NotifyPythonNotFound("Cannot export plot data for PNG creation");
                return(false);
            }

            try
            {
                var success = GeneratePlotsWithPython(exportFile, pngFile.Directory);

                if (DeleteTempFiles)
                {
                    exportFile.Delete();
                }

                return(success);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error creating 3D plot with Python using " + exportFile.Name, ex);
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Save the plot, along with any defined annotations, to a png file
        /// </summary>
        /// <param name="pngFilePath">Output file path</param>
        /// <param name="width">PNG file width, in pixels</param>
        /// <param name="height">PNG file height, in pixels</param>
        /// <param name="resolution">Image resolution, in dots per inch</param>
        /// <remarks></remarks>
        public override void SaveToPNG(string pngFilePath, int width, int height, int resolution)
        {
            if (string.IsNullOrWhiteSpace(pngFilePath))
            {
                throw new ArgumentException("PNG file path cannot be blank", nameof(pngFilePath));
            }

            FileInfo exportFile;

            try
            {
                exportFile = new FileInfo(Path.ChangeExtension(pngFilePath, null) + "_TmpExportData.txt");

                using (var writer = new StreamWriter(new FileStream(exportFile.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
                {
                    // Plot options: set of square brackets with semicolon separated key/value pairs
                    writer.WriteLine("[" + GetPlotOptions() + "]");

                    // Column names
                    writer.WriteLine(XAxisInfo.Title + "\t" + YAxisInfo.Title);

                    // Column options: semicolon separated key/value pairs for each column, e.g.
                    // Autoscale=false;Minimum=0;Maximum=0;StringFormat=#,##0;MinorGridlineThickness=0;MajorStep=1
                    writer.WriteLine(XAxisInfo.GetOptions() + "\t" + YAxisInfo.GetOptions());

                    // Data
                    foreach (var dataPoint in Data)
                    {
                        writer.WriteLine(dataPoint.X + "\t" + dataPoint.Y);
                    }
                }

                if (DeleteTempFiles)
                {
                    exportFile.Delete();
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error exporting data in SaveToPNG", ex);
                return;
            }

            if (string.IsNullOrWhiteSpace(PythonPath) && !FindPython())
            {
                OnErrorEvent("Cannot export plot data for PNG creation; Python not found");
                return;
            }

            try
            {
                var args = "";

                var cmdLine = string.Format("{0} {1} {2}", PythonPath, PRISM.clsPathUtils.PossiblyQuotePath(exportFile.FullName), args);

                Console.WriteLine("ToDo: generate 2D plot with " + cmdLine);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error creating 2D plot with Python using " + exportFile.Name, ex);
            }
        }
        /// <summary>
        /// Save the plot, along with any defined annotations, to a png file
        /// </summary>
        /// <param name="pngFile">Output PNG file</param>
        /// <param name="width">PNG file width, in pixels</param>
        /// <param name="height">PNG file height, in pixels</param>
        /// <param name="resolution">Image resolution, in dots per inch</param>
        /// <remarks></remarks>
        public override bool SaveToPNG(FileInfo pngFile, int width, int height, int resolution)
        {
            if (pngFile == null)
            {
                throw new ArgumentNullException(nameof(pngFile), "PNG file instance cannot be blank");
            }

            var exportFile = new FileInfo(Path.ChangeExtension(pngFile.FullName, null) + TMP_FILE_SUFFIX + ".txt");

            try
            {
                using (var writer = new StreamWriter(new FileStream(exportFile.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
                {
                    // Plot options: set of square brackets with semicolon separated key/value pairs
                    writer.WriteLine("[" + GetPlotOptions() + "]");

                    // Column options: semicolon separated key/value pairs for each column, with options for each column separated by a tab
                    // Note: these options aren't actually used by the Python plotting library

                    // Example XAxis options: Autoscale=false;Minimum=0;Maximum=12135006;StringFormat=#,##0;MinorGridlineThickness=1
                    // Example YAxis options: Autoscale=true;StringFormat=0.00E+00;MinorGridlineThickness=1

                    writer.WriteLine(XAxisInfo.GetOptions() + "\t" + YAxisInfo.GetOptions());

                    // Column names
                    writer.WriteLine(XAxisInfo.Title + "\t" + YAxisInfo.Title);

                    // Data
                    foreach (var dataPoint in Data)
                    {
                        writer.WriteLine(dataPoint.X + "\t" + dataPoint.Y);
                    }
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error exporting data in SaveToPNG", ex);
                return(false);
            }

            if (string.IsNullOrWhiteSpace(PythonPath) && !PythonInstalled)
            {
                NotifyPythonNotFound("Cannot export plot data for PNG creation");
                return(false);
            }

            try
            {
                var success = GeneratePlotsWithPython(exportFile, pngFile.Directory);

                if (DeleteTempFiles)
                {
                    exportFile.Delete();
                }

                return(success);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error creating 2D plot with Python using " + exportFile.Name, ex);
                return(false);
            }
        }