-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from TravisWheelerLab/develop
Version 0.0.5
- Loading branch information
Showing
34 changed files
with
659 additions
and
150 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
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,29 @@ | ||
from typing import Optional | ||
from diplomat.frontends import DIPLOMATFrontend, DIPLOMATCommands | ||
|
||
|
||
class DEEPLABCUTFrontend(DIPLOMATFrontend): | ||
""" | ||
The CSV frontend for DIPLOMAT. Contains functions for running some DIPLOMAT operations on csv trajectory files. | ||
Supports video creation, and tweak UI commands. | ||
""" | ||
@classmethod | ||
def init(cls) -> Optional[DIPLOMATCommands]: | ||
try: | ||
from diplomat.frontends.csv._verify_func import _verify | ||
from diplomat.frontends.csv.label_videos import label_videos | ||
from diplomat.frontends.csv.tweak_results import tweak_videos | ||
except ImportError: | ||
return None | ||
|
||
return DIPLOMATCommands( | ||
_verifier=_verify, | ||
label_videos=label_videos, | ||
tweak_videos=tweak_videos | ||
) | ||
|
||
@classmethod | ||
def get_package_name(cls) -> str: | ||
return "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,17 @@ | ||
from diplomat.processing.type_casters import typecaster_function, Union, List, PathLike | ||
from .csv_utils import _fix_paths, _header_check | ||
|
||
|
||
@typecaster_function | ||
def _verify( | ||
config: Union[List[PathLike], PathLike], | ||
**kwargs | ||
) -> bool: | ||
if("videos" not in kwargs): | ||
return False | ||
|
||
try: | ||
config, videos = _fix_paths(config, kwargs["videos"]) | ||
return all(_header_check(c) for c in config) | ||
except (IOError, ValueError): | ||
return False |
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,33 @@ | ||
|
||
|
||
def _header_check(csv): | ||
with open(csv, "r") as csv_handle: | ||
first_lines = [csv_handle.readline().strip("\n").split(",") for i in range(3)] | ||
|
||
header_cols = len(first_lines[0]) | ||
|
||
if(not all(header_cols == len(line) for line in first_lines)): | ||
return False | ||
|
||
last_header_line = first_lines[-1] | ||
last_line_exp = ["x", "y", "likelihood"] * (len(last_header_line) // 3) | ||
|
||
if(last_header_line != last_line_exp): | ||
return False | ||
|
||
return True | ||
|
||
|
||
def _fix_paths(csvs, videos): | ||
csvs = csvs if(isinstance(csvs, (tuple, list))) else [csvs] | ||
videos = videos if(isinstance(videos, (tuple, list))) else [videos] | ||
|
||
if(len(csvs) == 1): | ||
csvs = csvs * len(videos) | ||
if(len(videos) == 1): | ||
videos = videos * len(csvs) | ||
|
||
if(len(videos) != len(csvs)): | ||
raise ValueError("Number of videos and csv files passes don't match!") | ||
|
||
return csvs, videos |
Oops, something went wrong.