• Google Earth Engine —— 隐形错误get获取元素后结果无法筛选(字符串转数字函数)


    我正在编写一个脚本,该脚本试图将直方图的输出用作输入,以通过元数据属性选择性地过滤图像集合。我正在使用 Sentinel-1 图像收集,并希望根据相对轨道对图像进行分组。

    如果我在相对轨道号中硬编码,我可以让它工作,但是当我尝试从列表中输入相对轨道号时,我遇到了问题。我尝试了许多不同的路径,包括 getInfo() 和其他路径,但我似乎被卡住了。

    我将不胜感激任何帮助或想法。问题出现在第 31 行。第 27 行工作并生成 3 波段图像。我希望第 31 行具有相同的结果,但会自动插入过滤器的相对轨道数(我最终将创建一个函数来计算集合中所有相对轨道的值)。我可以说这是客户端与服务器对象的问题,但不确定如何解决。非常欢迎任何其他评论或批评。

    原代码链接:

    https://code.earthengine.google.com/55c3ab5ca2f711b6cc7e7735416a7801

    代码:

     

    1. var tiny =
    2. /* color: #d63000 */
    3. /* shown: false */
    4. ee.Geometry.Polygon(
    5. [[[-49.255086793346706, 64.32587384507364],
    6. [-49.310018433971706, 63.869960581677994],
    7. [-46.524984254284206, 63.87237972158039],
    8. [-46.546956910534206, 64.35679549831973]]]);
    9. //Initial parameters
    10. var studysite = tiny;
    11. var start = ee.Date('2018-10-01');
    12. var finish = ee.Date('2019-04-01');
    13. //Import Sentinel-1 Collection
    14. var S1 = ee.ImageCollection('COPERNICUS/S1_GRD');
    15. //Filter image collection
    16. // Filter by point and dates and sort by date
    17. var s1filtered = S1
    18. .filterBounds(studysite)
    19. .filterDate(start, finish)
    20. .sort('date')
    21. .filter(ee.Filter.eq('instrumentMode','EW'))
    22. .filter(ee.Filter.eq('resolution','H'));
    23. //Create mean composite of S1filtered, all orbits
    24. var meanS1AllOrbits = s1filtered.mean();
    25. Map.addLayer(meanS1AllOrbits,{min:-35, max:0},'meancomposite');
    26. //print histogram of relative orbit numbers in filtered collection
    27. var histOrbs = s1filtered.aggregate_histogram('relativeOrbitNumber_start');
    28. var relOrbs = histOrbs.keys(); //gives list of relative orbit numbers from histogram
    29. //create mean composite for each relative orbit within collection
    30. var s1relorb_119 = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',119)).mean().set('relOrb',119);
    31. print('using number input', s1relorb_119);
    32. //attempting the same thing but substituting the list input for the hard coded relative orbit number
    33. var s1relorb_first = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',ee.Number.parse(relOrbs.get(0)))).mean().set('relOrb',119);
    34. print('using list input',s1relorb_first);

     

    上面的第31行代码得出的结果是0个波段,我们的错误其实并没有提示,只是打印出来的结果不同,这里的主要问题是31行代码处有问题,再筛选的过程中get所获取的将会自动转化为字符串,而你需要用一个函数将其转化为数字类型,这里需要用到一个函数:

    ee.Number.parse(input, radix)

    Convert a string to a number.

    Arguments:

    input (String):

    The string to convert to a number.

    radix (Integer, default: 10):

    An integer representing the base number system from which to convert. If input is not an integer, radix must equal 10 or not be specified.

    Returns: Number

    ee.Number.parse(输入,基数)
    将字符串转换为数字。

    论据:
    输入(字符串):
    要转换为数字的字符串。

    基数(整数,默认值:10):
    一个整数,表示要转换的基数系统。如果输入不是整数,则基数必须等于 10 或不指定。

    返回:数字

    修改后的结果:

     修改后的代码:

    1. //Initial parameters
    2. var studysite = tiny;
    3. var start = ee.Date('2018-10-01');
    4. var finish = ee.Date('2019-04-01');
    5. //Import Sentinel-1 Collection
    6. var S1 = ee.ImageCollection('COPERNICUS/S1_GRD');
    7. //Filter image collection
    8. // Filter by point and dates and sort by date
    9. var s1filtered = S1
    10. .filterBounds(studysite)
    11. .filterDate(start, finish)
    12. .sort('date')
    13. .filter(ee.Filter.eq('instrumentMode','EW'))
    14. .filter(ee.Filter.eq('resolution','H'));
    15. //Create mean composite of S1filtered, all orbits
    16. var meanS1AllOrbits = s1filtered.mean();
    17. Map.addLayer(meanS1AllOrbits,{min:-35, max:0},'meancomposite');
    18. //print histogram of relative orbit numbers in filtered collection
    19. var histOrbs = s1filtered.aggregate_histogram('relativeOrbitNumber_start');
    20. var relOrbs = histOrbs.keys(); //gives list of relative orbit numbers from histogram
    21. //create mean composite for each relative orbit within collection
    22. var s1relorb_119 = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',119)).mean().set('relOrb',119);
    23. print('using number input', s1relorb_119);
    24. //attempting the same thing but substituting the list input for the hard coded relative orbit number
    25. //这里我们需要对字符串进行转化为数字,否则就没有办法筛选出来
    26. var s1relorb_first = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',ee.Number.parse(relOrbs.get(0)))).mean().set('relOrb',119);
    27. print('using list input',s1relorb_first);

  • 相关阅读:
    安科瑞变电站综合自动化系统在变电站的应用-Susie 周
    softmax回归python实现
    谷粒商城--品牌管理(OSS、JSR303数据校验)
    部署:端口映射相关问题
    (三)组合特征与特征变换 学习简要笔记 #机器学习特征工程 #CDA学习打卡
    开发实践丨昇腾CANN的推理应用开发体验
    如何安装 Wnmp 并结合内网穿透实现外网访问内网Wnmp 服务
    用Excel制作甘特图跟踪项目进度(附绘制教程)
    redis为什么使用跳跃表而不是树
    证书过期问题: https://registry.npm.taobao.org npm ERR! code CERT_HAS_EXPIRED npm ERR
  • 原文地址:https://blog.csdn.net/qq_31988139/article/details/127691033