Esempio n. 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);
        }
Esempio n. 2
0
        private void Convert(BrainVisionPackage bvPackage, IBidsPackage bidsPackage, CustomizationInfo info)
        {
            Warnings = Array.Empty <string>();
            PackageConverter converter = new PackageConverter(bvPackage, bidsPackage, info);

            converter.CopyBrainVisionFilesToBidsEegModalityFolder();
            bvPackage.UpdateMissingKeysWithDefaultValues();
            converter.ConvertBrainVisionFilesToBidsFormatFiles();
            Warnings = converter.Warnings;
        }
Esempio n. 3
0
        /// <exception cref="ArgumentException">Thrown when <paramref name="brainVisionHeaderFilePath"/>consists only of white characters.</exception>
        /// <exception cref="InvalidOperationException">Thrown when vision file fails to load.</exception>
        /// <exception cref="NotSupportedException">Thrown when units are not recognized.</exception>
        public void Convert(string brainVisionHeaderFilePath, CustomizationInfo info)
        {
            if (string.IsNullOrWhiteSpace(brainVisionHeaderFilePath))
            {
                throw new ArgumentException(Resources.ArgumentEmptyOrWhiteCharactersExceptionMessage, nameof(brainVisionHeaderFilePath));
            }

            GenerateSubjectSessionAndTaskIfNotProvided(info, brainVisionHeaderFilePath, out string subjectName, out string?sessionName, out string taskName);

            IBidsPackage       bidsPackage = CreateBidsPackage(subjectName, sessionName, taskName);
            BrainVisionPackage bvPackage   = CreateBvPackage(brainVisionHeaderFilePath);

            Convert(bvPackage, bidsPackage, info);
        }
Esempio n. 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);
        }
Esempio n. 5
0
        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,
Esempio n. 6
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);
        }
Esempio n. 7
0
 private static BrainVisionPackage CreateBvPackage(string brainVisionHeaderFilePath)
 => BrainVisionPackage.Load(brainVisionHeaderFilePath);