Skip to main content

To convert snirf file to bids format.

Project description

module snirf2bids

Module for converting snirf file into bids format

Maintained by the Boston University Neurophotonics Center


function snirf_to_bids

snirf_to_bids(inputpath: str, outputpath: str, participants: dict = None)

Creates a BIDS-compliant folder structure (right now, just the metadata files) from a SNIRF file

Args:

  • inputpath: The file path to the reference SNIRF file
  • outputpath: The file path/directory for the created BIDS metadata files
  • participants: A dictionary with participant information Example =
  • {participant_id: 'sub-01',
  • age: 34,
  • sex: 'M'}
  • scans: A dictionary with SNIRF/run information and its acquisition time

class Field

Class which encapsulates fields inside a Metadata class

Attributes:

  • _value: The value of the field

method __init__

__init__(val)

Generic constructor for a Field class

It stores a specific value declared in the class initialization in _value


property value

Value Getter for Field class


class String

Subclass which encapsulates fields with string values inside a Metadata class

Attributes:

  • _value: The value of the field
  • type: Data type of the field - in this case, it's "str"

method __init__

__init__(val)

Generic constructor for a String Field class inherited from the Field class

Additionally, it stores the datatype which in this case, it is string


property value

Value Getter for Field class


method get_type

get_type()

Datatype getter for the String class


method validate

validate(val)

Datatype Validation function for String class


class Number

Subclass which encapsulates fields with numerical values inside a Metadata class

Attributes:

  • _value: The value of the field
  • type: Data type of the field - in this case, it's "int"

method __init__

__init__(val)

Generic constructor for a Number Field class inherited from the Field class

Additionally, it stores the datatype which in this case, it is integer


property value

Value Getter for Field class


method get_type

get_type()

Datatype getter for the Number class


method validate

validate(val)

Datatype Validation function for Number class


class Metadata

Metadata File Class

Class object that encapsulates the JSON and TSV Metadata File Class

Attributes:

  • _fields: A dictionary of the fields and the values contained in it for a specific Metadata class
  • _source_snirf: The filepath to the reference SNIRF file to create the specific Metadata class

method __init__

__init__()

Generic constructor for a Metadata class

Most importantly, it constructs the default fields with empty values within _fields in a dictionary format


method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


class JSON

JSON Class

Class object that encapsulates subclasses that create and contain BIDS JSON files

method __init__

__init__()

Generic constructor for JSON class - uses the one inherited from the Metadata class


method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_json

load_from_json(fpath)

Create the JSON metadata class from a JSON file

Args:

  • fpath: The file path to the reference JSON file

Raises:

  • TypeError: Incorrect data type for a specific field based on data loaded from the JSON file

method save_to_json

save_to_json(info, fpath)

Save a JSON inherited class into an output JSON file with a BIDS-compliant name in the file directory designated by the user

Args:

  • info: Subject info field from the Subject class
  • fpath: The file path that points to the folder where we intend to save the metadata file in

Returns: Outputs a metadata JSON file with a BIDS-compliant name in the specified file path


class TSV

TSV Class

Class object that encapsulates subclasses that create and contain BIDS TSV files

Attributes:

  • _sidecar: Contains the field names and descriptions for each field for the Sidecar JSON file

method __init__

__init__()

Generic Constructor for TSV class - uses the one inherited from the Metadata class

Additionally, added the sidecar property for the Sidecar JSON files


method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method export_sidecar

export_sidecar(info, fpath)

Exports sidecar as a json file


method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_tsv

load_from_tsv(fpath)

Create the TSV metadata class from a TSV file

Args:

  • fpath: The file path to the reference TSV file

method make_sidecar

make_sidecar()

Makes a dictionary with the default description noted in BIDS specification into the Sidecar dictionary

Returns: Dictionary with correct fields(that have values) with description of each field within TSV file filled out


method save_to_tsv

save_to_tsv(info, fpath)

Save a TSV inherited class into an output TSV file with a BIDS-compliant name in the file directory designated by the user

Args:

 - <b>`info`</b>:  Subject info field from the Subject class 
 - <b>`fpath`</b>:  The file path that points to the folder where we intend to save the metadata file in 

Returns: Outputs a metadata TSV file with BIDS-compliant name in the specified file path


class Coordsystem

Coordinate System Metadata Class

Class object that mimics and contains the data for the coordsystem.JSON metadata file

method __init__

__init__(fpath=None)

Inherited constructor for the Coordsystem class

Args:

  • fpath: The file path to a reference SNIRF file

method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_SNIRF

load_from_SNIRF(fpath)

Creates the Coordsystem class based on information from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method load_from_json

load_from_json(fpath)

Create the JSON metadata class from a JSON file

Args:

  • fpath: The file path to the reference JSON file

Raises:

  • TypeError: Incorrect data type for a specific field based on data loaded from the JSON file

method save_to_json

save_to_json(info, fpath)

Save a JSON inherited class into an output JSON file with a BIDS-compliant name in the file directory designated by the user

Args:

  • info: Subject info field from the Subject class
  • fpath: The file path that points to the folder where we intend to save the metadata file in

Returns: Outputs a metadata JSON file with a BIDS-compliant name in the specified file path


class Optodes

Optodes Metadata Class

Class object that mimics and contains the data for the optodes.tsv metadata file

method __init__

__init__(fpath=None)

Inherited constructor for the Optodes class

Args:

  • fpath: The file path to a reference SNIRF file

method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method export_sidecar

export_sidecar(info, fpath)

Exports sidecar as a json file


method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_SNIRF

load_from_SNIRF(fpath)

Creates the Optodes class based on information from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method load_from_tsv

load_from_tsv(fpath)

Create the TSV metadata class from a TSV file

Args:

  • fpath: The file path to the reference TSV file

method make_sidecar

make_sidecar()

Makes a dictionary with the default description noted in BIDS specification into the Sidecar dictionary

Returns: Dictionary with correct fields(that have values) with description of each field within TSV file filled out


method save_to_tsv

save_to_tsv(info, fpath)

Save a TSV inherited class into an output TSV file with a BIDS-compliant name in the file directory designated by the user

Args:

 - <b>`info`</b>:  Subject info field from the Subject class 
 - <b>`fpath`</b>:  The file path that points to the folder where we intend to save the metadata file in 

Returns: Outputs a metadata TSV file with BIDS-compliant name in the specified file path


class Channels

Channels Metadata Class

Class object that mimics and contains the data for the channels.tsv metadata file

method __init__

__init__(fpath=None)

Inherited constructor for the Channels class

Args:

  • fpath: The file path to a reference SNIRF file

method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method export_sidecar

export_sidecar(info, fpath)

Exports sidecar as a json file


method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_SNIRF

load_from_SNIRF(fpath)

Creates the Channels class based on information from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method load_from_tsv

load_from_tsv(fpath)

Create the TSV metadata class from a TSV file

Args:

  • fpath: The file path to the reference TSV file

method make_sidecar

make_sidecar()

Makes a dictionary with the default description noted in BIDS specification into the Sidecar dictionary

Returns: Dictionary with correct fields(that have values) with description of each field within TSV file filled out


method save_to_tsv

save_to_tsv(info, fpath)

Save a TSV inherited class into an output TSV file with a BIDS-compliant name in the file directory designated by the user

Args:

 - <b>`info`</b>:  Subject info field from the Subject class 
 - <b>`fpath`</b>:  The file path that points to the folder where we intend to save the metadata file in 

Returns: Outputs a metadata TSV file with BIDS-compliant name in the specified file path


class Events

Channels Metadata Class

Class object that mimics and contains the data for the events.tsv metadata file

method __init__

__init__(fpath=None)

Inherited constructor for the Events class

Args:

  • fpath: The file path to a reference SNIRF file

method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method export_sidecar

export_sidecar(info, fpath)

Exports sidecar as a json file


method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_SNIRF

load_from_SNIRF(fpath)

Creates the Events class based on information from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method load_from_tsv

load_from_tsv(fpath)

Create the TSV metadata class from a TSV file

Args:

  • fpath: The file path to the reference TSV file

method make_sidecar

make_sidecar()

Makes a dictionary with the default description noted in BIDS specification into the Sidecar dictionary

Returns: Dictionary with correct fields(that have values) with description of each field within TSV file filled out


method save_to_tsv

save_to_tsv(info, fpath)

Save a TSV inherited class into an output TSV file with a BIDS-compliant name in the file directory designated by the user

Args:

 - <b>`info`</b>:  Subject info field from the Subject class 
 - <b>`fpath`</b>:  The file path that points to the folder where we intend to save the metadata file in 

Returns: Outputs a metadata TSV file with BIDS-compliant name in the specified file path


class Sidecar

NIRS Sidecar(_nirs.JSON) Metadata Class

Class object that mimics and contains the data for the _nirs.JSON metadata file

method __init__

__init__(fpath=None)

Inherited constructor for the Sidecar class

Args:

  • fpath: The file path to a reference SNIRF file

method change_type

change_type(name)

Change the data type restriction for a field (from a String class to a Number class or vice versa)

Args:

  • name: The field name

Raises:

  • TypeError: If it's an invalid/undeclared field

method default_fields

default_fields()

Obtain the default fields and their data type for a specific metadata file/class

Returns: The list of default fields for a specific metadata class and the data type

  • default_list: List of default field names for a specific metadata class
  • default_type: List of default field data types for a specific metadata class

method get_class_name

get_class_name()

Obtains the name of the specific metadata class

Returns: The name of the (specific metadata) class


method get_column

get_column(name)

Obtains the value of a specified field/'column' of a Metadata class

Args:

  • name: Name of the field/'column'

Returns: The value of a specified field/'column' - similar to getattr


method get_column_names

get_column_names()

Get the names of the field in a specific metadata class/file that has a value(s)

Returns: A list of field names that have a value in a specific metadata file


method load_from_SNIRF

load_from_SNIRF(fpath)

Creates the Sidecar class based on information from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method load_from_json

load_from_json(fpath)

Create the JSON metadata class from a JSON file

Args:

  • fpath: The file path to the reference JSON file

Raises:

  • TypeError: Incorrect data type for a specific field based on data loaded from the JSON file

method save_to_json

save_to_json(info, fpath)

Save a JSON inherited class into an output JSON file with a BIDS-compliant name in the file directory designated by the user

Args:

  • info: Subject info field from the Subject class
  • fpath: The file path that points to the folder where we intend to save the metadata file in

Returns: Outputs a metadata JSON file with a BIDS-compliant name in the specified file path


class Subject

'Subject' Class

Class object that encapsulates a single 'run' (for now) with fields containing the metadata and 'subject'/run information

Attributes:

  • coordsystem: Contains a Coordsystem class object for a specific 'subject'/run
  • optodes: Contains an Optodes class object for a specific 'subject'/run
  • channel: Contains a Channels class object for a specific 'subject'/run
  • sidecar: Contains a Sidecar (_nirs.JSON) class object for a specific 'subject'/run
  • events: Contains an Events class object for a specific 'subject'/run
  • subinfo: Contains the 'subject'/run information related to the data stored in a 'Subject' object
  • participants: Contains the metadata related to the participants.tsv file

method __init__

__init__(fpath=None)

Constructor for the 'Subject' class


method export

export(outputFormat: str = 'Folder', fpath: str = None)

Exports/creates the BIDS-compliant metadata files based on information stored in the 'subject' class object

Args:

  • outputFormat: The target destination and indirectly, the output format of the metadata file The default value is 'Folder', which outputs the metadata file to a specific file directory specified by the user The other option is 'Text', which outputs the files and data as a string (JSON-like format)
  • fpath: The file path that points to the folder where we intend to save the metadata files in

Returns: A string containing the metadata file names and its content if the user chose the 'Text' output format or a set of metadata files in a specified folder if the user chose the default or 'Folder' output format


method get_ses

get_ses()

Obtains the session ID/number for a particular 'subject'/run

Returns: The session ID/number (returns an empty string if there is no information)


method get_subj

get_subj()

Obtains the subject ID/number for a particular 'subject'/run

Returns: The subject ID/number (returns an empty string if there is no information)


method load_from_snirf

load_from_snirf(fpath)

Loads the metadata from a reference SNIRF file

Args:

  • fpath: The file path to the reference SNIRF file

method pull_fnames

pull_fnames()

Check directory for files (not folders)

Returns: A dictionary of file names for specific metadata files based on the existence of a session label (different nomenclature) that are split into subject-level and session-level metadata files

  • subj_fnames: Contains a dictionary of metadata filenames that are on the subject level
  • ses_fnames: Contains a dictionary of metadata filenames that are on the session level

Notes:

Have to figure out how to do this based on the database structure In the case of the test snirf file, there is no presence of: 1. session number 2. run number


method pull_task

pull_task(fpath=None)

Pull the Task label from either the SNIRF file name or from the Sidecar class (if available)

Args:

  • fpath: The file path to the reference SNIRF file

Returns: The task label/name


This file was automatically generated via lazydocs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snirf2bids-0.1.14.tar.gz (7.8 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page