Exemple #1
0
        public async Task TestFullFileWriteRead()
        {
            string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test2.h5");

            Console.WriteLine(filename);
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            kama = new KamaAcquisitionFile(filename, AcquisitionInterface.Simulator, Logger);
            ProcedureInfo info = new ProcedureInfo
            {
                Age         = 18,
                FirstName   = "Lior",
                LastName    = "Banai",
                ExamDate    = DateTime.Now,
                Procedure   = "test",
                ProcedureID = "ID",
                Patient     = new PatientInfo()
            };

            kama.SavePatientInfo(info);
            kama.UpdateSystemInformation("32423423", new[] { "11", "12" });
            kama.SetProcedureInformation(info);
            string data = File.ReadAllText(AcquisitionScanProtocolPath);
            AcquisitionProtocolParameters parameters = AcquisitionProtocolParameters.FromJson(data);
            await kama.StartLogging(parameters);

            var ecgTask = WriteECGData(kama, 2, 1);
            var eitTask = WriteEITData(parameters, kama, 5, 1);
            var seTask  = WriteSystemEvents(kama);
            await Task.WhenAll(ecgTask, eitTask, seTask);

            var ecgTestData  = await ecgTask;
            var eitsTestData = await eitTask;

            kama.StopRecording();
            await kama.StopProcedure();


            using (KamaAcquisitionReadOnlyFile readFile = new KamaAcquisitionReadOnlyFile(filename))
            {
                readFile.ReadSystemInformation();
                readFile.ReadProcedureInformation();
                readFile.ReadPatientInformation();
                Assert.IsTrue(readFile.PatientInformation.Equals(kama.PatientInfo));
                Assert.IsTrue(readFile.ProcedureInformation.Equals(kama.ProcedureInformation));
                Assert.IsTrue(readFile.SystemInformation.Equals(kama.SystemInformation));

                readFile.ReadECGData();

                readFile.ReadEITData();
                Assert.IsTrue(readFile.EITs.SequenceEqual(eitsTestData));
                readFile.ReadSystemEvents();
                Assert.IsTrue(readFile.Events.Count == 100);
            }

            File.Delete(filename);
        }
Exemple #2
0
        public async Task TestEventsWrite()
        {
            string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testEvents.h5");

            Console.WriteLine(filename);
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            kama = new KamaAcquisitionFile(filename, AcquisitionInterface.Simulator, Logger);
            ProcedureInfo info = new ProcedureInfo
            {
                Age         = 18,
                FirstName   = "First",
                LastName    = "Last",
                ExamDate    = DateTime.Now,
                Procedure   = "test",
                ProcedureID = "ID",
                Patient     = new PatientInfo()
            };

            kama.SavePatientInfo(info);
            kama.UpdateSystemInformation("32423423", new[] { "11", "12" });
            string data = File.ReadAllText(AcquisitionScanProtocolPath);
            AcquisitionProtocolParameters parameters = AcquisitionProtocolParameters.FromJson(data);
            await kama.StartLogging(parameters);



            kama.StopRecording();
            await kama.StopProcedure();

            File.Delete(filename);
        }
 public Task StartLogging(AcquisitionProtocolParameters acquisitionProtocol)
 {
     EIT = new EIT(RecordNumber++, EITDefaultChunkSize, acquisitionProtocol.AsJson(), fileId, groupEIT, Logger);
     //var acquisitionInformation = new AcquisitionInformation(acquisitionProtocol, fileId, groupEIT, Logger);
     //acquisitionInformation.FlushDataAndCloseObject();
     ECG = new ECG(fileId, groupRoot, ECGDefaultChunkSize, (int)acquisitionProtocol.ScanDescription.EcgParams.SampleRate, Logger);
     SystemEvents.StartLogging();
     RPosition.StartLogging();
     Tags.StartLogging();
     return(Task.CompletedTask);
 }
Exemple #4
0
        private async Task <List <EITEntry> > WriteEITData(AcquisitionProtocolParameters parameters,
                                                           KamaAcquisitionFile file, int loop, int sleepsBetweenWritesMilliseconds)
        {
            var result = await Task.Factory.StartNew(() =>
            {
                Random random = new Random();
                List <ElectrodeFrame> samples = new List <ElectrodeFrame>();
                for (int index = 0; index < loop; index++)
                {
                    ElectrodeFrame frame       = new ElectrodeFrame();
                    frame.ComplexCurrentMatrix = Enumerable.Range(0, 2441)
                                                 .Select(i => ((float)random.NextDouble(), (float)random.NextDouble())).ToArray();
                    frame.ComplexVoltageMatrix = Enumerable.Range(0, 2441)
                                                 .Select(i => ((float)random.NextDouble(), (float)random.NextDouble())).ToArray();
                    frame.PacketId       = (ulong)index;
                    var timestamp        = DateTimeOffset.Now;
                    frame.timestamp      = timestamp.ToUnixTimeMilliseconds();
                    ulong saturationMask = (ulong)random.Next();
                    saturationMask       = (saturationMask << 32);
                    saturationMask       = saturationMask | (ulong)random.Next();
                    frame.SaturationMask = saturationMask;
                    Thread.Sleep(sleepsBetweenWritesMilliseconds);
                    file.AppendElectrodeSample(frame);
                    samples.Add(frame);
                }

                EITEntry entry = new EITEntry
                {
                    Configuration = parameters.AsJson(),
                    StartDateTime = DateTimeOffset.FromUnixTimeMilliseconds(samples.First().timestamp).DateTime,
                    EndDateTime   = DateTimeOffset.FromUnixTimeMilliseconds(samples.Last().timestamp).DateTime,
                    VoltagesReal  = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    VoltagesIm    = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    CurrentsIm    = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    CurrentsReal  = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    Saturation    = new ulong[samples.Count, 1],
                    Timestamps    = new long[samples.Count, 1]
                };

                for (var i = 0; i < samples.Count; i++)
                {
                    ElectrodeFrame electrodeFrame = samples[i];

                    for (int j = 0; j < electrodeFrame.ComplexVoltageMatrix.Length; j++)
                    {
                        entry.VoltagesReal[i, j] = electrodeFrame.ComplexVoltageMatrix[j].Re;
                        entry.VoltagesIm[i, j]   = electrodeFrame.ComplexVoltageMatrix[j].Im;
                    }

                    for (int j = 0; j < electrodeFrame.ComplexCurrentMatrix.Length; j++)
                    {
                        entry.CurrentsReal[i, j] = electrodeFrame.ComplexCurrentMatrix[j].Re;
                        entry.CurrentsIm[i, j]   = electrodeFrame.ComplexCurrentMatrix[j].Im;
                    }

                    entry.Saturation[i, 0] = electrodeFrame.SaturationMask;
                    entry.Timestamps[i, 0] = electrodeFrame.timestamp;
                }

                return(entry);
            });

            return(new List <EITEntry>
            {
                result
            });
        }
Exemple #5
0
        public async Task CreatePatientInfoTest()
        {
            string data     = File.ReadAllText(AcquisitionScanProtocolPath);
            string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "h5test.h5");

            kama = new KamaAcquisitionFile(filename, AcquisitionInterface.Simulator, Logger);
            CreatePatientDetails(kama);
            UpdateSystemInformation(kama);


            AcquisitionProtocolParameters parameters = AcquisitionProtocolParameters.FromJson(data);
            await kama.StartLogging(parameters);


            string lineVoltage, lineCurrent, lineEcg;
            string directory   = AppDomain.CurrentDomain.BaseDirectory;
            string voltagePath = Path.Combine(directory, voltage);
            string currentPath = Path.Combine(directory, current);

            using StreamReader srVoltage = new StreamReader(voltagePath);
            using StreamReader srCurrent = new StreamReader(currentPath);
            int i = 0;

            while (!string.IsNullOrEmpty(lineVoltage = await srVoltage.ReadLineAsync()) &&
                   !string.IsNullOrEmpty(lineCurrent = await srCurrent.ReadLineAsync()))
            {
                ElectrodeFrame sample       = new ElectrodeFrame();
                var            itemsVoltage = lineVoltage.Split(',', StringSplitOptions.RemoveEmptyEntries);
                var            itemsCurrent = lineCurrent.Split(',', StringSplitOptions.RemoveEmptyEntries);
                sample.timestamp      = long.Parse(itemsCurrent.First());
                sample.SaturationMask = Convert.ToUInt64(itemsCurrent.Skip(1).Take(1).Single().Trim(), 16);
                var evenvals = itemsCurrent.Skip(2).Where((c, i) => i % 2 == 0).Select(float.Parse);
                var oddvals  = itemsCurrent.Skip(2).Where((c, i) => i % 2 != 0).Select(float.Parse);

                sample.ComplexCurrentMatrix = evenvals.Zip(oddvals).Select(itm => (itm.First, itm.Second)).ToArray();

                evenvals = itemsVoltage.Skip(2).Where((c, i) => i % 2 == 0).Select(float.Parse);
                oddvals  = itemsVoltage.Skip(2).Where((c, i) => i % 2 != 0).Select(float.Parse);

                sample.ComplexVoltageMatrix = evenvals.Zip(oddvals).Select(itm => (itm.First, itm.Second)).ToArray();
                kama.AppendElectrodeSample(sample);
            }

            using StreamReader srEcg = new StreamReader(ecg);

            var filteredFrameData = new List <List <float> > {
                new List <float>(), new List <float>()
            };
            var frameData = new List <List <float> > {
                new List <float>(), new List <float>()
            };
            var timestamps = new List <long>();

            while (!string.IsNullOrEmpty(lineEcg = await srEcg.ReadLineAsync()))
            {
                var items = lineEcg.Split(",", StringSplitOptions.RemoveEmptyEntries);
                var c1    = float.Parse(items[0]);
                var c2    = float.Parse(items[1]);
                var time  = long.Parse(items[2]);

                var c1_filtered = float.Parse(items[4]);
                var c2_filtered = float.Parse(items[5]);

                frameData[0].Add(c1);
                frameData[1].Add(c2);

                filteredFrameData[0].Add(c1_filtered);
                filteredFrameData[1].Add(c2_filtered);
                timestamps.Add(time);
            }

            ECGFrame frame = new ECGFrame(filteredFrameData, frameData, timestamps[0], 0);

            kama.AppendEcgSample(frame);
            await kama.StopProcedure();

            var       fileId   = Hdf5.OpenFile(filename);
            Stopwatch st       = Stopwatch.StartNew();
            var       readback = Hdf5.ReadDatasetToArray <float>(fileId, "/eit/d1/voltages.re");

            st.Stop();
            Console.WriteLine("read time: " + st.ElapsedMilliseconds);
            Hdf5.CloseFile(fileId);
            File.Delete(filename);
        }