forked from gee-community/geemap
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request gee-community#342 from lopezvoliver/netcdf_to_ee
Netcdf to ee
- Loading branch information
Showing
3 changed files
with
227 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Uncomment the following line to install [geemap](https://geemap.org) if needed.\n", | ||
"\n", | ||
"You will also need to install the following package:\n", | ||
"- `xarray`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# !pip install geemap" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import geemap\n", | ||
"import ee\n", | ||
"ee.Initialize()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"if not os.path.exists('wind-global.nc'):\n", | ||
" url = 'https://github.com/giswqs/geemap/blob/master/examples/data/wind-global.nc'\n", | ||
" import requests\n", | ||
" r = requests.get(url)\n", | ||
" wind_data = r.content\n", | ||
" with open('wind-global.nc', 'wb') as f:\n", | ||
" f.write(wind_data)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "f0ec3a01364a4eb391e4e25c6fe2725b", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Map(center=[40, -100], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton(value=…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# Test with only one variable\n", | ||
"img = geemap.netcdf_to_ee(nc_file=\"wind-global.nc\", var_names='u_wind')\n", | ||
"import geemap.colormaps as cm\n", | ||
"palette=cm.palettes.YlOrRd\n", | ||
"Map = geemap.Map()\n", | ||
"Map.addLayer(img, {'min':-20, 'max':25, 'palette':palette, 'opacity':0.6})\n", | ||
"Map" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "cbe695f1593144d5a13bcfe52add9776", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Map(center=[40, -100], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton(value=…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# Test with two variables\n", | ||
"img2 = geemap.netcdf_to_ee(nc_file=\"wind-global.nc\", var_names=['u_wind','v_wind'])\n", | ||
"Map2 = geemap.Map()\n", | ||
"Map2.addLayer(img2, {'bands':['u_wind'],'min':-20, 'max':25, 'palette':palette, 'opacity':0.6})\n", | ||
"Map2" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "geemap", | ||
"language": "python", | ||
"name": "geemap" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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