Skip to content

Commit

Permalink
Updates namespaces on FSharp projects
Browse files Browse the repository at this point in the history
For some reason unix tooling was refusing to recognise type from FSharp assemblies.
This was a rather pointless namespace change made to try and get things to build 🤷‍♂️

Work done for #196
  • Loading branch information
atruskie committed Mar 13, 2020
1 parent 5f08faa commit ac009d8
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 93 deletions.
3 changes: 2 additions & 1 deletion src/AED/AED.fsproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Acoustics.AED</RootNamespace>
<AssemblyName>Acoustics.AED</AssemblyName>
<Name>AED</Name>
<Deterministic>true</Deterministic>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.7.0" />
<PackageReference Include="MathNet.Numerics.FSharp" Version="4.9.0" />
<PackageReference Include="Microsoft.Bcl.Build" Version="1.0.21" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-unstable0024" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-unstable0702" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-unstable0421" />
Expand Down
4 changes: 2 additions & 2 deletions src/AED/AcousticEventDetection.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.AcousticEventDetection
module Acoustics.AED.AcousticEventDetection

open Microsoft.FSharp.Math
open GetAcousticEvents
Expand Down Expand Up @@ -169,5 +169,5 @@ let detectEvents options a =
detectEventsMinor options a
|> Seq.map (fun ae ->
let points = new System.Collections.Generic.HashSet<Point>(Seq.map toPoint2 ae.Elements)
new Oblong(ae.Bounds.Left, ae.Bounds.Top, right ae.Bounds, bottom ae.Bounds, points))
Oblong(ae.Bounds.Left, ae.Bounds.Top, right ae.Bounds, bottom ae.Bounds, points))

12 changes: 6 additions & 6 deletions src/AED/Default.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace QutSensors.AudioAnalysis.AED
namespace Acoustics.AED

module Default =
open Util
Expand All @@ -18,7 +18,7 @@ module Default =
let doNoiseRemoval = true

type SeparateParameters = {
AreaThreshold : int<px^2>
AreaThreshold : int<Px^2>
MainThreshold : Percent
OrthogonalThreshold : Percent
ExtrapolateBridgeEvents : bool
Expand All @@ -30,9 +30,9 @@ module Default =
| Skip

let largeAreaHorizontal = Horizontal {
AreaThreshold = 3000<px * px>;
MainThreshold = 20.0.percent;
OrthogonalThreshold = 100.0.percent / 3.0;
AreaThreshold = 3000<Px * Px>;
MainThreshold = 20.0.Percent;
OrthogonalThreshold = 100.0.Percent / 3.0;
ExtrapolateBridgeEvents = true
}

Expand All @@ -41,7 +41,7 @@ module Default =
let eprNormalisedMinScore = 4.0/15.0

open System.Runtime.InteropServices
type AedOptions (nyquistFrequency : double,
type public AedOptions (nyquistFrequency : double,
?intensityThreshold,
?smallAreaThreshold ,
?bandPassFilter,
Expand Down
10 changes: 5 additions & 5 deletions src/AED/EventPatternRecog.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.EventPatternRecog
module Acoustics.AED.EventPatternRecog

open Microsoft.FSharp.Math.SI

Expand Down Expand Up @@ -47,8 +47,8 @@ module EprInternals =
/// x'
/// // then, apply g twice in tuple, once each for time and frequency
/// (g t startTime timedimensions nt, g f startfrequency frequencyrange nf)
let normaliseTimeFreq (st:float<s>) (sf:float<Hz>) (td:float<s>) (fr:float<Hz>) (nt:pxf) (nf:pxf) ((t:float<s>),(f:float<Hz>)) =
let rnd l v = let x' = (round v) * px in if x' < px then px else if x' > l then l else x'
let normaliseTimeFreq (st:float<s>) (sf:float<Hz>) (td:float<s>) (fr:float<Hz>) (nt:Pxf) (nf:Pxf) ((t:float<s>),(f:float<Hz>)) =
let rnd l v = let x' = (round v) * Px in if x' < Px then Px else if x' > l then l else x'
let g x s d l = (x - s) / d * (float l) |> rnd l
let h x s d l = (x - s) / d * (float l) |> rnd l
(g t st td nt, h f sf fr nf)
Expand Down Expand Up @@ -106,8 +106,8 @@ module EprInternals =
/// templateFrequency / freqMax * (freqBins - 1.0) //e.g. 11025 / 22050 * (255) = 0.0??
let pixelAxisLengths (ttd:float<s>) (tfr:float<Hz>) =
(
ttd / (freqBins / samplingRate) |> round |> (+) 1.0 |> (*) 1.0<px>,
(tfr / freqMax) * (freqBins - 1.0) |> round |> (+) 1.0 |> (*) 1.0<px>
ttd / (freqBins / samplingRate) |> round |> (+) 1.0 |> (*) 1.0<Px>,
(tfr / freqMax) * (freqBins - 1.0) |> round |> (+) 1.0 |> (*) 1.0<Px>
)

/// function: absLeftAbsBottom rectangleSequence : Seq<a' Rectangle> -> a' * a'
Expand Down
2 changes: 1 addition & 1 deletion src/AED/GetAcousticEvents.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.GetAcousticEvents
module Acoustics.AED.GetAcousticEvents

open Util
open Microsoft.FSharp.Math
Expand Down
2 changes: 1 addition & 1 deletion src/AED/Matlab.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.Matlab
module Acoustics.AED.Matlab

open Util
open Microsoft.FSharp.Math
Expand Down
2 changes: 1 addition & 1 deletion src/AED/SpectralPeakTrack.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.SpectralPeakTrack
module Acoustics.AED.SpectralPeakTrack

open GetAcousticEvents
open Matlab
Expand Down
26 changes: 14 additions & 12 deletions src/AED/Util.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module QutSensors.AudioAnalysis.AED.Util
module Acoustics.AED.Util

open Microsoft.FSharp.Math.SI
open System.Text
Expand Down Expand Up @@ -81,21 +81,22 @@ let matrixMapi2Unzip f (m:matrix) =
(r,s)

/// A unit of measure for a Pixel
[<Measure>] type px
let px = 1.0<px>
[<Measure>] type Px
let Px = 1.0<Px>

type Pixelf = float<px>
type Pixel = int<px>
type Pixelf = float<Px>
type Pixel = int<Px>

// fsharplint:disable-next-line
[<Measure>] type percent
type Percent = float<percent>
let unit p = p / 100.0<percent>
let percent u : Percent = u * 100.0<percent>

type System.Double with
member x.percent = x * 1.0<percent>
member x.toPercent = percent x
member x.toUnit = unit x
member x.Percent = x * 1.0<percent>
member x.ToPercent = percent x
member x.ToUnit = unit x

let inline s x y = x - y
//type 'a Rectangle = {Left:'a; Top:'a; Right:'a; Bottom:'a; Width:'a; Height:'a;}
Expand Down Expand Up @@ -131,7 +132,7 @@ let inline removeDimensions (r:Rectangle<'a,'b>) (convertA:'a) (convertB:'b) : R
}

type EventRect = Rectangle<float<s>, float<Hz>>
type pxf = float<px>
type Pxf = float<Px>

let inline cornersToRect l r t b = {Left=l; Top=t; Right=r; Bottom=b}
let inline lengthsToRect l t w h =
Expand Down Expand Up @@ -161,7 +162,7 @@ let inline oldWidth r = (right r) - (left r)
let inline height r = (top r) - (bottom r) |> abs |> increment
let inline height2 (top:float<_>) (bottom:float<_>) = top - bottom |> abs |> (+) (LanguagePrimitives.FloatWithMeasure 1.0)
let inline area r = (width r) * (height r)
let inline areaUnits r = (area r) * 1<px^2>
let inline areaUnits r = (area r) * 1<Px^2>
let inline isWithin r (x,y) =
not (x < r.Left || x > r.Right || y < r.Top || y > r.Bottom)
//x >= r.Left && x < r.Right && y >= r.Top && y < r.Bottom
Expand All @@ -171,8 +172,8 @@ let inline isWithin2 r (y,x) =
let inline toFloatRect r =
cornersToRect (left r |> float) (right r |> float) (top r |> float) (bottom r |> float)

let inline toPoint (x, y) = new Point(x, y)
let inline toPoint2 (y, x) = new Point(x, y)
let inline toPoint (x, y) = Point(x, y)
let inline toPoint2 (y, x) = Point(x, y)

(* This is currently done the easy, inefficient way.
Expand Down Expand Up @@ -202,5 +203,6 @@ let matrixToCsv (m:matrix) f =

let itemsToFile path (transformer: 'a -> string) items =
use file = File.CreateText(path)
// fsharplint:disable-next-line
Seq.iter (fun x -> x |> transformer |> file.WriteLine) items

76 changes: 61 additions & 15 deletions src/Acoustics.Shared/ImageSharp/Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ public static class Drawing
{
public static readonly Configuration DefaultConfiguration = Configuration.Default;

public static readonly Font Tahoma6 = SystemFonts.CreateFont(Tahoma, 6f);
public static readonly Font Tahoma9 = SystemFonts.CreateFont(Tahoma, 9f);
public static readonly Font Tahoma8 = SystemFonts.CreateFont(Tahoma, 8f);
public static readonly Font Tahoma12 = SystemFonts.CreateFont(Tahoma, 12f);
public static readonly Font Arial8 = SystemFonts.CreateFont(Arial, 8f);
public static readonly Font Arial8Bold = SystemFonts.CreateFont(Arial, 8f, FontStyle.Bold);
public static readonly Font Arial9 = SystemFonts.CreateFont(Arial, 9f);
public static readonly Font Arial9Bold = SystemFonts.CreateFont(Arial, 9f, FontStyle.Bold);
public static readonly Font Arial10 = SystemFonts.CreateFont(Arial, 10f);
public static readonly Font Arial12 = SystemFonts.CreateFont(Arial, 12f);
public static readonly Font Arial12Bold = SystemFonts.CreateFont(Arial, 12f, FontStyle.Bold);
public static readonly Font Arial14 = SystemFonts.CreateFont(Arial, 14f);

public static readonly Configuration NoParallelConfiguration = new Configuration()
{
MaxDegreeOfParallelism = 1,
Expand All @@ -47,17 +34,76 @@ public static class Drawing
//IntersectionRule = IntersectionRule.OddEven,
};

/// <summary>
/// An open source sans-serif font produced by Google that is hopefully a good fallback for missing fonts.
/// </summary>
public const string Roboto = "Roboto";

private const string Tahoma = "Tahoma";

private const string Arial = "Arial";

/// <summary>
/// Fonts bundled with AP.exe.
/// </summary>
private static readonly FontCollection BundledFonts = new FontCollection();

static Drawing()
{
BundledFonts.InstallCollection(System.IO.Path.Combine(AppConfigHelper.ExecutingAssemblyDirectory, Roboto));
}

public static Font GetArial(float size)
public static Font Tahoma6 => GetFont(Tahoma, 6f);

public static Font Tahoma9 => GetFont(Tahoma, 9f);

public static Font Tahoma8 => GetFont(Tahoma, 8f);

public static Font Tahoma12 => GetFont(Tahoma, 12f);

public static Font Arial8 => GetFont(Arial, 8f);

public static Font Arial8Bold => GetFont(Arial, 8f, FontStyle.Bold);

public static Font Arial9 => GetFont(Arial, 9f);

public static Font Arial9Bold => GetFont(Arial, 9f, FontStyle.Bold);

public static Font Arial10 => GetFont(Arial, 10f);

public static Font Arial12 => GetFont(Arial, 12f);

public static Font Arial12Bold => GetFont(Arial, 12f, FontStyle.Bold);

public static Font Arial14 => GetFont(Arial, 14f);

public static Font Arial16 => GetFont(Arial, 16f);

/// <summary>
/// Gets the requested font family or falls back to using <see cref="Roboto" />.
/// </summary>
/// <param name="fontFamily">The name of the font family to get.</param>
/// <param name="size">The requested size of the returned font.</param>
/// <param name="style">The requested style of the returned font.</param>
/// <returns>Thr requested font, or the Roboto font if the requested font cannot be found.</returns>
public static Font GetFont(string fontFamily, float size, FontStyle style = FontStyle.Regular)
{
// TODO: cache?
return SystemFonts.CreateFont(Arial, size);
if (fontFamily == Roboto)
{
// shortcut case
return BundledFonts.CreateFont(fontFamily, size, style);
}
else if (SystemFonts.TryFind(fontFamily, out var family))
{
// default case
return family.CreateFont(size, style);
}
else
{
// fallback case
return BundledFonts.CreateFont(fontFamily, size, style);
}
}

public static Image<Rgb24> NewImage(int width, int height, Color fill)
Expand Down
15 changes: 0 additions & 15 deletions src/Acoustics.Tools/Acoustics.testsettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
<Description>These are default test settings for a local test run.</Description>
<Deployment>
<DeploymentItem filename="AnalysisConfigFiles\" />
<DeploymentItem filename="I:\Projects\QUT\QutSensors\sensors-trunk\Extra Assemblies\mp3splt\" />
<DeploymentItem filename="I:\Projects\QUT\QutSensors\sensors-trunk\Extra Assemblies\wavpack\" />
<DeploymentItem filename="I:\Projects\QUT\QutSensors\sensors-trunk\Extra Assemblies\sox\" />
<DeploymentItem filename="I:\Projects\QUT\QutSensors\sensors-trunk\Extra Assemblies\shntool\" />
<DeploymentItem filename="I:\Projects\QUT\QutSensors\sensors-trunk\Extra Assemblies\ffmpeg\" />
</Deployment>
<Execution>
<TestTypeSpecific>
Expand All @@ -16,16 +11,6 @@
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 9.0" MaxConnections="6">
<Headers>
<Header name="User-Agent" value="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
Expand Down
3 changes: 2 additions & 1 deletion src/AnalysisPrograms/AED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace AnalysisPrograms
using McMaster.Extensions.CommandLineUtils;
using Microsoft.FSharp.Core;
using Production.Arguments;
using QutSensors.AudioAnalysis.AED;
using Acoustics.AED;
using TowseyLibrary;

/// <summary>
Expand Down Expand Up @@ -152,6 +152,7 @@ public static Tuple<AcousticEvent[], AudioRecording, BaseSonogram> Detect(
public static AcousticEvent[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
{
Log.Info("AED start");

var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
{
IntensityThreshold = aedConfiguration.IntensityThreshold,
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/ConcatenateIndexFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public static void ConcatenateRibbonImages(DirectoryInfo[] dataDirs, string patt
var compositeBmp = (Image<Rgb24>)ImageTools.CombineImagesVertically(imageList);

// create left side day scale
var stringFont = Drawing.GetArial(16);
var stringFont = Drawing.Arial16;
imageList = new List<Image<Rgb24>>();

for (int i = 0; i < imageCount; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/EPR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace AnalysisPrograms
///
/// var binaryMatrix = ConvertSpectrogram2Binary(spectrogram, threshold);
/// var matrix = Microsoft.FSharp.Math.MatrixModule.ofArray2D(binaryMatrix);
/// var aeList = QutSensors.AudioAnalysis.AED.GetAcousticEvents.getAcousticEvents(matrix);
/// var aeList = Acoustics.AED.GetAcousticEvents.getAcousticEvents(matrix);
///
/// more info here:
/// http://stackoverflow.com/questions/271966/about-using-f-to-create-a-matrix-assembly-usable-from-c
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/GroundParrotRecogniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace AnalysisPrograms
using McMaster.Extensions.CommandLineUtils;
using Production;
using Production.Arguments;
using QutSensors.AudioAnalysis.AED;
using Acoustics.AED;
using TowseyLibrary;
using Path = System.IO.Path;

Expand Down
4 changes: 2 additions & 2 deletions src/AnalysisPrograms/SnrAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public static void Execute(Arguments arguments)

//bool DRAW_SONOGRAMS = (bool?)configuration.DrawSonograms ?? true; //options to draw sonogram

//double intensityThreshold = QutSensors.AudioAnalysis.AED.Default.intensityThreshold;
//double intensityThreshold = Acoustics.AED.Default.intensityThreshold;
//if (dict.ContainsKey(key_AED_INTENSITY_THRESHOLD)) intensityThreshold = Double.Parse(dict[key_AED_INTENSITY_THRESHOLD]);
//int smallAreaThreshold = QutSensors.AudioAnalysis.AED.Default.smallAreaThreshold;
//int smallAreaThreshold = Acoustics.AED.Default.smallAreaThreshold;
//if( dict.ContainsKey(key_AED_SMALL_AREA_THRESHOLD)) smallAreaThreshold = Int32.Parse(dict[key_AED_SMALL_AREA_THRESHOLD]);

// COnvert input recording into wav
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/Spt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace AnalysisPrograms
using Microsoft.FSharp.Math;
using Production.Arguments;
using Production.Validation;
using QutSensors.AudioAnalysis.AED;
using Acoustics.AED;
using TowseyLibrary;

public class SPT
Expand Down
Loading

0 comments on commit ac009d8

Please sign in to comment.