Difference between revisions of "Grid Generation"

From WikiROMS
Jump to navigationJump to search
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Grid Generation =
<div class="title">Grid Generation</div>


ROMS uses an Arakawa "C" Grid. The grid can be specified using analytical functions or with a netcdf file. To create a netcdf grid file, there are several grid generation tools.  
To create a grid, you must understand how the variables are placed on it and where the boundaries lie relative to it. Here is a diagram of it:


[[Image:Whole_grid.png]]


== SEAGRID ==
The thick lines denote the outer boundary of the grid, though some tools may draw the boundary through the rho points lying outside the box. If your domain has walls, the walls will be where the thick line is. If your domain is periodic, the periodicity is from one thick line to the next.


{{note}} Note that there are Lm by Mm computational points. If you want to create a grid that's neatly divisible by powers of 2, make sure Lm and Mm have those factors.


A GUI-based Matlab program for creating curvilinear orthogonal grids with 4 corners
==Grid Generation Software==
Several software packages are available to generate the orthogonal curvilinear grids that ROMS requires. 


http://woodshole.er.usgs.gov/operations/modeling/seagrid/seagrid.html


SEAGRID includes tools to create ROMS NetCDF grid files.
===SEAGRID by Chuck Denham===
A GUI-based Matlab program for creating curvilinear orthogonal grids with 4 corners <span class="red">SEAGRID</span> includes tools to create ROMS NetCDF grid files. See [[seagrid]] for more information.


Some useful additional m-files for working with SEAGRID are


* join_cst.m: Turn coastline segments (e.g. from the [http://rimmer.ngdc.noaa.gov/coast/ Coastline Extractor]) into coastline polygons that will then mask land when used in SEAGRID.
===GRIDGEN by Pavel Sakov===
* read_srtm30plus.m: Read SRTM30+ worldwide 30sec (~1km) topography via Web Mapping Service.
A C program for creating curvilinear orthogonal grids with an arbitrary number of corners.
*http://www.marine.csiro.au/~sakov/ (scroll down Pavel's page to the section on "orthogonal grid generation")


These tools are part of the RPSstuff Matlab toolbox available via SVN:
*Rob Hetland has a nice movie about how to [http://pong.tamu.edu/~rob/python/tutorials/making_grids_with_python.mov make a ROMS grid using GRIDGEN with Python]
<nowiki> svn co https://svn1.hosted-projects.com/cmgsoft/m_cmg/trunk/RPSstuff  ./rps_stuff </nowiki>
Here is one way to prepare coastline and bathymetry for Seagrid:
* Go to the [http://rimmer.ngdc.noaa.gov/coast/ Coastline Extractor]) and extract the coastline for your region, making sure you check the "Matlab format" box instead of the default format. Note that the highest worldwide shoreline is the default World Vector Shoreline, but for the US Waters, there is a higher resolution "NOAA Medium Resolution Shoreline" available.  For example here, let's assume that you save the file on your computer as "coast.txt".


* Load the coastline into Matlab using "load coast.txt".  You now have a variable called "coast" in Matlab with two columns.  The first column is longitude in decimal degrees, west negative. The second column is latitude in decimal degrees, south negative.  Each coastline segment is separated by a pair of NaN values.


* Assuming you've obtained the m-files from the SVN above, you can now type
==Bathymetry==
>> plot(coast(:,1),coast(:,2));    % plot the coast as line segments
The bathymetry for ROMS is measured positive downwards, from a datum such as mean sea level (MSL). For a 'typical' ROMS application, the bathymetry would consist of all positive values. Also, for a 'typical' application, the bathymetry can not have values of 0 or any negative values. Most users would set some minimum 'clipping' depth and not allow the values of [[Variables#h|h]] to be less than that depth. However, if an application requires land, ''i.e.'' values of [[Variables#h|h]] that are negative, then the user is required to activate the [[Options#WET_DRY|WET_DRY]] CPP option.
>> fillseg(coast);                % attempt to fill all line segments separated by NaNs.  


This will probably look bad since in most coastline datasets, coastlines that look continuous are actually composed of many line segments.


You can join together line segments whose ends are closer than a certain tolerance using the "join_cst.m" command:
==Land/Sea Masking==
 
>> coast_new=join_cst(coast,.0001);  % join coastline segments closer than 0.0001 degrees
 
This will also sort the coastline segments so that the longest segment is first.  Often this segment is the main coastline, while the rest of the segments are islands.    To see what has happened, clear the figure and try "fillseg" again:
 
>> clf;
>> fillseg(coast_new);
 
this should look better, but typically you have to add a point to the first coastline segment so that the polygon closes the way you want.  Usually just changing the latitude or longitude of the first data pair (2nd line of the coast_new file) to be the appropriate limit of your coastline region will work.
 
* Once "fillseg(coast_new)" shows filled polygons in the region you want masked, then save the longitude and latitude values as "lon" and "lat" to a .mat file (you *must* use the names "lon" and "lat"):
 
>> lon=coast_new(:,1);
>> lat=coast_new(:,2);
>> save seagrid_coast.mat lon lat
 
* For bathymetry, try using "read_srtm30plus.m".  If you've still got your coastline plot up, type
 
>> ax=axis;  % grab the lon/lat range
>> lon_range=ax(1:2);
>> lat_range=ax(3:4);
>> [xbathy,ybathy,zbathy]=read_srtm30plus(lon_range,lat_range,60);
 
This reads in worldwide bathymetry at 60 second (1 minute) resolution.  The highest resolution available is 30 second, but you might want to use a lower resolution when you make your grid so that Seagrid doesn't take too long, and then when once you've got your ROMS grid, create higher resolution bathymetry. 
 
* Seagrid expects bathymetry as three vectors describing bathymetry sounding triplets, with depth positive.  Since we've got a grid, we need to construct the lon and lat points using "meshgrid", and then save remembering that Seagrid expects the names "xbathy", "ybathy", "zbathy" and that depths are positive (not negative):
 
>> [xbathy,ybathy]=meshgrid(xbathy,ybathy); 
>> xbathy =  xbathy(:);  %columnize
>> ybathy = ybathy(:);  %columnize
>> zbathy = -zbathy(:);  %columnize, and make depth positive
>> save bathy_seagrid.mat xbathy ybathy zbathy
 
* Now start up Seagrid and loast the coastline and bathymetry data.  If your whole screen turns purple when you load the bathymetry, you'll probably want to toggle off the display of the depth values, or reduce the number of depth points.
 
* Remember to save often when using SeaGrid, as the GUI has become buggy over then many releases of Matlab since it was designed.
 
== GRIDGEN by Pavel Sakov ==
 
 
A C program for creating curvilinear orthogonal grids with an arbitrary number of corners
 
http://www.marine.csiro.au/~sakov/
(scroll down Pavel's page to the section on "orthogonal grid generation")

Latest revision as of 23:06, 20 June 2008

Grid Generation

To create a grid, you must understand how the variables are placed on it and where the boundaries lie relative to it. Here is a diagram of it:

Whole grid.png

The thick lines denote the outer boundary of the grid, though some tools may draw the boundary through the rho points lying outside the box. If your domain has walls, the walls will be where the thick line is. If your domain is periodic, the periodicity is from one thick line to the next.

Note Note that there are Lm by Mm computational points. If you want to create a grid that's neatly divisible by powers of 2, make sure Lm and Mm have those factors.

Grid Generation Software

Several software packages are available to generate the orthogonal curvilinear grids that ROMS requires.


SEAGRID by Chuck Denham

A GUI-based Matlab program for creating curvilinear orthogonal grids with 4 corners SEAGRID includes tools to create ROMS NetCDF grid files. See seagrid for more information.


GRIDGEN by Pavel Sakov

A C program for creating curvilinear orthogonal grids with an arbitrary number of corners.


Bathymetry

The bathymetry for ROMS is measured positive downwards, from a datum such as mean sea level (MSL). For a 'typical' ROMS application, the bathymetry would consist of all positive values. Also, for a 'typical' application, the bathymetry can not have values of 0 or any negative values. Most users would set some minimum 'clipping' depth and not allow the values of h to be less than that depth. However, if an application requires land, i.e. values of h that are negative, then the user is required to activate the WET_DRY CPP option.


Land/Sea Masking