Пример #1
0
        public void EnumeratesDataBlocks(
            [Values(100, 500, 1000, 5000)] double blockMilliseconds,
            [Values(1000, 5000, 10000)] double sampleRateHz
            )
        {
            var parameters = new Dictionary <string, object>();
            var sampleRate = new Measurement((decimal)sampleRateHz, "Hz");

            IOutputData data = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz")))
                                              .Select(i => new Measurement(i, "units")).ToList(),
                                              sampleRate,
                                              false);

            var s = new RenderedStimulus((string)"RenderedStimulus", (IDictionary <string, object>)parameters, data);

            var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds);
            IEnumerator <IOutputData> iter = s.DataBlocks(blockSpan).GetEnumerator();

            while (iter.MoveNext())
            {
                var cons = data.SplitData(blockSpan);
                data = cons.Rest;
                Assert.That(iter.Current.Duration, Is.EqualTo(cons.Head.Duration));
                Assert.That(iter.Current.Data, Is.EqualTo(cons.Head.Data));
            }
        }
Пример #2
0
        public void OutputPipelineContinuity(
            [Values(1000, 5000, 10000, 15000, 20000)] double sampleRate,
            [Values(0.1, 0.5, 1, 5)] double blockDurationSeconds
            )
        {
            const double epochDuration = 2; //seconds
            var srate = new Measurement((decimal) sampleRate, "Hz");

            var daq = new TestDAQController();
            var outStream = new DAQOutputStream("OUT")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };
            var inStream = new DAQInputStream("IN")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };

            var controller = new Controller() { Clock = daq, DAQController = daq };

            var dev = new UnitConvertingExternalDevice("dev", "co", controller, new Measurement(0, "V"))
                          {
                              Clock = daq,
                              MeasurementConversionTarget = "V",
                              OutputSampleRate = srate,
                              InputSampleRate = srate
                          };
            dev.BindStream(outStream).BindStream(inStream);

            // Setup Epoch
            var e = new Epoch("OutputPipelineContinuity");

            var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(srate);
            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();
            IOutputData stimOutputData = new OutputData(stimData, srate);

            var stim = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                            stimOutputData);
            e.Stimuli[dev] = stim;
            e.Responses[dev] = new Response();
            e.Backgrounds[dev] = new Background(new Measurement(0, "V"), srate);

            controller.EnqueueEpoch(e);

            var blockSpan = TimeSpan.FromSeconds(blockDurationSeconds);
            foreach (var stimBlock in stim.DataBlocks(blockSpan))
            {
                var cons = stimOutputData.SplitData(blockSpan);
                var expected = cons.Head.Data;
                stimOutputData = cons.Rest;

                Assert.That(stimBlock.Data, Is.EqualTo(expected));
            }
        }
Пример #3
0
        public void OutputPipelineContinuity(
            [Values(1000, 5000, 10000, 15000, 20000)] double sampleRate,
            [Values(0.1, 0.5, 1, 5)] double blockDurationSeconds
            )
        {

            const double epochDuration = 2; //seconds
            var srate = new Measurement((decimal) sampleRate, "Hz");

            var daq = new TestDAQController();
            var outStream = new DAQOutputStream("OUT")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };

            var controller = new Controller() { Clock = daq, DAQController = daq };

            var dev = new UnitConvertingExternalDevice("dev", "co", controller, new Measurement(0, "V"))
                          {
                              Clock = daq,
                              MeasurementConversionTarget = "V"
                          };
            dev.BindStream(outStream);

            // Setup Epoch
            var e = new Epoch("OutputPipelineContinuity");

            var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(srate);
            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();
            IOutputData stimOutputData = new OutputData(stimData, srate);

            var stim = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                            stimOutputData);
            e.Stimuli[dev] = stim;
            e.Responses[dev] = new Response();
            e.Background[dev] = new Epoch.EpochBackground(new Measurement(0, "V"), srate);

            controller.EnqueueEpoch(e);
            controller.NextEpoch();

            var blockSpan = TimeSpan.FromSeconds(blockDurationSeconds);
            foreach (var stimBlock in stim.DataBlocks(blockSpan))
            {
                var cons = stimOutputData.SplitData(blockSpan);
                var expected = cons.Head.Data;
                stimOutputData = cons.Rest;

                Assert.That(stimBlock.Data, Is.EqualTo(expected));
            }

        }
Пример #4
0
        public void MarksAsNotLastIfMoreBlocks()
        {
            var parameters = new Dictionary <string, object>();
            var sampleRate = new Measurement(1000, "Hz");

            IOutputData data = new OutputData(Enumerable.Range(0, 1000).Select(i => new Measurement(i, "units")).ToList(),
                                              sampleRate,
                                              true);

            var s = new RenderedStimulus((string)"RenderedStimulus", (IDictionary <string, object>)parameters, data);

            var block = TimeSpan.FromMilliseconds(100);
            IEnumerator <IOutputData> iter = s.DataBlocks(block).GetEnumerator();

            Assert.True(iter.MoveNext());
            Assert.False(iter.Current.IsLast);
        }
Пример #5
0
        public void MarksAsNotLastIfMoreBlocks()
        {
            var parameters = new Dictionary<string, object>();
            var sampleRate = new Measurement(1000, "Hz");

            IOutputData data = new OutputData(Enumerable.Range(0, 1000).Select(i => new Measurement(i, "units")).ToList(),
                sampleRate,
                true);

            var s = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) parameters, data);

            var block = TimeSpan.FromMilliseconds(100);
            IEnumerator<IOutputData> iter = s.DataBlocks(block).GetEnumerator();
            Assert.True(iter.MoveNext());
            Assert.False(iter.Current.IsLast);
        }
Пример #6
0
        public void EnumeratesDataBlocks(
            [Values(100, 500, 1000, 5000)] double blockMilliseconds,
            [Values(1000, 5000, 10000)] double sampleRateHz
            )
        {
            var parameters = new Dictionary<string, object>();
            var sampleRate = new Measurement((decimal)sampleRateHz, "Hz");

            IOutputData data = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz")))
                .Select(i => new Measurement(i, "units")).ToList(),
                sampleRate,
                false);

            var s = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) parameters, data);

            var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds);
            IEnumerator<IOutputData> iter = s.DataBlocks(blockSpan).GetEnumerator();
            while (iter.MoveNext())
            {
                var cons = data.SplitData(blockSpan);
                data = cons.Rest;
                Assert.That(iter.Current.Duration, Is.EqualTo(cons.Head.Duration));
                Assert.That(iter.Current.Data, Is.EqualTo(cons.Head.Data));
            }
        }