def search_api(sname, bbox, time, collection=None): """ API search of the different satellite granules and return metadata dictionary :param sname: short name satellite product, ex: 'MOD03' :param bbox: polygon with the search bounding box :param time: time interval as datetime (init_time_datetime,final_time_datetime) :return metas: a dictionary with all the metadata for the API search """ logging.info('search_api - CMR API search for {0} collection {1}'.format(sname,collection)) maxg=1000 time_esmf=(dt_to_esmf(time[0]),dt_to_esmf(time[1])) api = GranuleQuery() search = api.parameters( short_name=sname, downloadable=True, polygon=bbox, temporal=time_esmf) sh=search.hits() if sh>maxg: logging.warning('search_api - the number of hits {0} is larger than the limit {1}'.format(sh,maxg)) logging.warning('search_api - any satellite data with prefix {} used'.format(sname)) logging.warning('search_api - use a reduced bounding box or a reduced time interval') metas = [] else: metas = api.get(sh) if collection: metas = [m for m in metas if m['collection_concept_id'] == collection] logging.info('search_api - {} hits in this range'.format(len(metas))) return metas
def search_api(sname, bbox, time, maxg=50, platform="", version=""): """ API search of the different satellite granules :param sname: short name :param bbox: polygon with the search bounding box :param time: time interval (init_time,final_time) :param maxg: max number of granules to process :param platform: string with the platform :param version: string with the version :return granules: dictionary with the metadata of the search Developed in Python 2.7.15 :: Anaconda 4.5.10, on MACINTOSH. Angel Farguell ([email protected]), 2018-09-17 """ api = GranuleQuery() if not version: if not platform: search = api.parameters(short_name=sname, downloadable=True, polygon=bbox, temporal=time) else: search = api.parameters(short_name=sname, platform=platform, downloadable=True, polygon=bbox, temporal=time) else: if not platform: search = api.parameters(short_name=sname, downloadable=True, polygon=bbox, temporal=time, version=version) else: search = api.parameters(short_name=sname, platform=platform, downloadable=True, polygon=bbox, temporal=time, version=version) sh = search.hits() print "%s gets %s hits in this range" % (sname, sh) if sh > maxg: print "The number of hits %s is larger than the limit %s." % (sh, maxg) print "Use a reduced bounding box or a reduced time interval." granules = [] else: granules = api.get(sh) return granules
def search_api_sat(self, sname, bounds, time, collection=None): """ API search of the different satellite granules and return metadata dictionary :param sname: short name satellite product, ex: 'MOD03' :param bounds: bounding box as (lon_min,lon_max,lat_min,lat_max) :param time: time interval (init_time_iso,final_time_iso) :param collection: id of the collection to specify :return metas: a dictionary with all the metadata for the API search """ maxg = 1000 # creating polygon with the search bounding box lonmin, lonmax, latmin, latmax = bounds bbox = [(lonmin, latmax), (lonmin, latmin), (lonmax, latmin), (lonmax, latmax), (lonmin, latmax)] time_utcf = (utc_to_utcf(time[0]), utc_to_utcf(time[1])) api = GranuleQuery() search = api.parameters(short_name=sname, downloadable=True, polygon=bbox, temporal=time_utcf) sh = search.hits() if sh > maxg: logging.warning( "The number of hits %s is larger than the limit %s." % (sh, maxg)) logging.warning("Any satellite data with prefix %s used." % self.prefix) logging.warning( "Use a reduced bounding box or a reduced time interval.") metas = [] else: metas = api.get(sh) if collection: metas = [ m for m in metas if m['collection_concept_id'] == collection ] logging.info( 'search_api_sat - CMR API gives {0} hits for {1} of collection {2}' .format(len(metas), sname, collection)) return metas
def fetch_datasets(self, download_type='ROI_polygon', roi_polygon=None, startdate=None, enddate=None, cloudcover_max=5, product_shortname="SPL3SMP", max_products=-1, inverse_polygon_order=False): """Query NASA API for products See: https://modis.ornl.gov/data/modis_webservice.html """ from cmr import GranuleQuery self.product_shortname = product_shortname self.roi_polygon = roi_polygon if download_type == 'ROI_polygon': if roi_polygon.split('.')[-1] == 'geojson': list_coords = from_geojson_to_list_coords(self.roi_polygon) #print(list_coords) else: raise RuntimeError("Unknown download type") if inverse_polygon_order: list_coords = list_coords[::-1] api = GranuleQuery().polygon(list_coords).short_name(self.product_shortname).temporal(startdate, enddate) n_produtes = api.hits() #print(f"{n_produtes} products found for these parameters") if max_products == -1: max_products = n_produtes self.list_products = api.get(limit=max_products) self.list_products_id = [ f["producer_granule_id"] for f in self.list_products]
def search_api_sat(self, sname, bbox, time, version=None): """ API search of the different satellite granules and return metadata dictionary :param sname: short name satellite product, ex: 'MOD03' :param bbox: polygon with the search bounding box :param time: time interval (init_time_iso,final_time_iso) :return metas: a dictionary with all the metadata for the API search """ maxg=100 time_utcf=(utc_to_utcf(time[0]),utc_to_utcf(time[1])) api = GranuleQuery() if not version: search = api.parameters( short_name=sname, downloadable=True, polygon=bbox, temporal=time_utcf ) else: search = api.parameters( short_name=sname, downloadable=True, polygon=bbox, temporal=time_utcf, version=version ) sh=search.hits() logging.info("CMR API: %s gets %s hits in this range" % (sname,sh)) if sh>maxg: logging.warning("The number of hits %s is larger than the limit %s." % (sh,maxg)) logging.warning("Any satellite data with prefix %s used." % self.prefix) logging.warning("Use a reduced bounding box or a reduced time interval.") metas = [] else: metas = api.get(sh) return metas
import os import sys api = GranuleQuery() fire = GranuleQuery() #MOD14: bounding box = Colorado (gps coord sorted lat,lon; counterclockwise) MOD14granules = api.parameters( short_name="MOD14", platform="Terra", downloadable=True, polygon=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)], temporal=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end ) print "MOD14 gets %s hits in this range" % MOD14granules.hits() MOD14granules = api.get(10) #MOD03: geoloc data for MOD14 MOD03granules = api.parameters( short_name="MOD03", platform="Terra", downloadable=True, polygon=[(-109.0507527,40.99898), (-109.0698568,37.0124375), (-102.0868788,36.9799819),(-102.0560592,40.999126), (-109.0507527,40.99898)], temporal=("2017-01-01T00:00:00Z", "2017-01-07T00:00:00Z") #time start,end ) print "MOD03 gets %s hits in this range" % MOD03granules.hits() MOD03granules = api.get(10) #VNP14: fire data, res 750m VNP14granules = fire.parameters( short_name="VNP14",
from cmr import CollectionQuery, GranuleQuery import json api = GranuleQuery() #MOD14: data - auto-sorted by start_time MOD14granules = api.parameters( short_name="MOD14", platform="Terra", downloadable=True) print MOD14granules.hits() #MOD14granules = api.get_all() MOD14granules = api.get(10) for granule in MOD14granules: print granule["title"], granule["time_start"], granule["time_end"], granule["polygons"] #MOD03: geolocation data - auto-sorted by start_time MOD03granules = api.parameters( short_name="MOD03", platform="Terra", downloadable=True) print MOD03granules.hits() MOD03granules = api.get(10) for granule in MOD03granules: print json.dumps(granule, indent=4, separators=(',', ': ')) #print granule["title"], granule["time_start"], granule["time_end"], granule["longitude"] #"polygons" gives long/lat data in pairs-first/last pair are the same # note - it appears that all granules are quadrilaterals