コード例 #1
0
        //[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");
        }
コード例 #2
0
        //[Ignore]
        public void ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose()
        {
            if (File.Exists("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5"))
            {
                File.Delete("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5");
            }

            var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}");

            using (
                var exp =
                    new EpochHDF5Persistor("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.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.Close();
            }

            Approvals.VerifyFile("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5");
        }
コード例 #3
0
        public void ShouldThrowExceptionIfNoOpenEpochGroup()
        {
            if (File.Exists("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5"))
            {
                File.Delete("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5");
            }

            using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5", null, 9))
            {
                Assert.That(() => exp.Serialize(testEpoch), Throws.InvalidOperationException);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public void ShouldAllowMultipleOpenPersistors()
        {
            if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5"))
            {
                File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5");
            }

            if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5"))
            {
                File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5");
            }

            var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}");

            using (var p1 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.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");

                p1.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid,
                                   time);

                p1.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2,
                                   time);

                using (
                    var p2 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5", null, () => gID)
                    )
                {
                    p2.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid,
                                       time);

                    p2.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2,
                                       time);

                    p2.Serialize(testEpoch);
                    p2.EndEpochGroup();
                    p2.EndEpochGroup();
                }

                p1.Serialize(testEpoch);
                p1.EndEpochGroup();
                p1.EndEpochGroup();
            }

            Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5");
            Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5");
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        /// <summary>
        /// Begin a new Epoch Group (i.e. a logical block of Epochs). As each Epoch Group is persisted
        /// to a separate data file, this method creates the appropriate output file and
        /// EpochPersistor instance.
        /// </summary>
        /// <param name="path">The name of the file into which to store the epoch; if the name
        ///   ends in ".xml", it will store the file using the EpochXMLPersistor, and if the name
        ///   ends in ".hdf5", it will store the file using the EpochHDF5Persistor. This file will
        ///   be overwritten if it already exists at this location.</param>
        /// <param name="epochGroupLabel">Label for the new Epoch Group</param>
        /// <param name="source">Identifier for EpochGroup's Source</param>
        /// <param name="keywords"></param>
        /// <param name="properties"></param>
        /// <returns>The EpochPersistor instance to be used for saving Epochs</returns>
        /// <see cref="RunEpoch"/>
        public EpochPersistor BeginEpochGroup(string path, string epochGroupLabel, string source, IEnumerable <string> keywords, IDictionary <string, object> properties)
        {
            EpochPersistor result = null;

            if (path.EndsWith(".xml"))
            {
                result = new EpochXMLPersistor(path);
            }
            else if (path.EndsWith(".hdf5"))
            {
                result = new EpochHDF5Persistor(path, null);
            }
            else
            {
                throw new ArgumentException(String.Format("{0} doesn't look like a legit Epoch filename", path));
            }

            var kws   = keywords == null ? new string[0] : keywords.ToArray();
            var props = properties ?? new Dictionary <string, object>();

            result.BeginEpochGroup(epochGroupLabel, source, kws, props, Guid.NewGuid(), DateTime.Now);

            return(result);
        }
コード例 #8
0
        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();

                }
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public void ShouldThrowExceptionIfNoOpenEpochGroup()
        {
            if (File.Exists("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5"))
                File.Delete("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5");

            using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldThrowExceptionIfNoOpenEpochGroup.h5", null, 9))
            {
                Assert.That(() => exp.Serialize(testEpoch), Throws.InvalidOperationException);
            }
        }
コード例 #11
0
        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");
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        public void ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose()
        {
            if (File.Exists("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5"))
                File.Delete("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5");

            var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}");
            using (
                var exp =
                    new EpochHDF5Persistor("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.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.Close();
            }

            Approvals.VerifyFile("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5");
        }
コード例 #14
0
        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");
        }
コード例 #15
0
        public void ShouldAllowMultipleOpenPersistors()
        {
            if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5"))
                File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5");

            if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5"))
                File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5");

            var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}");
            using (var p1 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.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");

                p1.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid,
                                   time);

                p1.BeginEpochGroup("label2", "source2", new string[0], new Dictionary<string, object>(), guid2,
                                   time);

                using (
                    var p2 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5", null, () => gID)
                    )
                {
                    p2.BeginEpochGroup("label1", "source1", new string[0], new Dictionary<string, object>(), guid,
                                       time);

                    p2.BeginEpochGroup("label2", "source2", new string[0], new Dictionary<string, object>(), guid2,
                                       time);

                    p2.Serialize(testEpoch);
                    p2.EndEpochGroup();
                    p2.EndEpochGroup();
                }

                p1.Serialize(testEpoch);
                p1.EndEpochGroup();
                p1.EndEpochGroup();
            }

            Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5");
            Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5");
        }
コード例 #16
0
        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());
        }
コード例 #17
0
        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());
        }
コード例 #18
0
        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");
        }
コード例 #19
0
        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));
        }