Example #1
0
        public static TaskEventCollection?Collect(BrainVisionPackage filesContent)
        {
            IHeaderFileContentVer1 headerContent = filesContent.HeaderFileContent;
            IMarkerFileContentVer1?markerContent = filesContent.MarkerFileContent;

            List <MarkerInfo>?markers = markerContent?.GetMarkers();

            if (markers == null)
            {
                return(null);
            }

            double samplingFrequency = Common.GetSamplingFrequencyFromSamplingInterval(headerContent.SamplingInterval !.Value);

            TaskEventCollection taskEvents = new TaskEventCollection();

            foreach (MarkerInfo marker in markers)
            {
                TaskEvent taskEvent = new TaskEvent(
                    //REQUIRED
                    onset: marker.Position / samplingFrequency,
                    duration: marker.Length / samplingFrequency)
                {
                    //OPTIONAL
                    Sample    = marker.Position + 1, // I suppose bids uses 1-based sample position. This info is not present in the official bids documentations
                    TrialType = marker.Type,
                    Value     = !string.IsNullOrEmpty(marker.Description) ? marker.Description : Defs.NotAvailable,
                };

                taskEvents.Add(taskEvent);
            }

            return(taskEvents);
        }
Example #2
0
 public static void Save(StreamWriter writer, IHeaderFileContentVer1 content)
 {
     if (content.Comment != null)
     {
         writer.WriteLine();
         writer.WriteLine(IniFormat.FormatSectionName(Definitions.GetSectionName(Definitions.Section.Comment) !));
         FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.BelowCommentSection);
         writer.WriteLine(content.Comment);
     }
 }
Example #3
0
        public void SaveVer1(IHeaderFileContentVer1 content)
        {
            _writer.BaseStream.SetLength(0);

            SaveFileHeader(content);
            CommonInfosSectionSaver.Save(_writer, content);
            BinaryInfosSectionSaver.Save(_writer, content);
            ChannelInfosSectionSaver.Save(_writer, content);
            CoordinatesSectionSaver.Save(_writer, content);
            CommentSectionSaver.Save(_writer, content);

            _writer.Flush();
        }
Example #4
0
        public static EegChannelCollection?Collect(BrainVisionPackage filesContent)
        {
            IHeaderFileContentVer1 headerContent = filesContent.HeaderFileContent;
            List <ChannelInfo>?    inputChannels = headerContent.GetChannelInfos();

            if (inputChannels == null)
            {
                return(null);
            }

            double samplingFrequency = Common.GetSamplingFrequencyFromSamplingInterval(headerContent.SamplingInterval !.Value);

            EegChannelCollection eegChannels = new EegChannelCollection();

            foreach (ChannelInfo inputChannel in inputChannels)
            {
                PrefixedUnit?channelUnits = Common.ConvertTextToPrefixedUnit(inputChannel.Unit);
                if (channelUnits == null)
                {
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Resources.UrecognizedUnitExceptionMessage, inputChannel.Unit, inputChannel.Name));
                }

                EegChannel eegChannel = new EegChannel(
                    //REQUIRED
                    name: inputChannel.Name,
                    type: ChannelType.EEG,
                    units: channelUnits.Value)
                {
                    //OPTIONAL
                    SamplingFrequency = samplingFrequency,
                    //Reference = null,
                    //LowCutoff = null,
                    //HighCutoff = null,
                    //Notch = null,
                };

                eegChannels.Add(eegChannel);
            }

            return(eegChannels);
        }
        public static void Save(StreamWriter writer, IHeaderFileContentVer1 content)
        {
            writer.WriteLine();
            writer.WriteLine(IniFormat.FormatSectionName(Definitions.GetSectionName(Definitions.Section.BinaryInfos) !));
            FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.BelowBinaryInfosSection);

            foreach (Definitions.BinaryInfosKeys key in (Definitions.BinaryInfosKeys[])Enum.GetValues(typeof(Definitions.BinaryInfosKeys)))
            {
                string?keyValue = key switch
                {
                    Definitions.BinaryInfosKeys.BinaryFormat => content.BinaryFormat?.ToString(),
                    _ => throw new NotImplementedException(), // should never happen
                };

                if (keyValue != null)
                {
                    string line = IniFormat.FormatKeyValueLine(key.ToString(), keyValue);
                    writer.WriteLine(line);
                }
            }
        }
Example #6
0
        public static void Save(StreamWriter writer, IHeaderFileContentVer1 content)
        {
            List <Coordinates>?channelCoordinates = content.GetChannelCoordinates();

            if (channelCoordinates != null)
            {
                writer.WriteLine();
                writer.WriteLine(IniFormat.FormatSectionName(Definitions.GetSectionName(Definitions.Section.Coordinates) !));
                FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.BelowCoordinatesInfosSection);

                for (int ch = 0; ch < channelCoordinates.Count; ++ch)
                {
                    Coordinates coordinates = channelCoordinates[ch];

                    string keyName  = Invariant($"{Definitions.KeyChPlaceholder}{ch + 1}");
                    string keyValue = Invariant($"{coordinates.Radius},{coordinates.Theta},{coordinates.Phi}");

                    string line = IniFormat.FormatKeyValueLine(keyName, keyValue);
                    writer.WriteLine(line);
                }
            }
        }
        public static void Save(StreamWriter writer, IHeaderFileContentVer1 content)
        {
            List <ChannelInfo>?channelInfos = content.GetChannelInfos();

            if (channelInfos != null)
            {
                writer.WriteLine();
                writer.WriteLine(IniFormat.FormatSectionName(Definitions.GetSectionName(Definitions.Section.ChannelInfos) !));
                FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.BelowChannelInfosSection);

                for (int ch = 0; ch < channelInfos.Count; ++ch)
                {
                    ChannelInfo channelInfo = channelInfos[ch];

                    string keyName  = Invariant($"{Definitions.KeyChPlaceholder}{ch + 1}");
                    string keyValue = ConvertChannelInfoToString(channelInfo);

                    string line = IniFormat.FormatKeyValueLine(keyName, keyValue);
                    writer.WriteLine(line);
                }
            }
        }
        public static EegElectrodeCollection?Collect(BrainVisionPackage filesContent)
        {
            IHeaderFileContentVer1 headerContent    = filesContent.HeaderFileContent;
            List <Coordinates>?    inputCoordinates = headerContent.GetChannelCoordinates();

            if (inputCoordinates == null)
            {
                return(null);
            }

            List <ChannelInfo>?inputChannels = headerContent.GetChannelInfos();
            int inputChannelsCount           = inputChannels == null ? 0 : inputChannels.Count;

            EegElectrodeCollection eegElectrodes = new EegElectrodeCollection();

            for (int channelNumber = 0; channelNumber < inputCoordinates.Count; ++channelNumber)
            {
                Coordinates coordinates = inputCoordinates[channelNumber];

                (double cartesianX, double cartesianY, double cartesianZ) = SphericalToCartesian(coordinates);

                EegElectrode eegElectrode = new EegElectrode(
                    //REQUIRED
                    name: channelNumber < inputChannelsCount ? inputChannels ![channelNumber].Name : string.Empty,
Example #9
0
        public static EegSidecar Collect(BrainVisionPackage filesContent, CustomizationInfo info, string actualTaskName)
        {
            IHeaderFileContentVer1 headerContent = filesContent.HeaderFileContent;
            List <ChannelInfo>?    channelInfos  = headerContent.GetChannelInfos();

            EegSidecar sidecar = new EegSidecar(
                //REQUIRED Generic
                actualTaskName,

                //REQUIRED EEG
                info.EEGReference,
                Common.GetSamplingFrequencyFromSamplingInterval(headerContent.SamplingInterval !.Value), // SamplingInterval is in µs
                info.PowerLineFrequency,
                Defs.NotAvailable)
            {
                #region Generic
                //RECOMMENDED
                Manufacturer = info.Manufacturer,
                #endregion

                #region EEG
                //RECOMMENDED
                EEGChannelCount     = channelInfos == null ? 0 : channelInfos.Count,
                ECGChannelCount     = 0,
                EMGChannelCount     = 0,
                EOGChannelCount     = 0,
                MiscChannelCount    = 0,
                TriggerChannelCount = 0,
                //RecordingDuration = 0,
                RecordingType = headerContent.Averaged !.Value ? EegSidecar.Recordingtype.epoched : EegSidecar.Recordingtype.continuous,
                EpochLength   = headerContent.Averaged.Value ? ((headerContent.SegmentDataPoints !.Value * headerContent.SamplingInterval.Value) / 1000000.0) as double?: null,
                #endregion
            };

            return(sidecar);
        }
        public static void Save(StreamWriter writer, IHeaderFileContentVer1 content)
        {
            writer.WriteLine();
            writer.WriteLine(IniFormat.FormatSectionName(Definitions.GetSectionName(Definitions.Section.CommonInfos) !));
            FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.BelowCommonInfosSection);

            Definitions.CommonInfosKeys[] commonInfosKeys = (Definitions.CommonInfosKeys[])Enum.GetValues(typeof(Definitions.CommonInfosKeys));

            foreach (Definitions.CommonInfosKeys key in commonInfosKeys)
            {
                string?keyValue;

                switch (key)
                {
                case Definitions.CommonInfosKeys.Codepage:
                    // replacing Utf8 enum with Utf-8 string
                    keyValue = (content.CodePage == Codepage.Utf8) ? Definitions.Utf8Enum : content.CodePage?.ToString();
                    break;

                case Definitions.CommonInfosKeys.DataFile:
                    keyValue = content.DataFile;
                    break;

                case Definitions.CommonInfosKeys.MarkerFile:
                    keyValue = content.MarkerFile;
                    break;

                case Definitions.CommonInfosKeys.DataFormat:
                    keyValue = content.DataFormat?.ToString();
                    break;

                case Definitions.CommonInfosKeys.DataType:
                    keyValue = content.DataType?.ToString();
                    break;

                case Definitions.CommonInfosKeys.DataOrientation:
                    if (content.DataOrientation != null)
                    {
                        FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.AboveDataOrientation);
                    }
                    keyValue = content.DataOrientation?.ToString();
                    break;

                case Definitions.CommonInfosKeys.SamplingInterval:
                    if (content.SamplingInterval != null)
                    {
                        FileSaverCommon.WriteCommentBlock(writer, content.InlinedComments.AboveSamplingInterval);
                    }
                    keyValue = content.SamplingInterval?.ToString("R", CultureInfo.InvariantCulture);
                    break;

                case Definitions.CommonInfosKeys.NumberOfChannels:
                    keyValue = content.NumberOfChannels?.ToString(CultureInfo.InvariantCulture);
                    break;

                case Definitions.CommonInfosKeys.Averaged:
                    keyValue = content.Averaged.HasValue ?
                               content.Averaged.Value ? YesNo.YES.ToString() : YesNo.NO.ToString() :
                               null;
                    break;

                case Definitions.CommonInfosKeys.AveragedSegments:
                    keyValue = content.AveragedSegments?.ToString(CultureInfo.InvariantCulture);
                    break;

                case Definitions.CommonInfosKeys.SegmentDataPoints:
                    keyValue = content.SegmentDataPoints?.ToString(CultureInfo.InvariantCulture);
                    break;

                case Definitions.CommonInfosKeys.SegmentationType:
                    keyValue = content.SegmentationType?.ToString();
                    break;

                default:
                    throw new NotImplementedException();     // should never happen
                }

                if (keyValue != null)
                {
                    string line = IniFormat.FormatKeyValueLine(key.ToString(), keyValue);
                    writer.WriteLine(line);
                }
            }
        }
Example #11
0
 private void SaveFileHeader(IHeaderFileContentVer1 content)
 {
     _writer.WriteLine(content.IdentificationText);
     FileSaverCommon.WriteCommentBlock(_writer, content.InlinedComments.BelowHeaderSection);
 }
Example #12
0
        public void SaveVer1(IHeaderFileContentVer1 header)
        {
            FileSaver fileSaver = new FileSaver(_file);

            fileSaver.SaveVer1(header);
        }