• GEE错误——Tile error: Arrays must have same lengths on all axes but the cat axis


    错误:

    我想使用 arrayCat 来联系图像。但是,我总是收到错误“数组必须在除猫轴之外的所有轴上具有相同的长度”。
    imgCat: Tile error: Arrays must have same lengths on all axes but the cat axis

     

    原始代码:

    1. var modis = ee.ImageCollection("MODIS/061/MOD13Q1"),
    2. ext =
    3. /* color: #d63000 */
    4. /* shown: false */
    5. /* displayProperties: [
    6. {
    7. "type": "rectangle"
    8. }
    9. ] */
    10. ee.Geometry.Polygon(
    11. [[[-97.06328232288361, 37.62180252692555],
    12. [-97.06328232288361, 32.220887742314595],
    13. [-85.28593857288362, 32.220887742314595],
    14. [-85.28593857288362, 37.62180252692555]]], null, false),
    15. testPt = /* color: #98ff00 */ee.Geometry.Point([-93.9324058090546, 35.00147792091121]);
    16. var VIs = modis.filterDate('2021','2023')
    17. .select('NDVI');
    18. Map.centerObject(testPt,16);
    19. var arrVIs = VIs.map(function (img){
    20. return img.clip(ext).set('system:time_start',img.get('system:time_start'));
    21. }).toBands().toArray().toArray(1);
    22. var mask_NDVI_Higher = arrVIs.gt(6500);
    23. var zeroImg = ee.Image(0).toArray().toArray(1);
    24. // I want to replace the last mask pixel with my own mask. However, it
    25. // failed due to the dimension of the array was varied at pixel scale.
    26. var imgCat = arrVIs.arrayMask(mask_NDVI_Higher).arraySlice(1,0,-1)
    27. .arrayCat(zeroImg,1);
    28. Map.addLayer(VIs,{},'VIs',false);
    29. Map.addLayer(arrVIs,{},'arrVIs',false);
    30. Map.addLayer(mask_NDVI_Higher,{},'mask_NDVI_Higher',false);
    31. Map.addLayer(imgCat,{},'imgCat')

    函数:

    toArray(axis)
    Concatenates pixels from each band into a single array per pixel. The result will be masked if any input bands are masked.

    Arguments:
    this:image (Image):
    Image of bands to convert to an array per pixel. Bands must have scalar pixels, or array pixels with equal dimensionality.

    axis (Integer, default: 0):
    Axis to concatenate along; must be at least 0 and at most the dimension of the inputs. If the axis equals the dimension of the inputs, the result will have 1 more dimension than the inputs.

    Returns: Image

    arraySlice(axis, start, end, step)
    Creates a subarray by slicing out each position along the given axis from the 'start' (inclusive) to 'end' (exclusive) by increments of 'step'. The result will have as many dimensions as the input, and the same length in all directions except the slicing axis, where the length will be the number of positions from 'start' to 'end' by 'step' that are in range of the input array's length along 'axis'. This means the result can be length 0 along the given axis if start=end, or if the start or end values are entirely out of range.

    Arguments:
    this:input (Image):
    Input array image.

    axis (Integer, default: 0):
    Axis to subset.

    start (Image, default: null):
    The coordinate of the first slice (inclusive) along 'axis'. Negative numbers are used to position the start of slicing relative to the end of the array, where -1 starts at the last position on the axis, -2 starts at the next to last position, etc. There must one band for start indices, or one band per 'input' band. If this argument is not set or masked at some pixel, then the slice at that pixel will start at index 0.

    end (Image, default: null):
    The coordinate (exclusive) at which to stop taking slices. By default this will be the length of the given axis. Negative numbers are used to position the end of slicing relative to the end of the array, where -1 will exclude the last position, -2 will exclude the last two positions, etc. There must be one band for end indices, or one band per 'input' band. If this argument is not set or masked at some pixel, then the slice at that pixel will end just after the last index.

    step (Integer, default: 1):
    The separation between slices along 'axis'; a slice will be taken at each whole multiple of 'step' from 'start' (inclusive) to 'end' (exclusive). Must be positive.

    Returns: Image

    arrayMask(mask)
    Creates an array image where each array-valued pixel is masked with another array-valued pixel, retaining only the elements where the mask is non-zero. If the mask image has one band it will be applied to all the bands of 'input', otherwise they must have the same number of bands.

    Arguments:
    this:input (Image):
    Array image to mask.

    mask (Image):
    Array image to mask with.

    Returns: Image

    arrayCat(image2, axis)
    Creates an array image by concatenating each array pixel along the given axis in each band.

    Arguments:
    this:image1 (Image):
    First array image to concatenate.

    image2 (Image):
    Second array image to concatenate.

    axis (Integer):
    Axis to concatenate along.

    Returns: Image
     

    修改后代码:

    1. var modis = ee.ImageCollection("MODIS/061/MOD13Q1"),
    2. ext =
    3. /* color: #d63000 */
    4. /* shown: false */
    5. /* displayProperties: [
    6. {
    7. "type": "rectangle"
    8. }
    9. ] */
    10. ee.Geometry.Polygon(
    11. [[[-97.06328232288361, 37.62180252692555],
    12. [-97.06328232288361, 32.220887742314595],
    13. [-85.28593857288362, 32.220887742314595],
    14. [-85.28593857288362, 37.62180252692555]]], null, false),
    15. testPt = /* color: #98ff00 */ee.Geometry.Point([-93.9324058090546, 35.00147792091121]);
    16. var VIs = modis.filterDate('2021','2023')
    17. .select('NDVI');
    18. Map.centerObject(testPt,16);
    19. var arrVIs = VIs.map(function (img){
    20. return img.clip(ext).set('system:time_start',img.get('system:time_start'));
    21. }).toBands().toArray().toArray(1);
    22. var mask_NDVI_Higher = arrVIs.gt(6500);
    23. var zeroImg = ee.Image(0).toArray().toArray(1);
    24. Map.addLayer(zeroImg)
    25. Map.addLayer(arrVIs.arraySlice(1,0,-1))
    26. // I want to replace the last mask pixel with my own mask. However, it
    27. // failed due to the dimension of the array was varied at pixel scale.
    28. var imgCat = arrVIs.arrayMask(mask_NDVI_Higher).arraySlice(1,0,-1)
    29. .arrayCat(zeroImg,1);
    30. /*Map.addLayer(VIs,{},'VIs',false);
    31. Map.addLayer(arrVIs,{},'arrVIs',false);
    32. Map.addLayer(mask_NDVI_Higher,{},'mask_NDVI_Higher',false);
    33. Map.addLayer(imgCat,{},'imgCat')
    34. */

    建议:

    在 toArray() 之前做你想做的一些工作,然后加载影像

  • 相关阅读:
    集美大学 - 2840 - 实验1
    crypto:篱笆墙的影子
    若依前后端分离发布富文本框内容 | uni-app微信小程序展示富文本框内容
    C++二分算法的应用:寻找峰值原理、源码及测试用例
    产品工作流| B端产品竞品分析
    小编推荐几款好用的MySQL开源客户端,建议收藏哦
    ssm基于BS架构的校园爱心捐赠与物品交换平台的设计与实现毕业设计源码
    嵌入式Linux入门-彻底理解UART串口,手把手教你写程序
    如何实现校园网的规划与设计
    互联网突破和 SD-WAN
  • 原文地址:https://blog.csdn.net/qq_31988139/article/details/132725635