Skip to content

Commit

Permalink
Clean up Obsolete code
Browse files Browse the repository at this point in the history
This is work for the open source release (see #140)

Remove obsolete classes and clean up others keeping only core
funcionality. Still retain Sandpit class

More clean up and resharper work
  • Loading branch information
towsey authored and atruskie committed Jan 27, 2018
1 parent 799891f commit 88715b7
Show file tree
Hide file tree
Showing 16 changed files with 1,091 additions and 3,016 deletions.
14 changes: 0 additions & 14 deletions AudioAnalysis/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@
<Compile Include="EventStatistics\EventStatisticsAnalysis.cs" />
<Compile Include="EventStatistics\EventStatisticsEntry.cs" />
<Compile Include="EventStatistics\ImportedEvent.cs" />
<Compile Include="LitoriaFallax_OBSOLETE.cs" />
<Compile Include="LimnodynastesConvex_OBSOLETE.cs" />
<Compile Include="CanetoadOld_OBSOLETE.cs" />
<Compile Include="Audio2InputForConvCNN.cs" />
<Compile Include="ChannelIntegrity.cs" />
<Compile Include="DrawEasyImage.cs" />
Expand Down Expand Up @@ -375,12 +372,10 @@
<Compile Include="SURFAnalysis.cs" />
<Compile Include="OscillationsGeneric.cs" />
<Compile Include="DifferenceSpectrogram.cs" />
<Compile Include="Dong.Felt.Main.cs" />
<Compile Include="DrawLongDurationSpectrograms.cs" />
<Compile Include="DummyAnalysis.cs" />
<Compile Include="EPR.cs" />
<Compile Include="FileRenamer.cs" />
<Compile Include="Frogs_OBSOLETE.cs" />
<Compile Include="GroundParrotRecogniser.cs" />
<Compile Include="Production\Actions.cs" />
<Compile Include="Production\CustomArgumentParsing.cs" />
Expand All @@ -389,35 +384,26 @@
<Compile Include="Production\MainEntryUtilities.cs" />
<Compile Include="Production\Exceptions.cs" />
<Compile Include="Crow.cs" />
<Compile Include="GratingDetection_OBSOLETE.cs" />
<Compile Include="Human1.cs" />
<Compile Include="DrawSummaryIndexTracks.cs" />
<Compile Include="KoalaMale.cs" />
<Compile Include="LewinsRail3OBSOLETE.cs" />
<Compile Include="LSKiwi3.cs" />
<Compile Include="LSKiwiHelper.cs" />
<Compile Include="LSKiwiROC.cs" />
<Compile Include="OscillationRecogniser.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="PlanesTrainsAndAutomobiles.cs" />
<Compile Include="Rain_OBSOLETE.cs" />
<Compile Include="RheobatrachusSilus.cs" />
<Compile Include="Sandpit.cs" />
<Compile Include="SpeciesAccumulationCurve.cs" />
<Compile Include="AcousticIndices.cs" />
<Compile Include="FrogRibit_OBSOLETE.cs" />
<Compile Include="FeltTemplate_Edit.cs" />
<Compile Include="FeltTemplate_Create.cs" />
<Compile Include="FeltTemplates_Use.cs" />
<Compile Include="MainEntry.cs" />
<Compile Include="Create4Sonograms.cs" />
<Compile Include="Segment.cs" />
<Compile Include="SnrAnalysis.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SPR_OBSOLETE.cs" />
<Compile Include="Spt.cs" />
<Compile Include="XiesAnalysis.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Acoustics\Acoustics.Shared\Acoustics.Shared.csproj">
Expand Down
584 changes: 58 additions & 526 deletions AudioAnalysis/AnalysisPrograms/Crow.cs

Large diffs are not rendered by default.

139 changes: 65 additions & 74 deletions AudioAnalysis/AnalysisPrograms/DrawEasyImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,21 @@
// </copyright>

// <summary>
// Defines the ConcatenateIndexFiles type.
//
// Action code for this activity = "drawEasyImage"

/// Activity Codes for other tasks to do with spectrograms and audio files:
///
/// audio2csv - Calls AnalyseLongRecording.Execute(): Outputs acoustic indices and LD false-colour spectrograms.
/// audio2sonogram - Calls AnalysisPrograms.Audio2Sonogram.Main(): Produces a sonogram from an audio file - EITHER custom OR via SOX.Generates multiple spectrogram images and oscilllations info
/// indicescsv2image - Calls DrawSummaryIndexTracks.Main(): Input csv file of summary indices. Outputs a tracks image.
/// colourspectrogram - Calls DrawLongDurationSpectrograms.Execute(): Produces LD spectrograms from matrices of indices.
/// zoomingspectrograms - Calls DrawZoomingSpectrograms.Execute(): Produces LD spectrograms on different time scales.
/// differencespectrogram - Calls DifferenceSpectrogram.Execute(): Produces Long duration difference spectrograms
/// concatenateIndexFiles - Concatenates all the index files in a 24 hour period. Used wherever partial recordings must be stitched to make whole day.
///
/// audiofilecheck - Writes information about audio files to a csv file.
/// snr - Calls SnrAnalysis.Execute(): Calculates signal to noise ratio.
/// audiocutter - Cuts audio into segments of desired length and format
/// createfoursonograms
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AnalysisPrograms
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

using Acoustics.Shared;

using Production;

using AudioAnalysisTools;
using AudioAnalysisTools.Indices;
using AudioAnalysisTools.LongDurationSpectrograms;

using AudioAnalysisTools.StandardSpectrograms;
using PowerArgs;
using AudioAnalysisTools;
using System.Collections.Generic;
using Production;
using TowseyLibrary;
using System.Drawing;

using AudioAnalysisTools.StandardSpectrograms;

/// <summary>
/// First argument on command line to call this action is "drawEasyImage"
Expand Down Expand Up @@ -73,6 +47,7 @@ public class Arguments
public DateTimeOffset? EndDate { get; set; }

public TimeSpan? timeSpanOffsetHint = new TimeSpan(10, 0, 0);

[ArgDescription("TimeSpan offset hint required if file names do not contain time zone info. Set default to east coast Australia")]
public TimeSpan? TimeSpanOffsetHint {
get { return this.timeSpanOffsetHint; }
Expand All @@ -85,7 +60,6 @@ public TimeSpan? TimeSpanOffsetHint {
internal FileInfo IndexPropertiesConfig { get; set; }

public FileInfo BrisbaneSunriseDatafile { get; set; }

}

/// <summary>
Expand Down Expand Up @@ -113,18 +87,21 @@ public static Arguments Dev()
string opPath = @"Y:\Results\YvonneResults\Cooloola_ConcatenatedResults";

dtoStart = new DateTimeOffset(2015, 06, 22, 0, 0, 0, TimeSpan.Zero);
dtoEnd = new DateTimeOffset(2015, 10, 11, 0, 0, 0, TimeSpan.Zero);
dtoEnd = new DateTimeOffset(2015, 10, 11, 0, 0, 0, TimeSpan.Zero);

if(!indexPropertiesConfig.Exists) LoggedConsole.WriteErrorLine("# indexPropertiesConfig FILE DOES NOT EXIST.");
if (!indexPropertiesConfig.Exists)
{
LoggedConsole.WriteErrorLine("# indexPropertiesConfig FILE DOES NOT EXIST.");
}

return new Arguments
{
InputDataDirectories = dataDirs,
OutputDirectory = new DirectoryInfo(opPath),
FileFilter = fileFilter,
FileStemName = opFileStem,
StartDate = dtoStart,
EndDate = dtoEnd,
FileFilter = fileFilter,
FileStemName = opFileStem,
StartDate = dtoStart,
EndDate = dtoEnd,
IndexPropertiesConfig = indexPropertiesConfig,
BrisbaneSunriseDatafile = sunrisesetData,
};
Expand Down Expand Up @@ -154,18 +131,25 @@ public static void Execute(Arguments arguments)
}
LoggedConsole.WriteLine("# Output directory: " + arguments.OutputDirectory.FullName);
if (arguments.StartDate == null)
{
LoggedConsole.WriteLine("# Start date = NULL (No argument provided). Will revise start date ....");
}
else
{
LoggedConsole.WriteLine("# Start date = " + arguments.StartDate.ToString());
}

if (arguments.EndDate == null)
{
LoggedConsole.WriteLine("# End date = NULL (No argument provided). Will revise end date ....");
}
else
{
LoggedConsole.WriteLine("# End date = " + arguments.EndDate.ToString());
}

LoggedConsole.WriteLine("# FILE FILTER = " + arguments.FileFilter);
LoggedConsole.WriteLine();
//LoggedConsole.WriteLine("# Index Properties Config file: " + arguments.IndexPropertiesConfig);
}

// PATTERN SEARCH FOR SUMMARY INDEX FILES.
Expand Down Expand Up @@ -199,14 +183,17 @@ public static void Execute(Arguments arguments)
{
LoggedConsole.WriteLine("\n# Start date = " + startDate.ToString());
LoggedConsole.WriteLine("# End date = " + endDate.ToString());
LoggedConsole.WriteLine(string.Format("# Elapsed time = {0:f1} hours", (dayCount * 24)));
LoggedConsole.WriteLine(string.Format("# Elapsed time = {0:f1} hours", dayCount * 24));
LoggedConsole.WriteLine("# Day count = " + dayCount + " (inclusive of start and end days)");
LoggedConsole.WriteLine("# Time Zone = " + arguments.TimeSpanOffsetHint.ToString());
}

// create top level output directory if it does not exist.
DirectoryInfo opDir = arguments.OutputDirectory;
if (!opDir.Exists) arguments.OutputDirectory.Create();
if (!opDir.Exists)
{
arguments.OutputDirectory.Create();
}

// SET UP DEFAULT SITE LOCATION INFO -- DISCUSS IWTH ANTHONY
// The following location data is used only to draw the sunrise/sunset tracks on images.
Expand All @@ -218,7 +205,6 @@ public static void Execute(Arguments arguments)
siteDescription.Longitude = longitude;

// the following required if drawing the index images
IndexGenerationData indexGenerationData = null;
FileInfo indexPropertiesConfig = null;

// require IndexGenerationData and indexPropertiesConfig for drawing
Expand All @@ -230,7 +216,6 @@ public static void Execute(Arguments arguments)

// default EASY indices
int redID = 3; // backgroundNoise
//int grnID = 4; //SNR
int grnID = 5; // avSNROfActiveframes
int bluID = 7; // events per second
string rep = @"bgn-avsnr-evn";
Expand Down Expand Up @@ -271,8 +256,6 @@ public static void Execute(Arguments arguments)
var oneDay = TimeSpan.FromHours(24);
int graphWidth = colCount;
int trackHeight = 20;
Pen whitePen = new Pen(Color.White);
//Pen grayPen = new Pen(Color.Gray);
Font stringFont = new Font("Arial", 8);
string[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

Expand All @@ -295,11 +278,13 @@ public static void Execute(Arguments arguments)
bitmap.SetPixel(c, currentRow, Color.Gray);
bitmap.SetPixel(c, nextRow, Color.Gray);
}

for (int c = 0; c < scaleWidth; c++)
{
yAxisScale.SetPixel(c, currentRow + trackHeight, Color.Gray);
yAxisScale.SetPixel(c, nextRow + trackHeight, Color.Gray);
}

string month = monthNames[thisday.Month-1];
if (thisday.Month == 1) // January
{
Expand All @@ -314,13 +299,10 @@ public static void Execute(Arguments arguments)
}

// get the exact date and time
LoggedConsole.WriteLine(string.Format("READING DAY {0} of {1}: {2}", (d+1), dayCount, thisday.ToString()));
LoggedConsole.WriteLine($"READING DAY {d + 1} of {dayCount}: {thisday.ToString()}");

// CREATE DAY LEVEL OUTPUT DIRECTORY for this day
string dateString = string.Format("{0}{1:D2}{2:D2}", thisday.Year, thisday.Month, thisday.Day);

string opFileStem = string.Format("{0}_{1}", arguments.FileStemName, dateString);
//var indicesFile = FilenameHelpers.AnalysisResultPath(resultsDir, opFileStem, LDSpectrogramStitching.SummaryIndicesStr, LDSpectrogramStitching.CsvFileExt);
string dateString = $"{thisday.Year}{thisday.Month:D2}{thisday.Day:D2}";

tuple = CsvTools.ReadCSVFile(csvFiles[d].FullName);
var arrays = tuple.Item2;
Expand All @@ -333,34 +315,51 @@ public static void Execute(Arguments arguments)
redArray = DataTools.NormaliseInZeroOne(redArray, redIndexProps.NormMin, redIndexProps.NormMax);
grnArray = DataTools.NormaliseInZeroOne(grnArray, grnIndexProps.NormMin, grnIndexProps.NormMax);
bluArray = DataTools.NormaliseInZeroOne(bluArray, bluIndexProps.NormMin, bluIndexProps.NormMax);
double transformedValue;

for (int c = 0; c < colCount; c++)
{
for (int r = 0; r < dayPixelHeight; r++)
{
//transformedValue = Math.Sqrt(redArray[c]);
transformedValue = redArray[c] * redArray[c]; // square the value
var transformedValue = redArray[c] * redArray[c];
int redVal = (int)Math.Round(transformedValue * 255);
if (redVal < 0) redVal = 0;
if (redVal < 0)
{
redVal = 0;
}
else
if (redVal > 255) redVal = 255;
if (redVal > 255)
{
redVal = 255;
}

//transformedValue = Math.Sqrt(grnArray[c]);
transformedValue = grnArray[c] * grnArray[c]; // square the value
int grnVal = (int)Math.Round(transformedValue * 255);
if (grnVal < 0) grnVal = 0;
if (grnVal < 0)
{
grnVal = 0;
}
else
if (grnVal > 255) grnVal = 255;
if (grnVal > 255)
{
grnVal = 255;
}

//transformedValue = Math.Sqrt(bluArray[c]);
transformedValue = bluArray[c] * bluArray[c]; // square the value
int bluVal = (int)Math.Round(transformedValue * 255);
if (bluVal < 0) bluVal = 0;
if (bluVal < 0)
{
bluVal = 0;
}
else
if (bluVal > 255) bluVal = 255;
bitmap.SetPixel(c, (currentRow + r), Color.FromArgb(redVal, grnVal, bluVal));
if (bluVal > 255)
{
bluVal = 255;
}

bitmap.SetPixel(c, currentRow + r, Color.FromArgb(redVal, grnVal, bluVal));
}
} // over all columns

Expand All @@ -372,42 +371,34 @@ public static void Execute(Arguments arguments)
{
bitmap.SetPixel(c, currentRow, Color.Gray);
}

currentRow++;
}

} // over days

// draw on civil dawn and dusk lines
int startdayOfYear = ((DateTimeOffset)startDate).DayOfYear;
int endDayOfYear = ((DateTimeOffset)endDate).DayOfYear;
SunAndMoon.AddSunRiseSetLinesToImage((Bitmap)bitmap, arguments.BrisbaneSunriseDatafile, startdayOfYear, endDayOfYear, dayPixelHeight);
int endDayOfYear = ((DateTimeOffset)endDate).DayOfYear;
SunAndMoon.AddSunRiseSetLinesToImage(bitmap, arguments.BrisbaneSunriseDatafile, startdayOfYear, endDayOfYear, dayPixelHeight);

// add the time scales
Bitmap timeBmp1 = ImageTrack.DrawTimeRelativeTrack(oneDay, graphWidth, trackHeight);
var imageList = new List<Image>();
imageList.Add(timeBmp1);
imageList.Add(bitmap);
imageList.Add(timeBmp1);
var imageList = new List<Image> { timeBmp1, bitmap, timeBmp1 };
Bitmap compositeBmp1 = (Bitmap)ImageTools.CombineImagesVertically(imageList);

imageList = new List<Image>();
imageList.Add(yAxisScale);
imageList.Add(compositeBmp1);
imageList = new List<Image> { yAxisScale, compositeBmp1 };
Bitmap compositeBmp2 = (Bitmap)ImageTools.CombineImagesInLine(imageList);

// indices used for image
string indicesDescription = $"{redIndexProps.Name}|{grnIndexProps.Name}|{bluIndexProps.Name}";
string startString = $"{startDate.Value.Year}/{startDate.Value.Month}/{startDate.Value.Day}";
string endString = $"{endDate.Value.Year}/{endDate.Value.Month}/{endDate.Value.Day}";
string endString = $"{endDate.Value.Year}/{endDate.Value.Month}/{endDate.Value.Day}";
string title = $"EASY: {arguments.FileStemName} From {startString} to {endString} Indices: {indicesDescription}";
Bitmap titleBar = ImageTrack.DrawTitleTrack(compositeBmp2.Width, trackHeight, title);
imageList = new List<Image>();
imageList.Add(titleBar);
imageList.Add(compositeBmp2);
imageList = new List<Image> { titleBar, compositeBmp2 };
compositeBmp2 = (Bitmap)ImageTools.CombineImagesVertically(imageList);
var outputFileName = Path.Combine(opDir.FullName, arguments.FileStemName + "." + rep + ".EASY.png");
compositeBmp2.Save(outputFileName);

} // Execute()
}
}
Loading

0 comments on commit 88715b7

Please sign in to comment.