Skip to content

Commit

Permalink
csv to .csv
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Jul 22, 2024
1 parent e7f31c5 commit be1c989
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
17 changes: 9 additions & 8 deletions movement/validators/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def csv_file_contains_valid_header(self, attribute, value):

@path.validator
def csv_file_contains_valid_frame_numbers(self, attribute, value):
"""Ensure that the VIA tracks csv file contains valid frame numbers.
"""Ensure that the VIA tracks .csv file contains valid frame numbers.
This involves:
- Checking that frame numbers are included in `file_attributes` or
Expand Down Expand Up @@ -309,13 +309,14 @@ def csv_file_contains_valid_frame_numbers(self, attribute, value):
raise log_error(
ValueError,
"The number of unique frame numbers does not match the number "
"of unique image files. Please review the VIA tracks csv file "
"and ensure a unique frame number is defined for each file. ",
"of unique image files. Please review the VIA tracks .csv "
"file and ensure a unique frame number is defined for each "
"file. ",
)

@path.validator
def csv_file_contains_tracked_bboxes(self, attribute, value):
"""Ensure that the VIA tracks csv contains tracked bounding boxes.
"""Ensure that the VIA tracks .csv contains tracked bounding boxes.
This involves:
- Checking that the bounding boxes are defined as rectangles.
Expand Down Expand Up @@ -365,7 +366,7 @@ def csv_file_contains_tracked_bboxes(self, attribute, value):
f"{row.filename} (row {row.Index}): "
"bounding box does not have a 'track' attribute defined "
"under 'region_attributes'. "
"Please review the VIA tracks csv file.",
"Please review the VIA tracks .csv file.",
)

# check track ID is castable as an integer
Expand All @@ -376,14 +377,14 @@ def csv_file_contains_tracked_bboxes(self, attribute, value):
ValueError,
f"{row.filename} (row {row.Index}): "
"the track ID for the bounding box cannot be cast "
"as an integer. Please review the VIA tracks csv file.",
"as an integer. Please review the VIA tracks .csv file.",
) from e

@path.validator
def csv_file_contains_unique_track_IDs_per_filename(
self, attribute, value
):
"""Ensure the VIA tracks csv contains unique track IDs per filename.
"""Ensure the VIA tracks .csv contains unique track IDs per filename.
It checks that bounding boxes IDs are defined once per image file.
"""
Expand All @@ -406,5 +407,5 @@ def csv_file_contains_unique_track_IDs_per_filename(
f"{file}: "
"multiple bounding boxes in this file "
"have the same track ID. "
"Please review the VIA tracks csv file.",
"Please review the VIA tracks .csv file.",
)
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def via_tracks_csv_with_valid_header(tmp_path):
def frame_number_in_file_attribute_not_integer(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with invalid frame
"""Return the file path for a VIA tracks .csv file with invalid frame
number defined as file_attribute.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -383,7 +383,7 @@ def frame_number_in_file_attribute_not_integer(
def frame_number_in_filename_wrong_pattern(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with invalid frame
"""Return the file path for a VIA tracks .csv file with invalid frame
number defined in the frame's filename.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -404,7 +404,7 @@ def frame_number_in_filename_wrong_pattern(
def more_frame_numbers_than_filenames(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with more
"""Return the file path for a VIA tracks .csv file with more
frame numbers than filenames.
"""
file_path = via_tracks_csv_with_valid_header
Expand Down Expand Up @@ -435,7 +435,7 @@ def more_frame_numbers_than_filenames(
def less_frame_numbers_than_filenames(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with with less
"""Return the file path for a VIA tracks .csv file with with less
frame numbers than filenames.
"""
file_path = via_tracks_csv_with_valid_header
Expand Down Expand Up @@ -466,7 +466,7 @@ def less_frame_numbers_than_filenames(
def region_shape_attribute_not_rect(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with invalid shape in
"""Return the file path for a VIA tracks .csv file with invalid shape in
region_shape_attributes.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -487,7 +487,7 @@ def region_shape_attribute_not_rect(
def region_shape_attribute_missing_x(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with invalid shape in
"""Return the file path for a VIA tracks .csv file with missing `x` key in
region_shape_attributes.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -508,7 +508,7 @@ def region_shape_attribute_missing_x(
def region_attribute_missing_track(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with missing track
"""Return the file path for a VIA tracks .csv file with missing track
attribute in region_attributes.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -529,7 +529,7 @@ def region_attribute_missing_track(
def track_id_not_castable_as_int(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with a track ID
"""Return the file path for a VIA tracks .csv file with a track ID
attribute not castable as an integer.
"""
file_path = via_tracks_csv_with_valid_header
Expand All @@ -550,7 +550,7 @@ def track_id_not_castable_as_int(
def track_ids_not_unique_per_frame(
via_tracks_csv_with_valid_header,
):
"""Return the file path for a VIA tracks csv file with a track ID
"""Return the file path for a VIA tracks .csv file with a track ID
that appears twice in the same frame.
"""
file_path = via_tracks_csv_with_valid_header
Expand Down
16 changes: 8 additions & 8 deletions tests/test_unit/test_validators/test_files_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def test_deeplabcut_csv_validator_with_invalid_input(
(
"more_frame_numbers_than_filenames",
"The number of unique frame numbers does not match the number "
"of unique image files. Please review the VIA tracks csv file and "
"ensure a unique frame number is defined for each file. ",
"of unique image files. Please review the VIA tracks .csv file "
"and ensure a unique frame number is defined for each file. ",
),
(
"less_frame_numbers_than_filenames",
"The number of unique frame numbers does not match the number "
"of unique image files. Please review the VIA tracks csv file and "
"ensure a unique frame number is defined for each file. ",
"of unique image files. Please review the VIA tracks .csv file "
"and ensure a unique frame number is defined for each file. ",
),
(
"region_shape_attribute_not_rect",
Expand All @@ -127,20 +127,20 @@ def test_deeplabcut_csv_validator_with_invalid_input(
"04.09.2023-04-Right_RE_test_frame_01.png (row 0): "
"bounding box does not have a 'track' attribute defined "
"under 'region_attributes'. "
"Please review the VIA tracks csv file.",
"Please review the VIA tracks .csv file.",
),
(
"track_id_not_castable_as_int",
"04.09.2023-04-Right_RE_test_frame_01.png (row 0): "
"the track ID for the bounding box cannot be cast "
"as an integer. "
"Please review the VIA tracks csv file.",
"Please review the VIA tracks .csv file.",
),
(
"track_ids_not_unique_per_frame",
"04.09.2023-04-Right_RE_test_frame_01.png: "
"multiple bounding boxes in this file have the same track ID. "
"Please review the VIA tracks csv file.",
"Please review the VIA tracks .csv file.",
),
],
)
Expand All @@ -150,7 +150,7 @@ def test_via_tracks_csv_validator_with_invalid_input(
"""Test that invalid VIA tracks CSV files raise the appropriate errors.
Errors to check:
- error if csv header is wrong
- error if .csv header is wrong
- error if frame number is not defined in the file
(frame number extracted either from the filename or from attributes)
- error if extracted frame numbers are not 1-based integers
Expand Down

0 comments on commit be1c989

Please sign in to comment.