3

I recently started to use ERA5 land-hourly data and python code.

I will use data of 2 variables (total precipitation and 2 metre temperature) from an entire year (2017).

Data downloaded are in GRIB or netCDF format.

The things I want to do are:

1) Convert units. In the case of:

  • Total precipitation - convert "m" into "mm"
  • 2m temperature - convert "Kelvin" into "Celsius"

2) Convert hourly to daily values:

I've found the following code from ECMWF's offficial site: https://confluence.ecmwf.int/display/CKB/ERA5%3A+How+to+calculate+daily+total+precipitation Unfortunately, the code is designed only to compile daily values for one day (January 1st, 2017).

I want to convert all values for an entirely year. I know that (if I'm right):

  • total precipitation presents acumulated values. So daily value is the sum of 24 hours.
  • temperature presents mean values. So daily value is the mean of 24 hours.

3) Pick especific information from data files:

In order to do an analysis, I want to keep only information about:

  • values
  • latitude
  • longitude
  • time

for both variables (total precipitation and 2 metre temperature)

4) Convert GRIB or netCDF files into some format that can be read by Stata software

I really will appreciate any gesture of help

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Brian
  • 89
  • 1
  • 10
  • For the tasks 1-3, the best tool would be cdo (climate data operators). The tasks can be done with a single command. I have no clue about sdata. I guess, more or less standard (i.e. compliant with CF-conventions) output of cdo should do. – Roux Nov 19 '19 at 20:02

2 Answers2

2

Most of these tasks are easy to do if you use xarray

1) Unit conversion:

import xarray as xr 
ds = xr.open_dataset(path/to/netcdf/file)

# converting total precipitation from m to mm
ds.tp = ds.tp * 1000

# converting t2m from K to C
ds.t2m = ds.t2m - 273.15

2) Hourly to Daily data:

xarray .resample method can help you here.

# daily temperature mean from hourly values
ds.t2m.resample(time='1D').mean()
# daily precipitation sum from hourly values
ds.tp.resample(time='1D').sum()

Your points 3) and 4) should be better explained to increase your chances of getting proper help

igrolvr
  • 343
  • 4
  • 13
  • Hi @igrolvr ! Thanks for your comment. I used the codes for unit conversion and rearranged them. I have a doubt that I posted as a new question, the link is (https://stackoverflow.com/q/58964781/12375837). The points 3 and 4, I'll clarify later. – Brian Nov 20 '19 at 23:12
  • Hi @igrolvr and Brian. I want to do something very similar to what have been discussed here. But, after steps 1 and 2, I would like to have a simple pandas dataframe with columns Date, Lat, Longitude, T2 Daily Max, T2 Daily Sum, t2 Daily Min and Total Precipitation. Is there a way to accomplish that (convert de ds above to pandas dataframe? – user9585960 Apr 13 '21 at 02:34
0

ERA5-Land Hourly precipitation and ERA5 Reanalysis Hourly precipitation are different. See https://confluence.ecmwf.int/pages/viewpage.action?pageId=197702790 and refer to the Hydrological parameter table. ERA5 Reanalysis Hourly and ERA5-Land Hourly have quite different specifications of how to extract daily totals.
For ERA5-Land Hourly the precipitation values are totals since the beginning of each day. ERA5 Reanalysis Hourly precipitation are totals for the hour. This means that daily totals from ERA5-Land Hourly are not the sum of the precipitation values for each hour, but is the precipitation value for the 00 hour of the next day.

Rainfall.NZ
  • 197
  • 1
  • 12
  • This is [data](https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land?tab=overview). I guess the total precipitation variable refers to ERA 5 - Land hourly data in the link you provided, am I right? – Brian May 25 '21 at 22:19
  • The link I provided shows the applicable dataset in the left hand column called "Dataset". It is the fifth row you need for calculation details of ERA5 - Land hourly precipitation accumulation – Rainfall.NZ May 26 '21 at 23:18