Skip to content

Commit

Permalink
Merge pull request #2 from nasa/harmony-829
Browse files Browse the repository at this point in the history
HARMONY-829: Update to use latest Zarr version and add User-Agent
  • Loading branch information
bilts authored Apr 22, 2021
2 parents ce20cde + 6d9b142 commit 0895c84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ To allow the technique to work with EOSDIS data, we have extended it and optimiz
* The store caches redirect URLs for a period of time set by the Cache-Control header. Doing this avoids the overhead
of repeated redirects when accessing parts of files.
* In addition to backward-compatible APIs, the store exposes a proposed API that allows it to make more efficient access
decisions. The ticket describing the API is available here: `<https://github.com/zarr-developers/zarr-python/issues/536>`_.
The store works without this implementation but is significantly faster with it, making the following optimizations:
* The store uses a parallel API that allows it to make more efficient access optimizations:
*
* When the Zarr library accesses data that requires reading multiple near-sequential bytes in the file, the store combines
these smaller requests into a single larger request.
Expand Down
15 changes: 12 additions & 3 deletions eosdis_store/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xml.etree.ElementTree as ElementTree

from .dmrpp import to_zarr
from .version import __version__
from zarr.storage import ConsolidatedMetadataStore

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -99,7 +100,10 @@ def _async_read(self, offset, size):
"""
logger.debug(f"Reading {self.url} [{offset}:{offset+size}] ({size} bytes)")
range_str = '%d-%d' % (offset, offset + size)
request = self.session.get(self.url, headers={ 'Range': 'bytes=' + range_str })
request = self.session.get(self.url, headers={
'Range': 'bytes=' + range_str,
'User-Agent': f'zarr-eosdis-store/{__version__}'
})
if self.first_fetch:
self.first_fetch = False
request.result()
Expand Down Expand Up @@ -132,9 +136,9 @@ def __getitem__(self, key):
Returns:
The data or metadata value of the item
"""
return next(self.getitems((key, )))[1]
return self.getitems((key, ))[key]

def getitems(self, keys):
def getitems(self, keys, **kwargs):
"""Get values for the provided list of keys from the Zarr store
Args:
Expand All @@ -143,6 +147,11 @@ def getitems(self, keys):
Returns:
An iterator returning tuples of the input keys to their data or metadata values
"""
return dict(self._getitems_generator(keys, **kwargs))

def _getitems_generator(self, keys, **kwargs):
"""Generate results for getitems
"""
ranges = []
for key in keys:
if re.search(r'/\d+(\.\d+)*$', key):
Expand Down
2 changes: 2 additions & 0 deletions presentation/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
matplotlib>=3.4.1
h5py>=3.2.1
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CacheControl>=0.12.6
requests>=2.23.0
requests-futures>=1.0.0
# Updates to Zarr to implement the getitems method proposed in https://github.com/zarr-developers/zarr-python/issues/536
zarr @ git+https://github.com/bilts/zarr-python.git@getitems-prototype#egg=zarr
zarr>=2.7.1
ipypb~=0.5
xarray~=0.16

0 comments on commit 0895c84

Please sign in to comment.