//[UseReporter(typeof(FileLauncherReporter))]
        public void SingleEpochHDF5Persistence()
        {
            if (File.Exists("SingleEpochHDF5Persistence.h5"))
            {
                File.Delete("SingleEpochHDF5Persistence.h5");
            }

            var gID = new Guid("a5839fe9-90ef-4e39-bf26-8f75048306a4");

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

            Approvals.VerifyFile("SingleEpochHDF5Persistence.h5");
        }
Esempio n. 2
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();
                    }
                }
            }
        }