Skip to content

80 solar

image image image

Uncomment the following line to install leafmap if needed.

1
# %pip install -U leafmap
1
2
import os
import leafmap

Set Google API key. Get one from https://developers.google.com/maps/documentation/solar/get-api-key

You also need to enable the Google Solar API at https://console.cloud.google.com/google/maps-apis/api-list

1
os.environ["GOOGLE_API_KEY"] = "YOUR-API-KEY"

Set download directory.

1
out_dir = os.path.expanduser("~/Downloads")

Download Solar data from Google's Solar API.

1
2
3
4
5
6
lat = 50.97579908646006
lon = 11.023334842349778
radiusMeters = 50
view = "FULL_LAYERS"
requiredQuality = "HIGH"
pixelSizeMeters = 0.1
1
2
3
4
files = leafmap.get_solar_data(
    lat, lon, radiusMeters, view, requiredQuality, pixelSizeMeters, out_dir=out_dir
)
files

Create an interactive map and add the Solar data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
m = leafmap.Map()
m.add_raster(files["rgb"], layer_name="RGB")
m.add_raster(files["mask"], layer_name="Mask")
m.add_raster(files["dsm"], colormap="terrain", layer_name="DSM", visible=False)
m.add_raster(files["annualFlux"], colormap="plasma", layer_name="annualFlux")
m.add_raster(
    files["monthlyFlux"],
    colormap="plasma",
    band=[7],
    layer_name="monthlyFlux",
    visible=False,
)

m.add_colormap(cmap="terrain", vmin=190, vmax=250, label="Elevation (m)")
m.add_colormap(cmap="plasma", vmin=500, vmax=1000, label="Annual flux (kWh/kW/year)")
m