//[Ignore] public void ShouldAllowNestedEpochGroupsInHDF5() { if (File.Exists("..\\..\\..\\ShouldAllowNestedEpochGroupsInHDF5.h5")) { File.Delete("..\\..\\..\\ShouldAllowNestedEpochGroupsInHDF5.h5"); } var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNestedEpochGroupsInHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var guid2 = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid, time); exp.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.EndEpochGroup(); exp.Close(); } Approvals.VerifyFile("..\\..\\..\\ShouldAllowNestedEpochGroupsInHDF5.h5"); }
//[Ignore] public void ShouldPersistToHDF5() { // Check and delete the HDF5 file here, NOT in TearDown, because we // want the file to exist after the test run (contrary to everything // unit-testing preaches) so that we can look at the file contents via // h5dump to verify what it looks like; unfortunately, at this time, // unit-testing HDF5 is a PITA (pain in the ass, for those of you // who are acronymatically challenged), so approval testing // is the next-best-thing we can do at the moment. if (File.Exists("..\\..\\..\\ShouldPersistToHDF5.h5")) { File.Delete("..\\..\\..\\ShouldPersistToHDF5.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldPersistToHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldPersistToHDF5.h5"); }
public void ShouldThrowInvalidOperationExcpetionClosingEpochGroupWithoutOpenEpochGroup() { if (File.Exists("epochtest.h5")) { File.Delete("epochtest.h5"); } using (var exp = new EpochHDF5Persistor("epochtest.h5", null, 9)) { Assert.That(() => exp.EndEpochGroup(), Throws.InvalidOperationException); } }
public void AppendToExistingHDF5() { if (File.Exists("AppendToExistingHDF5.h5")) File.Delete("AppendToExistingHDF5.h5"); var gID = new Guid("a5839fe9-90ef-4e39-bf26-8f75048306a4"); using (var exp = new EpochHDF5Persistor("AppendToExistingHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6)); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid, time); RunSingleEpoch(5000, 2, exp); exp.EndEpochGroup(); exp.Close(); } gID = new Guid("a5839fe9-90ef-4e39-bf26-8f75048306a5"); using (var exp = new EpochHDF5Persistor("AppendToExistingHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6)); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid, time); RunSingleEpoch(5000, 2, exp); exp.EndEpochGroup(); exp.Close(); } Approvals.VerifyFile("AppendToExistingHDF5.h5"); }
public void ShouldThrowInvalidOperationExcpetionClosingEpochGroupWithoutOpenEpochGroup() { if (File.Exists("epochtest.h5")) File.Delete("epochtest.h5"); using (var exp = new EpochHDF5Persistor("epochtest.h5", null, 9)) { Assert.That(() => exp.EndEpochGroup(), Throws.InvalidOperationException); } }
public void ShouldPersistToHDF5() { // Check and delete the HDF5 file here, NOT in TearDown, because we // want the file to exist after the test run (contrary to everything // unit-testing preaches) so that we can look at the file contents via // h5dump to verify what it looks like; unfortunately, at this time, // unit-testing HDF5 is a PITA (pain in the ass, for those of you // who are acronymatically challenged), so approval testing // is the next-best-thing we can do at the moment. if (File.Exists("..\\..\\..\\ShouldPersistToHDF5.h5")) File.Delete("..\\..\\..\\ShouldPersistToHDF5.h5"); var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldPersistToHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldPersistToHDF5.h5"); }
public void ShouldCompressNumericData() { String uncompressedPath = "ShouldCompressNumericData_0.h5"; String compressedPath = "ShouldCompressNumericData_9.h5"; long uncompressedLength = 0; long compressedLength = 0; var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); try { using (var exp = new EpochHDF5Persistor(uncompressedPath, null, () => gID, 0)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } uncompressedLength = new FileInfo(uncompressedPath).Length; } finally { if (File.Exists(uncompressedPath)) File.Delete(uncompressedPath); } gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5386}"); try { using (var exp = new EpochHDF5Persistor(compressedPath, null, () => gID, 9)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); var props = new Dictionary<string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } compressedLength = new FileInfo(compressedPath).Length; } finally { if (File.Exists(compressedPath)) File.Delete(compressedPath); } Console.WriteLine("{0} => {1} bytes", uncompressedLength, compressedLength); Assert.That(compressedLength, Is.LessThan(uncompressedLength/2)); }
public void ShouldAppendToExistingFile() { if (File.Exists("..\\..\\..\\ShouldAppendToExistingFile.h5")) File.Delete("..\\..\\..\\ShouldAppendToExistingFile.h5"); var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAppendToExistingFile.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var guid2 = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid, time); exp.BeginEpochGroup("label2", "source2", new string[0], new Dictionary<string, object>(), guid2, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.EndEpochGroup(); } using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAppendToExistingFile.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); var guid2 = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97F"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid, time); exp.BeginEpochGroup("label2", "source2", new string[0], new Dictionary<string, object>(), guid2, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.EndEpochGroup(); } Approvals.VerifyFile("..\\..\\..\\ShouldAppendToExistingFile.h5"); }
public void ShouldAllowNumericEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowNumericEpochParameters.h5")) File.Delete("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNumericEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["int"] = 2; props["float"] = 2.0f; props["double"] = 2.0d; props["decimal"] = 2.0m; props["array"] = new[] {1.0, 2.0, 3.0}; props["short"] = (short) 2; props["unit16"] = (UInt16) 1; props["uint32"] = (UInt32) 2; props["byte"] = (byte) 1; props["bool"] = true; const string protocolID = "Epoch.Fixture"; Dictionary<string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List<Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal) Math.Sin((double) i/100), "V")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe<DateTimeOffset>.Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary<string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); }
public void ShouldAllowLongStringEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5")) File.Delete("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5"); var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["key1"] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; //100 elements props["key2"] = 2; const string protocolID = "Epoch.Fixture"; Dictionary<string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List<Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal) Math.Sin((double) i/100), "mV")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe<DateTimeOffset>.Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary<string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(time.AddMilliseconds(100)); exp.Close(); } H5.Close(); var startInfo = new ProcessStartInfo(@"..\..\..\..\..\..\externals\HDF5\bin\h5dump", @" --xml ..\..\..\ShouldAllowLongStringEpochParameters.h5"); startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; Process proc = Process.Start(startInfo); Approvals.VerifyXml(proc.StandardOutput.ReadToEnd()); }
public void ShouldCompressNumericData() { String uncompressedPath = "ShouldCompressNumericData_0.h5"; String compressedPath = "ShouldCompressNumericData_9.h5"; long uncompressedLength = 0; long compressedLength = 0; var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); try { using (var exp = new EpochHDF5Persistor(uncompressedPath, null, () => gID, 0)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } uncompressedLength = new FileInfo(uncompressedPath).Length; } finally { if (File.Exists(uncompressedPath)) { File.Delete(uncompressedPath); } } gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5386}"); try { using (var exp = new EpochHDF5Persistor(compressedPath, null, () => gID, 9)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); var props = new Dictionary <string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } compressedLength = new FileInfo(compressedPath).Length; } finally { if (File.Exists(compressedPath)) { File.Delete(compressedPath); } } Console.WriteLine("{0} => {1} bytes", uncompressedLength, compressedLength); Assert.That(compressedLength, Is.LessThan(uncompressedLength / 2)); }
public void ShouldAllowNumericEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowNumericEpochParameters.h5")) { File.Delete("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNumericEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["int"] = 2; props["float"] = 2.0f; props["double"] = 2.0d; props["decimal"] = 2.0m; props["array"] = new[] { 1.0, 2.0, 3.0 }; props["short"] = (short)2; props["unit16"] = (UInt16)1; props["uint32"] = (UInt32)2; props["byte"] = (byte)1; props["bool"] = true; const string protocolID = "Epoch.Fixture"; Dictionary <string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List <Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); }
public void ShouldAllowLongStringEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5")) { File.Delete("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["key1"] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; //100 elements props["key2"] = 2; const string protocolID = "Epoch.Fixture"; Dictionary <string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List <Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "mV")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(time.AddMilliseconds(100)); exp.Close(); } H5.Close(); var startInfo = new ProcessStartInfo(@"..\..\..\..\..\..\externals\HDF5\bin\h5dump", @" --xml ..\..\..\ShouldAllowLongStringEpochParameters.h5"); startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; Process proc = Process.Start(startInfo); Approvals.VerifyXml(proc.StandardOutput.ReadToEnd()); }
public void LongEpochPersistence( [Values(5,60)] double epochDuration, //seconds [Values(2)] int nEpochs ) { const decimal sampleRate = 10000m; const string h5Path = "..\\..\\..\\LongEpochPersistence.h5"; if (File.Exists(h5Path)) File.Delete(h5Path); Logging.ConfigureConsole(); Converters.Clear(); Converters.Register("V", "V", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); HekaDAQInputStream.RegisterConverters(); HekaDAQOutputStream.RegisterConverters(); Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0)); foreach (var daq in HekaDAQController.AvailableControllers()) { try { daq.InitHardware(); daq.SampleRate = new Measurement(sampleRate, "Hz"); var controller = new Controller {Clock = daq, DAQController = daq}; var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, new Measurement(0, "V")) { MeasurementConversionTarget = "V", Clock = daq }; dev0.BindStream((IDAQOutputStream) daq.GetStreams("ANALOG_OUT.0").First()); dev0.BindStream((IDAQInputStream) daq.GetStreams("ANALOG_IN.0").First()); for (int j = 0; j < nEpochs; j++) { // Setup Epoch var e = new Epoch("HekaIntegration"); var nSamples = (int) TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate); IList<IMeasurement> stimData = (IList<IMeasurement>) Enumerable.Range(0, nSamples) .Select( i => new Measurement( (decimal) (8* Math.Sin(((double) i)/ (nSamples/10.0))), "V") as IMeasurement) .ToList(); e.Stimuli[dev0] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(), (IOutputData) new OutputData(stimData, daq.SampleRate)); e.Responses[dev0] = new Response(); e.Background[dev0] = new Epoch.EpochBackground(new Measurement(0, "V"), daq.SampleRate); //Run single epoch using (var persistor = new EpochHDF5Persistor(h5Path, null, 9)) { persistor.BeginEpochGroup("label", "source", new string[0], new Dictionary<string, object>(), Guid.NewGuid(), DateTimeOffset.Now); controller.RunEpoch(e, persistor); persistor.EndEpochGroup(); } Assert.That((bool) e.StartTime, Is.True); Assert.That((DateTimeOffset) e.StartTime, Is.LessThanOrEqualTo(controller.Clock.Now)); Assert.That(e.Responses[dev0].Duration, Is.EqualTo(((TimeSpan) e.Duration)) .Within(TimeSpanExtensions.FromSamples(1, daq. SampleRate))); //Assert.That(e.Responses[dev1].Duration, Is.EqualTo(((TimeSpan) e.Duration)) // .Within(TimeSpanExtensions.FromSamples(1, // daq. // SampleRate))); } } finally { if (File.Exists(h5Path)) File.Delete(h5Path); if (daq.HardwareReady) daq.CloseHardware(); } } }