@@ -1338,7 +1338,7 @@ def _write_raw_brainvision(raw, bids_fname, events, overwrite):
13381338 )
13391339
13401340
1341- def _write_raw_edf (raw , bids_fname , overwrite ):
1341+ def _write_raw_edf_bdf (raw , bids_fname , overwrite ):
13421342 """Store data as EDF.
13431343
13441344 Parameters
@@ -1350,8 +1350,24 @@ def _write_raw_edf(raw, bids_fname, overwrite):
13501350 overwrite : bool
13511351 Whether to overwrite an existing file or not.
13521352 """
1353- assert str (bids_fname ).endswith (".edf" )
1354- raw .export (bids_fname , overwrite = overwrite )
1353+ ext = bids_fname .suffix [1 :].upper ()
1354+ assert ext in ("EDF" , "BDF" )
1355+ if raw .info ["meas_date" ] is not None and raw .info ["meas_date" ].year < 1985 :
1356+ warn (
1357+ f"Attempting to write a { ext } file with a meas_date of "
1358+ f"{ raw .info ['meas_date' ]} . This is not supported; { ext } limits `startdate` "
1359+ "to dates after 1985-01-01. Setting `startdate` to 1985-01-01 00:00:00 in "
1360+ f"the { ext } file; the original anonymized date will be written to scans.tsv"
1361+ )
1362+ # make a copy, so that anonymized meas_date is unchanged in orig raw,
1363+ # and thus scans.tsv ends up with the properly anonymized meas_date
1364+ raw_anon = raw .copy ()
1365+ raw_anon .set_meas_date (
1366+ raw_anon .info ["meas_date" ].replace (
1367+ year = 1985 , month = 1 , day = 1 , hour = 0 , minute = 0 , second = 0 , microsecond = 0
1368+ )
1369+ )
1370+ raw_anon .export (bids_fname , overwrite = overwrite )
13551371
13561372
13571373def _write_raw_eeglab (raw , bids_fname , overwrite ):
@@ -2361,7 +2377,7 @@ def write_raw_bids(
23612377 )
23622378 elif bids_path .datatype in ["eeg" , "ieeg" ] and format == "EDF" :
23632379 warn ("Converting data files to EDF format" )
2364- _write_raw_edf (raw , bids_path .fpath , overwrite = overwrite )
2380+ _write_raw_edf_bdf (raw , bids_path .fpath , overwrite = overwrite )
23652381 elif bids_path .datatype in ["eeg" , "ieeg" ] and format == "EEGLAB" :
23662382 warn ("Converting data files to EEGLAB format" )
23672383 _write_raw_eeglab (raw , bids_path .fpath , overwrite = overwrite )
0 commit comments