You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
First of all, thank you for your great work!
I attempted to write an EDF file into BIDS and followed the instructions on this page: https://www.axonlab.org/hcph-sops/data-management/edf-to-bids/#writing-the-data-into-the-bids-structure
After parsing the recording and messages from the Pandas DataFrame, I became uncertain about how to use the 'write_bids' function.
So here I provide a code snippet for directly converting 'recording' and 'metadata' into BIDS format.
Convert the type of "int64" or "int32" in "metadata" into Type "int" for proper json saving.
def convert_to_int(metadata):
if 'CalibrationCount' in metadata:
metadata['CalibrationCount'] = int(metadata['CalibrationCount']) if isinstance(metadata['CalibrationCount'], (np.int32, np.int64, int)) else metadata['CalibrationCount']
if "CalibrationLog" in metadata:
metadata["CalibrationLog"] = [(int(x[0]),x[1]) if isinstance(x[0], (np.int32, np.int64, int)) else x for x in metadata['CalibrationLog']]
return metadata
convert_metadata = convert_to_int(metadata)
Save BIDS from dataframe "recording" and dict "metadata"
def write_bids_from_df(
recording, metadata,
out_dir,
filename,
# exp_run: str | Path,
) -> List[str]:
"""
Directly save the eye-tracking recording/metadata into a BIDS structure.
Parameters
----------
recording : dataframe
The recording data extracted from the EDF file.
metadata : dict
The metadata extracted from the EDF file.
out_dir : obj:`os.pathlike`
The path of EDF file. Refers to the folder (not the EDF file).
filename: str
The filename of the EDF file. The file name without the suffix, eg: "Subject001"
Returns
-------
List[str]
A list of generated files.
"""
out_json = out_dir / (filename + ".json")
out_json.write_text(
json.dumps(metadata, sort_keys=True, indent=2)
)
# Write out data
out_tsvgz = out_dir / (filename + ".tsv.gz")
recording.to_csv(
out_tsvgz,
sep="\t",
index=True,
header=True,
compression="gzip",
na_rep="n/a",
)
return str(out_tsvgz), str(out_json)
Hi,
First of all, thank you for your great work!
I attempted to write an EDF file into BIDS and followed the instructions on this page:
https://www.axonlab.org/hcph-sops/data-management/edf-to-bids/#writing-the-data-into-the-bids-structure
After parsing the recording and messages from the Pandas DataFrame, I became uncertain about how to use the 'write_bids' function.
So here I provide a code snippet for directly converting 'recording' and 'metadata' into BIDS format.
#455
The text was updated successfully, but these errors were encountered: