예제 #1
0
        /// <summary>
        /// Compress high resolution indices - intended to be used when summarizing results.
        /// Summarize method not yet written.
        /// </summary>
        /// <param name="analysisResults"></param>
        /// <param name="indexResults"></param>
        /// <param name="highResolutionParsedConfiguration"></param>
        private void SummarizeHighResolutionIndices(
            AnalysisResult2 analysisResults,
            IndexCalculateResult[] indexResults,
            AcousticIndices.AcousticIndicesConfig highResolutionParsedConfiguration)
        {
            // NOW COMPRESS THE HI-RESOLUTION SPECTRAL INDICES TO LOW RES
            double   lowResolution = highResolutionParsedConfiguration.GetDoubleOrNull("LowResolution") ?? 60.0;
            TimeSpan imageScale    = TimeSpan.FromSeconds(lowResolution);
            TimeSpan dataScale     = highResolutionParsedConfiguration.IndexCalculationDuration.Seconds();

            var dictionaryOfSpectra = indexResults.Select(icr => icr.SpectralIndexValues).ToArray().ToTwoDimensionalArray(SpectralIndexValues.CachedSelectors, TwoDimensionalArray.Rotate90ClockWise);

            var spectralSelection = IndexMatrices.CompressIndexSpectrograms(dictionaryOfSpectra, imageScale, dataScale);

            // check that have not compressed matrices to zero length
            double[,] matrix = spectralSelection.First().Value;
            if (matrix.GetLength(0) == 0 || matrix.GetLength(1) == 0)
            {
                LoggedConsole.WriteErrorLine("WARNING: SPECTRAL INDEX MATRICES compressed to zero length!!!!!!!!!!!!!!!!!!!!!!!!");
            }

            // Place LOW RESOLUTION SPECTRAL INDICES INTO analysisResults before returning.
            //int windowLength = (int?)highResolutionConfig[AnalysisKeys.FrameLength] ?? IndexCalculate.DefaultWindowSize;
            var indexProperties = highResolutionParsedConfiguration.IndexProperties;

            SpectralIndexValues.CheckExistenceOfSpectralIndexValues(indexProperties);

            // Init a new spectral indices class and populate it with spectral indices
            var spectrums = SpectralIndexValues.ImportFromDictionary(spectralSelection);

            for (int i = 0; i < spectrums.Length; i++)
            {
                spectrums[i].ResultStartSeconds     = (analysisResults.SegmentStartOffset + TimeSpan.FromSeconds(i * lowResolution)).TotalSeconds;
                spectrums[i].SegmentDurationSeconds = imageScale.TotalSeconds;
                spectrums[i].FileName = ((SegmentSettings <object>)analysisResults.SegmentSettings).Segment.SourceMetadata.Identifier;
            }

            // assign to the analysis result
            analysisResults.SpectralIndices = spectrums;

            // TODO TODO TODO
            // ALSO NEED TO COMPRESS THE analysisResults.SummaryIndices To LOW RESOLUTION
            //var summaryIndexValues = new SummaryIndexValues();
            //summaryIndexValues.BackgroundNoise = ETC;
            // ETC
            //var summaryiv = new SummaryIndexValues[1];
            //summaryiv[0] = summaryIndexValues;
            //analysisResults.SummaryIndices = summaryiv;
        }
예제 #2
0
        public void FindReturnsNullOnGivenEmpty()
        {
            var emptyConfig = new IndexCalculateConfig()
            {
                IndexPropertiesConfig = string.Empty,
            };

            Assert.IsNull(IndexProperties.Find(emptyConfig));

            AnalyzerConfig genericConfig = new AcousticIndices.AcousticIndicesConfig()
            {
                IndexPropertiesConfig = string.Empty,
            };

            Assert.IsNull(IndexProperties.Find(genericConfig as IIndexPropertyReferenceConfiguration));

            // and test direct
            Assert.IsNull(IndexProperties.Find(string.Empty, null));
        }
예제 #3
0
        private Lazy <IndexCalculateResult[]> GetLazyIndices <T>(
            AudioRecording recording,
            AnalysisSettings analysisSettings,
            SegmentSettings <T> segmentSettings,
            AcousticIndices.AcousticIndicesConfig acousticConfiguration)
        {
            // Convert the Config config to IndexCalculateConfig class and merge in the unnecesary parameters.

            IndexCalculateResult[] Callback()
            {
                IndexCalculateResult[] subsegmentResults = AcousticIndices.CalculateIndicesInSubsegments(
                    recording,
                    segmentSettings.SegmentStartOffset,
                    segmentSettings.AnalysisIdealSegmentDuration,
                    acousticConfiguration.IndexCalculationDuration.Seconds(),
                    acousticConfiguration.IndexProperties,
                    segmentSettings.Segment.SourceMetadata.SampleRate,
                    acousticConfiguration);

                return(subsegmentResults);
            }

            return(new Lazy <IndexCalculateResult[]>(Callback, LazyThreadSafetyMode.ExecutionAndPublication));
        }
예제 #4
0
        private void DrawLongDurationSpectrogram(
            DirectoryInfo outputDirectory,
            string fileStem,
            Image <Rgb24> scoreTrack,
            IndexCalculateResult[] indexResults,
            AcousticIndices.AcousticIndicesConfig acousticIndicesConfig)
        {
            var dictionaryOfSpectra = indexResults.Select(icr => icr.SpectralIndexValues).ToArray().ToTwoDimensionalArray(SpectralIndexValues.CachedSelectors, TwoDimensionalArray.Rotate90ClockWise);

            FileInfo ipConfig       = acousticIndicesConfig.IndexPropertiesConfig.ToFileInfo();
            double   hiResScale     = acousticIndicesConfig.IndexCalculationDuration;
            TimeSpan hiResTimeScale = TimeSpan.FromSeconds(hiResScale);

            FileInfo spectrogramConfig = ConfigFile.Resolve(acousticIndicesConfig["SpectrogramConfig"]);

            // Assemble arguments for drawing the GRAY-SCALE and RIDGE SPECTROGRAMS
            var output = outputDirectory.Combine("SpectrogramImages");
            var ldfcSpectrogramArguments = new DrawLongDurationSpectrograms.Arguments
            {
                // passed null for first InputDataDirectory on purpose: we don't want to read files off disk
                InputDataDirectory           = null,
                OutputDirectory              = output.FullName,
                FalseColourSpectrogramConfig = spectrogramConfig.FullName,
                IndexPropertiesConfig        = ipConfig.FullName,
                ColourMap1    = "BGN-DMN-EVN",
                ColourMap2    = "RHZ-RVT-SPT", //R3D replaces PHN as new derived index
                TemporalScale = hiResTimeScale,
            };

            bool saveRidgeSpectrograms = acousticIndicesConfig.GetBoolOrNull("SaveRidgeSpectrograms") ?? false;

            if (saveRidgeSpectrograms)
            {
                // 1: DRAW the coloured ridge spectrograms

                // passed null for first argument on purpose: we don't want to read files off disk
                var ridgeSpectrogram = DrawLongDurationSpectrograms.DrawRidgeSpectrograms(null, ipConfig, fileStem, hiResScale, dictionaryOfSpectra);

                //var opImages = new List<Image>();
                //opImages.Add(ridgeSpectrogram);
                //opImages.Add(scoreTrackImage);
                // combine and save
                //Image opImage = ImageTools.CombineImagesVertically(opImages);

                var fileName = FilenameHelpers.AnalysisResultPath(output, fileStem, "Ridges", ".png");

                //opImage.Save(fileName);
                ridgeSpectrogram.Save(fileName);
            } // if (saveRidgeSpectrograms)

            // 2. DRAW the aggregated GREY-SCALE SPECTROGRAMS of SPECTRAL INDICES
            Image <Rgb24> opImage;
            bool          saveGrayScaleSpectrograms = acousticIndicesConfig.GetBoolOrNull("SaveGrayScaleSpectrograms") ?? false;

            if (saveGrayScaleSpectrograms)
            {
                opImage = DrawLongDurationSpectrograms.DrawGrayScaleSpectrograms(ldfcSpectrogramArguments, fileStem, hiResTimeScale, dictionaryOfSpectra);
                var fileName = FilenameHelpers.AnalysisResultPath(output, fileStem, "CombinedGreyScale", ".png");
                opImage.Save(fileName);
            }

            // 3. DRAW False-colour Spectrograms
            bool saveTwoMapsSpectrograms = acousticIndicesConfig.GetBoolOrNull("SaveTwoMapsSpectrograms") ?? false;

            if (saveTwoMapsSpectrograms)
            {
                opImage = DrawLongDurationSpectrograms.DrawFalseColourSpectrograms(ldfcSpectrogramArguments, fileStem, dictionaryOfSpectra);
                var opImages = new [] { opImage, scoreTrack };
                opImage = ImageTools.CombineImagesVertically(opImages);
                var fileName = FilenameHelpers.AnalysisResultPath(output, fileStem, "TwoMaps", ".png");
                opImage.Save(fileName);
            }
        }