1- # pyre-unsafe
1+ # pyre-strict
2+ from __future__ import annotations
3+
24import argparse
35import json
4- import typing as t
56from collections import defaultdict , OrderedDict
67from os import PathLike
78from pathlib import Path
8- from typing import Union
99
1010import numpy as np
1111from flask import Flask
@@ -57,7 +57,9 @@ def get_parser() -> argparse.ArgumentParser:
5757 return parser
5858
5959
60- def file_sanity_check (root , seq_dict , fname ) -> t .Set [str ]:
60+ def file_sanity_check (
61+ root : Path , seq_dict : dict [str , list [str ]], fname : str | PathLike [str ]
62+ ) -> set [str ]:
6163 # Images available under ./images for a sanity check
6264 available_images = {p .name for p in (root / "images" ).iterdir ()}
6365 keys_in_seq_dict = {im_key for seq_keys in seq_dict .values () for im_key in seq_keys }
@@ -75,7 +77,7 @@ def file_sanity_check(root, seq_dict, fname) -> t.Set[str]:
7577 return available_images
7678
7779
78- def load_rig_assignments (root : Path ) -> t . Dict [str , t . List [str ]]:
80+ def load_rig_assignments (root : Path ) -> dict [str , list [str ]]:
7981 """
8082 Returns a dict mapping every shot to all the other corresponding shots in the rig
8183 """
@@ -85,7 +87,7 @@ def load_rig_assignments(root: Path) -> t.Dict[str, t.List[str]]:
8587
8688 output = {}
8789 with open (p_json ) as f :
88- assignments : t . Dict [str , t . List [ t . Tuple [str , str ]]] = json .load (f )
90+ assignments : dict [str , list [ tuple [str , str ]]] = json .load (f )
8991 for shot_group in assignments .values ():
9092 group_shot_ids = [s [0 ] for s in shot_group ]
9193 for shot_id , _ in shot_group :
@@ -96,9 +98,9 @@ def load_rig_assignments(root: Path) -> t.Dict[str, t.List[str]]:
9698
9799def load_sequence_database_from_file (
98100 root : Path ,
99- fname : Union [ " PathLike[str]" , str ] = "sequence_database.json" ,
101+ fname : PathLike [str ] | str = "sequence_database.json" ,
100102 skip_missing : bool = False ,
101- ):
103+ ) -> OrderedDict [ str , list [ str ]] | None :
102104 """
103105 Simply loads a sequence file and returns it.
104106 This doesn't require an existing SfM reconstruction
@@ -128,7 +130,7 @@ def load_sequence_database_from_file(
128130 return seq_dict
129131
130132
131- def load_shots_from_reconstructions (path , min_ims ) -> t . List [ t . List [str ]]:
133+ def load_shots_from_reconstructions (path : str , min_ims : int ) -> list [ list [str ]]:
132134 data = dataset .DataSet (path )
133135 reconstructions = data .load_reconstruction ()
134136
@@ -160,8 +162,8 @@ def load_shots_from_reconstructions(path, min_ims) -> t.List[t.List[str]]:
160162
161163
162164def group_by_reconstruction (
163- args , groups_from_sequence_database
164- ) -> t . Dict [str , t . List [str ]]:
165+ args : argparse . Namespace , groups_from_sequence_database : dict [ str , list [ str ]] | None
166+ ) -> dict [str , list [str ]]:
165167 all_recs_shots = load_shots_from_reconstructions (
166168 args .dataset , min_ims = args .min_images_in_reconstruction
167169 )
@@ -184,7 +186,7 @@ def group_by_reconstruction(
184186 return groups
185187
186188
187- def group_images (args ) -> t . Dict [str , t . List [str ]]:
189+ def group_images (args : argparse . Namespace ) -> dict [str , list [str ]]:
188190 """
189191 Groups the images to be shown in different windows/views
190192
@@ -214,11 +216,13 @@ def group_images(args) -> t.Dict[str, t.List[str]]:
214216 return groups_from_sequence_database
215217
216218
217- def find_suitable_cad_paths (path_cad_files : Path , path_dataset , n_paths : int = 6 ):
219+ def find_suitable_cad_paths (
220+ path_cad_files : Path | None , path_dataset : str , n_paths : int = 6
221+ ) -> list [Path ]:
218222 if path_cad_files is None :
219223 return []
220224
221- def latlon_from_meta (path_cad ) -> t . Tuple [float , float ]:
225+ def latlon_from_meta (path_cad : Path ) -> tuple [float , float ]:
222226 path_meta = path_cad .with_suffix (".json" )
223227 with open (path_meta ) as f :
224228 meta = json .load (f )
@@ -242,7 +246,7 @@ def latlon_from_meta(path_cad) -> t.Tuple[float, float]:
242246 return [cad_files [i ] for i in ixs_sort ]
243247
244248
245- def init_ui () -> t . Tuple [Flask , argparse .Namespace ]:
249+ def init_ui () -> tuple [Flask , argparse .Namespace ]:
246250 app = Flask (__name__ )
247251 parser = get_parser ()
248252 args = parser .parse_args ()
0 commit comments