Search code examples
rtime-seriesrasterarcmapera5

Issue in ERA5 and ERA5-Land Monthly Precipitation Dataset


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 <- "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)

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("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)
}

The code below is used for unit conversion from m to 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")
}

Solution

  • 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.