@@ -33,6 +33,7 @@ def csv_to_wfdb(
33
33
header = True ,
34
34
delimiter = "," ,
35
35
verbose = False ,
36
+ write_dir = "" ,
36
37
):
37
38
"""
38
39
Read a WFDB header file and return either a `Record` object with the
@@ -235,6 +236,10 @@ def csv_to_wfdb(
235
236
verbose : bool, optional
236
237
Whether to print all the information read about the file (True) or
237
238
not (False).
239
+ write_dir : str, optional
240
+ The directory where the output files will be saved. If write_dir is not
241
+ provided, the output files will be saved in the same directory as the
242
+ input file.
238
243
239
244
Returns
240
245
-------
@@ -291,6 +296,7 @@ def csv_to_wfdb(
291
296
df_CSV = pd .read_csv (file_name , delimiter = delimiter , header = None )
292
297
if verbose :
293
298
print ("Successfully read CSV" )
299
+
294
300
# Extract the entire signal from the dataframe
295
301
p_signal = df_CSV .values
296
302
# The dataframe should be in (`sig_len`, `n_sig`) dimensions
@@ -300,6 +306,7 @@ def csv_to_wfdb(
300
306
n_sig = p_signal .shape [1 ]
301
307
if verbose :
302
308
print ("Number of signals: {}" .format (n_sig ))
309
+
303
310
# Check if signal names are valid and set defaults
304
311
if not sig_name :
305
312
if header :
@@ -318,15 +325,12 @@ def csv_to_wfdb(
318
325
if verbose :
319
326
print ("Signal names: {}" .format (sig_name ))
320
327
321
- # Set the output header file name to be the same, remove path
322
- if os .sep in file_name :
323
- file_name = file_name .split (os .sep )[- 1 ]
324
- record_name = file_name .replace (".csv" , "" )
328
+ record_name = os .path .splitext (os .path .basename (file_name ))[0 ]
325
329
if verbose :
326
- print ("Output header : {}.hea" .format (record_name ))
330
+ print ("Record name : {}.hea" .format (record_name ))
327
331
328
332
# Replace the CSV file tag with DAT
329
- dat_file_name = file_name . replace ( ".csv" , ".dat" )
333
+ dat_file_name = record_name + ".dat"
330
334
dat_file_name = [dat_file_name ] * n_sig
331
335
if verbose :
332
336
print ("Output record: {}" .format (dat_file_name [0 ]))
@@ -450,7 +454,6 @@ def csv_to_wfdb(
450
454
if verbose :
451
455
print ("Record generated successfully" )
452
456
return record
453
-
454
457
else :
455
458
# Write the information to a record and header file
456
459
wrsamp (
@@ -465,6 +468,7 @@ def csv_to_wfdb(
465
468
comments = comments ,
466
469
base_time = base_time ,
467
470
base_date = base_date ,
471
+ write_dir = write_dir
468
472
)
469
473
if verbose :
470
474
print ("File generated successfully" )
0 commit comments