def query(self, start_date: str, end_date: str, product: str, provider: str = 'LPDAAC_ECS', bbox: List = []) -> List[Dict]: """ Search CMR database for spectral MODIS tiles matching a temporal range, defined by a start date and end date. Returns metadata containing the URL of each image. Parameters ---------- start_date: string Start date yyyy-mm-dd end_date: string End date yyyy-mm-dd product: string Product name provider: string Provider (default is 'LPDAAC_ECS') bbox: List[float] Bounding box [lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat] Returns ---------- List[Dict] List of granules """ q = GranuleQuery() prod, ver = product['products'][0].split('.') q.short_name(prod).version(ver) q.temporal(f"{start_date}T00:00:00Z", f"{end_date}T23:59:59Z") if (len(bbox) >= 4): q.bounding_box(*bbox[:4]) _granules = q.get_all() # filter dates if 'day_offset' in product.keys(): day_offset = products[product]['day_offset'] else: day_offset = 0 granules = [] for gran in _granules: # CMR uses day 1 of window - correct this to be middle of window date = (dateparser(gran['time_start'].split('T')[0]) + datetime.timedelta(days=day_offset)).date() if (dateparser(start_date).date() <= date <= dateparser(end_date).date()): granules.append(gran) logger.info("%s granules found within %s - %s" % (len(granules), start_date, end_date)) return granules
def query(start_date, end_date, product='MCD43A4.006', provider='LPDAAC_ECS'): """ Search CMR database for spectral MODIS tiles matching a temporal range, defined by a start date and end date. Returns metadata containing the URL of each image. """ q = GranuleQuery() prod, ver = product.split('.') q.short_name(prod).version(ver) q.temporal('%sT00:00:00Z' % str(start_date), '%sT23:59:00Z' % str(end_date)) _granules = q.get_all() # filter dates day_offset = products[product]['day_offset'] granules = [] for gran in _granules: # CMR uses day 1 of window - correct this to be middle of window date = (dateparser(gran['time_start'].split('T')[0]) + datetime.timedelta(days=day_offset)).date() if (start_date <= date <= end_date): granules.append(gran) logger.info("%s granules found within %s - %s" % (len(granules), start_date, end_date)) return granules