31
31
file_extension = ".tar"
32
32
downloads_dir_example = os .path .expanduser ("~/Downloads" )
33
33
34
- # throttle params
34
+ # throttle params (seconds) - to avoid overloading the server with requests and to avoid getting blocked by the server for too many requests in a short time period
35
35
default_period_duration = 10 * 60
36
36
default_chunks_per_period = 1000
37
37
default_chunk_length = 1 * 1024
38
38
39
- # download errors handling params
39
+ # download errors handling params (seconds) - to avoid overloading the server and to avoid losing data due to network errors
40
40
default_relogin_duration = 10 * 60
41
41
default_nb_tries_reconnection = 5
42
42
default_reconnection_duration = 10 * 60
43
+ default_choice_sensors = 'all'
44
+ default_choice_runs_file = 'all'
43
45
44
46
45
47
class Datasets :
@@ -62,7 +64,10 @@ def __init__(self, parse_args):
62
64
self .datasets_file = Datasets .get_dataset_file (parse_args )
63
65
64
66
# read datasets file
65
- self .datasets = Datasets .get_datasets (self .datasets_file )
67
+ self .choice_sensors = parse_args .choice_sensors .split (',' )
68
+ self .choice_runs_file = parse_args .choice_runs_file
69
+ self .datasets = Datasets .get_datasets (self .datasets_file , self .choice_runs_file , self .choice_sensors )
70
+
66
71
67
72
@staticmethod
68
73
def get_dataset_file (parse_args ):
@@ -86,7 +91,7 @@ def get_dataset_file(parse_args):
86
91
parse_args .datasets_file )
87
92
88
93
@staticmethod
89
- def get_datasets (datasets_file ):
94
+ def get_datasets (datasets_file , choice_runs_file , choice_sensors ):
90
95
"""Reads known datasets list and file patterns from input file.
91
96
92
97
Args:
@@ -99,12 +104,28 @@ def get_datasets(datasets_file):
99
104
100
105
print ("reading datasets_file: " + datasets_file )
101
106
datasets = []
107
+ # choose dataset and sensor type to download
108
+ if choice_runs_file == 'all' :
109
+ choice_runs = 'all'
110
+ else :
111
+ with open (choice_runs_file , 'r' ) as f :
112
+ choice_runs = f .read ().splitlines ()
102
113
with open (datasets_file , "r" ) as file_handle :
103
114
lines = file_handle .readlines ()
104
115
for line in lines :
105
116
line = line .strip ("\n " ).split ("," )
106
- dataset = {"dataset" : line [0 ], "file_patterns" : line [1 :]}
107
- datasets .append (dataset )
117
+ if choice_runs == 'all' or line [0 ] in choice_runs : # choose this run
118
+ if choice_sensors [0 ] == 'all' :
119
+ dataset = {"dataset" : line [0 ], "file_patterns" : line [1 :]}
120
+ else : # not all sensors
121
+ exist_sensors = [] # sensors that will be downloaded
122
+ for exist_sensor in line [1 :]: # enumerate exist_sensor in this run
123
+ for choice_sensor in choice_sensors : # enumerate choice_sensor the user want to download
124
+ if choice_sensor in exist_sensor : # if choice_sensor is in exist_sensor
125
+ exist_sensors .append (exist_sensor ) # add exist_sensor to exist_sensors
126
+ dataset = {"dataset" : line [0 ], "file_patterns" : exist_sensors }
127
+ datasets .append (dataset )
128
+
108
129
print ("got num_datasets: " + str (len (datasets )))
109
130
return datasets
110
131
@@ -695,6 +716,18 @@ def get_local_file_path(file_url, dataset_handler):
695
716
default = default_nb_tries_reconnection ,
696
717
help = "Number of downloading tries for a file e.g. " +
697
718
str (default_nb_tries_reconnection ))
719
+ argument_parser .add_argument (
720
+ "--choice_sensors" ,
721
+ dest = "choice_sensors" ,
722
+ type = str ,
723
+ default = default_choice_sensors ,
724
+ help = "choice of sensors in [tags, stereo_centre, stereo_left, stereo_right, vo, mono_left, mono_right, mono_rear, lms_front, lms_rear, ldmrs, gps, all] to download e.g. " + default_choice_sensors )
725
+ argument_parser .add_argument (
726
+ "--choice_runs_file" ,
727
+ dest = "choice_runs_file" ,
728
+ type = str ,
729
+ default = default_choice_runs_file ,
730
+ help = "choice of runs recorded in a file to download, if 'all' all runs are downloaded" )
698
731
699
732
# parse CL
700
733
args = argument_parser .parse_args ()
0 commit comments