Skip to content

Commit

Permalink
Implement get_range for GOES
Browse files Browse the repository at this point in the history
  • Loading branch information
dopplershift committed Jan 9, 2025
1 parent 7b29b0a commit 6099b7c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/metpy/remote/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6099b7c

Please sign in to comment.