68 netcdf to ee
Uncomment the following line to install geemap if needed.
You will also need to install the following package:
xarray
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import os
import ee
import geemap
import geemap.colormaps as cm
import os
import ee
import geemap
import geemap.colormaps as cm
In [3]:
Copied!
geemap.ee_initialize()
geemap.ee_initialize()
In [4]:
Copied!
nc_file = '../data/wind-global.nc'
nc_file = '../data/wind-global.nc'
In [5]:
Copied!
if not os.path.exists(nc_file):
url = 'https://github.com/giswqs/geemap/blob/master/examples/data/wind-global.nc'
import requests
r = requests.get(url)
wind_data = r.content
with open('wind-global.nc', 'wb') as f:
f.write(wind_data)
if not os.path.exists(nc_file):
url = 'https://github.com/giswqs/geemap/blob/master/examples/data/wind-global.nc'
import requests
r = requests.get(url)
wind_data = r.content
with open('wind-global.nc', 'wb') as f:
f.write(wind_data)
In [6]:
Copied!
# Test with only one variable
img = geemap.netcdf_to_ee(nc_file=nc_file, var_names='u_wind')
palette = cm.palettes.YlOrRd
Map = geemap.Map()
Map.addLayer(img, {'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6}, "u_wind")
Map
# Test with only one variable
img = geemap.netcdf_to_ee(nc_file=nc_file, var_names='u_wind')
palette = cm.palettes.YlOrRd
Map = geemap.Map()
Map.addLayer(img, {'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6}, "u_wind")
Map
found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see: https://docs.xarray.dev/en/stable/user-guide/io.html https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [6], in <cell line: 6>() 3 palette = cm.palettes.YlOrRd 5 Map = geemap.Map() ----> 6 Map.addLayer(img, {'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6}, "u_wind") 7 Map File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:195, in Map.add_layer(self, ee_object, vis_params, name, shown, opacity, **kwargs) 187 if ( 188 not isinstance(ee_object, ee.Image) 189 and not isinstance(ee_object, ee.ImageCollection) (...) 192 and not isinstance(ee_object, ee.Geometry) 193 ): 194 err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection." --> 195 raise AttributeError(err_str) 197 if ( 198 isinstance(ee_object, ee.geometry.Geometry) 199 or isinstance(ee_object, ee.feature.Feature) 200 or isinstance(ee_object, ee.featurecollection.FeatureCollection) 201 ): 202 features = ee.FeatureCollection(ee_object) AttributeError: The image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection.
In [7]:
Copied!
# Test with two variables
img2 = geemap.netcdf_to_ee(nc_file=nc_file, var_names=['u_wind', 'v_wind'])
Map2 = geemap.Map()
Map2.addLayer(
img2,
{'bands': ['u_wind'], 'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6},
"uv_wind",
)
Map2
# Test with two variables
img2 = geemap.netcdf_to_ee(nc_file=nc_file, var_names=['u_wind', 'v_wind'])
Map2 = geemap.Map()
Map2.addLayer(
img2,
{'bands': ['u_wind'], 'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6},
"uv_wind",
)
Map2
found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see: https://docs.xarray.dev/en/stable/user-guide/io.html https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in <cell line: 4>() 2 img2 = geemap.netcdf_to_ee(nc_file=nc_file, var_names=['u_wind', 'v_wind']) 3 Map2 = geemap.Map() ----> 4 Map2.addLayer( 5 img2, 6 {'bands': ['u_wind'], 'min': -20, 'max': 25, 'palette': palette, 'opacity': 0.6}, 7 "uv_wind", 8 ) 9 Map2 File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:195, in Map.add_layer(self, ee_object, vis_params, name, shown, opacity, **kwargs) 187 if ( 188 not isinstance(ee_object, ee.Image) 189 and not isinstance(ee_object, ee.ImageCollection) (...) 192 and not isinstance(ee_object, ee.Geometry) 193 ): 194 err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection." --> 195 raise AttributeError(err_str) 197 if ( 198 isinstance(ee_object, ee.geometry.Geometry) 199 or isinstance(ee_object, ee.feature.Feature) 200 or isinstance(ee_object, ee.featurecollection.FeatureCollection) 201 ): 202 features = ee.FeatureCollection(ee_object) AttributeError: The image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection.
Last update:
2022-03-14