Skip to content

Commit

Permalink
Add support fot Google Solar API
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Sep 6, 2023
1 parent 80998c5 commit 817515a
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/notebooks/78_read_raster.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 0 additions & 2 deletions docs/notebooks/79_timeseries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@
},
{
"cell_type": "markdown",
"id": "b58a3410",
"metadata": {},
"source": [
"![](https://i.imgur.com/mufTpVD.gif)"
]
},
{
"cell_type": "markdown",
"id": "1f03535f",
"metadata": {},
"source": []
}
Expand Down
162 changes: 162 additions & 0 deletions docs/notebooks/80_solar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/80_solar.ipynb)\n",
"[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/80_solar.ipynb)\n",
"[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/80_solar.ipynb&branch=master)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/80_solar.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import leafmap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set Google API key. Get one from https://developers.google.com/maps/documentation/solar/get-api-key\n",
"\n",
"You also need to enable the Google Solar API at https://console.cloud.google.com/google/maps-apis/api-list"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"GOOGLE_API_KEY\"] = \"YOUR-API-KEY\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set download directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"out_dir = os.path.expanduser(\"~/Downloads\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download Solar data from Google's [Solar API](https://developers.google.com/maps/documentation/solar)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lat = 50.97579908646006\n",
"lon = 11.023334842349778\n",
"radiusMeters = 50\n",
"view = \"FULL_LAYERS\"\n",
"requiredQuality = \"HIGH\"\n",
"pixelSizeMeters = 0.1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"files = leafmap.get_solar_data(\n",
" lat, \n",
" lon, \n",
" radiusMeters, \n",
" view, \n",
" requiredQuality, \n",
" pixelSizeMeters, \n",
" out_dir=out_dir\n",
" )\n",
"files"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an interactive map and add the Solar data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_raster(files['rgb'], layer_name=\"RGB\")\n",
"m.add_raster(files['mask'], layer_name=\"Mask\")\n",
"m.add_raster(files['dsm'], cmap='terrain', layer_name=\"DSM\", visible=False)\n",
"m.add_raster(files['annualFlux'], cmap='plasma', layer_name=\"annualFlux\")\n",
"m.add_raster(files['monthlyFlux'], cmap='plasma', band=[7], layer_name=\"monthlyFlux\", visible=False)\n",
"\n",
"m.add_colormap(cmap='terrain', vmin=190, vmax=250, label='Elevation (m)')\n",
"m.add_colormap(cmap='plasma', vmin=500, vmax=1000, label='Annual flux (kWh/kW/year)')\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/XZ1i8O6.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
77. Spitting a raster dataset into multiple tiles ([notebook](https://leafmap.org/notebooks/77_split_raster))
78. Interactive Extraction and Visualization of AWS Open Geospatial Data ([notebook](https://leafmap.org/notebooks/78_read_raster))
79. Visualizing time series images interactively with a time slider ([notebook](https://leafmap.org/notebooks/79_timeseries))
80. Visualizing solar radiation data from Google Solar API ([notebook](https://leafmap.org/notebooks/80_solar))

## Demo

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
77. Spitting a raster dataset into multiple tiles ([notebook](https://leafmap.org/notebooks/77_split_raster))
78. Interactive Extraction and Visualization of AWS Open Geospatial Data ([notebook](https://leafmap.org/notebooks/78_read_raster))
79. Visualizing time series images interactively with a time slider ([notebook](https://leafmap.org/notebooks/79_timeseries))
80. Visualizing solar radiation data from Google Solar API ([notebook](https://leafmap.org/notebooks/80_solar))

## Demo

Expand Down
2 changes: 0 additions & 2 deletions examples/notebooks/79_timeseries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@
},
{
"cell_type": "markdown",
"id": "58e58e1a",
"metadata": {},
"source": [
"![](https://i.imgur.com/mufTpVD.gif)"
]
},
{
"cell_type": "markdown",
"id": "5405a890",
"metadata": {},
"source": []
}
Expand Down
162 changes: 162 additions & 0 deletions examples/notebooks/80_solar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/80_solar.ipynb)\n",
"[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/80_solar.ipynb)\n",
"[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/80_solar.ipynb&branch=master)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/80_solar.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import leafmap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set Google API key. Get one from https://developers.google.com/maps/documentation/solar/get-api-key\n",
"\n",
"You also need to enable the Google Solar API at https://console.cloud.google.com/google/maps-apis/api-list"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"GOOGLE_API_KEY\"] = \"YOUR-API-KEY\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set download directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"out_dir = os.path.expanduser(\"~/Downloads\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download Solar data from Google's [Solar API](https://developers.google.com/maps/documentation/solar)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lat = 50.97579908646006\n",
"lon = 11.023334842349778\n",
"radiusMeters = 50\n",
"view = \"FULL_LAYERS\"\n",
"requiredQuality = \"HIGH\"\n",
"pixelSizeMeters = 0.1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"files = leafmap.get_solar_data(\n",
" lat, \n",
" lon, \n",
" radiusMeters, \n",
" view, \n",
" requiredQuality, \n",
" pixelSizeMeters, \n",
" out_dir=out_dir\n",
" )\n",
"files"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an interactive map and add the Solar data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_raster(files['rgb'], layer_name=\"RGB\")\n",
"m.add_raster(files['mask'], layer_name=\"Mask\")\n",
"m.add_raster(files['dsm'], cmap='terrain', layer_name=\"DSM\", visible=False)\n",
"m.add_raster(files['annualFlux'], cmap='plasma', layer_name=\"annualFlux\")\n",
"m.add_raster(files['monthlyFlux'], cmap='plasma', band=[7], layer_name=\"monthlyFlux\", visible=False)\n",
"\n",
"m.add_colormap(cmap='terrain', vmin=190, vmax=250, label='Elevation (m)')\n",
"m.add_colormap(cmap='plasma', vmin=500, vmax=1000, label='Annual flux (kWh/kW/year)')\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/XZ1i8O6.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 817515a

Please sign in to comment.