Skip to content

Instantly share code, notes, and snippets.

@M3nin0
Created October 3, 2020 01:41
Show Gist options
  • Select an option

  • Save M3nin0/bfa3a06afe33c5cc8b496e7acca7093c to your computer and use it in GitHub Desktop.

Select an option

Save M3nin0/bfa3a06afe33c5cc8b496e7acca7093c to your computer and use it in GitHub Desktop.
Drill an BDC-Datacube
# STAC.py
bdc_stac_service = stac.STAC('http://brazildatacube.dpi.inpe.br/stac/')
# Select a collection and get items
collection = bdc_stac_service.collection('S2_10_16D_STK-1')
items = collection.get_items(filter={'bbox':'-61, 2.8, -60, 1.8', 'datetime':'2018-08-01/2019-07-31'})
# Generate a "1D" (One variable) datacube
## mutate_1d_cube from github.com/M3nin0/xarray-stac/
cube1d = mutate_1d_cube(items['features'], 'NDVI')
# drill the datacube!
pixel_drill_index = cube1d.sel(x = 4122211.779451, y = 11634313.492611, method = 'nearest')
# plot!
(pixel_drill_index.where(pixel_drill_index.NDVI >= 0, drop = True).NDVI / 10000).plot(
figsize = (12, 12), linestyle = '-', marker = 'o', color = 'k', markerfacecolor='red', markersize = 7
)
plt.title('NDVI Time Series', fontsize = 17)
plt.xlabel('Time', fontsize = 16)
plt.ylabel('NDVI Value', fontsize = 16)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment