import xarray
import mikeio
Bathymetric data
NetCDF
data import
GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)
= xarray.open_dataset("../tests/testdata/gebco_2020_n56.3_s55.2_w12.2_e13.1.nc")
ds ds
<xarray.Dataset> Dimensions: (lat: 264, lon: 216) Coordinates: * lat (lat) float64 55.2 55.21 55.21 55.21 ... 56.29 56.29 56.29 56.3 * lon (lon) float64 12.2 12.21 12.21 12.21 ... 13.09 13.09 13.09 13.1 Data variables: elevation (lat, lon) int16 -8 -8 -8 -8 -9 -9 -9 -9 ... 72 71 72 77 80 80 86 Attributes: Conventions: CF-1.6 title: The GEBCO_2020 Grid - a continuous terrain model for oceans... institution: On behalf of the General Bathymetric Chart of the Oceans (G... source: The GEBCO_2020 Grid is the latest global bathymetric produc... history: Information on the development of the data set and the sour... references: DOI: 10.5285/a29c5465-b138-234d-e053-6c86abc040b9 comment: The data in the GEBCO_2020 Grid should not be used for navi... node_offset: 1.0
; ds.elevation.plot()
=12.74792, lat=55.865, method="nearest") ds.elevation.sel(lon
<xarray.DataArray 'elevation' ()> array(-43, dtype=int16) Coordinates: lat float64 55.86 lon float64 12.75 Attributes: standard_name: height_above_reference_ellipsoid long_name: Elevation relative to sea level units: m sdn_parameter_urn: SDN:P01::BATHHGHT sdn_parameter_name: Sea floor height (above mean sea level) {bathymetric... sdn_uom_urn: SDN:P06::ULAA sdn_uom_name: Metres
Check ordering of dimensions, should be (y,x)
ds.elevation.dims
('lat', 'lon')
= ds.elevation.values
el el.shape
(264, 216)
Check that axes are increasing, S->N W->E
0],ds.lat.values[-1] ds.lat.values[
(55.20208333333332, 56.29791666666665)
0] < ds.lat.values[-1] ds.lat.values[
True
0],ds.lon.values[-1] ds.lon.values[
(12.20208333333332, 13.097916666666663)
0,0] # Bottom left el[
-8
-1,0] # Top Left el[
-31
= mikeio.Grid2D(x=ds.lon.values, y=ds.lat.values, projection="LONG/LAT")
geometry geometry
<mikeio.Grid2D>
x: [12.2, 12.21, ..., 13.1] (nx=216, dx=0.004167)
y: [55.2, 55.21, ..., 56.3] (ny=264, dy=0.004167)
projection: LONG/LAT
= mikeio.DataArray(data=el,
da =mikeio.ItemInfo("Elevation", mikeio.EUMType.Total_Water_Depth),
item=geometry,
geometry=("y","x") # No time dimension
dims
) da
<mikeio.DataArray>
name: Elevation
dims: (y:264, x:216)
time: 2018-01-01 00:00:00 (time-invariant)
geometry: Grid2D (ny=264, nx=216)
; da.plot()
='coolwarm', vmin=-100, vmax=100); da.plot(cmap
"gebco.dfs2") da.to_dfs(
= mikeio.read("gebco.dfs2")
ds ds.Elevation.plot()
<AxesSubplot: xlabel='Longitude [degrees]', ylabel='Latitude [degrees]'>
Clean up
import os
"gebco.dfs2") os.remove(