Time Series Data
Magnetocardiography (MCG) devices are measurement systems of time-varying magnetic fields generated by the heart activity. Cardiac magnetic signals are recorded with multi-sensors designed to sense the weak magnetic fields (almost \(10 fT\)-\(10 pT\)). Then, the primary data structure of MCG is the time-stream array of magnetic fields at different locations. The data obtained from each sensor is commonly called the channel.
The TimeSeries
from mcgpy.timeseries import TimeSeries
MCGpy provides the TimeSeries class which creates the time-series data with metadata and reads a single data from raw files. Since this object is based on numpy.ndarray and astropy.units.Quantity, numpy and astropy users might be easy to learn how to use it.
There are the available source formats:
Format | Read | Write | Auto identify |
---|---|---|---|
KDF | Yes | No | Yes |
HDF5 | Yes | will be supported | Yes |
CSV | - | - | |
TXT | - | - |
The KDF is a multi-channel data format for the magnetocardiography system. It is based on the BioSemi Data Format, for BDF format is mainly used in the reseaches of electrocardiogram(ECG) and electroencephalography(EEG).
The HDF5 format is high-performance data management and storage suite. Thanks to its flexibility and capability, multi-array dataset like MCG datasets can easily be handled.
Other formats, such as CSV and TXT, will be supported for reading a single time-series data of MCG.
For examples, to create a simple TimeSeries by a ramdom data, and to read a channel data from a frame file:
User defined dataset
>>> from mcgpy.timeseries import TimeSeries
>>> import numpy as np
>>> source = np.random.random(100)
>>> data = TimeSeries(source)
>>> print(data)
<TimeSeries [0.15538315, 0.37469937, 0.25495241, ..., 0.25465358, 0.65668087] 1e-15 T>
TimeSeries contains several properties to show metadata:
Properties | Description |
---|---|
unit | The physical unit of the data, default unit is \(1 fT\) |
t0 | The first data point of time-axis, default value is \(0 s\) |
dt | The inderval bwteen time points of time-axis, default value is \(1 s\) |
duration | Data recording duration |
sample_rate | Data sample frequency, default value is \(1 Hz\) |
times | The time-axis coordinate |
number | Number of a channel i.e., 1, 2, 3, … |
label | Label of a channel i.e., X1, Y1, Z1, … |
KDF or HDF5 format
Since KDF and HDF5 files have consisted of multi-channel datasets as mentioned above, the number
or label
parameter is required to read a single channel from the bundle dataset.
>>> from mcgpy.timeseries import TimeSeries
>>> path = '~/test/data/file.kdf'
>>> data_ch1 = TimeSeires(path, number=1)
>>> print(data_ch1)
<TimeSeries [ 136.26813889 156.58140182 ... -67.71087646 33.00905228] 1e-15 T>
By using the Channel
class, the channel information, such as number and label, can be read from frame files.
See detailed explanation in Data Tabels section.
Alongside basic properties, this object provides additonal metadata:
Properties | Description |
---|---|
position | The sensor coordinate on the sensor grid i.e., [0., 0., 0.,] |
direction | The sensor direction for measuring a magnetic field i.e., [1.,0.,0.] |
datetime | The data time at the point of data recording i.e., ‘2020-02-02 02:02:02.00000' |
biosemi | Identification code i.e., National Hospital, National Reaserch, … |
note | It might be included with the patient information or medical options |
Every metadata can be redefined as well:
>>> print(data_ch1.datetime)
'2222-02-22 22:22:22.00000'
>>> data_ch1.datetime = '2020-02-02 02:02:02.00000'
>>> print(data_ch1.datetime)
'2020-02-02 02:02:02.00000'
Associated classes
Note that in addition to the TimeSeires associated classes listed below.
Classes | Description |
---|---|
TimeSeires | Dealing with a single time-series of a MCG dataset |
TimeSeriesArray | Dealing with a multi-channel time-series array of a MCG dataset |
FrequencySeries | Build time-frequency dataset |
ChannelActive | Listing the channel status |