@@ -774,26 +774,56 @@ def download_products(self, products, *, download_dir=None, flat=False,
774
774
775
775
return manifest
776
776
777
- def get_cloud_uris (self , data_products , * , include_bucket = True , full_url = False ):
777
+ def get_cloud_uris (self , data_products = None , * , include_bucket = True , full_url = False , pagesize = None , page = None ,
778
+ mrp_only = False , extension = None , filter_products = {}, ** criteria ):
778
779
"""
779
- Takes an `~astropy.table.Table` of data products and returns the associated cloud data uris.
780
+ Given an `~astropy.table.Table` of data products or query criteria and filter parameters,
781
+ returns the associated cloud data URIs.
780
782
781
783
Parameters
782
784
----------
783
785
data_products : `~astropy.table.Table`
784
- Table containing products to be converted into cloud data uris.
786
+ Table containing products to be converted into cloud data uris. If provided, this will supercede
787
+ page_size, page, or any arguments passed in as **criteria.
785
788
include_bucket : bool
786
- Default True. When false returns the path of the file relative to the
789
+ Default True. When False, returns the path of the file relative to the
787
790
top level cloud storage location.
788
791
Must be set to False when using the full_url argument.
789
792
full_url : bool
790
793
Default False. Return an HTTP fetchable url instead of a cloud uri.
791
794
Must set include_bucket to False to use this option.
795
+ pagesize : int, optional
796
+ Default None. Can be used to override the default pagesize when making a query.
797
+ E.g. when using a slow internet connection. Query criteria must also be provided.
798
+ page : int, optional
799
+ Default None. Can be used to override the default behavior of all results being returned for a query
800
+ to obtain one specific page of results. Query criteria must also be provided.
801
+ mrp_only : bool, optional
802
+ Default False. When set to True, only "Minimum Recommended Products" will be returned.
803
+ extension : string or array, optional
804
+ Default None. Option to filter by file extension.
805
+ filter_products : dict, optional
806
+ Filters to be applied to data products. Valid filters are all products fields listed
807
+ `here <https://masttest.stsci.edu/api/v0/_productsfields.html>`__.
808
+ The column name as a string is the key. The corresponding value is one
809
+ or more acceptable values for that parameter.
810
+ Filter behavior is AND between the filters and OR within a filter set.
811
+ For example: {"productType": "SCIENCE", "extension"=["fits","jpg"]}
812
+ **criteria
813
+ Criteria to apply. At least one non-positional criteria must be supplied.
814
+ Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
815
+ and all observation fields returned by the ``get_metadata("observations")``.
816
+ The Column Name is the keyword, with the argument being one or more acceptable values for that parameter,
817
+ except for fields with a float datatype where the argument should be in the form [minVal, maxVal].
818
+ For non-float type criteria wildcards maybe used (both * and % are considered wildcards), however
819
+ only one wildcarded value can be processed per criterion.
820
+ RA and Dec must be given in decimal degrees, and datetimes in MJD.
821
+ For example: filters=["FUV","NUV"],proposal_pi="Ost*",t_max=[52264.4586,54452.8914]
792
822
793
823
Returns
794
824
-------
795
825
response : list
796
- List of URIs generated from the data products, list way contain entries that are None
826
+ List of URIs generated from the data products. May contain entries that are None
797
827
if data_products includes products not found in the cloud.
798
828
"""
799
829
@@ -802,6 +832,29 @@ def get_cloud_uris(self, data_products, *, include_bucket=True, full_url=False):
802
832
'Please enable anonymous cloud access by calling `enable_cloud_dataset` method. '
803
833
'Refer to `~astroquery.mast.ObservationsClass.enable_cloud_dataset` documentation for more info.' )
804
834
835
+ if data_products is None :
836
+ if not criteria :
837
+ raise InvalidQueryError (
838
+ 'Please provide either a `~astropy.table.Table` of data products or query criteria.'
839
+ )
840
+ else :
841
+ # Get table of observations based on query criteria
842
+ obs = self .query_criteria (pagesize = pagesize , page = page , ** criteria )
843
+
844
+ if not len (obs ):
845
+ # Warning raised by ~astroquery.mast.ObservationsClass.query_criteria
846
+ return
847
+
848
+ # Return list of associated data products
849
+ data_products = self .get_product_list (obs )
850
+
851
+ # Filter product list
852
+ data_products = self .filter_products (data_products , mrp_only = mrp_only , extension = extension , ** filter_products )
853
+
854
+ if not len (data_products ):
855
+ warnings .warn ("No matching products to fetch associated cloud URIs." , NoResultsWarning )
856
+ return
857
+
805
858
# Remove duplicate products
806
859
data_products = self ._remove_duplicate_products (data_products )
807
860
@@ -841,59 +894,6 @@ def get_cloud_uri(self, data_product, *, include_bucket=True, full_url=False):
841
894
# Query for product URIs
842
895
return self ._cloud_connection .get_cloud_uri (data_product , include_bucket , full_url )
843
896
844
- def get_cloud_uris_query (self , * , pagesize = None , page = None , mrp_only = False , extension = None ,
845
- filter_products = {}, ** criteria ):
846
- """
847
- Given a set of criteria and optional filters, get a list of matching data products and return their
848
- associated cloud data URIs.
849
-
850
- Parameters
851
- ----------
852
- pagesize : int, optional
853
- Default None. Can be used to override the default pagesize.
854
- E.g. when using a slow internet connection.
855
- page : int, optional
856
- Default None. Can be used to override the default behavior of all results being returned to obtain
857
- one specific page of results.
858
- mrp_only : bool, optional
859
- Default False. When set to True, only "Minimum Recommended Products" will be returned.
860
- extension : string or array, optional
861
- Default None. Option to filter by file extension.
862
- filter_products : dict, optional
863
- Filters to be applied. Valid filters are all products fields listed
864
- `here <https://masttest.stsci.edu/api/v0/_productsfields.html>`__.
865
- The column name as a string is the key. The corresponding value is one
866
- or more acceptable values for that parameter.
867
- Filter behavior is AND between the filters and OR within a filter set.
868
- For example: {"productType": "SCIENCE", "extension"=["fits","jpg"]}
869
- **criteria
870
- Criteria to apply. At least one non-positional criteria must be supplied.
871
- Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
872
- and all observation fields returned by the ``get_metadata("observations")``.
873
- The Column Name is the keyword, with the argument being one or more acceptable values for that parameter,
874
- except for fields with a float datatype where the argument should be in the form [minVal, maxVal].
875
- For non-float type criteria wildcards maybe used (both * and % are considered wildcards), however
876
- only one wildcarded value can be processed per criterion.
877
- RA and Dec must be given in decimal degrees, and datetimes in MJD.
878
- For example: filters=["FUV","NUV"],proposal_pi="Ost*",t_max=[52264.4586,54452.8914]
879
-
880
- Returns
881
- -------
882
- response : list
883
-
884
- """
885
- # Get table of observations based on query criteria
886
- obs = self .query_criteria (pagesize = pagesize , page = page , ** criteria )
887
-
888
- # Return list of associated data products
889
- prod = self .get_product_list (obs )
890
-
891
- # Filter product list
892
- filt = self .filter_products (prod , mrp_only = mrp_only , extension = extension , ** filter_products )
893
-
894
- # Return list of cloud URIs
895
- return self .get_cloud_uris (filt )
896
-
897
897
def _remove_duplicate_products (self , data_products ):
898
898
"""
899
899
Removes duplicate data products that have the same dataURI.
0 commit comments