105 netcdf
In [ ]:
Copied!
# !pip install geemap xarray rioxarray netcdf4 localtileserver
# !pip install geemap xarray rioxarray netcdf4 localtileserver
In [ ]:
Copied!
import geemap
import geemap
Download a sample NetCDF dataset.
In [ ]:
Copied!
url = 'https://github.com/giswqs/leafmap/raw/master/examples/data/wind_global.nc'
filename = 'wind_global.nc'
url = 'https://github.com/giswqs/leafmap/raw/master/examples/data/wind_global.nc'
filename = 'wind_global.nc'
In [ ]:
Copied!
geemap.download_file(url, output=filename)
geemap.download_file(url, output=filename)
Read the NetCDF dataset.
In [ ]:
Copied!
data = geemap.read_netcdf(filename)
data
data = geemap.read_netcdf(filename)
data
Convert the NetCDF dataset to GeoTIFF. Note that the longitude range of the NetCDF dataset is [0, 360]
. We need to convert it to [-180, 180]
by setting shift_lon=True
so that it can be displayed on the map.
In [ ]:
Copied!
tif = 'wind_global.tif'
geemap.netcdf_to_tif(filename, tif, variables=['u_wind', 'v_wind'], shift_lon=True)
tif = 'wind_global.tif'
geemap.netcdf_to_tif(filename, tif, variables=['u_wind', 'v_wind'], shift_lon=True)
Add the GeoTIFF to the map. We can also overlay the country boundary on the map.
In [ ]:
Copied!
geojson = 'https://github.com/giswqs/leafmap/raw/master/examples/data/countries.geojson'
geojson = 'https://github.com/giswqs/leafmap/raw/master/examples/data/countries.geojson'
In [ ]:
Copied!
m = geemap.Map(layer_ctrl=True)
m.add_raster(tif, band=[1], palette='coolwarm', layer_name='u_wind')
m.add_geojson(geojson, layer_name='Countries')
m
m = geemap.Map(layer_ctrl=True)
m.add_raster(tif, band=[1], palette='coolwarm', layer_name='u_wind')
m.add_geojson(geojson, layer_name='Countries')
m
You can also use the add_netcdf()
function to add the NetCDF dataset to the map without having to convert it to GeoTIFF explicitly.
In [ ]:
Copied!
m = geemap.Map(layer_ctrl=True)
m.add_netcdf(
filename,
variables=['v_wind'],
palette='coolwarm',
shift_lon=True,
layer_name='v_wind',
)
m.add_geojson(geojson, layer_name='Countries')
m
m = geemap.Map(layer_ctrl=True)
m.add_netcdf(
filename,
variables=['v_wind'],
palette='coolwarm',
shift_lon=True,
layer_name='v_wind',
)
m.add_geojson(geojson, layer_name='Countries')
m
Visualizing wind velocity.
In [ ]:
Copied!
m = geemap.Map(layer_ctrl=True)
m.add_basemap('CartoDB.DarkMatter')
m.add_velocity(filename, zonal_speed='u_wind', meridional_speed='v_wind')
m
m = geemap.Map(layer_ctrl=True)
m.add_basemap('CartoDB.DarkMatter')
m.add_velocity(filename, zonal_speed='u_wind', meridional_speed='v_wind')
m