Updates to MATLAB code for reading ERA5 from UCAR

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
wilkin
Posts: 947
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

Updates to MATLAB code for reading ERA5 from UCAR

#1 Unread post by wilkin »

There have been changes to the way UCAR serves ERA5 reanalysis data (see announcement here: https://data.ucar.edu/dataset/era5-reanalysis) that necessitate changes to my ROMS MATLAB tools (roms_wilkin) https://github.com/johnwilkin for reading ERA5 and writing ROMS format meteorology forcing files, i.e. function roms_get_era5_NCARds633_bulkflux.m. The updated code is in the GitHub repo.

Along with this update, I also modified the output coordinates so that lon() and lat() are 1-D vectors instead of 2-D matrices. This allows a workaround to the fact that the ERA5 data break at the prime meridian (0 longitude) and requesting a longitude range that spans the 0 longitude is not accommodated. The workaround is to do two downloads for east and west files, and then use the NCO UNIX tool ncrcat to join them. For example, to get 2 files in the Gulf of Guinea west and east of 0 ...

Code: Select all

  ROMS_APP = 'w_GulfOfGuinea';
  bbox = [-16.0   -0.25/2  -11.0000    8.0000];     % west
  E = roms_get_era5_NCARds633_bulkflux(yyyy,mm,bbox);
  roms_write_era5_NCARds633_frcfile
  ROMS_APP = 'e_GulfOfGuinea';
  bbox = [  0.0   14.5000  -11.0000    8.0000];     % east
  E = roms_get_era5_NCARds633_bulkflux(yyyy,mm,bbox);
  roms_write_era5_NCARds633_frcfile
Then to join them in a bash shell using ncrcat from the NCO tools https://nco.sourceforge.net/ you do something like this ...

Code: Select all

#!/bin/bash
# This assumes the two files have prefix w_ and e_
file=GulfOfGuinea_frc_ERA5_bulkflux_202412.nc
westfile=w_$file
eastfile=e_$file

# permute lon to the first dimension
# which also makes it the record dimension 
ncpdq -O -a lon,lat,time $westfile tmp$westfile
ncpdq -O -a lon,lat,time $eastfile tmp$eastfile

# concatenate along lon
ncrcat -O tmp$westfile tmp$eastfile mergedfile      

# restore the order of dimensions
# which also returns time to being the record dimension 
ncpdq -O -a time,lat,lon mergedfile $file

# clean up
rm tmp$westfile
rm tmp$eastfile
rm mergedfile
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

shakhawat_ouc
Posts: 1
Joined: Tue Dec 26, 2023 2:00 pm
Location: Ocean University of China

Re: Updates to MATLAB code for reading ERA5 from UCAR

#2 Unread post by shakhawat_ouc »

Dear Wilkin,
Thank you for the codes you updated and shared. I am new to ROMS, can you tell me how to use your scripts to download and make forcing for more than one month or for several years?

User avatar
wilkin
Posts: 947
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

Re: Updates to MATLAB code for reading ERA5 from UCAR

#3 Unread post by wilkin »

... can you tell me how to use your scripts to download and make forcing for more than one month or for several years?
In MATLAB, set the space and time bounds for your grid and then put the calls to get and write the ERA5 data inside a loop ...

Code: Select all

bbox = [-105 -35 -5 55]; % set the lon,lat bounding box
Time0 = datenum(2011,1,1); % set the base date for your time coordinate
ROMS_APP = 'eccofs'; % this string is embedded in the output filename
fluxopt = 'allflux'; 
% fluxopt = 'bulkfluxes'
Outdir = '.'; % change if you want the files written to some other directory
for yyyy = 2024 % one year or a loop over multiple years
  for mm = [1 2] % loop over some or all months
    E = roms_get_era5_NCARds633_bulkflux(yyyy,mm,bbox,fluxopt); % get the data
    roms_write_era5_NCARds633_frcfile % write the data
  end
end
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

Post Reply