Exemple #1
0
        public void OutputDataSplitsDataAtDuration(
            [Values(0.01, 0.5, 0.751)] double splitDuration
            )
        {
            IDictionary <string, object> config = new Dictionary <string, object>();
            const int nSamples = 1000;
            var       srate    = new Measurement(nSamples, "Hz");

            var data = Enumerable.Range(0, nSamples).Select(i => new Measurement(i, "V")).ToList();

            IOutputData outData = new OutputData(data,
                                                 srate, false);

            var duration = new TimeSpan((long)Math.Ceiling(splitDuration * TimeSpan.TicksPerSecond));
            var result   = outData.SplitData(duration);

            //rounds samples up for duration
            int numSamples = (int)Math.Ceiling(duration.TotalSeconds * (double)outData.SampleRate.QuantityInBaseUnit);

            IEnumerable firstData = Enumerable.Range(0, numSamples).Select(i => outData.Data[i]).ToList();
            IEnumerable restData  = Enumerable.Range(numSamples, outData.Data.Count - numSamples).Select(i => outData.Data[i]).ToList();


            Assert.AreEqual(firstData, result.Head.Data);
            Assert.AreEqual(restData, result.Rest.Data);
        }
        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));
            }
        }
        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));
            }

        }
Exemple #4
0
        public void OutputDataSplitDataReturnsEntireDataForOverDuration()
        {
            IDictionary <string, object> config = new Dictionary <string, object>();
            var srate = new Measurement(1000, "Hz");

            IOutputData outData = new OutputData(this.Data,
                                                 srate, false);

            var duration = new TimeSpan(1, 0, 0); //1 hr
            var result   = outData.SplitData(duration);

            Assert.AreEqual(outData.Data, result.Head.Data);
            Assert.AreEqual(0, result.Rest.Duration.Ticks);
        }