Skip to content

Commit ca2159e

Browse files
committed
Adding collection_version flag and filter
1 parent 9b2b93a commit ca2159e

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

subscriber/podaac_data_subscriber.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def create_parser():
107107
help="Specify a provider for collection search. Default is POCLOUD.") # noqa E501
108108
parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="Search and identify files to download, but do not actually download them") # noqa E501
109109
parser.add_argument("--subset", dest="subset", action="store_true", help="Subset the data via Harmony calls.") # noqa E501
110+
parser.add_argument("--collection-version",dest="collection_version", help="Restrict download to files within a specific collection version")
110111

111112
return parser
112113

@@ -136,6 +137,7 @@ def run(args=None):
136137
extensions = args.extensions
137138
process_cmd = args.process_cmd
138139
data_path = args.outputDirectory
140+
collection_version = args.collection_version
139141

140142
defined_time_range = False
141143
if start_date_time or end_date_time:
@@ -281,7 +283,8 @@ def run(args=None):
281283
file_start_times=file_start_times,
282284
ts_shift=ts_shift,
283285
cycles=cycles,
284-
process_cmd=process_cmd
286+
process_cmd=process_cmd,
287+
collection_version=collection_version
285288
)
286289

287290
if len(granules) > 0 and not args.dry_run:
@@ -298,9 +301,18 @@ def run(args=None):
298301
logging.info('END\n\n')
299302

300303

301-
def cmr_downloader(granules, extensions, args, data_path, file_start_times, ts_shift, cycles, process_cmd):
304+
def cmr_downloader(granules, extensions, args, data_path, file_start_times, ts_shift, cycles, process_cmd, collection_version):
302305
downloads_all = []
303306

307+
if collection_version:
308+
granules = list(
309+
filter(
310+
lambda g: "Version" in g["umm"]["CollectionReference"]
311+
and g["umm"]["CollectionReference"]["Version"] == collection_version,
312+
granules,
313+
)
314+
)
315+
304316
downloads_data = [
305317
[
306318
u['URL'] for u in r['umm']['RelatedUrls']
@@ -316,10 +328,8 @@ def cmr_downloader(granules, extensions, args, data_path, file_start_times, ts_s
316328
]
317329
checksums = pa.extract_checksums(granules)
318330

319-
for f in downloads_data:
320-
downloads_all.append(f)
321-
for f in downloads_metadata:
322-
downloads_all.append(f)
331+
downloads_all.extend(downloads_data)
332+
downloads_all.extend(downloads_metadata)
323333

324334
downloads = [item for sublist in downloads_all for item in sublist]
325335

0 commit comments

Comments
 (0)