-
Notifications
You must be signed in to change notification settings - Fork 235
Refactor the _load_remote_dataset function to load tiled and non-tiled grids in a consistent way #3120
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
Conversation
d0517e0 to
4ba67df
Compare
278f21e to
d18fc1d
Compare
d18fc1d to
004f985
Compare
| # Full path to the grid if not tiled grids. | ||
| source = which(fname, download="a") if not resinfo.tiled else None | ||
| # Manually add source to xarray.DataArray encoding to make the GMT accessors work. | ||
| if source: | ||
| grid.encoding["source"] = source |
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.
Currently, the GMT accessors require the grid.encoding["source"] to work. So, for non-tiled gris, we get the full path to the grid and set grid.encoding["source"]. For tiled grids, grid.encoding["source"] is undefined.
| if dataset.resolutions[resolution].tiled: | ||
| raise GMTInvalidInput( | ||
| f"'region' is required for {dataset.title} resolution '{resolution}'." | ||
| fname = f"@{dataset_prefix}{resolution}_{registration[0]}" |
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.
I also propose to
- Rename
dataset_nametoname - Rename
dataset_prefixtoprefix - Remove the trailing
_fromdataset_prefix, e.g.,dataset_prefix="earth_relief_"should beprefix="earth_relief".
Please leave your comments before I make the changes.
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.
I feel it's better to do it in a separate PR to make this PR small for review.
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.
Issue opened at #3190.
| f"'region' is required for {dataset.title} resolution '{resolution}'." | ||
| ) | ||
|
|
||
| # Currently, only grids are supported. Will support images in the future. |
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.
Please note that: currently we use -Tg so it only works for grids. For images, we need to use -Ti.
To support images, we need to know whether the remote dataset is a grid or an image. It means we need to add the data kind information to the GMTRemoteDataset class.
Description of proposed changes
The
_load_remote_datasetfunction uses two different ways when loading tiled and non-tiled remote datasets.whichto download the grid, get the full path and load it by callingload_dataarray(i.e.,xr.load_dataarray)grdcut, which downloads the needed tiles, assembles them into a single grid and loads it by callingload_dataarray.Currently, both tiled and non-tiled grids are loaded from a grid file on disk by
xr.load_dataarray, so the returned xarray.DataArray are similar for tiled and non-tiled grids. The only difference is, the source file given ingrid.encoding["source"]doesn't exist for tiled grids, because the assembled grid is a temporary file.We're working on refactoring the
grdcutwrapper to use virtual files in #3115. After #3115 is finished, the returned xarray.DataArray would have different attributes for tiled and non-tiled grids. So, it's better to have a consistent way for loading tiled and non-tiled grids. This can be done by calling the specialreadmodule. Its syntax looks like (the specialreadmodule is only available for external wrappers, so the command doesn't work in bash):in which,
vfilecan be an actual file name or a virtual file name, and-Tgmeans the input is a grid.