GEE C28 在GEE中使用脚本和资源协作 Collaborating in Earth Engine with Scripts and Assets(Part6)
导语:
许多用户发现自己在某些时候需要与地球引擎中的其他人协作。学生可能需要在一个小组项目中工作,来自不同组织的人可能想要一起合作进行研究,或者人们可能想要与他人共享他们创建的脚本或资产。将展示如何与他人协作并分享工作。
学习要点:
•了解何时共享脚本或资产是重要的。
•了解可用的角色和权限选项。
•与他人分享脚本。
•与他人共享资产。
•共享资源,以便在应用程序中显示。
•与其他人共享存储库。
•查看谁对脚本进行了更改以及做了哪些更改。
•恢复到脚本的先前版本。
•使用require函数加载模块。
•创建脚本作为模块共享。
Section 1: 使用 Get Link 分享脚本
Section 2: 分享 Assets from Y our Asset Manager
通过get link 分享代码的时候,如果代码中引用了你 Assets中的数据,别人通过你分享的代码run的时候,会提示错误。
Section 3: Working with Shared Repositories 使用共享存储库
Section 4: 使用Require函数加载模块
1、加载别人创建的模块
var dem = ee.Image('USGS/SRTMGL1_003');
var palettes = require('users/gena/packages:palettes');
// colorbrewer
Map.addLayer(dem, {
min: 0,
max: 3000,
palette: palettes.colorbrewer.Blues[9]
}, 'colorbrewer Blues[9]');
// cmocean
Map.addLayer(dem, {
min: 0,
max: 3000,
palette: palettes.cmocean.Algae[7]
}, 'cmocean Algae[7]');
结果:
2、自己创建一个模块(函数),然后require
示例:写一个去云函数,存储在Repository。
先跟之前一样,编译一个脚本:
// This example demonstrates the use of the Landsat 8 Collection 2, Level 2
// QA_PIXEL band (CFMask) to mask unwanted pixels.
function maskL8sr(image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
// Apply the scaling factors to the appropriate bands.
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802) .add(149.0);
// Replace the original bands with the scaled ones and apply the masks.
return image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true)
.updateMask(qaMask)
.updateMask(saturationMask);
}
// Map the function over one year of data.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2020-01-01', '2021-01-01')
.map(maskL8sr);
var composite = collection.median();
// Display the results.
Map.setCenter(-4.52, 40.29, 7); // Iberian Peninsula
// Display the results.
Map.setCenter(-4.52, 40.29, 7); // Iberian Peninsula
Map.addLayer(composite, {
bands: ['SR_B4', 'SR_B3', 'SR_B2'],
min: 0,
max: 0.3
});
现在让这段脚本对其他用户和脚本可用,将函数转换为模块。
// This example demonstrates the use of the Landsat 8 Collection 2, Level 2
// QA_PIXEL band (CFMask) to mask unwanted pixels.
exports.maskL8sr = function (image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
// Apply the scaling factors to the appropriate bands.
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802) .add(149.0);
// Replace the original bands with the scaled ones and apply the masks.
return image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true)
.updateMask(qaMask)
.updateMask(saturationMask);
}
require上面自己的模块:
// Load the module
//var myCloudFunctions = require( 'users/myusername/my-shared-repo:cloudmasking');
var myCloudFunctions = require( 'users/xxxxxxxx/mzwRequireModel:S1maskL8sr');
// Map the function over one year of data.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2020-01-01', '2021-01-01')
.map(myCloudFunctions.maskL8sr);
var composite = collection.median();
// Display the results.
Map.setCenter(-4.52, 40.29, 7); // Iberian Peninsula
Map.addLayer(composite, {
bands: ['SR_B4', 'SR_B3', 'SR_B2'],
min: 0,
max: 0.3
});