Delft3D grids to NetCDF

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
jmjaneiro

Delft3D grids to NetCDF

#1 Post by jmjaneiro » Wed Apr 16, 2008 1:04 pm

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 Post by lanerolle » Thu Apr 17, 2008 2:42 pm

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: 34
Joined: Thu Oct 04, 2007 4:14 am
Location: NCSU
Contact:

Re: Delft3D grids to NetCDF

#3 Post by hbzong » Tue Oct 21, 2008 9:34 am

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 Post by helvioprevelato » Wed Oct 22, 2008 11:23 am

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 Post by lanerolle » Thu Oct 23, 2008 3:52 am

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 Post by sbergman » Thu Oct 06, 2011 1:06 pm

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: 123
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Delft3D grids to NetCDF

#7 Post by rsignell » Mon Oct 10, 2011 5:17 pm

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 Post by Vera » Tue Jun 27, 2017 8:48 am

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
Posts: 46
Joined: Thu Oct 03, 2019 4:43 pm
Location: the Chinese University of Hong Kong

Re: Delft3D grids to NetCDF

#9 Post by venuscheung » Thu Dec 12, 2019 10:05 am

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: 73
Joined: Wed Oct 01, 2014 8:57 pm
Location: Tokyo Institute of Technology

Re: Delft3D grids to NetCDF

#10 Post by lcbernardo » Fri Dec 13, 2019 5:26 am

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: 34
Joined: Thu Oct 04, 2007 4:14 am
Location: NCSU
Contact:

Re: Delft3D grids to NetCDF

#11 Post by hbzong » Fri Dec 13, 2019 5:46 am

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
Posts: 46
Joined: Thu Oct 03, 2019 4:43 pm
Location: the Chinese University of Hong Kong

Re: Delft3D grids to NetCDF

#12 Post by venuscheung » Fri Dec 13, 2019 7:41 am

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: 34
Joined: Thu Oct 04, 2007 4:14 am
Location: NCSU
Contact:

Re: Delft3D grids to NetCDF

#13 Post by hbzong » 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.

lcbernardo
Posts: 73
Joined: Wed Oct 01, 2014 8:57 pm
Location: Tokyo Institute of Technology

Re: Delft3D grids to NetCDF

#14 Post by lcbernardo » Tue Dec 17, 2019 7:51 am

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
Posts: 46
Joined: Thu Oct 03, 2019 4:43 pm
Location: the Chinese University of Hong Kong

Re: Delft3D grids to NetCDF

#15 Post by venuscheung » 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.

lcbernardo
Posts: 73
Joined: Wed Oct 01, 2014 8:57 pm
Location: Tokyo Institute of Technology

Re: Delft3D grids to NetCDF

#16 Post by lcbernardo » Wed Dec 18, 2019 5:19 am

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
Posts: 46
Joined: Thu Oct 03, 2019 4:43 pm
Location: the Chinese University of Hong Kong

Re: Delft3D grids to NetCDF

#17 Post by venuscheung » 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.

lcbernardo
Posts: 73
Joined: Wed Oct 01, 2014 8:57 pm
Location: Tokyo Institute of Technology

Re: Delft3D grids to NetCDF

#18 Post by lcbernardo » Wed Dec 18, 2019 12:57 pm

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 Post by thiago.pdpaula » 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.

lcbernardo
Posts: 73
Joined: Wed Oct 01, 2014 8:57 pm
Location: Tokyo Institute of Technology

Re: Delft3D grids to NetCDF

#20 Post by lcbernardo » Fri Dec 20, 2019 7:44 am

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 Post by thiago.pdpaula » Sat Dec 21, 2019 5:38 pm

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 19 times

Post Reply