-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from jarq6c/add-azure-client
Add interface to `nwm_client_new` for Azure Blob Storage
- Loading branch information
Showing
5 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
python/nwm_client_new/src/hydrotools/nwm_client_new/AzureFileCatalog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
""" | ||
============================================= | ||
NWM Azure Blob Storage Container File Catalog | ||
============================================= | ||
Concrete implementation of a National Water Model file client for discovering | ||
files on Microsoft Azure. | ||
https://planetarycomputer.microsoft.com/dataset/storage/noaa-nwm | ||
Classes | ||
------- | ||
AzureFileCatalog | ||
""" | ||
from .NWMFileCatalog import NWMFileCatalog | ||
from hydrotools._restclient.urllib import Url | ||
import azure.storage.blob | ||
import planetary_computer | ||
import adlfs | ||
from typing import List | ||
|
||
class AzureFileCatalog(NWMFileCatalog): | ||
"""An Azure Cloud client class for NWM data. | ||
This AzureFileCatalog class provides various methods for discovering NWM | ||
files on Azure Blob Storage. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
server: str = 'https://noaanwm.blob.core.windows.net/' | ||
) -> None: | ||
"""Initialize catalog of NWM data source on Azure Blob Storage. | ||
Parameters | ||
---------- | ||
server : str, required | ||
Fully qualified path to Azure Cloud endpoint. | ||
Returns | ||
------- | ||
None | ||
""" | ||
super().__init__() | ||
self.server = server | ||
|
||
def list_blobs( | ||
self, | ||
configuration: str, | ||
reference_time: str, | ||
must_contain: str = 'channel_rt' | ||
) -> List[str]: | ||
"""List available blobs with provided parameters. | ||
Parameters | ||
---------- | ||
configuration : str, required | ||
Particular model simulation or forecast configuration. For a list | ||
of available configurations see NWMDataService.configurations | ||
reference_time : str, required | ||
Model simulation or forecast issuance/reference time in | ||
YYYYmmddTHHZ format. | ||
must_contain : str, optional, default 'channel_rt' | ||
Optional substring found in each blob name. | ||
Returns | ||
------- | ||
A list of blob names that satisfy the criteria set by the parameters. | ||
""" | ||
# Validate configuration | ||
self.raise_invalid_configuration(configuration) | ||
|
||
# Break-up reference time | ||
issue_date, issue_time = self.separate_datetime(reference_time) | ||
|
||
# Get list of blobs | ||
fs = adlfs.AzureBlobFileSystem( | ||
"noaanwm", credential=planetary_computer.sas.get_token("noaanwm", "nwm").token | ||
) | ||
blobs = fs.glob(f"nwm/nwm.{issue_date}/{configuration}/nwm.t{issue_time}*") | ||
|
||
# Return blob URLs | ||
return [ | ||
str(self.server / suffix) | ||
for suffix in list(blobs) | ||
if must_contain in suffix | ||
] | ||
|
||
@property | ||
def server(self) -> str: | ||
return self._server | ||
|
||
@server.setter | ||
def server(self, server: str) -> None: | ||
self._server = Url(server) | ||
|
2 changes: 1 addition & 1 deletion
2
python/nwm_client_new/src/hydrotools/nwm_client_new/_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "7.2.1" | ||
__version__ = "7.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters