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: 941
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

Post Reply