diff --git a/src/AnalysisConfigFiles/IndexPropertiesConfig.yml b/src/AnalysisConfigFiles/IndexPropertiesConfig.yml index 4681d3ef8..ae05e1a52 100644 --- a/src/AnalysisConfigFiles/IndexPropertiesConfig.yml +++ b/src/AnalysisConfigFiles/IndexPropertiesConfig.yml @@ -508,7 +508,7 @@ ACI: DoDisplay: true NormMin: 0.4 NormMax: 0.7 - CalculateNormBounds: true + CalculateNormBounds: false ProjectID: Acoustic Indices Units: "" BGN: @@ -518,10 +518,10 @@ BGN: DefaultValue: -100.0 DoDisplay: true # min = SNR.MINIMUM_dB_BOUND_FOR_ZERO_SIGNAL - 20 = -80-20 = -100, - # Usual value is -30. However -20 adds more contrast into BGN spectrogram + # Usual max value is around -30 to -40. NormMin: -100.0 NormMax: -30.0 - CalculateNormBounds: true + CalculateNormBounds: false ProjectID: Acoustic Indices Units: "dB" CVR: @@ -532,8 +532,8 @@ CVR: DefaultValue: 0.0 DoDisplay: true NormMin: 0.0 - NormMax: 0.7 - CalculateNormBounds: true + NormMax: 0.2 + CalculateNormBounds: false ProjectID: Acoustic Indices Units: "" DIF: @@ -555,7 +555,7 @@ ENT: DoDisplay: true NormMin: 0.0 NormMax: 0.6 - CalculateNormBounds: true + CalculateNormBounds: false ProjectID: Acoustic Indices Units: "" EVN: @@ -566,7 +566,7 @@ EVN: DoDisplay: true NormMin: 0.0 NormMax: 2.0 - CalculateNormBounds: true + CalculateNormBounds: false ProjectID: Acoustic Indices Units: "events/s" OSC: diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index 0076ab6d9..aa02b3281 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -74,7 +74,7 @@ public override Task Execute(CommandLineApplication app) //CodeToPlaceScoreTracksUnderLdfcSpectrograms(); //CodeToPlaceScoreTracksUnderSingleImage(); - //ConcatenateIndexFilesAndSpectrograms(); + ConcatenateIndexFilesAndSpectrograms(); //ConcatenateGreyScaleSpectrogramImages(); //ConcatenateMarineImages(); //ConcatenateImages(); @@ -96,7 +96,7 @@ public override Task Execute(CommandLineApplication app) //TestEigenValues(); //TestChannelIntegrity(); //TestDct(); - Statistics.TestGetNthPercentileBin(); + //Statistics.TestGetNthPercentileBin(); //TEST_FilterMovingAverage(); //TestImageProcessing(); @@ -705,6 +705,11 @@ public static void ConcatenateIndexFilesAndSpectrograms() string gapRendering = "TimedGaps"; // the default bool concatenateEverythingYouCanLayYourHandsOn = false; // default is 24-hour blocks + // WARNING: Be careful about Search option. The default is all directories but in some of my work require TopDirectoryOnly. + // See LdSpectrogramStitching.GetSubDirectoriesForSiteData() lines 64 and 65. + // var searchOption = SearchOption.AllDirectories; + // var searchOption = SearchOption.TopDirectoryOnly; + /* // ########################## CONCATENATION of Sarah Lowe's recordings // The drive: work = G; home = E diff --git a/src/AudioAnalysisTools/Indices/IndexProperties.cs b/src/AudioAnalysisTools/Indices/IndexProperties.cs index d26c7731f..531c49690 100644 --- a/src/AudioAnalysisTools/Indices/IndexProperties.cs +++ b/src/AudioAnalysisTools/Indices/IndexProperties.cs @@ -120,11 +120,8 @@ public IndexProperties() this.DoDisplay = true; this.NormMin = 0.0; this.NormMax = 1.0; - this.CalculateNormMin = false; - this.CalculateNormMax = false; + this.CalculateNormBounds = false; this.Units = string.Empty; - this.IncludeInComboIndex = false; - this.ComboWeight = 0.0; } // ignored because we don't want to dump this info in ConfigFile log @@ -147,7 +144,7 @@ public string DataType [YamlIgnore] [JsonIgnore] - //TODO: this information should really be encoded rather than inferred + // TODO: this information should really be encoded rather than inferred public bool IsSpectralIndex => this.DataType == "double[]"; public double DefaultValue @@ -181,21 +178,14 @@ public double DefaultValue public double NormMin { get; set; } - public bool CalculateNormMin { get; set; } - public double NormMax { get; set; } - public bool CalculateNormMax { get; set; } + public bool CalculateNormBounds { get; set; } // ignored because we don't want to dump this info in ConfigFile log [JsonIgnore] public string Units { get; set; } - // use these when calculated combination index. - public bool IncludeInComboIndex { get; set; } - - public double ComboWeight { get; set; } - public double NormaliseValue(double value) => DataTools.NormaliseInZeroOne(value, this.NormMin, this.NormMax); /// diff --git a/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramRGB.cs b/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramRGB.cs index a8244edc5..cf3c361e2 100644 --- a/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramRGB.cs +++ b/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramRGB.cs @@ -103,7 +103,7 @@ public static string[] GetArrayOfAvailableKeys() /// /// Initializes a new instance of the class. - /// No Arguments CONSTRUCTOR + /// No Arguments CONSTRUCTOR. /// public LDSpectrogramRGB() { @@ -118,7 +118,7 @@ public LDSpectrogramRGB() /// /// Initializes a new instance of the class. - /// CONSTRUCTOR + /// CONSTRUCTOR. /// public LDSpectrogramRGB(TimeSpan xScale, int sampleRate, string colourMap) { @@ -145,10 +145,10 @@ public LDSpectrogramRGB(TimeSpan xScale, int sampleRate, string colourMap) /// /// Initializes a new instance of the class. /// CONSTRUCTOR - /// WARNING: Ths will create a linear herz scale spectrogram + /// WARNING: Ths will create a linear herz scale spectrogram. /// - /// minute of day at which the spectrogram starts - /// time scale : pixels per hour + /// minute of day at which the spectrogram starts. + /// time scale : pixels per hour. /// recording sample rate which also determines scale of Y-axis. /// frame size - which also determines scale of Y-axis. /// acoustic indices used to assign the three colour mapping. @@ -227,7 +227,7 @@ public LDSpectrogramRGB(LdSpectrogramConfig config, IndexGenerationData indexGen /// /// Gets or sets the date and time at which the current LDspectrogram starts - /// This can be used to correctly + /// This can be used to correctly. /// public DateTimeOffset RecordingStartDate { get; set; } @@ -243,7 +243,7 @@ public LDSpectrogramRGB(LdSpectrogramConfig config, IndexGenerationData indexGen public TimeSpan StartOffset { get; set; } /// - /// Gets or sets the temporal duration of one subsegment interval for which indices are calculated + /// Gets or sets the temporal duration of one subsegment interval for which indices are calculated. /// public TimeSpan IndexCalculationDuration { get; set; } @@ -264,7 +264,10 @@ public LDSpectrogramRGB(LdSpectrogramConfig config, IndexGenerationData indexGen /// public FrequencyScale FreqScale { get; set; } - public int YInterval // mark 1 kHz intervals + /// + /// Gets the 1 kHz intervals. + /// + public int GetYinterval { get { @@ -281,7 +284,7 @@ public int YInterval // mark 1 kHz intervals public string ColorMap { get; set; } /// - /// Gets or sets pOSITIVE or NEGATIVE + /// Gets or sets pOSITIVE or NEGATIVE. /// public string ColorMode { get; set; } @@ -300,7 +303,7 @@ public int YInterval // mark 1 kHz intervals /// /// Gets or sets a file from which can be obtained information about sunrise and sunset times for the recording site. /// The csv file needs to be in the correct format and typically should contain 365 lines. - /// Have not attempted to deal with leap years! + /// Have not attempted to deal with leap years!. /// [Obsolete] public FileInfo SunriseDataFile { get; set; } @@ -340,8 +343,7 @@ public bool ReadCsvFiles(DirectoryInfo ipdir, string fileName, string[] keys) var file = new FileInfo(path); if (File.Exists(path)) { - int freqBinCount; - double[,] matrix = IndexMatrices.ReadSpectrogram(file, out freqBinCount); + double[,] matrix = IndexMatrices.ReadSpectrogram(file, out var freqBinCount); matrix = MatrixTools.MatrixRotate90Anticlockwise(matrix); this.SpectrogramMatrices.Add(this.SpectrogramKeys[i], matrix); this.FrameWidth = freqBinCount * 2; @@ -421,7 +423,7 @@ public void LoadSpectrogramDictionary(Dictionary dictionary) } /// - /// Call this method to access a spectrogram matrix + /// Call this method to access a spectrogram matrix. /// public double[,] GetMatrix(string key) { @@ -469,8 +471,9 @@ public void LoadSpectrogramDictionary(Dictionary dictionary) { // get the stats for this key var stats = this.IndexStats[key]; - if (indexProperties.CalculateNormMin) + if (indexProperties.CalculateNormBounds) { + // FIRST CALCULATE THE MIN BOUND // By default the minimum bound is set slightly below the modal value of the index. minBound = stats.Mode - (stats.StandardDeviation * 0.1); @@ -492,10 +495,8 @@ public void LoadSpectrogramDictionary(Dictionary dictionary) { minBound = indexProperties.NormMin; } - } - if (indexProperties.CalculateNormMax) - { + // NOW CALCULATE THE MAX BOUND stats.GetValueOfNthPercentile(IndexDistributions.UpperPercentileDefault, out int binId, out maxBound); // correct for case where max bound = zero. This can happen where ICD is very short i.e. 0.1s. @@ -525,7 +526,7 @@ public void LoadSpectrogramDictionary(Dictionary dictionary) } /// - /// draws only those spectrograms in the passed array of keys + /// draws only those spectrograms in the passed array of keys. /// public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName, string[] keys) { @@ -567,6 +568,7 @@ public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName, st Graphics g = Graphics.FromImage(header); g.Clear(Color.LightGray); g.SmoothingMode = SmoothingMode.AntiAlias; + //g.InterpolationMode = InterpolationMode.HighQualityBicubic; //g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawString(key, new Font("Tahoma", 9), Brushes.Black, 4, 4); @@ -579,7 +581,7 @@ public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName, st } /// - /// Assume calling method has done all the reality checks + /// Assume calling method has done all the reality checks. public Image DrawGreyscaleSpectrogramOfIndex(string key) { var matrix = this.GetNormalisedSpectrogramMatrix(key); @@ -1019,7 +1021,7 @@ public Image GetSpectrogramRibbon(string colorMap, int height) } /// - /// This method not currently called but might be useful in future + /// This method not currently called but might be useful in future. /// public double[] GetSummaryIndicesWeightedAtDistance(double[,] normalisedIndex1, double[,] normalisedIndex2, double[,] normalisedIndex3, int minuteInDay, int distanceInMeters) { @@ -1104,15 +1106,11 @@ public static Image FrameLDSpectrogram(Image bmp1, Image titleBar, LDSpectrogram int trackHeight = 18; Bitmap timeBmp1 = ImageTrack.DrawTimeRelativeTrack(fullDuration, bmp1.Width, trackHeight); Bitmap timeBmp2 = (Bitmap)timeBmp1.Clone(); - Bitmap suntrack = null; - DateTimeOffset? dateTimeOffset = cs.RecordingStartDate; if (dateTimeOffset.HasValue) { // draw extra time scale with absolute start time. AND THEN Do SOMETHING WITH IT. timeBmp2 = ImageTrack.DrawTimeTrack(fullDuration, cs.RecordingStartDate, bmp1.Width, trackHeight); - - //suntrack = SunAndMoon.AddSunTrackToImage(bmp1.Width, dateTimeOffset, cs.SunriseDataFile); } if (cs.FreqScale == null) @@ -1127,11 +1125,6 @@ public static Image FrameLDSpectrogram(Image bmp1, Image titleBar, LDSpectrogram // draw the composite bitmap var imageList = new List { titleBar, timeBmp1, bmp1, timeBmp2 }; - //if (suntrack != null) - //{ - // imageList.Add(suntrack); - //} - var compositeBmp = (Bitmap)ImageTools.CombineImagesVertically(imageList); return compositeBmp; } @@ -1208,11 +1201,9 @@ public static Image DrawRgbColourMatrix(double[,] redM, double[,] grnM, double[, { int rows = redM.GetLength(0); //number of rows int cols = redM.GetLength(1); //number - var bmp = new Bitmap(cols, rows, PixelFormat.Format24bppRgb); - const int maxRgbValue = 255; - + //const int maxRgbValue = 255; for (int row = 0; row < rows; row++) { for (int column = 0; column < cols; column++) @@ -1262,7 +1253,7 @@ public static Image DrawRgbColourMatrix(double[,] redM, double[,] grnM, double[, /// /// A technique to derive a spectrogram from four different indices - /// same as above method but multiply index value by the amplitude value instead of squaring the value + /// same as above method but multiply index value by the amplitude value instead of squaring the value. /// public static Image DrawFourColourSpectrogram(double[,] redM, double[,] grnM, double[,] bluM, double[,] greM, bool doReverseColour) { @@ -1344,41 +1335,41 @@ public static Image DrawColourScale(int maxScaleLength, int ht) Color c = Color.FromArgb(250, 15, 250); gr2.Clear(c); int x = 0; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); c = Color.FromArgb(250, 15, 15); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); //yellow c = Color.FromArgb(250, 250, 15); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); //green c = Color.FromArgb(15, 250, 15); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); // pale blue c = Color.FromArgb(15, 250, 250); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); // blue c = Color.FromArgb(15, 15, 250); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); // purple c = Color.FromArgb(250, 15, 250); gr2.Clear(c); x += offset; - gr.DrawImage(colorBmp, x, 0); //dra + gr.DrawImage(colorBmp, x, 0); return colorScale; } @@ -1387,16 +1378,16 @@ public static Image DrawColourScale(int maxScaleLength, int ht) /// IT CAN BE COPIED AND APPROPRIATELY MODIFIED BY ANY USER FOR THEIR OWN PURPOSE. /// WARNING: Make sure the parameters in the CONFIG file are consistent with the CSV files. /// - /// inputDirectory - /// outputDirectory - /// config for drawing FCSs + /// inputDirectory. + /// outputDirectory. + /// config for drawing FCSs. /// The indices Config Path. - /// indexGenerationData - /// stem name of the original recording - /// will usually be "Towsey.Acoustic" - /// Optional spectra to pass in. If specified the spectra will not be loaded from disk! - /// an array of summary index results - /// Info about the distributions of the spectral statistics + /// indexGenerationData. + /// stem name of the original recording. + /// will usually be "Towsey.Acoustic". + /// Optional spectra to pass in. If specified the spectra will not be loaded from disk. + /// an array of summary index results. + /// Info about the distributions of the spectral statistics. /// Optionally specify details about the site where the audio was recorded. /// This is only available for locations near Brisbane, Austalia. /// Note that these segment errors were derived from previous analysis of the summary indices. @@ -1439,7 +1430,6 @@ public static Tuple[] DrawSpectrogramsFromSpectralIndices( cs1.SiteName = siteDescription?.SiteName; cs1.Latitude = siteDescription?.Latitude; cs1.Longitude = siteDescription?.Longitude; - //cs1.SunriseDataFile = sunriseDataFile; cs1.ErroneousSegments = segmentErrors; // calculate start time by combining DatetimeOffset with minute offset. diff --git a/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramStitching.cs b/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramStitching.cs index 7d881f728..355af56c2 100644 --- a/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramStitching.cs +++ b/src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramStitching.cs @@ -61,8 +61,8 @@ public static DirectoryInfo[] GetSubDirectoriesForSiteData(IEnumerable dir.GetDirectories(searchPattern, searchOption))