From 6099b7cfc9e8ef6541c9da8d8355f62184af7aca Mon Sep 17 00:00:00 2001 From: Ryan May Date: Thu, 9 Jan 2025 12:04:29 -0700 Subject: [PATCH] Implement get_range for GOES --- src/metpy/remote/aws.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/metpy/remote/aws.py b/src/metpy/remote/aws.py index 37a0da8451..f188358573 100644 --- a/src/metpy/remote/aws.py +++ b/src/metpy/remote/aws.py @@ -186,9 +186,9 @@ def product_ids(self): """Return product_ids available.""" return (item.rstrip(self.delimiter) for item in self.common_prefixes('')) - def build_key(self, product, dt, depth=None): + def _build_time_prefix(self, product, dt): parts = [product, f'{dt:%Y}', f'{dt:%j}', f'{dt:%H}', f'OR_{product}'] - return self.delimiter.join(parts[slice(0, depth)]) + return self.delimiter.join(parts) def _subprod_prefix(self, prefix, mode, band): subprods = set(item.rstrip('_').rsplit('-', maxsplit=1)[-1] for item in @@ -221,15 +221,20 @@ def dt_from_key(self, key): return datetime.strptime(start_time[:-1], 's%Y%j%H%M%S') def get_nearest(self, product, dt, mode=None, band=None): - prefix = self.build_key(product, dt) - prefix = self._subprod_prefix(prefix, mode, band) - min_obj = min(self.objects(prefix), + time_prefix = self._build_time_prefix(product, dt) + prod_prefix = self._subprod_prefix(time_prefix, mode, band) + min_obj = min(self.objects(prod_prefix), key=lambda o: abs((self.dt_from_key(o.key) - dt).total_seconds())) return self._build_result(min_obj) - def get_range(self, product, dt, mode=None, band=None): - pass + def get_range(self, product, start, end, mode=None, band=None): + for dt in date_iterator(start, end, hours=1): + time_prefix = self._build_time_prefix(product, dt) + prod_prefix = self._subprod_prefix(time_prefix, mode, band) + for obj in self.objects(prod_prefix): + if start <= self.dt_from_key(obj.key) < end: + yield self._build_result(obj) def _build_result(self, obj): return AWSProduct(obj,