コード例 #1
0
        //public static Image DrawImageOfDistribution(double[,] matrix, int width, int height, string label)
        //{
        //    double[] array = DataTools.Matrix2Array(matrix);
        //    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
        //    double value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

        //    var image =
        //        GraphsAndCharts.DrawHistogram(
        //            label,
        //            stats.Distribution,
        //            stats.UpperPercentileBin,
        //            new Dictionary<string, double>()
        //            {
        //                        { "min",  stats.Minimum },
        //                        { "max",  stats.Maximum },
        //                        { "mode", stats.Mode },
        //                        { "sd",   stats.StandardDeviation },
        //                        { UpperPercentileLabel,  value },
        //                        { "count",  stats.Count },
        //            },
        //            width,
        //            height);
        //    return image;
        //}

        public static Dictionary <string, SpectralStats> WriteSummaryIndexDistributionStatistics(Dictionary <string, double[]> summaryIndices, DirectoryInfo outputDirectory, string fileStem)
        {
            // to accumulate the images
            int width     = 100; // pixels
            int height    = 100; // pixels
            var imageList = new List <Image>();
            Dictionary <string, SpectralStats> indexDistributionStatistics = new Dictionary <string, SpectralStats>();

            string[] indexKeys = summaryIndices.Keys.ToArray();

            foreach (string key in indexKeys)
            {
                if (summaryIndices.ContainsKey(key))
                {
                    double[]      array = summaryIndices[key];
                    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
                    stats.GetValueOfNthPercentile(UpperPercentileDefault, out int binId, out double value);
                    stats.UpperPercentileBin = binId;
                    indexDistributionStatistics.Add(key, stats); // add index statistics

                    // CVR (cover) and EVN (events/sec) have discrete, sparse distributions when calculating for zoomed tiles,
                    // and most values are in the zero bin.
                    // Therefore they return value = 0.0; This is a bug!
                    // To avoid this problem, set value = maximum when percentileBin = 0
                    if (binId == 0)
                    {
                        value = stats.Maximum;
                    }

                    imageList.Add(
                        GraphsAndCharts.DrawHistogram(
                            key,
                            stats.Distribution,
                            stats.UpperPercentileBin,
                            new Dictionary <string, double>()
                    {
                        { "min", stats.Minimum },
                        { "max", stats.Maximum },
                        { "mode", stats.Mode },
                        { "sd", stats.StandardDeviation },
                        { UpperPercentileLabel, value },
                        { "count", stats.Count },
                    },
                            width,
                            height));
                }
            }

            FileInfo statsFile = new FileInfo(GetSummaryStatsPath(outputDirectory, fileStem));

            Json.Serialise(statsFile, indexDistributionStatistics);

            Image  image3    = ImageTools.CombineImagesVertically(imageList.ToArray());
            string imagePath = GetSummaryImagePath(outputDirectory, fileStem);

            image3.Save(imagePath);

            return(indexDistributionStatistics);
        }
コード例 #2
0
        public static Dictionary <string, SpectralStats> WriteSummaryIndexDistributionStatistics(Dictionary <string, double[]> summaryIndices, DirectoryInfo outputDirectory, string fileStem)
        {
            // to accumulate the images
            int width     = 100; // pixels
            int height    = 100; // pixels
            var imageList = new List <Image>();
            Dictionary <string, SpectralStats> indexDistributionStatistics = new Dictionary <string, SpectralStats>();

            string[] indexKeys = summaryIndices.Keys.ToArray();

            foreach (string key in indexKeys)
            {
                if (summaryIndices.ContainsKey(key))
                {
                    double[]      array = summaryIndices[key];
                    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
                    indexDistributionStatistics.Add(key, stats); // add index statistics
                    double value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

                    imageList.Add(
                        GraphsAndCharts.DrawHistogram(
                            key,
                            stats.Distribution,
                            stats.UpperPercentileBin,
                            new Dictionary <string, double>()
                    {
                        { "min", stats.Minimum },
                        { "max", stats.Maximum },
                        { "mode", stats.Mode },
                        { "sd", stats.StandardDeviation },
                        { UpperPercentileLabel, value },
                        { "count", stats.Count },
                    },
                            width,
                            height));
                }
            }

            FileInfo statsFile = new FileInfo(GetSummaryStatsPath(outputDirectory, fileStem));

            Json.Serialise(statsFile, indexDistributionStatistics);

            Image  image3    = ImageTools.CombineImagesVertically(imageList.ToArray());
            string imagePath = GetSummaryImagePath(outputDirectory, fileStem);

            image3.Save(imagePath);

            return(indexDistributionStatistics);
        }
コード例 #3
0
        public static Image DrawImageOfDistribution(double[,] matrix, int width, int height, string label)
        {
            SpectralStats stats = GetModeAndOneTailedStandardDeviation(matrix, width, UpperPercentileDefault);
            double        value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

            var image =
                GraphsAndCharts.DrawHistogram(
                    label,
                    stats.Distribution,
                    stats.UpperPercentileBin,
                    new Dictionary <string, double>()
            {
                { "min", stats.Minimum },
                { "max", stats.Maximum },
                { "mode", stats.Mode },
                { "sd", stats.StandardDeviation },
                { UpperPercentileLabel, value },
                { "count", stats.Count },
            },
                    width,
                    height);

            return(image);
        }
コード例 #4
0
        }     // HiRes1()

        /// <summary>
        /// HERVE GLOTIN: This is used to analyse the BIRD50 data set.
        /// Draws HIres spectrogram images AFTER indices have been calculated.
        /// This method does NOT produce acoustic indices.
        /// That is, only call this method if hires1() has already been used to produce the indices.
        /// </summary>
        public static void HiRes2()
        {
            string histoDir  = @"C:\SensorNetworks\Output\BIRD50";
            string histoPath = Path.Combine(histoDir, "TrainingRecordingDurations.png");

            //string histoPath = Path.Combine(histoDir, "TestingRecordingDurations.png");
            // set up  histogram of recording durations
            int histogramWidth = 600; // equivalent to ten minutes at 0.1 second resolution

            int[] recordingDurations = new int[histogramWidth];

            // set up IP and OP directories
            string inputDir       = @"C:\SensorNetworks\Output\BIRD50\Training";
            string imageOutputDir = @"C:\SensorNetworks\Output\BIRD50\TrainingImages";

            //string imageOutputDir = @"C:\SensorNetworks\Output\BIRD50\TestingRidgeImages";
            string indexPropertiesConfig = @"C:\Work\GitHub\audio-analysis\AudioAnalysis\AnalysisConfigFiles\IndexPropertiesConfigHiRes.yml";

            // comment next two lines when debugging a single recording file
            var inputDirInfo = new DirectoryInfo(inputDir);

            //string match = @"*.wav";
            //DirectoryInfo[] directories = inputDirInfo.GetDirectories(match, SearchOption.AllDirectories);
            DirectoryInfo[] directories = inputDirInfo.GetDirectories();
            int             count       = directories.Length;

            //count = 3;

            //string fileStem = "ID0003";      //\ID0001\Towsey.Acoustic\
            string fileStemFormatString = "ID{0:d4}"; // for training files

            //string fileStemFormatString = "ID1{0:d3}"; // for testing files

            for (int i = 0; i < count; i++)
            {
                string fileStem = string.Format(fileStemFormatString, i + 1);
                string dataDir  = directories[i].FullName + @"\Towsey.Acoustic\";

                var ldfcSpectrogramArguments = new DrawLongDurationSpectrograms.Arguments
                {
                    // use the default set of index properties in the AnalysisConfig directory.
                    InputDataDirectory    = dataDir,
                    OutputDirectory       = imageOutputDir,
                    IndexPropertiesConfig = indexPropertiesConfig,
                };

                // there are two possible tasks
                // 1: draw the aggregated grey scale spectrograms
                int secDuration = DrawLongDurationSpectrograms.DrawAggregatedSpectrograms(ldfcSpectrogramArguments, fileStem);

                // 2: draw the coloured ridge spectrograms
                DrawLongDurationSpectrograms.DrawRidgeSpectrograms(ldfcSpectrogramArguments, fileStem);

                if (secDuration >= recordingDurations.Length)
                {
                    secDuration = recordingDurations.Length - 1;
                }

                recordingDurations[secDuration]++;
            }

            string title      = "Recording Duration: Width = " + histogramWidth + "secs";
            Image  histoImage = GraphsAndCharts.DrawHistogram(title, recordingDurations, 95, null, histogramWidth, 50);

            histoImage.Save(histoPath);
        } // HiRes2() produces spectrogram images