@@ -584,7 +584,7 @@ def download_file(self, uri, *, local_path=None, base_url=None, cache=True, clou
584
584
585
585
return status , msg , url
586
586
587
- def _download_files (self , products , base_dir , * , cache = True , cloud_only = False ,):
587
+ def _download_files (self , products , base_dir , * , flat = False , cache = True , cloud_only = False ,):
588
588
"""
589
589
Takes an `~astropy.table.Table` of data products and downloads them into the directory given by base_dir.
590
590
@@ -594,6 +594,9 @@ def _download_files(self, products, base_dir, *, cache=True, cloud_only=False,):
594
594
Table containing products to be downloaded.
595
595
base_dir : str
596
596
Directory in which files will be downloaded.
597
+ flat : bool
598
+ Default is False. If set to True, no subdirectories will be made for the
599
+ downloaded files.
597
600
cache : bool
598
601
Default is True. If file is found on disk it will not be downloaded again.
599
602
cloud_only : bool, optional
@@ -610,9 +613,12 @@ def _download_files(self, products, base_dir, *, cache=True, cloud_only=False,):
610
613
for data_product in products :
611
614
612
615
# create the local file download path
613
- local_path = os .path .join (base_dir , data_product ['obs_collection' ], data_product ['obs_id' ])
614
- if not os .path .exists (local_path ):
615
- os .makedirs (local_path )
616
+ if not flat :
617
+ local_path = os .path .join (base_dir , data_product ['obs_collection' ], data_product ['obs_id' ])
618
+ if not os .path .exists (local_path ):
619
+ os .makedirs (local_path )
620
+ else :
621
+ local_path = base_dir
616
622
local_path = os .path .join (local_path , os .path .basename (data_product ['productFilename' ]))
617
623
618
624
# download the files
@@ -642,8 +648,8 @@ def _download_curl_script(self, products, out_dir):
642
648
"""
643
649
644
650
url_list = [("uri" , url ) for url in products ['dataURI' ]]
645
- download_file = "mastDownload_" + time .strftime ("%Y%m%d%H%M%S" )
646
- local_path = os .path .join (out_dir . rstrip ( '/' ) , download_file + ".sh" )
651
+ download_file = "mastDownload_" + time .strftime ("%Y%m%d%H%M%S" ) + ".sh"
652
+ local_path = os .path .join (out_dir , download_file )
647
653
648
654
response = self ._download_file (self ._portal_api_connection .MAST_BUNDLE_URL + ".sh" ,
649
655
local_path , data = url_list , method = "POST" )
@@ -660,7 +666,7 @@ def _download_curl_script(self, products, out_dir):
660
666
'Message' : [msg ]})
661
667
return manifest
662
668
663
- def download_products (self , products , * , download_dir = None ,
669
+ def download_products (self , products , * , download_dir = None , flat = False ,
664
670
cache = True , curl_flag = False , mrp_only = False , cloud_only = False , ** filters ):
665
671
"""
666
672
Download data products.
@@ -673,6 +679,14 @@ def download_products(self, products, *, download_dir=None,
673
679
or a Table of products (as is returned by `get_product_list`)
674
680
download_dir : str, optional
675
681
Optional. Directory to download files to. Defaults to current directory.
682
+ flat : bool, optional
683
+ Default is False. If set to True, and download_dir is specified, it will put
684
+ all files into download_dir without subdirectories. Or if set to True and
685
+ download_dir is not specified, it will put files in the current directory,
686
+ again with no subdirs. The default of False puts files into the standard
687
+ directory structure of "mastDownload/<obs_collection>/<obs_id>/". If
688
+ curl_flag=True, the flat flag has no effect, as astroquery does not control
689
+ how MAST generates the curl download script.
676
690
cache : bool, optional
677
691
Default is True. If file is found on disc it will not be downloaded again.
678
692
Note: has no affect when downloading curl script.
@@ -731,13 +745,19 @@ def download_products(self, products, *, download_dir=None,
731
745
download_dir = '.'
732
746
733
747
if curl_flag : # don't want to download the files now, just the curl script
748
+ if flat :
749
+ # flat=True doesn't work with curl_flag=True, so issue a warning
750
+ warnings .warn ("flat=True has no effect on curl downloads." , InputWarning )
734
751
manifest = self ._download_curl_script (products ,
735
752
download_dir )
736
753
737
754
else :
738
- base_dir = download_dir .rstrip ('/' ) + "/mastDownload"
755
+ if flat :
756
+ base_dir = download_dir
757
+ else :
758
+ base_dir = os .path .join (download_dir , "mastDownload" )
739
759
manifest = self ._download_files (products ,
740
- base_dir = base_dir ,
760
+ base_dir = base_dir , flat = flat ,
741
761
cache = cache ,
742
762
cloud_only = cloud_only )
743
763
0 commit comments