aazuspan / sankee

Visualize classified time series data with interactive Sankey plots in Google Earth Engine
https://sankee.readthedocs.io/en/latest/index.html
MIT License
100 stars 15 forks source link

`KeyError` during data collection caused by mixed data types #22

Closed aazuspan closed 2 years ago

aazuspan commented 2 years ago

Currently, the second example in the readme (code below) throws a KeyError when the max_classes are filtered

# Load a set of classified images
img_list = [
    ee.Image("GOOGLE/DYNAMICWORLD/V1/20210616T185919_20210616T190431_T10TEQ"),
    ee.Image("GOOGLE/DYNAMICWORLD/V1/20210706T185919_20210706T190638_T10TEQ")
]

# Which band contains the classified data?
band = "label"

# What labels correspond to which pixel values?
labels = {
    0: "Water", 1: "Trees", 2: "Grass", 3: "Flooded", 4: "Crops",
    5: "Shrub / Scrub", 6: "Build", 7: "Bare", 8: "Snow / Ice",
}

# What colors should be applied to which pixel values?
palette = {
    0: "#419BDF", 1: "#397D49", 2: "#88B053", 3: "#7A87C6", 4: "#E49635",
    5: "#DFC35A", 6: "#C4281B", 7: "#A59B8F", 8: "#B39FE1"
}

plot = sankee.sankify(
    image_list=img_list, 
    band=band, 
    labels=labels,
    palette=palette,
    region=ee.Geometry.Point([-121.80183, 44.67655]).buffer(3000), 
    max_classes=3,
    title="Mt. Jefferson Snow Loss - June 2021"
)

The root cause seems to be that sampling.collect_sankee_data returns mixed datatypes due to NaN sampled values. Casting to int after removing NaNs should resolve this.