Skip to content

Commit

Permalink
Refactored code for the Boobook owl
Browse files Browse the repository at this point in the history
Issue #370
  • Loading branch information
towsey authored and atruskie committed Oct 14, 2020
1 parent def462a commit aef31d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ Profiles:

#################### POST-PROCESSING of EVENTS ###################

# A: First post-processing steps are to combine overlapping/proximal/sequential events
# The first two post-processing steps are to combine overlapping/proximal/sequential events
# 1: Combine overlapping events
CombineOverlappingEvents: true

# 2: Combine each pair of Boobook syllables as one event
# Can also use this to "mop up" events in neighbourhood - these can be removed later.
CombinePossibleSyllableSequence: true
SyllableStartDifference: 0.6
SyllableHertzGap: 350
# 2: Combine possible syllable sequences
# Can also use this to "mop up" events in neighbourhood - these can be removed later.
SyllableSequence:
CombinePossibleSyllableSequence: true
SyllableStartDifference: 0.6
SyllableHertzGap: 350
FilterSyllableSequence: true
SyllableMaxCount: 2
ExpectedPeriod: 0.4

# B: Filter the events for excess activity in their upper and lower buffer zones
# 3: Remove events whose bandwidth lies outside 3 SDs of an expected value.
ExpectedBandwidth: 280
BandwidthStandardDeviation: 40

# 4: Filter the events for excess activity in their upper and lower buffer zones
NeighbourhoodLowerHertzBuffer: 150
NeighbourhoodUpperHertzBuffer: 400
NeighbourhoodDbThreshold: 9.0
Expand Down
51 changes: 17 additions & 34 deletions src/AnalysisPrograms/Recognizers/Birds/NinoxBoobook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,46 +91,30 @@ public override RecognizerResults Recognize(
outputDirectory,
imageWidth);

// ################### POST-PROCESSING of EVENTS ###################
// Following two commented lines are different ways of casting lists.
//var newEvents = spectralEvents.Cast<EventCommon>().ToList();
//var spectralEvents = events.Select(x => (SpectralEvent)x).ToList();

var count = combinedResults.NewEvents.Count;
BoobookLog.Debug($"Event count before post-processing = {count}.");
if (combinedResults.NewEvents.Count == 0)
{
BoobookLog.Debug($"Return zero events.");
return combinedResults;
}

// 1: Filter the events for duration in seconds
// Get the BoobookSyllable config.
const string profileName = "BoobookSyllable";
var configuration = (NinoxBoobookConfig)genericConfig;
var chirpConfig = (ForwardTrackParameters)configuration.Profiles[profileName];
var minimumEventDuration = chirpConfig.MinDuration;
var maximumEventDuration = chirpConfig.MaxDuration;
if (genericConfig.CombinePossibleSyllableSequence)
{
minimumEventDuration *= 2.0;
maximumEventDuration *= 1.5;
}

combinedResults.NewEvents = EventExtentions.FilterOnDuration(combinedResults.NewEvents, minimumEventDuration.Value, maximumEventDuration.Value);
BoobookLog.Debug($"Event count after filtering on duration = {combinedResults.NewEvents.Count}");
// ################### POST-PROCESSING of EVENTS ###################
// Following two commented lines are different ways of casting lists.
//var newEvents = spectralEvents.Cast<EventCommon>().ToList();
//var spectralEvents = events.Select(x => (SpectralEvent)x).ToList();

// 2: Filter the events for bandwidth in Hertz
double average = 280;
double sd = 40;
double sigmaThreshold = 3.0;
combinedResults.NewEvents = EventExtentions.FilterOnBandwidth(combinedResults.NewEvents, average, sd, sigmaThreshold);
BoobookLog.Debug($"Event count after filtering on bandwidth = {combinedResults.NewEvents.Count}");
//NOTE:
// The generic recognizer does some post-processing of events prior to returning the list of combined events.
// Its post-processing steps are determined by config settings.
// Generic post processing step 1: Combine overlapping events.
// Generic post processing step 2: Combine possible syllable sequences and filter on excess syllable count.
// Generic post processing step 3: Remove events whose bandwidth is too small or large.
// Generic post processing step 4: Remove events that have excessive noise in their side-bands.

// 3: Filter on COMPONENT COUNT in Composite events.
int maxComponentCount = 2;
combinedResults.NewEvents = EventExtentions.FilterEventsOnCompositeContent(combinedResults.NewEvents, maxComponentCount);
BoobookLog.Debug($"Event count after filtering on component count = {combinedResults.NewEvents.Count}");
// The following post processing steps are specific for this species recognizer:
// 1: Pull out the chirp events and calculate their frequency profiles.
// Filter chirp events based on their frequency profiles.

// 4: Pull out the chirp events and calculate their frequency profiles.
var (chirpEvents, others) = combinedResults.NewEvents.FilterForEventType<ChirpEvent, EventCommon>();

// Uncomment the next line when want to obtain the event frequency profiles.
Expand All @@ -143,8 +127,7 @@ public override RecognizerResults Recognize(

if (combinedResults.NewEvents.Count == 0)
{
BoobookLog.Debug($"Return zero events.");
return combinedResults;
BoobookLog.Debug($"Zero events after post-processing.");
}

//UNCOMMENT following line if you want special debug spectrogram, i.e. with special plots.
Expand Down

0 comments on commit aef31d3

Please sign in to comment.