Skip to content

Commit

Permalink
Update sleap_roots/series.py
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
eberrigan and coderabbitai[bot] authored Apr 4, 2024
1 parent 0b488c3 commit 575308f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sleap_roots/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,27 @@ class Series:
Properties:
series_name: Name of the series derived from the HDF5 filename.
expected_count: Fetch the expected plant count for this series from the CSV.
group: Group name for the series from the CSV.
@property
def group(self) -> str:
"""Group name for the series from the CSV.

This property retrieves the group name (e.g., genotype) associated with the series,
based on the series name matched against the 'plant_qr_code' in the CSV file.

Returns:
The group name as a string, or np.nan if the CSV path is not set or the group name
cannot be found.
"""
if not self.csv_path or not Path(self.csv_path).exists():
print("CSV path is not set or the file does not exist.")
return np.nan
df = pd.read_csv(self.csv_path)
try:
# Match the series_name (or plant_qr_code in the CSV) to fetch the group
return df[df["plant_qr_code"] == self.series_name]["genotype"].iloc[0]
except IndexError:
print(f"No group found for series {self.series_name} in CSV.")
return np.nan
"""

h5_path: Optional[str] = None
Expand Down

0 comments on commit 575308f

Please sign in to comment.