D_ECMWF2ROMS Matlab scripts

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
barack99
Posts: 17
Joined: Thu Aug 31, 2017 4:33 pm

D_ECMWF2ROMS Matlab scripts

#1 Post by barack99 »

Dear all,

I am using D_ECMWF2ROMS to prepare the forcing ECMWF data for ROMS, but I still need to understand it clearly. I am a new ROMS user, so would you mind to help with the questions below:

1/ Why do we use F( 3).scale=? for each variable? Is it compulsory for ROMS?

2/ How do I select the mybasedate? should I select = datenum(1858,11,17,0,0,0) if I use HYCOM for initial/boundary conditions?

3/ How about LonMin LonMax LatMin LatMax ? Could I select these numbers to be larger than my grid domain? or these need to be same as the domain?

4/ Do I need to use the same time interval (e.g. every 3-hours) for all variables? or Could I use both 6 hours and 12 hours-interval? Does ROMS accepts it?

5. Last, what is the rule to arrange the forcing files in ocean*.in? if I use this script to prepare the forcing data.

Many thanks in advance!

Regards
Barack
Barack

User avatar
kate
Posts: 3980
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: D_ECMWF2ROMS Matlab scripts

#2 Post by kate »

I don't use that tool, but I can answer some of these:
2/ How do I select the mybasedate? should I select = datenum(1858,11,17,0,0,0) if I use HYCOM for initial/boundary conditions?
Just be consistent across everything from initial to boundary to forcing files. We chose 1900,1,1 some time ago and are sticking with it.
3/ How about LonMin LonMax LatMin LatMax ? Could I select these numbers to be larger than my grid domain? or these need to be same as the domain?
At least as big as your domain. We fetch the global grid to use for multiple domains.
4/ Do I need to use the same time interval (e.g. every 3-hours) for all variables? or Could I use both 6 hours and 12 hours-interval? Does ROMS accepts it?
ROMS will read the time variable for each forcing variable independently. Note that to resolve diurnal variations in shortwave, for instance, three hours does better than 12 hours. We average three of the hourly MERRA records into one for 3-hourly fields.
5. Last, what is the rule to arrange the forcing files in ocean*.in? if I use this script to prepare the forcing data.
The order doesn't matter, though if you have both 2011 and 2012 in separate files, they have to be listed in chronological order.

barack99
Posts: 17
Joined: Thu Aug 31, 2017 4:33 pm

Re: D_ECMWF2ROMS Matlab scripts

#3 Post by barack99 »

Thanks Kate, actually I use this tool because I read this: viewtopic.php?f=30&t=3003

My first question is important because it relates to the scale, and time interval.. Any further help would always be appreciated!

Regards
Barack
Barack

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

Re: D_ECMWF2ROMS Matlab scripts

#4 Post by wilkin »

I wrote this code a long time ago so my memory of the details is a biz fuzzy, but it required some awkward programming to get the ECMWF results into the form ROMS expects.

The challenging thing is that several of the values in the ECMWF raw data files are reported as a cumulative sum over the forecast interval. This is noted in comments in the Matlab routine ...

Code: Select all

% If the scale F(n).scale is set to negative, the input ECMWF data is a
% cumulative integral in forecast cycle from hour zero.
% For steps at 6, 9 and 12 hours we must separate last 3 hours of 
% integration from previous accumulation.
% At 3 hour step don't change anything
ROMS wants forcing data in some units per time, e.g. Joules per second (i.e. Watts) but ECMWF have integrated this over time. You can't just divide by 3 hours because the value at hour 6 is the integral from hours 0 through 6, not from hour 3 to 6.

There is a table in the comments in the preamble to the routine noting the translations between ECMWF variables and ROMS forcing variables.

Code: Select all

% This dataset is written in compact way (short numbers). We need to
% convert to floating-point data and scale to ROMS units:
%
%   Uwind       (m s-1)         v10u
%   Vwind       (m s-1)         v10v
%   sustr       (N m-2)         ewss / (3*3600);   3-hour step
%   svstr       (N m-2)         nsss / (3*3600);   3-hour step
%   shflux      (W m-2)         (ssr+str+sshf+slhf) / (3*3600)
%   swrad       (W m-2)         ssr  / (3*3600);   3-hour step
%   lwrad_down  (W m-2)         strd / (3*3600);   3-hour step
%   latent      (W m-2)         slhf / (3*3600);   3-hour step
%   sensible    (W m-2)         sshf / (3*3600):   3-hour step
%   rain        (kg m-2 s-1)    tp * Rho_w / (3*3600)
%   evaporation (kg m-2 s-1)    e  * Rho_w / (3*3600)
%   swflux      (cm day-1)      (-e - tp) * 100 / (3/24);  0.125 day step
%   cloud       (nondimesional) tcc
%   Pair        (mb)            msl / 100;   (1 mb = 100 Pa)
%   Tair        (Celsius)       t2m - 273.15;   (1 C = 273.15 K)
%   Qair        (percentage)    100 * (E/Es)

Unless ECMWF have changed how these data are stored, the code works provided you download all 3-hour interval data. That's why the instructions say:

Code: Select all

% The following parameters are used to extract ERA-Interim fields:
% Select time:   00:00:00     12:00:00
% Select step:   0  3  6  9  12
If you skip some data in your download from ECMWF, say only downloading 0, 6, 12 time-steps, you almost certainly break the logic for unraveling the cumulative summations and will have incorrect heat fluxes.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

barack99
Posts: 17
Joined: Thu Aug 31, 2017 4:33 pm

Re: D_ECMWF2ROMS Matlab scripts

#5 Post by barack99 »

Thanks John for your clarification.

Is there any updated/easier scripts to prepare the forcing data I could look at?

Best,
Barack

bkresning
Posts: 2
Joined: Wed Jul 15, 2015 8:59 pm
Location: University of Rhode Island

Re: D_ECMWF2ROMS Matlab scripts

#6 Post by bkresning »

Hi All,

I am trying to use d_ecmwf2roms (I check out the file at revision 914) to generate a forcing file and I encountered the problem below. Am I missing some files/toolboxes? Any suggestion would be helpful. Thank you

Code: Select all

** Creating ROMS NetCDF forcing file: gom_Tair_era.nc **
 
Wrote lon                 into record: , Min=-1.79250e+02 Max= 1.80000e+02
Wrote lat                 into record: , Min=-9.00000e+01 Max= 9.00000e+01
 
** Creating ROMS NetCDF forcing file: gom_Qair_era.nc **
 
Wrote lon                 into record: , Min=-1.79250e+02 Max= 1.80000e+02
Wrote lat                 into record: , Min=-9.00000e+01 Max= 9.00000e+01
 
** Processing: sustr  for  01-Oct-2012 03:00:00 **
Undefined function or variable 'nc_int'.

Error in nc_read>nc_read_matlab (line 430)
        case {nc_int, nc_short, nc_byte}

Error in nc_read (line 95)
    f =
    nc_read_matlab(ncfile,Vname,Tindex,ReplaceValue,PreserveType,Info);
    
Error in d_ecmwf2roms_na (line 476)
          field = nc_read(InpFile, Vecmwf, Rec);

mjfconan
Posts: 18
Joined: Mon Mar 03, 2014 1:57 pm
Location: SKLEC, ECNU, China

Re: D_ECMWF2ROMS Matlab scripts

#7 Post by mjfconan »

bkresning wrote: Undefined function or variable 'nc_int'.

Error in nc_read>nc_read_matlab (line 430)
case {nc_int, nc_short, nc_byte}

Error in nc_read (line 95)
f = nc_read_matlab(ncfile,Vname,Tindex,ReplaceValue,PreserveType,Info);

Error in d_ecmwf2roms_na (line 476)
field = nc_read(InpFile, Vecmwf, Rec);
I think it is a little bug in the function of "nc_read", line 430.
It should be similar to the next "switch" block, means,

Code: Select all

        case {netcdf.getConstant('nc_int'),                             ...
              netcdf.getConstant('nc_short'),                           ...
              netcdf.getConstant('nc_byte')}
              f = double(f).*scale+offset;
NOT

Code: Select all

        case {nc_int, nc_short, nc_byte}
              f = double(f).*scale+offset;

bkresning
Posts: 2
Joined: Wed Jul 15, 2015 8:59 pm
Location: University of Rhode Island

Re: D_ECMWF2ROMS Matlab scripts

#8 Post by bkresning »

Thank you, the suggested action solved the error.

User avatar
neelbasak08
Posts: 99
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: D_ECMWF2ROMS Matlab scripts

#9 Post by neelbasak08 »

Hello everyone,

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:
My location for files are as follows-
matlab_dir: C:\Users\aBc\Documents\MATLAB
mexcdf: C:\Users\aBc\Documents\MATLAB
netcdf_toolbox: C:\Users\aBc\Documents\MATLAB
'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:
>> d_ecmwf2roms

** Creating ROMS NetCDF forcing file: gom_sms_era.nc **

Error using internal.matlab.imagesci.nc/openToRead (line 1272)
Could not open ocean\repository\Projects\gom\Data\Forcing2\ecmwf_era_flux_2000.nc for reading.

Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();

Error in ncinfo (line 88)
ncObj = internal.matlab.imagesci.nc(ncFile);

Error in nc_getatt>nc_getatt_matlab (line 117)
Info = ncinfo(ncfile);

Error in nc_getatt (line 65)
A = nc_getatt_matlab(ncfile, Aname, Vname); % Matlab native interface

Error in nc_inq (line 69)
A = nc_getatt(ncfile); % NetCDF file global attributes

Error in nc_read (line 77)
Info = nc_inq(ncfile);

Error in d_ecmwf2roms (line 296)
lon = nc_read(InpFile, 'longitude', ...
I am quite new to ROMS (just ran the upwelling test case and created a grid on my own for myself using easygrid and just applied TPXO9 extraction to it ) and MATLAB, any help is extremely appreciated by me.

Thanks a lot and extreme regards

User avatar
neelbasak08
Posts: 99
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: D_ECMWF2ROMS Matlab scripts

#10 Post by neelbasak08 »

Hello everyone,

I wanted to use d_ecmwf2roms.m matlab script to create forcing file for a grid which I created myself. But I am unable to understand how to use and run the script and what values I need to change in order to run that. Here are my grid file and other mexcdf and other snctools all added to matlab path and their location:
My location for files are as follows-
matlab_dir: C:\Users\aBc\Documents\MATLAB
mexcdf: C:\Users\aBc\Documents\MATLAB
netcdf_toolbox: C:\Users\aBc\Documents\MATLAB
'mygrid.nc' grid file: C:\Users\aBc\Documents\MATLAB

I just kept my grid file on which I want forcing in ran the code with changing anything. It gave the following error:
>> d_ecmwf2roms

** Creating ROMS NetCDF forcing file: gom_sms_era.nc **

Error using internal.matlab.imagesci.nc/openToRead (line 1272)
Could not open ocean\repository\Projects\gom\Data\Forcing2\ecmwf_era_flux_2000.nc for reading.

Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();

Error in ncinfo (line 88)
ncObj = internal.matlab.imagesci.nc(ncFile);

Error in nc_getatt>nc_getatt_matlab (line 117)
Info = ncinfo(ncfile);

Error in nc_getatt (line 65)
A = nc_getatt_matlab(ncfile, Aname, Vname); % Matlab native interface

Error in nc_inq (line 69)
A = nc_getatt(ncfile); % NetCDF file global attributes

Error in nc_read (line 77)
Info = nc_inq(ncfile);

Error in d_ecmwf2roms (line 296)
lon = nc_read(InpFile, 'longitude', ...
I am quite new to ROMS (just ran the upwelling test case and created a grid on my own for myself using easygrid and just applied TPXO9 extraction to it ) and MATLAB, any help is extremely appreciated by me.

Thanks a lot and extreme regards

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

Re: D_ECMWF2ROMS Matlab scripts

#11 Post by wilkin »

This is a user modifiable script demonstrating how to create ROMS forcing NetCDF files, but you need to customize it for your own environment and application. The very first executable line in the script is:

Code: Select all

% Path to downloaded ERA data files.
Dir = fullfile(getenv('HOME'),                                          ...
               'ocean/repository/Projects/gom/Data/Forcing2');
which points to files the example user has downloaded from ECMWF. So clearly you need to modify this to point to files on your own computer.

The script is old and refers to ECMWF's ERA-Interim Dataset
at http://apps.ecmwf.int/datasets/data/interim_full_daily/ which has been superceded by ERA-5.

Maybe someone out there in the User Forum has already updated for ERA-5.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

Post Reply