ERA5与ERA5-Land月降水数据提取值偏低问题求助
ERA5-Land月降水提取值异常偏低问题排查请求
数据来源
使用哥白尼气候变化服务(CDS)提供的两类降水月均值数据:
- ERA5月均值数据(0.25×0.25°分辨率)
- ERA5-Land月均值数据(0.1×0.1°分辨率)
已完成的预处理流程
- 通过R语言将原始.nc格式文件转换为GeoTIFF格式
- 完成降水单位从米(m)到毫米(mm)的转换
- 基于研究区边界裁剪得到目标GeoTIFF文件
问题
编写R代码提取研究区月降水均值时,得到的数值范围仅在0.1-3.7mm之间,不符合预期,恳请分析原因并提供解决建议。
降水提取代码
library(raster) library(stringr) # Set the directory containing the monthly raster files raster_dir <- "D:/Datasets/ERA5-Land_Monthly_PRE/ERA5-Land/" # Set the directory where you want to export the CSV file output_dir <- "D:/Datasets/ERA5-Land_Monthly_PRE/" # Get a list of all GeoTIFF files in the directory raster_files <- list.files(raster_dir, pattern = ".tif$", full.names = TRUE) # Create empty vectors to store the dates and mean values dates <- character() mean_values <- numeric() # Iterate through the raster files for (file in raster_files) { # Extract the year and month from the file name date <- str_extract(file, "\\d{4}_\\d{2}") # Read the raster file raster_data <- raster(file) # Calculate the mean of the pixel values mean_val <- mean(values(raster_data), na.rm = TRUE) # Append the date and mean value to the vectors dates <- c(dates, date) mean_values <- c(mean_values, mean_val) } # Create a data frame with the dates and mean values mean_df <- data.frame(Date = dates, Mean_Value = mean_values, stringsAsFactors = FALSE) # Export the data frame to a CSV file in the specified output directory output_csv <- file.path(output_dir, "PRE.csv") write.csv(mean_df, file = output_csv, row.names = FALSE)
.nc转GeoTIFF代码
library(ncdf4) library(raster) # Set the working directory to the parent directory of the output folder setwd("D:/ERA5-Land_Monthly_PRE/ERA5-Land") # Specify output folder name output_dir <- "D:/ERA5-Land_Monthly_PRE/ERA5-Land" if(!dir.exists(output_dir)) dir.create(output_dir) fname <- file.choose() nc <- nc_open(fname) GRACE <- brick(fname, varname = "tp") GRACE_array <- getValues(GRACE) timeL <- colnames(GRACE_array) for(i in timeL) { # Specify the output file path output_path <- file.path(output_dir, paste0(i, ".tif")) writeRaster(GRACE[[i]], filename = output_path, format = "GTiff", overwrite = TRUE) }
单位转换(m转mm)代码
library(raster) # Set the directory containing the input raster files input_directory <- "D:/ERA5-Land_Monthly_PRE/ERA5-Land" # Set the directory for saving the output raster files output_directory <- "D:/ERA5-Land_Monthly_PRE/ERA5-Land" # Get a list of all raster files in the input directory raster_files <- list.files(input_directory, pattern = ".tif$", full.names = TRUE) # Loop through each raster file for (file in raster_files) { # Read the raster file r <- raster(file) # Convert the values from m to mm by multiplying by 1000 r_mm <- r * 1000 # Set the output file name by appending "_mm" to the original file name output_file <- file.path(output_directory, paste0(tools::file_path_sans_ext(basename(file)), "_mm.tif")) # Save the output raster file writeRaster(r_mm, filename = output_file, format = "GTiff", overwrite = TRUE) cat("Converted", basename(file), "and saved as", basename(output_file), "\n") }
内容的提问来源于stack exchange,提问作者user20664990
相关产品推荐
相关产品推荐

