Skip to content

csv

sleap.io.format.csv

Adaptor for writing SLEAP analysis as csv.

Classes:

Name Description
CSVAdaptor

CSVAdaptor

Bases: Adaptor

Methods:

Name Description
write

Writes csv file for :py:class:Labels source_object.

Source code in sleap/io/format/csv.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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,
        )

write(filename, source_object, source_path=None, video=None) classmethod

Writes csv file for :py:class:Labels source_object.

Parameters:

Name Type Description Default
filename str

The filename for the output file.

required
source_object Labels

The :py:class:Labels from which to get data from.

required
source_path str

Path for the labels object

None
video 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 Frames in the video, then no analysis file will be written.

None
Source code in sleap/io/format/csv.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@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,
    )