Example #1
0
            public void Validate(TimeSpan defaultIndexCalculationDuration)
            {
                SpectralIndexValues.CheckExistenceOfSpectralIndexValues(this.IndexProperties);

                // if tiling output we need to be able to parse the date from the file name
                Log.Info("Image tiling is " + (this.TileOutput ? string.Empty : "NOT ") + "enabled");
                if (this.TileOutput)
                {
                    if (!this.RequireDateInFilename)
                    {
                        throw new ConfigFileException(
                                  "If TileImageOutput is set then RequireDateInFilename must be set as well");
                    }
                }

                // set IndexCalculationDuration i.e. duration of a subsegment
                if (this.IndexCalculationDuration <= 0)
                {
                    this.IndexCalculationDuration = defaultIndexCalculationDuration.TotalSeconds;
                    Log.Warn(
                        "IndexCalculationDuration from config file is invalid"
                        + $" (Used default value = {this.IndexCalculationDuration})");
                }

                if (this.TileOutput && this.IndexCalculationDuration != 60.0)
                {
                    throw new ConfigFileException(
                              "Invalid configuration detected: tile image output is enabled but "
                              + "ICD != 60.0 so the images won'tbe created");
                }
            }
Example #2
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;
        }