-
Notifications
You must be signed in to change notification settings - Fork 49
add BGC-Argo+ dataset support to ArgoFloat.open_dataset()
#623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RaphaelBajon
wants to merge
5
commits into
euroargodev:master
Choose a base branch
from
RaphaelBajon:feature/bgcargo-plus-store
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf8a72b
BGCArgo+ dataset inclusion, test and doc.
RaphaelBajon 7121ba6
update ftp path depending on the dataset version + add version check
RaphaelBajon f05830c
hardcoded fix issue/h5py for prof->point point->prof
RaphaelBajon 9aff879
disclose the AI model
RaphaelBajon 819c9d2
Merge branch 'master' into feature/bgcargo-plus-store
RaphaelBajon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,163 @@ | ||
| """ | ||
| BGC-Argo+ dataset store for :class:`argopy.ArgoFloat`. | ||
|
|
||
| The BGC-Argo+ dataset (https://www.bgc-argo-plus.info) is a quality-controlled, | ||
| outlier-removed version of BGC-Argo float data curated at SOEST / University of | ||
| Hawaiʻi at Mānoa (Bushinsky et al, 2025, Bushinsky et al, submitted). Individual float files are served on the SOEST FTP server:: | ||
|
|
||
| ftp://ftp.soest.hawaii.edu/bgc_argo_plus/outliers_removed/ | ||
|
|
||
| Usage | ||
| ----- | ||
| The typical access path is through :class:`argopy.ArgoFloat`:: | ||
|
|
||
| from argopy import ArgoFloat | ||
| ds = ArgoFloat(6903091).open_dataset('BGCArgoPlus') | ||
|
|
||
| You can also use the store directly:: | ||
|
|
||
| from argopy.stores.float.bgcargo_plus import BGCArgoPlusStore | ||
| store = BGCArgoPlusStore(6903091) | ||
| ds = store.open_dataset() | ||
| url = store.url | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| import xarray as xr | ||
|
|
||
| from ...stores.implementations.ftp import ftpstore | ||
| from ...utils import check_wmo | ||
|
|
||
| log = logging.getLogger("argopy.stores.BGCArgoPlusStore") | ||
|
|
||
| #: Root of the BGC-Argo+ FTP tree (no trailing slash) | ||
| BGCARGO_PLUS_FTP_HOST = "ftp.soest.hawaii.edu" | ||
|
|
||
| #: Path template on the FTP server. | ||
| #: ``{version}`` can be overridden via :attr:`BGCArgoPlusStore.version`. | ||
| BGCARGO_PLUS_PATH_TEMPLATE = ( | ||
| "/bgc_argo_plus/outliers_removed/{version}/{wmo}_Sprof_BGCArgoPlus.nc" | ||
| ) | ||
|
|
||
| #: Default version tag that maps to the latest production release on the FTP. | ||
| BGCARGO_PLUS_DEFAULT_VERSION = "v0.1_2026_04" | ||
|
|
||
|
|
||
| def bgcargo_plus_url(wmo: int, version: str = BGCARGO_PLUS_DEFAULT_VERSION) -> str: | ||
| """Return the FTP URL for a BGC-Argo+ float file. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| wmo : int | ||
| Float WMO number. | ||
| version : str, optional | ||
| Dataset version string, e.g. ``"v0.1_2026_04"``. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| Full FTP URL | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from argopy.stores.float.bgcargo_plus import bgcargo_plus_url | ||
| >>> bgcargo_plus_url(6903091) | ||
| 'ftp://ftp.soest.hawaii.edu/bgc_argo_plus/outliers_removed/v0.1_2026_04/6903091_Sprof_BGCArgoPlus.nc' | ||
| """ | ||
| path = BGCARGO_PLUS_PATH_TEMPLATE.format(wmo=wmo, version=version) | ||
| return f"ftp://{BGCARGO_PLUS_FTP_HOST}{path}" | ||
|
|
||
|
|
||
| class BGCArgoPlusStore: | ||
| """Store that fetches BGC-Argo+ individual-float files from SOEST FTP. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| wmo : int or str | ||
| Float WMO number. | ||
| version : str, optional | ||
| BGC-Argo+ dataset version, default :data:`BGCARGO_PLUS_DEFAULT_VERSION`. | ||
| cache : bool, optional | ||
| Cache downloaded files locally (passed to :class:`ftpstore`). | ||
| cachedir : str, optional | ||
| Local cache directory (passed to :class:`ftpstore`). | ||
| timeout : int, optional | ||
| FTP connection timeout in seconds (passed to :class:`ftpstore`). | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from argopy.stores.float.bgcargo_plus import BGCArgoPlusStore | ||
| >>> store = BGCArgoPlusStore(6903091) | ||
| >>> ds = store.open_dataset() | ||
| >>> store.url | ||
| 'ftp://ftp.soest.hawaii.edu/bgc_argo_plus/...' | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| wmo: int | str, | ||
| version: str = BGCARGO_PLUS_DEFAULT_VERSION, | ||
| cache: bool = False, | ||
| cachedir: str = "", | ||
| timeout: int = 0, | ||
| ): | ||
| self.WMO = check_wmo(wmo)[0] | ||
| self.version = version | ||
| self.cache = cache | ||
| self.cachedir = cachedir | ||
| self.timeout = timeout | ||
|
|
||
| # Build the FTP store pointing at the SOEST server | ||
| ftp_root = f"{BGCARGO_PLUS_FTP_HOST}" | ||
| self._fs = ftpstore( | ||
| host=ftp_root, | ||
| cache=self.cache, | ||
| cachedir=self.cachedir if self.cachedir else None, | ||
| timeout=self.timeout if self.timeout else None, | ||
| ) | ||
|
|
||
| @property | ||
| def url(self) -> str: | ||
| """Full FTP URL of this float's BGC-Argo+ file.""" | ||
| return bgcargo_plus_url(self.WMO, version=self.version) | ||
|
|
||
| def open_dataset(self, **kwargs) -> xr.Dataset: | ||
| """Download and open the BGC-Argo+ netCDF file for this float. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| **kwargs | ||
| Additional keyword arguments forwarded to | ||
| :meth:`argopy.stores.ftpstore.open_dataset` (e.g. ``lazy=True``, | ||
| ``xr_opts={"decode_times": False}``). | ||
|
|
||
| Returns | ||
| ------- | ||
| :class:`xarray.Dataset` | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from argopy.stores.float.bgcargo_plus import BGCArgoPlusStore | ||
| >>> ds = BGCArgoPlusStore(6903091).open_dataset() | ||
| """ | ||
| log.debug("BGCArgoPlusStore: fetching %s", self.url) | ||
| try: | ||
| ds = self._fs.open_dataset(self.url, **kwargs) | ||
| except FileNotFoundError as exc: | ||
| raise FileNotFoundError( | ||
| f"Could not retrieve BGC-Argo+ file for WMO {self.WMO} " | ||
| f"(version='{self.version}') from {self.url}.\n" | ||
| f"Original error: {exc}" | ||
| ) from exc | ||
| return ds | ||
|
|
||
| def __repr__(self) -> str: | ||
| return ( | ||
| f"<BGCArgoPlusStore>\n" | ||
| f" WMO : {self.WMO}\n" | ||
| f" version : {self.version}\n" | ||
| f" URL : {self.url}\n" | ||
| ) | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RaphaelBajon are you sure of the url ?
I guess it should read:
'/bgc_argo_plus/outliers_removed/{version}/Individual_Floats/{wmo}_Sprof_BGCArgoPlus.nc'Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @gmaze ,
Yes, you were right. The path depends on the version of dataset I add something hardcoded in
bgcargo_plus.pyto handle this:path = BGCARGO_PLUS_PATH_TEMPLATE.format(wmo=wmo, version=version) if version != 'v0.1_2026_04' else BGCARGO_PLUS_PATH_TEMPLATE.format(wmo=wmo, version=version+"/Individual_Floats").