Delft3D grids to NetCDF

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
jmjaneiro

Delft3D grids to NetCDF

#1 Unread post by jmjaneiro »

Hello,

I'm looking in the possibility of converting some of my Delft3D grids to NetCDF to further run in ROMS.
Does anyone has, or know about, any tools or Matlab scripts that would allow this to be easily accomplished?

Thanks


Joao

lanerolle
Posts: 157
Joined: Mon Apr 28, 2003 5:12 pm
Location: NOAA

DELFT3D grid to ROMS NetCDF grid

#2 Unread post by lanerolle »

Hi,

We use the DELFT3D grid generator to generate our ROMS curvilinear, orthogonal grids and I have written a Matlab routine to convert a DELFT3D grid to a ROMS NetCDF grid file. As the DELFT3D only generates grid points at wet-points, we need to artificially construct land points (and if necessary give them a fictitious cut-off depth - say 2m) and my script does all this and also constructs the necessary metrics (eg. Coriolis factor, pm, pn, dmde, dndx, etc.) required by ROMS and puts them all into a NetCDF file. If you are interesting in using this Matlab script, please feel free to email me and I will send it to you.

Lyon Lanerolle.

hbzong
Posts: 36
Joined: Thu Oct 04, 2007 4:14 am
Location: Fathom Science/NCSU

Re: Delft3D grids to NetCDF

#3 Unread post by hbzong »

Hi,Lyon.Could you leave your email?

helvioprevelato
Posts: 1
Joined: Mon Sep 29, 2008 2:21 pm
Location: USP

Re: Delft3D grids to NetCDF

#4 Unread post by helvioprevelato »

Hi Lyon

I have the same problem of João. Cold you send to my e-mail this Matlab Script? (helvio@usp.br)

Thanks

Helvio

lanerolle
Posts: 157
Joined: Mon Apr 28, 2003 5:12 pm
Location: NOAA

Re: Delft3D grids to NetCDF

#5 Unread post by lanerolle »

My email address is : lyon.lanerolle@noaa.gov

When emailing me, please do so from your official/professional email address (and not from a personal email address)

sbergman
Posts: 5
Joined: Mon May 10, 2010 2:08 pm
Location: Dept of Environmental Affairs - SA Governemt (& Oceanography SA)

Re: Delft3D grids to NetCDF

#6 Unread post by sbergman »

Hello,

I ran into this thread by looking for the same solution as the original poster. I've already tried sending a message to the NOAA email - but there's no response. (It was a LONG time ago afterall...)

Nonetheless, I managed to google some scripts, which appear to be a way to convert the Delft grid to Seagrid, and from there to ROMS (Netcdf) grid.

Here's the important links I've come across:
http://svn1.hosted-projects.com/cmgsoft ... lft2roms.m
and
http://svn1.hosted-projects.com/cmgsoft ... rid2roms.m

I'm not sure if these are the same as what Lyon (from NOAA) used, but it appears to be able to do what I need.

There were some dependency issues, some of which I managed to sort out, and also a requirement to have Delft's matlab toolbox.

The place where I got stuck is a dependency called 'gmean' - it appears in lines 87 to 90 of the delft2roms.m script.

Does anyone know where this function comes from? or have access to it? or how its output looks?

Please help

- Regards

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Delft3D grids to NetCDF

#7 Unread post by rsignell »

The function "gmean" just calculates the mean over the "good" (not NaN) values. If you google "m_cmg" and "gmean.m" you will find it. Please let me know if that delft2roms.m function you found works for you. I might not have completely finished it.

It would be interesting to compare this with Lyon's routine. He can still be reached at: lyon.lanerolle@noaa.gov
but you might have to e-mail him twice to let him know you mean it! ;-)

-Rich

Vera
Posts: 15
Joined: Wed Apr 26, 2017 5:23 pm
Location: Sun Yat-sen University

Re: Delft3D grids to NetCDF

#8 Unread post by Vera »

Hi,rsignell and sbergman! Did you have got Lyon's scripts?
I have a complex, curvilinear and orthogongal grid generated by delft3D, and have deleted the land points.I have no idea how to transform it into ROMS grid.My teacher has send email to Lyon for 3~4 times, but get no response.Can you help me or give any advice?
Thanks very much.

venuscheung

Re: Delft3D grids to NetCDF

#9 Unread post by venuscheung »

Hi, I would like to have the script too.
Yet, the email link seems no longer function.
can anyone send me the script.
thank you very much

lcbernardo
Posts: 88
Joined: Wed Oct 01, 2014 8:57 pm
Location: International Coastal Research Center

Re: Delft3D grids to NetCDF

#10 Unread post by lcbernardo »

Hi,

Recently I've been needing to look into this too as I've been looking through some of my old Delft3D simulations, although I use mostly ROMS and COAWST now. I'd also appreciate information on how such a grid conversion can properly be carried out. I'm using Delft3D version 4.01.

Lawrence

hbzong
Posts: 36
Joined: Thu Oct 04, 2007 4:14 am
Location: Fathom Science/NCSU

Re: Delft3D grids to NetCDF

#11 Unread post by hbzong »

Usually, I use the following steps to convert Delft3d grid to ROMS
1. Read the Delft3D grid (see example codes)

%Read delft3D grid
%Get PSI-points location
try
fid = fopen(d3dgrd);
catch
disp('ERROR: Cannot Open file')
end
%
for m = 1:5
tline = fgetl(fid);
end
%
eta_num = fscanf(fid,'%d',1);
xi_num = fscanf(fid,'%d',1);
%
tline = fgetl(fid);
tline = fgetl(fid);
%
xx_psi = zeros(xi_num,eta_num);
for m = 1:xi_num
etastr = fscanf(fid,'%5s',1);
eta_no = fscanf(fid,'%d',1);
xx_psi(m,:) = fscanf(fid,'%f',eta_num);
end
%
yy_psi = zeros(xi_num,eta_num);
for m = 1:xi_num
etastr = fscanf(fid,'%5s',1);
eta_no = fscanf(fid,'%d',1);
yy_psi(m,:) = fscanf(fid,'%f',eta_num);
end
fclose(fid)
clear xi_num eta_num

2. Get rho point coordinates and interpolate bathymetry to rho points;
3. Use a script named mat2roms_rps.m to generate netCDF file. https://github.com/sea-mat/seagrid/blob ... roms_rps.m

venuscheung

Re: Delft3D grids to NetCDF

#12 Unread post by venuscheung »

thank you.
But as the Delft3D4 has a function to convert grid to _roms.nc, I am trying to use it.
However, the _roms.nc has a very strange structure as the boundary is -999 and it is non-readable for ROMS.
Also, pn and pm are 0, which also non-readable for ROMS.

Meanwhile, my ROMS still have error and I am trying to solve it.
Please me more method to convert _roms.nc to the readable roms grid.
Thank you.

hbzong
Posts: 36
Joined: Thu Oct 04, 2007 4:14 am
Location: Fathom Science/NCSU

Re: Delft3D grids to NetCDF

#13 Unread post by hbzong »

You could read lon_rho, lat_rho, and h from the _roms.nc then use mat2roms_rps.m to generate a *.nc file.

lcbernardo
Posts: 88
Joined: Wed Oct 01, 2014 8:57 pm
Location: International Coastal Research Center

Re: Delft3D grids to NetCDF

#14 Unread post by lcbernardo »

hbzong wrote: Fri Dec 13, 2019 4:34 pm You could read lon_rho, lat_rho, and h from the _roms.nc then use mat2roms_rps.m to generate a *.nc file.
One issue I notice when using Delft3D to output the grid as *_roms.nc is that a line of zeros is added on all four sides of the variables 'lon_rho' and 'lat_rho'. So perhaps these segments need to be deleted first before using mat2roms_rps.m? In this case, the *_roms.nc created by Delft3D will need to be modified as the variable dimensions may need to be adjusted. I imagine this process can be quite confusing, but if it will work to make Delft3D-created grids usable in ROMS, I'll try it.

venuscheung

Re: Delft3D grids to NetCDF

#15 Unread post by venuscheung »

Thanks all, I think i have solved the problem successfully by using a python code.
I create my d3d grid and make bathymetry in delftdashboard and generate _roms.nc.
Then I use my python code to generate the ROMS readable _roms.nc and convert it to swan.grd using COAWST matlab script.
Let me know if you guys want the python script.

lcbernardo
Posts: 88
Joined: Wed Oct 01, 2014 8:57 pm
Location: International Coastal Research Center

Re: Delft3D grids to NetCDF

#16 Unread post by lcbernardo »

venuscheung wrote: Tue Dec 17, 2019 9:11 am Thanks all, I think i have solved the problem successfully by using a python code.
I create my d3d grid and make bathymetry in delftdashboard and generate _roms.nc.
Then I use my python code to generate the ROMS readable _roms.nc and convert it to swan.grd using COAWST matlab script.
Let me know if you guys want the python script.
Thank you for your update. I work mainly with matlab, but I think I'd be interested to see the python script if you don't mind sharing it.

venuscheung

Re: Delft3D grids to NetCDF

#17 Unread post by venuscheung »

Sure. Would you mind to leave your email here?
As I want to double confirm the python code before posting it on here openly to prevent any misleading.

lcbernardo
Posts: 88
Joined: Wed Oct 01, 2014 8:57 pm
Location: International Coastal Research Center

Re: Delft3D grids to NetCDF

#18 Unread post by lcbernardo »

venuscheung wrote: Wed Dec 18, 2019 8:39 am Sure. Would you mind to leave your email here?
As I want to double confirm the python code before posting it on here openly to prevent any misleading.
Thanks for double confirming the code. You can reach me at: bernardo.l.aa@m.titech.ac.jp

thiago.pdpaula
Posts: 14
Joined: Thu Oct 03, 2013 6:44 pm
Location: Personal

Re: Delft3D grids to NetCDF

#19 Unread post by thiago.pdpaula »

I have recently build a ROMS grid using RGFGRID and QUICKPLOT, from Delft3D's Graphical User Interface (GUI), and pyroms (https://github.com/ESMG/pyroms).

The main idea is to convert a delft3d grid (.grd) created with RGFGRID into .mat using QUICKPLOT. This will give you the grid vertices in a .mat file.

Then, you can load this file in python and create the ROMS grid using pyroms tools.

If anyone is still interest, I can post my sample script.

lcbernardo
Posts: 88
Joined: Wed Oct 01, 2014 8:57 pm
Location: International Coastal Research Center

Re: Delft3D grids to NetCDF

#20 Unread post by lcbernardo »

thiago.pdpaula wrote: Thu Dec 19, 2019 2:20 pm I have recently build a ROMS grid using RGFGRID and QUICKPLOT, from Delft3D's Graphical User Interface (GUI), and pyroms (https://github.com/ESMG/pyroms).

The main idea is to convert a delft3d grid (.grd) created with RGFGRID into .mat using QUICKPLOT. This will give you the grid vertices in a .mat file.

Then, you can load this file in python and create the ROMS grid using pyroms tools.

If anyone is still interest, I can post my sample script.
I'm also interested to see it. Perhaps you can share it using the email address I gave in a previous message? Sharing it here directly would be okay too. Thanks!

thiago.pdpaula
Posts: 14
Joined: Thu Oct 03, 2013 6:44 pm
Location: Personal

Re: Delft3D grids to NetCDF

#21 Unread post by thiago.pdpaula »

Hi,

I'm attaching a python script here so it may be of use to others.

Good luck.

Thiago.
Attachments
delft2roms_grid.py
(7.52 KiB) Downloaded 602 times

luhputria
Posts: 14
Joined: Tue Mar 31, 2020 3:43 am
Location: The University of Western Australia

Re: Delft3D grids to NetCDF

#22 Unread post by luhputria »

venuscheung wrote: Tue Dec 17, 2019 9:11 am Thanks all, I think i have solved the problem successfully by using a python code.
I create my d3d grid and make bathymetry in delftdashboard and generate _roms.nc.
Then I use my python code to generate the ROMS readable _roms.nc and convert it to swan.grd using COAWST matlab script.
Let me know if you guys want the python script.
Hi cheung, Could you mind to send your python code for me? Because I have same problem with you regarding -999 in the border area in _roms.nc that i converted from rfgrid delft3d.
My email is luh.adnyani@research.uwa.edu.au
Thanks before.

Regards,
luh

pphu
Posts: 1
Joined: Wed Sep 21, 2022 9:15 pm
Location: Sun Yat-Sen University

Re: Delft3D grids to NetCDF

#23 Unread post by pphu »

Hi Cheung,
I have encountered the same issue as you regarding the -999 values in the border area of the _roms.nc file that I converted from rfgrid in Delft3D. I'm glad to hear that you were able to solve a similar problem.
Would you mind sharing your Python code with me?
My email is hupp5@mail2.sysu.edu.cn.
Thank you in advance for your help!
Best regards,
Hu

Post Reply