Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to export to CSV via sleap-convert and API #1713

Closed
eberrigan opened this issue Mar 17, 2024 Discussed in #1629 · 2 comments · Fixed by #1730
Closed

Add option to export to CSV via sleap-convert and API #1713

eberrigan opened this issue Mar 17, 2024 Discussed in #1629 · 2 comments · Fixed by #1730
Labels
enhancement New feature or request

Comments

@eberrigan
Copy link
Contributor

It would be convenient to be able to export predictions stored in .SLP files to .CSV (see linked discussion).

Enhancement plan

  1. Add csv as an option for the --format flag in the sleap-convert CLI here:

parser.add_argument(
"--format",
default="slp",
help="Output format. Default ('slp') is SLEAP dataset; "
"'analysis' results in analysis.h5 file; "
"'analysis.nix' results in an analysis nix file;"
"'h5' or 'json' results in SLEAP dataset "
"with specified file format.",
)

  1. If csv format is requested, use csv=True in the sleap-convert CLI entrypoint function:

sleap/sleap/io/convert.py

Lines 165 to 172 in 2d24296

write_analysis(
labels,
output_path=output_path,
labels_path=args.input_path,
all_frames=True,
video=video,
)

  1. The CSV writing is already handled through the IO format backends, so we can just route it through by adding csv as an option in the actual analysis exporting writer:

sleap/sleap/io/convert.py

Lines 177 to 181 in 2d24296

elif args.format in ("slp", "h5", "json"):
output_path = f"{args.input_path}.{args.format}"
print(f"Output SLEAP dataset: {output_path}")
Labels.save_file(labels, output_path)

Discussed in #1629

Originally posted by talmo December 7, 2023
In #1438, we added a feature to export tracks to CSV format from the GUI.

It would be great to be able to do that via the sleap-export CLI and the Labels.export() API.

For sleap-export, we just need to add CSV as a target format and pass in csv=True in the export call here.

For Labels.export(), we probably want to extend what's going on here.

We should also be sure to support the new functionality being added in #1624.

Relevant: #1627

@roomrys roomrys added the enhancement New feature or request label Mar 19, 2024
@roomrys roomrys changed the title Add option to export to CSV via sleap-export and API Add option to export to CSV via sleap-convert and API Mar 20, 2024
@eberrigan eberrigan linked a pull request Apr 8, 2024 that will close this issue
11 tasks
@roaldarbol
Copy link

Any idea when you're cutting a new release? This feature would be great to have without having to build from source. :-)

@talmo
Copy link
Collaborator

talmo commented Jul 29, 2024

Soon™ :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants