Skip to content

Commit

Permalink
Small Changes
Browse files Browse the repository at this point in the history
- Fixed a bug that would resulted in triggers with similar trigger
numbers but unequal timings to be removed.
- Added an option that has the tool offset the trigger onset in
Presentation software generated logs due to Pauses (Presentation time is
paused during the pauses so results in asynchrony.
  • Loading branch information
Chris van Run authored and Chris van Run committed Feb 20, 2015
1 parent 5204d6a commit 3b439f5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 16 deletions.
9 changes: 7 additions & 2 deletions EDFPlusCheckerEngine/Engine/Actions/ActionCompareTriggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override string Act()
// same triggernumber, unequal timing.
else
{
if (this.EqNumberUneqTiming_RemoveRec && !RemoveList.Contains(EDFPlusTriggers[j]))
if (this.EqNumberUneqTiming_RemoveRec && !RemoveList2.Contains(EDFPlusTriggers[j])&&!RemoveList.Contains(EDFPlusTriggers[j]))
RemoveList2.Add(EDFPlusTriggers[j]);
}
}
Expand All @@ -64,7 +64,7 @@ public override string Act()
// different triggernumber, equal timing.
if (Map[i].SameTiming(EDFPlusTriggers[j], ErrorMargin))
{
if (this.UneqNumberEqTiming_RemoveRec && !RemoveList.Contains(EDFPlusTriggers[j]))
if (this.UneqNumberEqTiming_RemoveRec && !RemoveList.Contains(EDFPlusTriggers[j]) && !RemoveList2.Contains(EDFPlusTriggers[j]))
RemoveList.Add(EDFPlusTriggers[j]);
}
// different triggernumber, different timing.
Expand Down Expand Up @@ -136,6 +136,11 @@ public override string Act()

Control.Log(Environment.NewLine, PrintInConsole);

foreach (Trigger trig in RemoveList2)
{
RemoveList.Add(trig);
}

//fill control variable with the differences
Control.DifferenceBetweenFiles = new DifferenceFile(AddList, RemoveList);

Expand Down
5 changes: 3 additions & 2 deletions EDFPlusCheckerEngine/Engine/Actions/ActionOpenFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public override string Act()
Control.EDFPlusHandle.ReadTALsToMemory();
}
else
throw new ActionCannotDoWhatDoBeDo("Couldn't find file: " + @EDFFileName);
throw new ActionCannotDoWhatDoBeDo("Couldn't find or access file: " + @EDFFileName);

if (File.Exists(@PresentationLogFilename))
Control.PresentationLogHandle = new PresentationLogFile(this.Control, @PresentationLogFilename);

else
throw new ActionCannotDoWhatDoBeDo("Couldn't find or access file: " + @PresentationLogFilename);
Active = false;

string Description = "Action: Opened File(s): ";
Expand Down
1 change: 1 addition & 0 deletions EDFPlusCheckerEngine/Engine/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public bool HasLogFiles
public int[] TriggerNumbersToIgnore = new int[0];
public int TriggerNumberLowerLimit = 0;
public int TriggerNumberUpperLimit = 9999;
public bool CorrectForPauses;

private StreamWriter ApplicationLogFile;

Expand Down
26 changes: 22 additions & 4 deletions EDFPlusCheckerEngine/Engine/FileHandles/PresentationLogFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Trigger[] Triggers {
get {
if(_Triggers == null)
{
_Triggers = GetTriggers(Owner.TriggerNumbersToIgnore, Owner.TriggerNumberLowerLimit, Owner.TriggerNumberUpperLimit);
_Triggers = GetTriggers(Owner.TriggerNumbersToIgnore, Owner.TriggerNumberLowerLimit, Owner.TriggerNumberUpperLimit, Owner.CorrectForPauses);
}
return _Triggers;
}
Expand All @@ -39,20 +39,38 @@ public string[] GetDataColumn(string header)
return Data[IndexOfColumn].ToArray<string>();
}

private Trigger[] GetTriggers( int[] triggersToIgnore, int lowerTriggerLimit, int upperTriggerLimit)
private Trigger[] GetTriggers( int[] triggersToIgnore, int lowerTriggerLimit, int upperTriggerLimit, bool CorrectForPauses = true)
{
string[] CodeColumn = GetDataColumn("Code");
string[] TimingColumn = GetDataColumn("Time");
string[] UncertaintyColumn = GetDataColumn("Uncertainty");

string[] EventTypeColumn = new string[0];
string[] DurationColumn = new string[0];

if (CorrectForPauses)
{
EventTypeColumn = GetDataColumn("Event Type");
DurationColumn = GetDataColumn("Duration");
}

if(CodeColumn.Length != TimingColumn.Length || TimingColumn.Length != UncertaintyColumn.Length)
throw new ActionCannotDoWhatDoBeDo("Something fishy going on with the length of the columns in the Presentation file " + this.FileName);

List<Trigger> Result = new List<Trigger>(CodeColumn.Length);
int PauseOffset = 0;

for (int i = 0; i < CodeColumn.Length; i++)
{
int TriggerNumber = -1;

if (CorrectForPauses && EventTypeColumn[i] == "Pause")
{
int PauseDuration;
if (!int.TryParse(DurationColumn[i], out PauseDuration))
throw new ActionCannotDoWhatDoBeDo("Something fishy going on with PresentationLog Event Type of Duration column");
PauseOffset += PauseDuration;
}

if (int.TryParse(CodeColumn[i], out TriggerNumber) && TriggerNumber <= upperTriggerLimit && TriggerNumber >= lowerTriggerLimit && !triggersToIgnore.Contains(TriggerNumber))
{
int OnsetTimeOneTenth = -9999;
Expand All @@ -61,7 +79,7 @@ private Trigger[] GetTriggers( int[] triggersToIgnore, int lowerTriggerLimit, in
if (!int.TryParse(TimingColumn[i], out OnsetTimeOneTenth) || !int.TryParse(UncertaintyColumn[i], out UncertaintyOneTenth))
throw new ActionCannotDoWhatDoBeDo("Something fishy going on with PresentationLog OnsetTime (TIME column)");

double OnsetTime = ((double) OnsetTimeOneTenth)/10000;
double OnsetTime = ((double)OnsetTimeOneTenth + PauseOffset) / 10000;
double Uncertainty = ((double) UncertaintyOneTenth)/10000;
Result.Add(new Trigger(OnsetTime, Uncertainty, TriggerNumber));
}
Expand Down
28 changes: 22 additions & 6 deletions EDFPlusCheckerEngine/Engine/TimeFrameConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class TimeFrameConverter
public Controller Control;

private double[,] TimeStamps;
private int[,] NumberStamps;

public int NumberOfTries;

//EEGtime_missing_marker = ( (Prestime_missing_marker - PresentationFirst) * (AnalyzerLast- AnalyzerFirst) / (PresentationLast - PresentationFirst) ) + AnalyzerFirst
public bool TimeConvertTriggers(Trigger[] mapFrom, out Trigger[] mapToo)
Expand All @@ -32,22 +35,25 @@ public bool TimeConvertTriggers(Trigger[] mapFrom, out Trigger[] mapToo)
return true;
}

public string ToString()
public override string ToString()
{
StringBuilder Description = new StringBuilder();
Description.Append("Time Conversion Target:\t");
Description.AppendLine(Math.Round(TimeStamps[0, 0], 3) + "s and " + Math.Round(TimeStamps[0, 1], 3) + "s");
Description.Append("Time Conversion Source:\t");
Description.AppendLine(Math.Round(TimeStamps[1, 0], 3) + "s and " + Math.Round(TimeStamps[1, 1], 3) + "s");
Description.Append("Time Conversion Logged File:\t");
Description.AppendLine(String.Format("{0:0.000}s ({1}) and {2:0.000}s ({3})", TimeStamps[0, 0], NumberStamps[0, 0], TimeStamps[0, 1], NumberStamps[0, 1]));
Description.Append("Time Conversion Recording File:\t");
Description.AppendLine(String.Format("{0:0.000}s ({1}) and {2:0.000}s ({3})", TimeStamps[1, 0], NumberStamps[1, 0], TimeStamps[1, 1], NumberStamps[1, 1]));
Description.AppendLine("Number of attempts: " + this.NumberOfTries);
return Description.ToString();
}

public bool FindTimeConversion(Trigger[] mapFrom, Trigger[] mapToo, int verificationWindowSize, double errorMargin)
{
double[,] TempTimeStamps = new double[2, 2];

int[,] TempNumberStamps = new int[2, 2];
bool TimeConversionFound = false;

this.NumberOfTries = 1;

//Initiate search starting from the tops.
for (int i = 0; i < mapToo.Length; i++)
{
Expand All @@ -63,14 +69,24 @@ public bool FindTimeConversion(Trigger[] mapFrom, Trigger[] mapToo, int verifica
{
TempTimeStamps[0, 0] = mapFrom[j].ApproximateOnsetInSeconds;
TempTimeStamps[0, 1] = mapFrom[b].ApproximateOnsetInSeconds;

TempNumberStamps[0, 0] = mapFrom[j].TriggerNumber;
TempNumberStamps[0, 1] = mapFrom[b].TriggerNumber;

TempTimeStamps[1, 0] = mapToo[i].ApproximateOnsetInSeconds;
TempTimeStamps[1, 1] = mapToo[a].ApproximateOnsetInSeconds;

TempNumberStamps[1, 0] = mapFrom[i].TriggerNumber;
TempNumberStamps[1, 1] = mapFrom[a].TriggerNumber;

if (FindVerificationWindow(mapFrom, mapToo, verificationWindowSize, errorMargin, TempTimeStamps))
{
this.TimeStamps = TempTimeStamps;
this.NumberStamps = TempNumberStamps;
return true;
}
else
this.NumberOfTries++;
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion EDFPlusCheckerGUI/ConfigurationWindow/ParseTriggerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@
</GroupBox>

<GroupBox Header="Log File (Presentation)" Grid.Row="4" FontSize="12" Margin="5" Padding="5">
<Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Content="Presentation-Log event codes are ignored if they do not parse into integers. "/>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" >
<Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Content="Presentation-Log event codes are ignored if they do not parse into integers. "/>
<CheckBox Margin="5" x:Name="CorrectForPausesCheckbox" Content="Correct for Pauses in trigger onsets." HorizontalAlignment="Center" IsChecked="True"/>
</StackPanel>

</GroupBox>

</Grid>
</src:ConfigurationPageBase>

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public override bool ConfigureEngine(out string possibleErrorMessage)
Engine.TriggerNumberLowerLimit = TriggerLowerLimit;
Engine.TriggerNumberUpperLimit = TriggerUpperLimit;
Engine.TriggerNumbersToIgnore = IgnoreTriggers_int;
Engine.CorrectForPauses = CorrectForPausesCheckbox.IsChecked == true;
}

}
Expand Down
2 changes: 1 addition & 1 deletion EDFPlusCheckerGUI/MainEDFPlusCheckerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void MyBackGroundWorker_RunWorkerCompleted(object sender, RunWorkerCom
else
{
StatusTextBox.Text = "An error has occured! The background worker has crashed!";
throw new Exception("The background worker has crashed!", e.Error);
throw new Exception("The background worker has crashed!", e.Error.InnerException);
}
ExitButton.IsEnabled = true;
StartButton.IsEnabled = false;
Expand Down

0 comments on commit 3b439f5

Please sign in to comment.