Skip to content

Commit

Permalink
Updated examples to use new group attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuederle committed Jun 23, 2022
1 parent 5f2b7ca commit a487b96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/datasets/_01_datasets_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ def data(self) -> str:
# Note that we need to make our checks from the least restrictive to the most restrictive (if there is only a
# single trail, there is only just a single recording).
if self.is_single(["participant", "recording"]):
return "This is the data for participant {} and rec {}".format(*self.groups[0])
return "This is the data for participant {} and rec {}".format(*self.group)
# None -> single row
if self.is_single(None):
return "This is the data for participant {}, rec {} and trial {}".format(*self.groups[0])
return "This is the data for participant {}, rec {} and trial {}".format(*self.group)
raise ValueError(
"Data can only be accessed when their is only a single recording of a single participant in the subset"
)
Expand All @@ -283,7 +283,7 @@ def segmented_stride_list_(self) -> str:
# We use assert here, as we don't have multiple options.
# (We could also used `None` for the `groupby_cols` here)
self.assert_is_single(["participant", "recording", "trial"], "segmented_stride_list_")
return "This is the segmented stride list for participant {}, rec {} and trial {}".format(*self.groups[0])
return "This is the segmented stride list for participant {}, rec {} and trial {}".format(*self.group)

def create_index(self):
return index
Expand Down
4 changes: 2 additions & 2 deletions examples/datasets/_02_datasets_real_world_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def data(self) -> pd.DataFrame:
# Check that there is only a single participant in the dataset
self.assert_is_single(None, "data")
# Reconstruct the ecg file path based on the data index
p_id = self.index["participant"][0]
p_id = self.group.participant
file_path = self.data_path / f"{p_id}.pk.gz"
# We try to use the cache if enabled.
if self.use_lru_cache:
Expand All @@ -369,7 +369,7 @@ def r_peak_positions_(self) -> pd.DataFrame:
This includes all R-Peaks (PVC or normal)
"""
self.assert_is_single(None, "r_peaks_")
p_id = self.index["participant"][0]
p_id = self.group.participant
r_peaks = pd.read_csv(self.data_path / f"{p_id}_all.csv", index_col=0)
r_peaks = r_peaks.rename(columns={"R": "r_peak_position"})
return r_peaks
Expand Down
4 changes: 2 additions & 2 deletions examples/datasets/datasets_final_ecg.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def r_peak_positions_(self) -> pd.DataFrame:
This includes all R-Peaks (PVC or normal)
"""
self.assert_is_single(None, "r_peaks_")
p_id = self.index["participant"][0]
p_id = self.group.participant
r_peaks = pd.read_csv(self.data_path / f"{p_id}_all.csv", index_col=0)
r_peaks = r_peaks.rename(columns={"R": "r_peak_position"})
return r_peaks
Expand All @@ -82,7 +82,7 @@ def pvc_positions_(self) -> pd.DataFrame:
The position is equivalent to a position entry in `self.r_peak_positions_`.
"""
self.assert_is_single(None, "pvc_positions_")
p_id = self.index["participant"][0]
p_id = self.group.participant
pvc_peaks = pd.read_csv(self.data_path / f"{p_id}_pvc.csv", index_col=0)
pvc_peaks = pvc_peaks.rename(columns={"PVC": "pvc_position"})
return pvc_peaks
Expand Down

0 comments on commit a487b96

Please sign in to comment.