我正在编写一个脚本,该脚本试图将直方图的输出用作输入,以通过元数据属性选择性地过滤图像集合。我正在使用 Sentinel-1 图像收集,并希望根据相对轨道对图像进行分组。
如果我在相对轨道号中硬编码,我可以让它工作,但是当我尝试从列表中输入相对轨道号时,我遇到了问题。我尝试了许多不同的路径,包括 getInfo() 和其他路径,但我似乎被卡住了。
我将不胜感激任何帮助或想法。问题出现在第 31 行。第 27 行工作并生成 3 波段图像。我希望第 31 行具有相同的结果,但会自动插入过滤器的相对轨道数(我最终将创建一个函数来计算集合中所有相对轨道的值)。我可以说这是客户端与服务器对象的问题,但不确定如何解决。非常欢迎任何其他评论或批评。
原代码链接:
https://code.earthengine.google.com/55c3ab5ca2f711b6cc7e7735416a7801
代码:
- var tiny =
- /* color: #d63000 */
- /* shown: false */
- ee.Geometry.Polygon(
- [[[-49.255086793346706, 64.32587384507364],
- [-49.310018433971706, 63.869960581677994],
- [-46.524984254284206, 63.87237972158039],
- [-46.546956910534206, 64.35679549831973]]]);
-
- //Initial parameters
- var studysite = tiny;
- var start = ee.Date('2018-10-01');
- var finish = ee.Date('2019-04-01');
-
- //Import Sentinel-1 Collection
- var S1 = ee.ImageCollection('COPERNICUS/S1_GRD');
-
- //Filter image collection
- // Filter by point and dates and sort by date
- var s1filtered = S1
- .filterBounds(studysite)
- .filterDate(start, finish)
- .sort('date')
- .filter(ee.Filter.eq('instrumentMode','EW'))
- .filter(ee.Filter.eq('resolution','H'));
-
- //Create mean composite of S1filtered, all orbits
- var meanS1AllOrbits = s1filtered.mean();
- Map.addLayer(meanS1AllOrbits,{min:-35, max:0},'meancomposite');
-
- //print histogram of relative orbit numbers in filtered collection
- var histOrbs = s1filtered.aggregate_histogram('relativeOrbitNumber_start');
- var relOrbs = histOrbs.keys(); //gives list of relative orbit numbers from histogram
-
- //create mean composite for each relative orbit within collection
- var s1relorb_119 = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',119)).mean().set('relOrb',119);
- print('using number input', s1relorb_119);
-
- //attempting the same thing but substituting the list input for the hard coded relative orbit number
- var s1relorb_first = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',ee.Number.parse(relOrbs.get(0)))).mean().set('relOrb',119);
- print('using list input',s1relorb_first);
上面的第31行代码得出的结果是0个波段,我们的错误其实并没有提示,只是打印出来的结果不同,这里的主要问题是31行代码处有问题,再筛选的过程中get所获取的将会自动转化为字符串,而你需要用一个函数将其转化为数字类型,这里需要用到一个函数:
ee.Number.parse(input, radix)
Convert a string to a number.
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.
ee.Number.parse(输入,基数)
将字符串转换为数字。
论据:
输入(字符串):
要转换为数字的字符串。
基数(整数,默认值:10):
一个整数,表示要转换的基数系统。如果输入不是整数,则基数必须等于 10 或不指定。
返回:数字
修改后的结果:
修改后的代码:
- //Initial parameters
- var studysite = tiny;
- var start = ee.Date('2018-10-01');
- var finish = ee.Date('2019-04-01');
-
- //Import Sentinel-1 Collection
- var S1 = ee.ImageCollection('COPERNICUS/S1_GRD');
-
- //Filter image collection
- // Filter by point and dates and sort by date
- var s1filtered = S1
- .filterBounds(studysite)
- .filterDate(start, finish)
- .sort('date')
- .filter(ee.Filter.eq('instrumentMode','EW'))
- .filter(ee.Filter.eq('resolution','H'));
-
- //Create mean composite of S1filtered, all orbits
- var meanS1AllOrbits = s1filtered.mean();
- Map.addLayer(meanS1AllOrbits,{min:-35, max:0},'meancomposite');
-
- //print histogram of relative orbit numbers in filtered collection
- var histOrbs = s1filtered.aggregate_histogram('relativeOrbitNumber_start');
- var relOrbs = histOrbs.keys(); //gives list of relative orbit numbers from histogram
-
- //create mean composite for each relative orbit within collection
- var s1relorb_119 = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',119)).mean().set('relOrb',119);
- print('using number input', s1relorb_119);
-
- //attempting the same thing but substituting the list input for the hard coded relative orbit number
- //这里我们需要对字符串进行转化为数字,否则就没有办法筛选出来
- var s1relorb_first = s1filtered.filter(ee.Filter.eq('relativeOrbitNumber_start',ee.Number.parse(relOrbs.get(0)))).mean().set('relOrb',119);
- print('using list input',s1relorb_first);
-
-