1

When I run my code on GEE I receive the following error in the line print(unitScale).

Image (Error) Invalid JSON.

var features = (elevation
    .addBands(slope)
    .addBands(curve)
    .addBands(landcover) // Can disaggregate to dummy features in Python
    .addBands(twi)
    .addBands(spi)
    .addBands(sti)
    .addBands(mtpi)
    .addBands(lith)
    .addBands(GSWPerm)
    .addBands(GSWDistSeasonal)
    .addBands(aspect)
    .addBands(hand)
    .clip(region))
// .clip(elevation.geometry()));

features = features.reproject({
    crs: aspect.projection().crs(),
    scale: 30
}).float()

var minMax = features.reduceRegion({
    reducer: ee.Reducer.minMax(),
    scale: 30,
    maxPixels: 40e9,
    bestEffort: true
})

// use unit scale to normalize the pixel values

var unitScale = ee.ImageCollection.fromImages(
    features.bandNames().map(function (name) {
        name = ee.String(name);

        var band = features.select(name);

        return band.unitScale(ee.Number(minMax.get(name.cat('_min'))), ee.Number(minMax.get(name.cat('_max'))))
    })).toBands().rename(features.bandNames());

print(unitScale) /// I receive the error in this line ///

print(features)
1
  • The error message "Invalid JSON" suggests that there is a problem with the format of the output that the code is trying to print, which is likely caused by the unitScale variable. One possible reason for the error is that unitScale may have a large size, and printing it as an ee.Image can cause memory issues. Try adding .limit(10) before .toBands() to limit the number of images in the collection to 10, which can reduce the size of the unitScale image and resolve the error Commented Mar 24, 2023 at 20:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.