ERA 5和ERA 5-陆地月降水数据集的问题

qij5mzcb  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(369)

我一直在尝试使用CDS提供的ERA 5和ERA 5-陆地降水数据(https://cds.climate.copernicus.eu/cdsapp#!具有0.25x0.25度的ERA 5月数据和具有0.1x0.1度的ERA 5-土地数据从以下链接下载:

  • ERA 5月度数据:https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels-monthly-means?tab=概述
  • ERA 5-土地月度数据:https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land-monthly-means?tab=概述
    我已经使用R将.nc文件转换为GeoTIFF格式,将单位从米(m)转换为毫米(mm),然后根据研究区域的边界提取GeoTIFF文件。
    为了提取研究区域的月降水量数据,我尝试了以下R代码。然而,我遇到了一个问题,提取的月降水量值非常低,范围在0.1到3.7毫米之间,这似乎不正确。
    我将非常感谢有关这个问题的任何见解或建议。如果你有任何关于可能导致月降水量低的原因的建议,我很乐意听取。感谢您的关注和协助。
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")
}

3vpjnl9f

3vpjnl9f1#

看起来最有可能的错误发生在你的单位转换中,你既没有说你做了什么,也没有提供代码-用代码复制的例子走了很长的路才能得到答案。
无论如何,我将在黑暗中进行一次疯狂的尝试,并猜测您通过将数据乘以1000将米转换为mm。如果你读过ERA5 documentation,你会看到monthly means的单位是米/,所以这样的转换会得到mm/天。因此,当乘以ca时,您的0.1到3.7范围。30给你3到100毫米/月,正如你所期望的。因此,如果这是您所做的,则值与您所期望的完全相同。
请注意,如果你想要精确的单位mm/month,你需要乘以每个月的天数,cdo中有一个函数允许你这样做,或者你可以直接在R中参考this posting的解决方案。

相关问题