-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GEBCO elevation bootstrap data. (#51)
* Add ZipDownloader class. * Chunk downloads to avoid overloading memory. * Allow trailing slashes in archive url. * Add dependency to rioxarray for reprojections. * Add hyoga.open.surface function and module. * Use decode_coords='all' for CF compatibility. * Set increasing y-coord for PISM compatibility. * Add hyoga.open.surface docstring. * Rename hyoga.open.surface to hyoga.open.bootstrap. * Update api docs, roadmap, whatsnew.
- Loading branch information
Showing
7 changed files
with
124 additions
and
14 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
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
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,68 @@ | ||
# Copyright (c) 2022, Julien Seguinot (juseg.github.io) | ||
# GNU General Public License v3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
""" | ||
This module contains a function to open surface-level bootstrapping datasets | ||
for predefined domains, including altitude, ice thickness and geothermal heat | ||
flux data. | ||
""" | ||
|
||
import xarray as xr | ||
import rioxarray # noqa pylint: disable=unused-import | ||
|
||
import hyoga.open.downloader | ||
|
||
|
||
def _download_gebco(): | ||
"""Download GEBCO sub-ice bathymetric and topographic data.""" | ||
downloader = hyoga.open.downloader.ZipDownloader() | ||
filepath = downloader( | ||
'https://www.bodc.ac.uk/data/open_download/gebco/' | ||
'gebco_2022_sub_ice_topo/zip/', 'gebco/GEBCO_2022_sub_ice_topo.nc') | ||
return filepath | ||
|
||
|
||
def bootstrap(crs, extent, resolution=1e3): | ||
""" | ||
Open bootstrapping data from online datasets for PISM. | ||
Currently a single dataset (GEBCO) is supported. | ||
Parameters | ||
---------- | ||
crs : str | ||
Coordinate reference system for the resulting dataset as OGC WKT or | ||
Proj.4 string, will be passed to Dataset.rio.reproject. | ||
extent : (west, east, south, north) | ||
Extent for the resulting dataset in projected coordinates given by | ||
``crs``, will be passed to Dataset.rio.clip_box. | ||
resolution : float, optional | ||
Resolution for the output dataset in projected coordinates given by | ||
``crs``, will be passed to Dataset.rio.reproject. | ||
Returns | ||
------- | ||
ds : Dataset | ||
The resulting dataset containing surface variables with the requested | ||
``crs``, ``extent``, and ``resolution``. Use ``ds.to_netcdf()`` to | ||
export as PISM bootstrapping file. | ||
""" | ||
|
||
# open global data (use decode_coords='all' to read grid_mapping attribute) | ||
filepath = _download_gebco() | ||
ds = xr.open_dataset(filepath, decode_coords='all') | ||
|
||
# clip, reproject and clip again | ||
west, east, south, north = extent | ||
ds = ds.rio.clip_box(west, south, east, north, crs=crs) | ||
ds = ds.rio.reproject(crs, resolution=resolution) | ||
ds = ds.rio.clip_box(west, south, east, north) | ||
|
||
# flip data to increasing y-coord (needed by PISM) | ||
ds = ds.isel(y=slice(None, None, -1)) | ||
|
||
# set better standard name | ||
ds.elevation.attrs.update(standard_name='bedrock_altitude') | ||
|
||
# return projected dataset | ||
return ds |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ install_requires = | |
geopandas | ||
matplotlib | ||
requests | ||
rioxarray | ||
scipy | ||
xarray | ||
python_requires = >=3.8 | ||
|