ERA5和ERA5-Land月降水数据集中的问题。

huangapple go评论96阅读模式
英文:

Issue in ERA5 and ERA5-Land Monthly Precipitation Dataset

问题

我已经尝试使用CDS提供的ERA5和ERA5-Land降水数据(https://cds.climate.copernicus.eu/cdsapp#!/home)。以下是从以下链接下载的ERA5每月数据(0.25 x 0.25度)和ERA5-Land数据(0.1x0.1度):

  • ERA5每月数据:https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels-monthly-means?tab=overview

  • ERA5-Land每月数据:https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land-monthly-means?tab=overview

我已经使用R将.nc文件转换为GeoTIFF格式,并将单位从米(m)转换为毫米(mm),然后根据我的研究区域边界提取了GeoTIFF文件。

为了提取我的研究区域的每月降水数据,我尝试了以下R代码。然而,我遇到了一个问题,提取的每月降水值非常低,介于0.1到3.7毫米之间,这似乎不正确。

如果您对可能导致低每月降水值的原因有任何见解或建议,我将不胜感激。感谢您的关注和帮助。

以下是用于.nc转换为GeoTIFF的代码:

library(ncdf4)
library(raster)

# 将工作目录设置为输出文件夹的父目录
setwd("D:/ERA5-Land_Monthly_PRE/ERA5-Land")

# 指定输出文件夹名称
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) {
  # 指定输出文件路径
  output_path <- file.path(output_dir, paste0(i, ".tif"))
  writeRaster(GRACE[[i]], filename = output_path, format = "GTiff", overwrite = TRUE)
}

以下是用于从m转换为mm的单位转换代码:

library(raster)

# 设置包含输入栅格文件的目录
input_directory <- "D:/ERA5-Land_Monthly_PRE/ERA5-Land"

# 设置保存输出栅格文件的目录
output_directory <- "D:/ERA5-Land_Monthly_PRE/ERA5-Land"

# 获取输入目录中所有栅格文件的文件列表
raster_files <- list.files(input_directory, pattern = ".tif$", full.names = TRUE)

# 遍历每个栅格文件
for (file in raster_files) {
  # 读取栅格文件
  r <- raster(file)
  
  # 通过乘以1000将值从m转换为mm
  r_mm <- r * 1000
  
  # 通过在原始文件名后附加"_mm"来设置输出文件名
  output_file <- file.path(output_directory, paste0(tools::file_path_sans_ext(basename(file)), "_mm.tif"))
  
  # 保存输出栅格文件
  writeRaster(r_mm, filename = output_file, format = "GTiff", overwrite = TRUE)
  
  cat("Converted", basename(file), "and saved as", basename(output_file), "\n")
}

希望这些代码对您有所帮助。

英文:

I have been attempting to use ERA5 and ERA5-Land precipitation data provided by CDS (https://cds.climate.copernicus.eu/cdsapp#!/home). The ERA5 monthly data with 0.25 x 0.25 degrees and ERA5-Land data with 0.1x0.1 degrees were downloaded from the links below:

- ERA5 Monthly Data: https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels-monthly-means?tab=overview

- ERA5-Land Monthly Data: https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land-monthly-means?tab=overview

I have converted the .nc files into GeoTIFF format using R, converted the unit from meters (m) to millimeters (mm), and then extracted the GeoTIFF files based on the boundary of my study area.

To extract the monthly precipitation data of my study area, I attempted the following R code. However, I am encountering an issue where the monthly precipitation values extracted are very low, ranging between 0.1 to 3.7 mm, which does not seem correct.

I would greatly appreciate any insights or recommendations regarding this issue. If you have any suggestions on what might be causing the low monthly precipitation values, I am open to hearing them. Thank you for your attention and assistance.

library(raster)
library(stringr)

# Set the directory containing the monthly raster files
raster_dir &lt;- &quot;D:/Datasets/ERA5-Land_Monthly_PRE/ERA5-Land/&quot;

# Set the directory where you want to export the CSV file
output_dir &lt;- &quot;D:/Datasets/ERA5-Land_Monthly_PRE/&quot;

# Get a list of all GeoTIFF files in the directory
raster_files &lt;- list.files(raster_dir, pattern = &quot;.tif$&quot;, full.names = TRUE)

# Create empty vectors to store the dates and mean values
dates &lt;- character()
mean_values &lt;- numeric()

# Iterate through the raster files
for (file in raster_files) {
  # Extract the year and month from the file name
  date &lt;- str_extract(file, &quot;\\d{4}_\\d{2}&quot;)
 
  # Read the raster file
  raster_data &lt;- raster(file)
 
  # Calculate the mean of the pixel values
  mean_val &lt;- mean(values(raster_data), na.rm = TRUE)
 
  # Append the date and mean value to the vectors
  dates &lt;- c(dates, date)
  mean_values &lt;- c(mean_values, mean_val)
}

# Create a data frame with the dates and mean values
mean_df &lt;- 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 &lt;- file.path(output_dir, &quot;PRE.csv&quot;)
write.csv(mean_df, file = output_csv, row.names = FALSE)

The code below is used for .nc to GeoTIFF conversion:

library(ncdf4)
library(raster)

# Set the working directory to the parent directory of the output folder
setwd(&quot;D:/ERA5-Land_Monthly_PRE/ERA5-Land&quot;)

# Specify output folder name
output_dir &lt;- &quot;D:/ERA5-Land_Monthly_PRE/ERA5-Land&quot;

if(!dir.exists(output_dir)) dir.create(output_dir)

fname &lt;- file.choose()
nc &lt;- nc_open(fname)

GRACE &lt;- brick(fname, varname = &quot;tp&quot;)

GRACE_array &lt;- getValues(GRACE)
timeL &lt;- colnames(GRACE_array)

for(i in timeL) {
  # Specify the output file path
  output_path &lt;- file.path(output_dir, paste0(i, &quot;.tif&quot;))
  writeRaster(GRACE[[i]], filename = output_path, format = &quot;GTiff&quot;, overwrite = TRUE)
}

The code below is used for unit conversion from m to mm.

library(raster)

# Set the directory containing the input raster files
input_directory &lt;- &quot;D:/ERA5-Land_Monthly_PRE/ERA5-Land&quot;

# Set the directory for saving the output raster files
output_directory &lt;- &quot;D:/ERA5-Land_Monthly_PRE/ERA5-Land&quot;

# Get a list of all raster files in the input directory
raster_files &lt;- list.files(input_directory, pattern = &quot;.tif$&quot;, full.names = TRUE)

# Loop through each raster file
for (file in raster_files) {
  # Read the raster file
  r &lt;- raster(file)
  
  # Convert the values from m to mm by multiplying by 1000
  r_mm &lt;- r * 1000
  
  # Set the output file name by appending &quot;_mm&quot; to the original file name
  output_file &lt;- file.path(output_directory, paste0(tools::file_path_sans_ext(basename(file)), &quot;_mm.tif&quot;))
  
  # Save the output raster file
  writeRaster(r_mm, filename = output_file, format = &quot;GTiff&quot;, overwrite = TRUE)
  
  cat(&quot;Converted&quot;, basename(file), &quot;and saved as&quot;, basename(output_file), &quot;\n&quot;)
}

答案1

得分: 2

似乎最可能的错误发生在你的单位转换上,但你既没有说明你做了什么,也没有提供相关代码 - 有可重现的示例和代码会更容易获得答案。

无论如何,我要大胆猜测一下,你是通过将数据乘以1000来将米转换为毫米的。如果你阅读了ERA5文档,你会发现月平均值的单位是每的米,所以这样的转换会得到毫米/天。因此,你的0.1到3.7范围,乘以约30,会得到3到100毫米/月,正如你所期望的那样。所以如果这是你所做的,那么这些值正如你所期望的那样。

请注意,如果你想要精确的毫米/月单位,你需要乘以每个月的天数,cdo中有一个函数可以实现这个目标,或者你可以参考这个帖子中的R解决方案。

英文:

It seems that the most likely error occurred in your units conversion, for which you neither say what you did, nor provide the code for that - reproducible examples with code go a long way to get an answer.

Anyway, I'm going to take a wild stab in the dark and guess that you converted from meters to mm by multiply the data by 1000. If you had read the ERA5 documentation, you would have seen that monthly means have units of meters per day, so doing such a conversion gives you mm/day. Thus your
0.1 to 3.7 range, when multiplied by ca. 30 gives you 3 to 100 mm/month as you expect. So if this is what you have done, the values are exactly as you would expect.

Note that you need to multiply by the number of days in each month if you want units of mm/month precisely, there is a function in cdo that allows you to do that, or you can refer to this posting for solutions directly in R.

huangapple
  • 本文由 发表于 2023年7月24日 16:48:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定