Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/docs/notebooks/105_netcdf.ipynb
2313 views
Kernel: Python 3

image image

Visualizing NetCDF data

Uncomment the following line to install geemap if needed.

# !pip install geemap xarray rioxarray netcdf4 localtileserver
import geemap

Download a sample NetCDF dataset.

url = "https://github.com/giswqs/leafmap/raw/master/examples/data/wind_global.nc" filename = "wind_global.nc"
geemap.download_file(url, output=filename)

Read the NetCDF dataset.

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.

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.

geojson = "https://github.com/giswqs/leafmap/raw/master/examples/data/countries.geojson"
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.

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.

m = geemap.Map(layer_ctrl=True) m.add_basemap("CartoDB.DarkMatter") m.add_velocity(filename, zonal_speed="u_wind", meridional_speed="v_wind") m