示例#1
0
        public void WriteAndOverrideChunkedDataset()
        {
            var    data        = CreateDataset();
            string filename    = Path.Combine(folder, "testOverrideChunks.H5");
            string groupName   = "/test";
            string datasetName = "Data";

            //create
            var fileId = Hdf5.CreateFile(filename);

            Assert.IsTrue(fileId > 0);
            var groupId = Hdf5.CreateOrOpenGroup(fileId, groupName);

            Assert.IsTrue(groupId >= 0);
            using (var chunkedDset = new ChunkedDataset <double>(datasetName, groupId))
            {
                chunkedDset.AppendOrCreateDataset(data);
            }

            Hdf5.CloseFile(fileId);

            //read
            fileId = Hdf5.OpenFile(filename);


            var dataRead = Hdf5.ReadDatasetToArray <double>(fileId, string.Concat(groupName, "/", datasetName));

            Hdf5.CloseFile(fileId);
            CompareDatasets(dataRead.result as double[, ], data);
        }
        public void WriteAndReadChunckedDataset2()
        {
            string filename    = Path.Combine(folder, "testChunks2.H5");
            string groupName   = "/test";
            string datasetName = "Data";

            try
            {
                var fileId = Hdf5.CreateFile(filename);
                Assert.IsTrue(fileId > 0);
                var groupId = Hdf5.CreateGroup(fileId, groupName);
                Assert.IsTrue(groupId >= 0);
                //var chunkSize = new ulong[] { 5, 5 };
                using (var chunkedDset = new ChunkedDataset <double>(datasetName, groupId))
                {
                    foreach (var ds in dsets)
                    {
                        chunkedDset.AppendOrCreateDataset(ds);
                    }
                    ;
                }
                Hdf5.CloseFile(fileId);
            }
            catch (Exception ex)
            {
                CreateExceptionAssert(ex);
            }

            try
            {
                var fileId = Hdf5.OpenFile(filename);
                //var groupId = H5G.open(fileId, groupName);
                //var dset = Hdf5.ReadDatasetToArray<double>(groupId, datasetName);
                var dset = Hdf5.ReadDatasetToArray <double>(fileId, string.Concat(groupName, "/", datasetName));

                Assert.IsTrue(dset.result.Rank == dsets.First().Rank);
                var xSum = dsets.Select(d => d.GetLength(0)).Sum();
                Assert.IsTrue(xSum == dset.result.GetLength(0));
                var testRange = Enumerable.Range(0, 30).Select(t => (double)t);

                // get every 5th element in the matrix
                var x0Range = dset.result.Cast <double>().Where((d, i) => i % 5 == 0);
                Assert.IsTrue(testRange.SequenceEqual(x0Range));

                Hdf5.CloseFile(fileId);
            }
            catch (Exception ex)
            {
                CreateExceptionAssert(ex);
            }
        }
示例#3
0
        //[TestMethod]
        public void TestRead()
        {
            //string filename = @"D:\Data\9_pig.h5";
            string filename = @"c:\kalpa\test.h5";
            //string filename = @"d:\data\test2400.h5";
            var       fileId = Hdf5.OpenFile(filename);
            Stopwatch st     = Stopwatch.StartNew();
            var       ds     = Hdf5.ReadDatasetToArray <float>(fileId, "/eit/d1/voltages.im");

            st.Stop();
            Console.WriteLine(ds.result.Length);
            Console.WriteLine("read time im: " + st.ElapsedMilliseconds);
            st.Restart();
            ds = Hdf5.ReadDatasetToArray <float>(fileId, "/eit/d1/voltages.re");
            st.Stop();
            Console.WriteLine(ds.result.Length);
            Console.WriteLine("read time re: " + st.ElapsedMilliseconds);
            Hdf5.CloseFile(fileId);
        }
示例#4
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);
        }