-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Option to Export CSV * Add Test Functions * Fomat Files * Change FormatID
- Loading branch information
1 parent
5ba6bc1
commit 47f8096
Showing
8 changed files
with
249 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Adaptor for writing SLEAP analysis as csv.""" | ||
|
||
from sleap.io import format | ||
|
||
from sleap import Labels, Video | ||
from typing import Optional, Callable, List, Text, Union | ||
|
||
|
||
class CSVAdaptor(format.adaptor.Adaptor): | ||
FORMAT_ID = 1.0 | ||
|
||
# 1.0 initial implementation | ||
|
||
@property | ||
def handles(self): | ||
return format.adaptor.SleapObjectType.labels | ||
|
||
@property | ||
def default_ext(self): | ||
return "csv" | ||
|
||
@property | ||
def all_exts(self): | ||
return ["csv", "xlsx"] | ||
|
||
@property | ||
def name(self): | ||
return "CSV" | ||
|
||
def can_read_file(self, file: format.filehandle.FileHandle): | ||
return False | ||
|
||
def can_write_filename(self, filename: str): | ||
return self.does_match_ext(filename) | ||
|
||
def does_read(self) -> bool: | ||
return False | ||
|
||
def does_write(self) -> bool: | ||
return True | ||
|
||
@classmethod | ||
def write( | ||
cls, | ||
filename: str, | ||
source_object: Labels, | ||
source_path: str = None, | ||
video: Video = None, | ||
): | ||
"""Writes csv file for :py:class:`Labels` `source_object`. | ||
Args: | ||
filename: The filename for the output file. | ||
source_object: The :py:class:`Labels` from which to get data from. | ||
source_path: Path for the labels object | ||
video: The :py:class:`Video` from which toget data from. If no `video` is | ||
specified, then the first video in `source_object` videos list will be | ||
used. If there are no :py:class:`Labeled Frame`s in the `video`, then no | ||
analysis file will be written. | ||
""" | ||
from sleap.info.write_tracking_h5 import main as write_analysis | ||
|
||
write_analysis( | ||
labels=source_object, | ||
output_path=filename, | ||
labels_path=source_path, | ||
all_frames=True, | ||
video=video, | ||
csv=True, | ||
) |
2 changes: 2 additions & 0 deletions
2
tests/data/csv_format/minimal_instance.000_centered_pair_low_quality.analysis.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
track,frame_idx,instance.score,A.x,A.y,A.score,B.x,B.y,B.score | ||
,0,nan,205.9300539013689,187.88964024221963,,278.63521449272383,203.3658657346604, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.