Skip to content

Instantly share code, notes, and snippets.

@M3nin0
Last active April 12, 2021 16:59
Show Gist options
  • Save M3nin0/0e9002a38ed9d88e994e97a50514d267 to your computer and use it in GitHub Desktop.
Save M3nin0/0e9002a38ed9d88e994e97a50514d267 to your computer and use it in GitHub Desktop.
import numpy
from wtss import WTSS
service = WTSS('https://brazildatacube.dpi.inpe.br/', access_token='seu-token')
cbers4_coverage = service['CB4_64_16D_STK-1']
#
# bandas
#
red_band = 'BAND15'
nir_band = 'BAND16'
cmask = "CMASK"
#
# recuperando as séries (Incluindo red, nir, cmask)
#
time_series = cbers4_coverage.ts(attributes=(red_band, nir_band, cmask),
latitude=-16.817, longitude=-52.079,
start_date="2017-01-01", end_date="2019-12-31")
#
# transformando os valores
#
cmask_arr = numpy.array(time_series.CMASK)
#
# transformando as nuvens em NAN
#
# nuvem (valor 4)
cmask_arr[cmask_arr == 4] = numpy.nan
# sombra de nuvem (valor 2)
cmask_arr[cmask_arr == 2] = numpy.nan
# tudo o que não é nuvem vai para valor 1
cmask_arr[~numpy.isnan(cmask_arr)] = 1
#
# aplicando a mascara (Banda 15)
time_series.BAND15 * cmask_arr
#
# aplicando a mascara (Banda 16)
time_series.BAND16 * cmask_arr
## Neste exemplo, os valores com nuvem irão ficar com valor NAN. Isto permite interpolação e outras operações
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment