22"""Download and verify the canonical full-scale MTC and SANDAG data."""
33
44import argparse
5+ import subprocess
56import sys
67from pathlib import Path
78
@@ -25,13 +26,24 @@ def prepare_mtc(model: Path, cache: Path) -> None:
2526 )
2627
2728
28- def prepare_sandag (model : Path ) -> None :
29+ def fetch_s3_cache (source : str , destination : str ) -> None :
30+ subprocess .run (
31+ ["aws" , "s3" , "sync" , source , destination , "--only-show-errors" ], check = True
32+ )
33+
34+
35+ def prepare_sandag (model : Path , s3_cache_uri : str | None ) -> None :
2936 scripts = model / "scripts"
3037 sys .path .insert (0 , str (scripts ))
3138 try :
3239 from fulldata import get_full_data
3340
34- get_full_data (model / "data-full" )
41+ full_data_dir = model / "data-full"
42+ full_data_dir .mkdir (parents = True , exist_ok = True )
43+ if s3_cache_uri :
44+ print (f"checking data cache { s3_cache_uri } " )
45+ fetch_s3_cache (s3_cache_uri .rstrip ("/" ) + "/" , str (full_data_dir ))
46+ get_full_data (full_data_dir )
3547 finally :
3648 sys .path .remove (str (scripts ))
3749
@@ -41,13 +53,17 @@ def main(argv=None) -> int:
4153 parser .add_argument ("model" , choices = ("mtc-extended" , "sandag" ))
4254 parser .add_argument ("repository" , type = Path )
4355 parser .add_argument ("--cache" , required = True , type = Path )
56+ parser .add_argument (
57+ "--s3-cache-uri" ,
58+ help = "s3://bucket/prefix of a pre-populated, read-only cache of the extracted data" ,
59+ )
4460 args = parser .parse_args (argv )
4561 args .cache .mkdir (parents = True , exist_ok = True )
4662 repository = args .repository .resolve ()
4763 if args .model == "mtc-extended" :
4864 prepare_mtc (repository , args .cache .resolve ())
4965 else :
50- prepare_sandag (repository )
66+ prepare_sandag (repository , args . s3_cache_uri )
5167 return 0
5268
5369
0 commit comments