-
Notifications
You must be signed in to change notification settings - Fork 220
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
Refactor the _load_remote_dataset function to load tiled and non-tiled grids in a consistent way #3120
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_name
toname
- Rename
dataset_prefix
toprefix
- 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_dataset
function uses two different ways when loading tiled and non-tiled remote datasets.which
to 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
grdcut
wrapper 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 specialread
module. Its syntax looks like (the specialread
module is only available for external wrappers, so the command doesn't work in bash):in which,
vfile
can be an actual file name or a virtual file name, and-Tg
means the input is a grid.