Skip to content

Commit

Permalink
Prepared code for first release
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleGiacomini committed Apr 16, 2024
1 parent 09e6265 commit 7626149
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 171 deletions.
18 changes: 0 additions & 18 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,3 @@ vbr_download --dataset <sequence_name> --save-dir <output_path>

You can get the list of all the available sequences by using the `-h | --help` flag

```shell
❯ vbr_download -h
usage: vbr_download [-h] --dataset
{all,campus_test0,campus_test1,campus_train0,campus_train1,ciampino_test0,ciampino_t
est1,ciampino_train0,ciampino_train1,colosseo_test0,colosseo_train0,diag_test0,diag_train0,pincio_test0,
pincio_train0,spagna_test0,spagna_train0}
--save-dir PATH

╭─ options ────────────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help show this help message and exit
│ --dataset │
│ {all,campus_test0,campus_test1,campus_train0,campus_train1,ciampino_test0,ciampino_test1,ciampino_t… │
│ (required) │
│ --save-dir PATH (required) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
```


7 changes: 2 additions & 5 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ dependencies = [
"natsort",
"numpy",
"rich",
"tqdm",
"typer[all]>=0.10.0",
"rosbags",
"tyro"
"rosbags"
]

[project.scripts]
vbr_download = "vbr_devkit.download.download_data:entrypoint"
vbr_convert = "vbr_devkit.datasets.convert_bag:entrypoint"
vbr = "vbr_devkit.tools.run:app"

[project.urls]
Homepage = "https://github.com/rvp-group/vbr-devkit"
Expand Down
2 changes: 1 addition & 1 deletion python/vbr_devkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.0-alpha"
2 changes: 2 additions & 0 deletions python/vbr_devkit/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .ros import RosReader
from .kitti import KittiWriter
42 changes: 23 additions & 19 deletions python/vbr_devkit/datasets/convert_bag.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import tyro
import sys
sys.path.append("/home/eg/source/vbr-devkit/python")

from pathlib import Path
from typing import Union
from dataclasses import dataclass
from typing_extensions import Annotated
from kitti import KittiWriter

@dataclass
class Args:
input_dir: Path = "/"
to = Union[
Annotated[KittiWriter, tyro.conf.subcommand(name="kitti")]
]
output_dir: Path = "/"
from vbr_devkit.datasets import KittiWriter, RosReader
import typer
from enum import Enum
from rich.progress import track

def main(args: Args) -> None:
...

def entrypoint():
tyro.run(main)
class OutputDataInterface(str, Enum):
kitti = "kitti",
# Can insert additional conversion formats

if __name__ == "__main__":
entrypoint()


OutputDataInterface_lut = {
OutputDataInterface.kitti: KittiWriter
}

def main(to: OutputDataInterface, input_dir: Path, output_dir: Path) -> None:
with RosReader(input_dir) as reader:
with OutputDataInterface_lut[to](output_dir) as writer:
for timestamp, topic, message in track(reader, description="Processing..."):
writer.publish(timestamp, topic, message)


if __name__ == "__main__":
typer.run(main)
16 changes: 2 additions & 14 deletions python/vbr_devkit/datasets/kitti.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, data_dir: Path):
def __enter__(self):
return self

def publish(self, topic: str, timestamp, message: Union[PointCloudXf, Image, Imu]):
def publish(self, timestamp, topic: str, message: Union[PointCloudXf, Image, Imu]):
if topic not in self.data_handles.keys():
# Infer path to store stuff
# Remove first / on topic
Expand All @@ -131,16 +131,4 @@ def publish(self, topic: str, timestamp, message: Union[PointCloudXf, Image, Imu

def __exit__(self, exc_type, exc_val, exc_tb):
for handle in self.data_handles:
self.data_handles[handle].close()


from ros import RosReader
from tqdm import tqdm

if __name__ == "__main__":
with KittiWriter(Path("/home/eg/data/test_download/vbr_slam/campus/campus_test0/campus_test0_00_kitti")) as writer:
with RosReader(Path("/home/eg/data/test_download/vbr_slam/campus/campus_test0/campus_test0_00.bag"),
topics=["/ouster/points"]) as reader:
for timestamp, topic, message in tqdm(reader, desc="Reading bag"):
# print(f"Topic={topic} | Timestamp={timestamp} (type=({type(timestamp)}) | message_type=({type(message)})")
writer.publish(topic, timestamp, message)
self.data_handles[handle].close()
2 changes: 1 addition & 1 deletion python/vbr_devkit/datasets/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class RosReader:
def __init__(self, data_dir: Sequence[Path], topics: List[str] = None, *args,
def __init__(self, data_dir: Union[Path, Sequence[Path]], topics: List[str] = None, *args,
**kwargs):
"""
:param data_dir: Directory containing rosbags or path to a rosbag file
Expand Down
69 changes: 0 additions & 69 deletions python/vbr_devkit/datasets/split_bag.py

This file was deleted.

84 changes: 40 additions & 44 deletions python/vbr_devkit/download/download_data.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from pathlib import Path
import ftplib
import tyro
from typing import TYPE_CHECKING
from rich.console import Console
from rich.progress import Progress
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.panel import Panel
from vbr_devkit.tools.console import console

DATASET_LINK = "151.100.59.119"
FTP_USER = "anonymous"

vbr_downloads = [
"all",
"campus_test0",
"campus_test1",
"campus_train0",
Expand All @@ -29,44 +26,51 @@
"spagna_train0",
]

if TYPE_CHECKING:
VbrSlamCaptureName = str
else:
VbrSlamCaptureName = tyro.extras.literal_type_from_choices(vbr_downloads)
def download_seq_fld(seq: str, output_dir: Path) -> None:
def human_readable_size(size, decimal_places=2):
for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:
if size < 1024.0 or unit == 'PiB':
break
size /= 1024.0
return f"{size:.{decimal_places}f} {unit}"

CONSOLE = Console(width=120)
def main(
dataset: VbrSlamCaptureName,
save_dir: Path,
):
CONSOLE.rule(f"[bold green] Downloading {dataset}")
if dataset == "all":
for seq in vbr_downloads:
if seq != "all":
main(seq, save_dir)


save_dir.mkdir(parents=True, exist_ok=True)
console.rule(f"[bold green] Downloading {seq}")
# output_dir.mkdir(parents=True, exist_ok=True)

# Establish FTP connection
console.log(f"Connecting to {DATASET_LINK}")
ftp = ftplib.FTP(DATASET_LINK)
ftp.login(FTP_USER, "")
db_path = "vbr_slam/" + dataset.split("_")[0] + "/" + dataset
ftp.cwd(db_path)
try:
available_files = ftp.nlst()
except ftplib.error_perm as resp:
if str(resp) == "550 No files found":
CONSOLE.log("[bold red] Invalid input sequence")
else:
raise
console.log(":white_check_mark: Connection established")
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
transient=True) as progress:
progress.add_task("Gathering files", total=None)
db_path = "vbr_slam/" + seq.split("_")[0] + "/" + seq
ftp.cwd(db_path)

CONSOLE.print(Panel(
" ".join([f"{f}" for f in available_files]), title="Download table"))
try:
available_files = ftp.nlst()
available_files = [(file, ftp.size(file)) for file in available_files]
except ftplib.error_perm as resp:
if str(resp) == "550 No files found":
console.log("[bold red] Invalid input sequence")
else:
raise
# Sort based on size
available_files = sorted(available_files, key=lambda x: x[1])

console.print(Panel(
"\n".join(f"{f[0]}\t{human_readable_size(f[1])}" for f in available_files), title="Downloading files"
))

available_files = [x[0] for x in available_files]
# Downloading routine
with Progress() as progress:
for f in available_files:
local_path = save_dir / "vbr_slam" / dataset.split("_")[0] / dataset
local_path.mkdir(parents=True, exist_ok=True)
local_path = output_dir / "vbr_slam" / seq.split("_")[0] / seq
local_path.mkdir(exist_ok=True, parents=True)
local_fname = local_path / f
fout = open(local_fname, "wb")
task = progress.add_task(f"Downloading {f}", total=ftp.size(f))
Expand All @@ -78,12 +82,4 @@ def write_cb(data):
ftp.retrbinary("RETR " + f, write_cb)
fout.close()
ftp.quit()
CONSOLE.print("[bold green] Done!")


def entrypoint():
tyro.cli(main)


if __name__ == "__main__":
entrypoint()
console.print(":tada: Completed")
3 changes: 3 additions & 0 deletions python/vbr_devkit/tools/console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from rich.console import Console

console = Console()
Loading

0 comments on commit 7626149

Please sign in to comment.