From ccfe4ef7bcc2bd2452c3a6a0e2775000bbe8fb54 Mon Sep 17 00:00:00 2001 From: gis-xh Date: Fri, 16 Jan 2026 08:59:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Weather=5Fdownload):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E5=A4=A9=E6=B0=94=E6=95=B0=E6=8D=AE=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=87=BD=E6=95=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GEE_Scripts/Weather_download.js | 117 +++++++++++++++++--------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/GEE_Scripts/Weather_download.js b/GEE_Scripts/Weather_download.js index 5bbddc2..3ee83ff 100644 --- a/GEE_Scripts/Weather_download.js +++ b/GEE_Scripts/Weather_download.js @@ -10,14 +10,15 @@ */ // 加载研究区域和影像 -var region_name = "应城市"; -var region_name_en = "Yingcheng"; -var region = Yingcheng; -var crs = "EPSG:4526"; -// var region_name = "保康县"; -// var region_name_en = "Baokang"; -// var region = Baokang; -// var crs = "EPSG:4525"; +// var region_name = "应城市"; +// var region_name_en = "Yingcheng"; +// var region = Yingcheng; +// var target_crs = "EPSG:4526"; +var region_name = "保康县"; +var region_name_en = "Baokang"; +var region = Baokang; +var target_crs = "EPSG:4525"; +var target_res = 30; var start_year = 2021; var end_year = 2025; var start_date = start_year + "-01-01"; @@ -46,7 +47,7 @@ function kelvinToCelsius(image) { // 加载 ERA5-Land 数据 var ERA5dataset = ee.ImageCollection("ECMWF/ERA5_LAND/MONTHLY_AGGR") .filter(common_filter) - .select(ERA5Bands, commonBands) + .select(ERA5Bands, commonBands); print(start_date + " - " + end_date + " ERA5-Land dataset", ERA5dataset); var ERA5Tempdataset = ERA5dataset.select("temperature").map(kelvinToCelsius); var ERA5Raindataset = ERA5dataset.select("total_precipitation_sum"); @@ -72,24 +73,24 @@ if (start_year == end_year) { } else { var year_str = start_year + "-" + end_year; } -print(year_str + " Annual Mean ERA5-Land temperature dataset", yearlyTemp); -print(year_str + " Annual Mean ERA5-Land rainfall dataset", yearlyRain); +print(year_str + " Annual Mean ERA5-Land Temperature dataset", yearlyTemp); +print(year_str + " Annual Mean ERA5-Land Precipitation dataset", yearlyRain); // 合成处理后会丢失投影信息, 需要重新设置投影 var proj = ERA5dataset.first().select(1).projection(); var annual_mean_temperature = ee.Image(yearlyTemp.mean()).setDefaultProjection(proj); -print(year_str + " Annual Mean ERA5-Land temperature Histogram", ui.Chart.image.histogram(annual_mean_temperature, region, 10000, 258)); +print(year_str + " Annual Mean ERA5-Land Temperature Histogram", ui.Chart.image.histogram(annual_mean_temperature, region, 10000, 258)); -var annual_mean_rainfall = ee.Image(yearlyRain.mean()).setDefaultProjection(proj); -print(year_str + " Annual Mean ERA5-Land rainfall Histogram", ui.Chart.image.histogram(annual_mean_rainfall, region, 10000, 258)); +var annual_mean_precipitation = ee.Image(yearlyRain.mean()).setDefaultProjection(proj); +print(year_str + " Annual Mean ERA5-Land Precipitation Histogram", ui.Chart.image.histogram(annual_mean_precipitation, region, 10000, 258)); var annual_mean_temp_1km = annual_mean_temperature.clip(bounds).resample("bicubic").reproject({ - crs: proj, - scale: 1000, + crs: "EPSG:4526", + scale: 30, }); -var annual_mean_rainfall_1km = annual_mean_rainfall.clip(bounds).resample("bicubic").reproject({ - crs: proj, - scale: 1000, +var annual_mean_precipitation_1km = annual_mean_precipitation.clip(bounds).resample("bicubic").reproject({ + crs: "EPSG:4526", + scale: 30, }); var temperature_vis = { @@ -119,45 +120,51 @@ var styling = { }; Map.centerObject(region, 7); -Map.addLayer(annual_mean_temperature, temperature_vis, year_str + " ERA5-Land Annual Mean temperature 0.1 degree"); -Map.addLayer(annual_mean_rainfall, precipitation_vis, year_str + " ERA5-Land Annual Mean precipitation 0.1 degree"); -Map.addLayer(annual_mean_temp_1km, temperature_vis, year_str + " ERA5-Land Annual Mean temperature 1km"); -Map.addLayer(annual_mean_rainfall_1km, precipitation_vis, year_str + " ERA5-Land Annual Mean precipitation 1km"); +Map.addLayer(annual_mean_temperature, temperature_vis, year_str + " Annual Mean Temperature 0.1 degree"); +Map.addLayer(annual_mean_precipitation, precipitation_vis, year_str + " Annual Mean Precipitation 0.1 degree"); +Map.addLayer(annual_mean_temp_1km, temperature_vis, year_str + " Annual Mean Temperature " + target_res + "m"); +Map.addLayer(annual_mean_precipitation_1km, precipitation_vis, year_str + " Annual Mean Precipitation " + target_res + "m"); Map.addLayer(region.style(styling), {}, region_name); // 导出合并后的影像 // 明确设置数据类型为Float32, 否则默认类型为Float64, 会占用更多内存 // 并对缺失值进行填充, 否则默认为nan不便于后续本地处理 -var processed_temp_img = annual_mean_temperature.toFloat().unmask(-9999.0); -print("Start exporting " + year_str + "Yearly Mean ERA5-Land temperature image (" + crs + ")", processed_temp_img); -Export.image.toDrive({ - image: processed_temp_img, - description: region_name_en + "_ERA5_Temperature_" + year_str + "_1km", - folder: "Weather", - region: region, // 添加后会自动裁剪 - scale: 1000, - crs: crs, - maxPixels: 1e13, // GEE 最多支持 1e8 像素, 当超过时会自动分块 - fileFormat: "GeoTIFF", - // 导出COG云优化的GeoTIFF影像, 并明确设置缺失值为-9999.0 - formatOptions: { - cloudOptimized: true, - noData: -9999.0, - }, -}); +function exportCOG(image, description, folder, region, scale, crs) { + image = image.toFloat().unmask(-9999.0); + // 默认为 EPSG:4526 投影 + crs = crs || "EPSG:4526"; + Export.image.toDrive({ + image: image, + description: description, + folder: folder, + region: region, // 添加后会自动裁剪 + scale: scale, + crs: crs, + maxPixels: 1e13, // GEE 最多支持 1e8 像素, 当超过时会自动分块 + fileFormat: "GeoTIFF", + // 导出COG云优化的GeoTIFF影像, 并明确设置缺失值为-9999.0 + formatOptions: { + cloudOptimized: true, + noData: -9999.0, + }, + }); +} -var processed_rain_img = annual_mean_rainfall.toFloat().unmask(-9999.0); -Export.image.toDrive({ - image: processed_rain_img, - description: region_name_en + "_ERA5_Precipitation_" + year_str + "_1km", - folder: "Weather", - region: region, - scale: 1000, - crs: crs, - maxPixels: 1e13, - fileFormat: "GeoTIFF", - formatOptions: { - cloudOptimized: true, - noData: -9999.0, - }, -}); \ No newline at end of file +print("Start exporting " + year_str + " Yearly Mean ERA5-Land Temperature (" + target_crs + " " + target_res + "m)", annual_mean_temperature); +exportCOG( + annual_mean_temperature, + region_name_en + "_ERA5_Temperature_" + year_str + "_" + target_res + "m", + "Temperature", + region, + target_res, + target_crs +); +print("Start exporting " + year_str + " Yearly Mean ERA5-Land Precipitation (" + target_crs + " " + target_res + "m)", annual_mean_precipitation); +exportCOG( + annual_mean_precipitation, + region_name_en + "_ERA5_Precipitation_" + year_str + "_" + target_res + "m", + "Precipitation", + region, + target_res, + target_crs +);