Skip to content

Commit b54afa1

Browse files
committed
width
1 parent 4b9b0b3 commit b54afa1

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

wfdb/_rdsamp.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,29 @@ def dlrecordfiles(pbrecname, targetdir):
3636
# For any missing file, check if the input physiobank record name is
3737
# valid, ie whether the file exists on physionet. Download if valid, exit
3838
# if invalid.
39-
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+baserecname+".hea", os.path.join(targetdir, baserecname+".hea"), dledfiles, displaydlmsg, targetdir)
39+
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+baserecname+".hea", os.path.join(targetdir,
40+
baserecname+".hea"), dledfiles, displaydlmsg, targetdir)
4041

4142
fields = readheader(os.path.join(targetdir, baserecname))
4243

4344
# Need to check validity of link if ANY file is missing.
4445
if fields["nseg"] == 1: # Single segment. Check for all the required dat files
4546
for f in set(fields["filename"]):
4647
# Missing dat file
47-
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles, displaydlmsg, targetdir)
48+
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+f, os.path.join(targetdir, f),
49+
dledfiles, displaydlmsg, targetdir)
4850
else: # Multi segment. Check for all segment headers and their dat files
4951
for segment in fields["filename"]:
5052
if segment != '~':
5153
# Check the segment header
52-
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+segment+".hea", os.path.join(targetdir, segment+".hea"), dledfiles, displaydlmsg, targetdir)
54+
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+segment+".hea",
55+
os.path.join(targetdir, segment+".hea"), dledfiles, displaydlmsg, targetdir)
5356
segfields = readheader(os.path.join(targetdir, segment))
5457
for f in set(segfields["filename"]):
5558
if f != '~':
5659
# Check the segment's dat file
57-
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+f, os.path.join(targetdir, f), dledfiles, displaydlmsg, targetdir)
60+
dledfiles, displaydlmsg = dlifmissing(physioneturl+pbdir+"/"+f,
61+
os.path.join(targetdir, f), dledfiles, displaydlmsg, targetdir)
5862

5963
if dledfiles:
6064
print('Downloaded all missing files for record.')
@@ -295,7 +299,8 @@ def readheader(recordname): # For reading signal headers
295299

296300

297301

298-
def skewsignal(sig, skew, fp, nsig, fmt, siglen, sampfrom, sampto, startbyte, nbytesread, byteoffset, sampsperframe, tsampsperframe):
302+
def skewsignal(sig, skew, fp, nsig, fmt, siglen, sampfrom, sampto, startbyte,
303+
nbytesread, byteoffset, sampsperframe, tsampsperframe):
299304
if max(skew) > 0:
300305
# Array of samples to fill in the final samples of the skewed channels.
301306
extrasig = np.empty([max(skew), nsig])
@@ -387,7 +392,8 @@ def readdat(
387392
fp, fmt, sampto - sampfrom, nsig, sampsperframe, floorsamp)
388393

389394
# Shift the samples in the channels with skew if any
390-
sig=skewsignal(sig, skew, fp, nsig, fmt, siglen, sampfrom, sampto, startbyte, nbytesread, byteoffset, sampsperframe, tsampsperframe)
395+
sig=skewsignal(sig, skew, fp, nsig, fmt, siglen, sampfrom, sampto, startbyte,
396+
nbytesread, byteoffset, sampsperframe, tsampsperframe)
391397

392398
fp.close()
393399

@@ -995,16 +1001,26 @@ def rdsamp(
9951001
"""Read a WFDB record and return the signal as a numpy array and the metadata as a dictionary.
9961002
9971003
Usage:
998-
sig, fields = rdsamp(recordname, sampfrom=0, sampto=[], channels=[], physical=1, stacksegments=1, pbdl=0, dldir=os.cwd())
1004+
sig, fields = rdsamp(recordname, sampfrom=0, sampto=[], channels=[], physical=1, stacksegments=1,
1005+
pbdl=0, dldir=os.cwd())
9991006
10001007
Input arguments:
1001-
- recordname (required): The name of the WFDB record to be read (without any file extensions). If the argument contains any path delimiter characters, the argument will be interpreted as PATH/baserecord and the data files will be searched for in the local path. If the pbdownload flag is set to 1, recordname will be interpreted as a physiobank record name including the database subdirectory.
1008+
- recordname (required): The name of the WFDB record to be read (without any file extensions).
1009+
If the argument contains any path delimiter characters, the argument will be interpreted as
1010+
PATH/baserecord and the data files will be searched for in the local path. If the pbdownload
1011+
flag is set to 1, recordname will be interpreted as a physiobank record name including the
1012+
database subdirectory.
10021013
- sampfrom (default=0): The starting sample number to read for each channel.
10031014
- sampto (default=length of entire signal): The final sample number to read for each channel.
10041015
- channels (default=all channels): Indices specifying the channel to be returned.
1005-
- physical (default=1): Flag that specifies whether to return signals in physical (1) or digital (0) units.
1006-
- stacksegments (default=1): Flag used only for multi-segment files. Specifies whether to return the signal as a single stacked/concatenated numpy array (1) or as a list of one numpy array for each segment (0).
1007-
- pbdl (default=0): If this argument is set, the function will assume that the user is trying to download a physiobank file. Therefore the 'recordname' argument will be interpreted as a physiobank record name including the database subdirectory, rather than a local directory.
1016+
- physical (default=1): Flag that specifies whether to return signals in physical (1) or
1017+
digital (0) units.
1018+
- stacksegments (default=1): Flag used only for multi-segment files. Specifies whether to
1019+
return the signal as a single stacked/concatenated numpy array (1) or as a list of one
1020+
numpy array for each segment (0).
1021+
- pbdl (default=0): If this argument is set, the function will assume that the user is trying
1022+
to download a physiobank file. Therefore the 'recordname' argument will be interpreted as
1023+
a physiobank record name including the database subdirectory, rather than a local directory.
10081024
- dldir (default=os.getcwd()): The directory to download physiobank files to.
10091025
10101026
Output variables:
@@ -1021,7 +1037,8 @@ def rdsamp(
10211037
: The last list element will be a list of dictionaries of metadata for each segment.
10221038
For empty segments, the dictionary will be replaced by a single string: 'Empty Segment'
10231039
1024-
Example: sig, fields = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, pbdl=1, dldir='/home/username/Downloads/wfdb')
1040+
Example: sig, fields = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, pbdl=1,
1041+
dldir='/home/username/Downloads/wfdb')
10251042
"""
10261043

10271044
if sampfrom < 0:
@@ -1040,7 +1057,8 @@ def rdsamp(
10401057

10411058
# Single segment file
10421059
if fields["nseg"] == 1:
1043-
sig, fields = processsegment(fields, dirname, baserecordname, sampfrom, sampto, channels, physical)
1060+
sig, fields = processsegment(fields, dirname, baserecordname, sampfrom, sampto,
1061+
channels, physical)
10441062

10451063
# Multi-segment file. Preprocess and recursively call rdsamp on segments
10461064
else:
@@ -1052,7 +1070,8 @@ def rdsamp(
10521070
readsegs, readsamps, sampto = requiredsections(fields, sampfrom, sampto, startseg)
10531071

10541072
# Preprocess/preallocate according to the chosen output format
1055-
sig, channels, nsamp, segmentfields, indstart= allocateoutput(fields, channels, stacksegments, sampfrom, sampto, physical, startseg, readsegs)
1073+
sig, channels, nsamp, segmentfields, indstart= allocateoutput(fields, channels,
1074+
stacksegments, sampfrom, sampto, physical, startseg, readsegs)
10561075

10571076
# Read and store segments one at a time.
10581077
# segnum (the segment number) accounts for the layout record if exists
@@ -1062,7 +1081,8 @@ def rdsamp(
10621081
segrecordname = fields["filename"][segnum]
10631082

10641083
# Work out the relative channels to return from this segment
1065-
segchannels, returninds, emptyinds = getsegmentchannels(startseg, segrecordname, dirname, layoutfields, channels)
1084+
segchannels, returninds, emptyinds = getsegmentchannels(startseg, segrecordname,
1085+
dirname, layoutfields, channels)
10661086

10671087
if stacksegments == 0: # Return list of np arrays
10681088
# Empty segment or no desired channels in segment. Store indicator and segment

0 commit comments

Comments
 (0)