Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 0 additions & 192 deletions src/wfdb/io/_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,51 +831,6 @@ def wrheader(self, write_dir="", expanded=True, wfdb_archive=None):
"""
self._write_checked_header(write_dir, expanded, wfdb_archive)

# Temporary pre-refactor path for #866 differential tests.
def _legacy_write_checked_header(self, write_dir, expanded, wfdb_archive):
"""Validate and write a header using one channel snapshot."""
self.check_field("n_sig")
fields = (
SIGNAL_SPECS.index
if expanded
else SIGNAL_SPECS.index.drop("samps_per_frame")
)
snapshot = _capture_write_signal_fields(self, fields)
# Get all the fields used to write the header
# sig_write_fields is a dictionary of
# {field_name:required_channels}
rec_write_fields, sig_write_fields = self.get_write_fields(snapshot)
if not expanded:
sig_write_fields.pop("samps_per_frame", None)

# Check the validity of individual fields used to write the header
# Record specification fields (and comments)
for field in rec_write_fields:
self.check_field(field)

# Signal specification fields.
for field in sig_write_fields:
self.check_field(
field,
required_channels=sig_write_fields[field],
signal_snapshot=snapshot,
)

# Check the cohesion of fields used to write the header
self.check_field_cohesion(
rec_write_fields, list(sig_write_fields), signal_snapshot=snapshot
)

# Write the header file using the specified fields
self.wr_header_file(
rec_write_fields,
sig_write_fields,
write_dir,
wfdb_archive,
signal_snapshot=snapshot,
)
return snapshot

def _write_checked_header(self, write_dir, expanded, wfdb_archive):
"""Validate and write a header from one explicit field snapshot."""
header_fields = {
Expand Down Expand Up @@ -1042,86 +997,6 @@ def check_field_cohesion(
"Each file_name (dat file) specified must have the same byte offset"
)

# Temporary pre-refactor path for #866 byte comparisons.
def _legacy_wr_header_file(
self,
rec_write_fields,
sig_write_fields,
write_dir,
wfdb_archive=None,
*,
signal_snapshot=None,
):
"""Write a header file using the specified fields.

Converts Record attributes into appropriate WFDB format strings.

Parameters
----------
rec_write_fields : list
List of record specification fields to write.
sig_write_fields : dict
Dictionary of signal specification fields to write, values
being equal to a list of channels to write for each field.
write_dir : str
The directory in which to write the header file.
wfdb_archive : WFDBArchive, optional
An open .wfdb archive to write the header file to, instead of
`write_dir`.

Returns
-------
N/A

"""
# Create record specification line
record_line = ""
# Traverse the ordered dictionary
for field in RECORD_SPECS.index:
# If the field is being used, add it with its delimiter
if field in rec_write_fields:
string_field = self.preprocess_header(field)
record_line += RECORD_SPECS.loc[field, "delimiter"] + string_field
# The 'base_counter' field needs to be closed with ')'
if field == "base_counter":
record_line += ")"

header_lines = [record_line]

# Create signal specification lines (if any) one channel at a time
n_channels = (
signal_snapshot.n_channels if signal_snapshot is not None else self.n_sig
)
if n_channels > 0:
signal_lines = n_channels * [""]
for ch in range(n_channels):
# Traverse the signal fields
for field in SIGNAL_SPECS.index:
# If the field is being used, add each of its
# elements with the delimiter to the appropriate
# line
if field in sig_write_fields and ch in sig_write_fields[field]:
value = (
getattr(signal_snapshot.channels[ch], field)
if signal_snapshot is not None
else getattr(self, field)[ch]
)
signal_lines[ch] += SIGNAL_SPECS.loc[field, "delimiter"] + str(
value
)
# The 'baseline' field needs to be closed with ')'
if field == "baseline":
signal_lines[ch] += ")"

header_lines += signal_lines

# Create comment lines (if any)
if "comments" in rec_write_fields:
comment_lines = ["# " + comment for comment in self.comments]
header_lines += comment_lines

self._write_header_lines(header_lines, write_dir, wfdb_archive)

def wr_header_file(
self,
rec_write_fields,
Expand Down Expand Up @@ -1184,23 +1059,6 @@ def set_defaults(self):
for field in self.get_write_fields():
self.set_default(field)

# Temporary pre-refactor path for #866 differential tests.
def _legacy_wrheader(self, write_dir="", wfdb_archive=None):
"""Write a multi-segment header through the legacy validation path."""

# Get all the fields used to write the header
write_fields = self.get_write_fields()

# Check the validity of individual fields used to write the header
for field in write_fields:
self.check_field(field)

# Check the cohesion of fields used to write the header
self.check_field_cohesion()

# Write the header file using the specified fields
self.wr_header_file(write_fields, write_dir, wfdb_archive)

def wrheader(self, write_dir="", wfdb_archive=None):
"""Write a multi-segment WFDB header file.

Expand Down Expand Up @@ -1328,56 +1186,6 @@ def check_field_cohesion(self, *, header_fields=None):
"The sum of the 'seg_len' fields do not match the 'sig_len' field"
)

# Temporary pre-refactor path for #866 byte comparisons.
def _legacy_wr_header_file(self, write_fields, write_dir, wfdb_archive=None):
"""Write a header file using the specified fields.

Parameters
----------
write_fields : list
All the default required fields, the user defined fields,
and their dependencies.
write_dir : str
The output directory in which the header is written.
wfdb_archive : WFDBArchive, optional
An open .wfdb archive to write the header file to, instead of
`write_dir`.

Returns
-------
N/A

"""
# Create record specification line
record_line = ""
# Traverse the ordered dictionary
for field in RECORD_SPECS.index:
# If the field is being used, add it with its delimiter
if field in write_fields:
string_field = self.preprocess_header(field)
record_line += RECORD_SPECS.loc[field, "delimiter"] + string_field

header_lines = [record_line]

# Create segment specification lines
segment_lines = self.n_seg * [""]
# For both fields, add each of its elements with the delimiter
# to the appropriate line
for field in SEGMENT_SPECS.index:
for seg_num in range(self.n_seg):
segment_lines[seg_num] += SEGMENT_SPECS.loc[field, "delimiter"] + str(
getattr(self, field)[seg_num]
)

header_lines = header_lines + segment_lines

# Create comment lines (if any)
if "comments" in write_fields:
comment_lines = ["# " + comment for comment in self.comments]
header_lines += comment_lines

self._write_header_lines(header_lines, write_dir, wfdb_archive)

def wr_header_file(
self,
write_fields,
Expand Down
8 changes: 4 additions & 4 deletions src/wfdb/io/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,11 @@ def calc_checksum(self, expanded=False):
values = self.e_d_signal if expanded else self.d_signal
return _digital_checksums(values, expanded=expanded)

# Temporary pre-refactor path for #866 differential tests and direct calls.
def _legacy_wr_dat_files(
# Keep direct Record.wr_dat_files calls working without a write snapshot.
def _write_dat_files_from_record(
self, expanded=False, write_dir="", wfdb_archive=None, *, signal_snapshot=None
):
"""Write dat files through the legacy field-grouping path."""
"""Write dat files from a Record without a prepared write snapshot."""
# Get the set of dat files to be written, and
# the channels to be written to each file.
storage = signal_snapshot.storage if signal_snapshot is not None else None
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def wr_dat_files(

"""
if signal_snapshot is None:
return self._legacy_wr_dat_files(
return self._write_dat_files_from_record(
expanded=expanded, write_dir=write_dir, wfdb_archive=wfdb_archive
)
values = self.e_d_signal if expanded else self.d_signal
Expand Down
Loading
Loading