Ocean Modeling Discussion

ROMS/TOMS

Search for:
It is currently Tue May 22, 2018 2:43 am




Post new topic Reply to topic  [ 10 posts ] 

All times are UTC

Author Message
PostPosted: Wed Feb 07, 2018 5:15 pm 
Offline

Joined: Tue Aug 04, 2015 4:42 pm
Posts: 30
Location: UMAR, Mexico
Hi ROMS users!
I'm working with SeaGrid, in my map I want to mask a part of the ocean, like it was a land mask. Already I'm doing it clicking on a each ocean cell where that I want do the mask, but I have many cells (because my resolution is 1/24°) and my masking will be very slow.
I wonder if exist an other method to do the mask in a specific area, if I don't want to click cell by cell?
Somebody know how? Thanks in advance.
I add my grid, and a select the part that i want to mask.

Mar.Mo.


Attachments:
Screenshot.jpg
Screenshot.jpg [ 392.4 KiB | Viewed 468 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 6:20 pm 
Offline
User avatar

Joined: Wed Jul 02, 2003 5:29 pm
Posts: 3393
Location: IMS/UAF, USA
Hmm, first, the model requires all angles to be right angles. From what I know of seagrid, your orthogonality errors could be substantial with that grid because you don't ask it to converge.

The matlab editmask has the capability of changing whole rectangles at a time.

I do this stuff outside matlab. Just figure out the patch I want to change and code it up. This is Python, but you can use your language of comfort (you have one, right???):
Code:
import numpy as np
import netCDF4
import sys

ncfile = 'grid_Arctic_2.nc'
nc = netCDF4.Dataset(ncfile, 'a', format='NETCDF3_CLASSIC')

mask_rho[828:980,640:] = 0
mask_rho[837:932,571:] = 0
mask_rho[932:1011,658:] = 0

nc.variables['mask_rho'][:] = mask_rho

nc.close()


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 10, 2018 1:04 am 
Offline

Joined: Tue Aug 04, 2015 4:42 pm
Posts: 30
Location: UMAR, Mexico
Hi Kate:
So many thanks for your help, I had not known that the model requires all angles to be right angles. I already corrected this, for the other hand I could mask the sea in matlab, based on your code. Thanks.

But I have a question, Do you know how can I save the netcdf file with the new variable (already edited)?
Thanks in advance.

Mar.Mo.

This is my code:

%% Load Netcdf file
ncfile ='/home/ahumada/roms-3.7/matlab/seagrid/GT4_roms_grd.nc'

nc=netcdf(ncfile)
ncdump(nc)

% extract variable

latr=nc{'lat_rho'}(:,:);
lonr=nc{'lon_rho'}(:,:);
mask_rho=nc{'mask_rho'}(:);
h=nc{'h'}(:,:);

%% mask

% nombre de la variable(renglon i:renglon n, columna i: columna n)= O
% cero es tierra

mask_rho(387:432,203:347) = 0
mask_rho(327:432,386:720) = 0
mask_rho(139:327,641:720) = 0
mask_rho(173:326,534:640) = 0
mask_rho(161:180,543:557) = 0
mask_rho(161:174,558:597) = 0
mask_rho(182:326,506:533) = 0
mask_rho(318:326,500:505) = 0


latr=nc{'lat_rho'}(:,:);
lonr=nc{'lon_rho'}(:,:);
h=nc{'h'}(:,:);
h=h.*mask_rho;

figure(1)
pcolor(lonr, latr,h);
colormap('jet');
hold on
shading interp

c=colorbar('SouthOutside');


Attachments:
Screenshota.png
Screenshota.png [ 116.91 KiB | Viewed 430 times ]
Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 11, 2018 11:27 am 
Offline

Joined: Fri Nov 14, 2003 4:57 pm
Posts: 176
Location: UCLA, USA
Is this the kind of grid you want to generate?


Attachments:
File comment: Is this the grid you want?
EastPac_curv_grid.png
EastPac_curv_grid.png [ 122.8 KiB | Viewed 413 times ]
Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 11, 2018 11:53 am 
Offline

Joined: Fri Nov 14, 2003 4:57 pm
Posts: 176
Location: UCLA, USA
The procedure for generating ROMS land mask from USGS coastline data described here:
https://www.myroms.org/forum/viewtopic.php?f=23&t=3878&p=14908


Attachments:
File comment: This is ready-to-go version of the same mask post-processed by single_connect and commit_rmask.
EastPac_curv_mask1.png
EastPac_curv_mask1.png [ 4.05 KiB | Viewed 413 times ]
File comment: This is "raw" mask generated by gshhs_to_roms_mask from USGS coastline data as seen in grid-index coordinates (basically by ncview)
EastPac_curv_mask.png
EastPac_curv_mask.png [ 5 KiB | Viewed 413 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 14, 2018 5:46 pm 
Offline

Joined: Tue Aug 04, 2015 4:42 pm
Posts: 30
Location: UMAR, Mexico
Hi Alexander F. Shchepetkin:
So many thanks for your help. Yes, it is the kind of grid that I want to create.
I followed your advice to do it with the new tools. But I had have some problems with the mpc compile.

I followed the README.compiling file, but when I compile mpc I get:

mpc.f:335:18: Error: Syntax error in IF-expression at (1)
mpc.f:336:19: Error: Syntax error in IF-expression at (1)
mpc.f:337:20: Error: Syntax error in IF-expression at (1)
mpc.f:338:21: Error: Syntax error in IF-expression at (1)
mpc.f:339:22: Error: Syntax error in IF-expression at (1)
mpc.f:340:23: Error: Syntax error in IF-expression at (1)
mpc.f:343:19:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:344:18:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:345:17:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:346:16:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:347:15:

endif ! After this moment "i" is
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:348:14:

endif ! index of the last character
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:349:13:

endif ! of Fortran type declaration
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:350:12:

endif ! which may be either "real",
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:351:11:

endif ! "integer", or "character"..
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:355:10:

do while (j < length .and. str(j)==' ')
1
Error: Unclassifiable statement at (1)
mpc.f:357:13:

enddo ! first non-blanc str
1
Error: Expecting END IF statement at (1)
mpc.f:374:17: Error: Syntax error in IF-expression at (1)
mpc.f:377:12:

do while( str(is) == ' ' .and. is < length)
1
Error: Unclassifiable statement at (1)
mpc.f:379:15:

enddo
1
Error: Expecting END IF statement at (1)
mpc.f:381:12:

do while( str(ie+1) /= ' ' .and. str(ie+1) /= ','
1
Error: Unclassifiable statement at (1)
mpc.f:384:15:

enddo
1
Error: Expecting END IF statement at (1)
mpc.f:386:19: Error: Syntax error in IF-expression at (1)
mpc.f:391:14:

bffr(k)=str(k+is-1)
1
Error: Unclassifiable statement at (1)
mpc.f:397:16:

str(k+isft)=str(k) ! "isft", then move the rest
1
Error: Unclassifiable statement at (1)
mpc.f:400:14:

str(i+1)='(' ! insertion, adjust the length
1
Error: Unclassifiable statement at (1)
mpc.f:401:14:

str(i+2)='l' ! of the line accordingly,
1
Error: Unclassifiable statement at (1)
mpc.f:402:14:

str(i+3)='e' ! then insert the new-style
1
Error: Unclassifiable statement at (1)
mpc.f:403:14:

str(i+4)='n' ! size specification.
1
Error: Unclassifiable statement at (1)
mpc.f:404:14:

str(i+5)='='
1
Error: Unclassifiable statement at (1)
mpc.f:406:16:

str(i+k+5)=bffr(k)
1
Error: Unclassifiable statement at (1)
mpc.f:408:14:

str(i+ie-is+7)=')'
1
Error: Unclassifiable statement at (1)
mpc.f:416:16:

str(k+isft)=str(k)
1
Error: Unclassifiable statement at (1)
mpc.f:420:14:

str(i+1)='('
1
Error: Unclassifiable statement at (1)
mpc.f:421:14:

str(i+2)='k'
1
Error: Unclassifiable statement at (1)
mpc.f:422:14:

str(i+3)='i'
1
Error: Unclassifiable statement at (1)
mpc.f:423:14:

str(i+4)='n'
1
Error: Unclassifiable statement at (1)
mpc.f:424:14:

str(i+5)='d'
1
Error: Unclassifiable statement at (1)
mpc.f:425:14:

str(i+6)='='
1
Error: Unclassifiable statement at (1)
mpc.f:427:16:

str(i+k+6)=bffr(k)
1
Error: Unclassifiable statement at (1)
mpc.f:429:14:

str(i+ie-is+8)=')'
1
Error: Unclassifiable statement at (1)
mpc.f:459:16:

elseif ( str(j) /= '(' .and. ( str(j) == ' ' .or.
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:490:16:

str(k+isft)=str(k) ! isft symbols to the right
1
Error: Unclassifiable statement at (1)
mpc.f:493:16:

str(k)=' ' ! and increase length of
1
Error: Unclassifiable statement at (1)
mpc.f:498:14:

str(i+1)='('
1
Error: Unclassifiable statement at (1)
mpc.f:499:14:

str(i+2)='k'
1
Error: Unclassifiable statement at (1)
mpc.f:500:14:

str(i+3)='i'
1
Error: Unclassifiable statement at (1)
mpc.f:501:14:

str(i+4)='n'
1
Error: Unclassifiable statement at (1)
mpc.f:502:14:

str(i+5)='d'
1
Error: Unclassifiable statement at (1)
mpc.f:503:14:

str(i+6)='='
1
Error: Unclassifiable statement at (1)
mpc.f:504:14:

str(i+7)=type
1
Error: Unclassifiable statement at (1)
mpc.f:505:14:

str(i+8)=')'
1
Error: Unclassifiable statement at (1)
mpc.f:507:13:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:508:11:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:613:17: Error: Syntax error in IF-expression at (1)
mpc.f:615:16:

elseif (str(i) == '.' .and. lswtch) then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:618:13:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:626:19: Error: Syntax error in IF-expression at (1)
mpc.f:628:18:

elseif (str(m) /= ' ') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:630:15:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:633:30:

if ( lswtch .or. str(m) < 'A' .or. ! Cond.(3)
1
Error: Syntax error in IF-expression at (1)
mpc.f:641:21: Error: Syntax error in IF-expression at (1)
mpc.f:643:20:

elseif (str(m) /= ' ') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:645:17:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:650:21: Error: Syntax error in IF-expression at (1)
mpc.f:653:16:

do while (str(i)==' ' .and. i<length)
1
Error: Unclassifiable statement at (1)
mpc.f:655:19:

enddo
1
Error: Expecting END IF statement at (1)
mpc.f:656:24: Error: Syntax error in IF-expression at (1)
mpc.f:660:20:

elseif (str(m) == '_') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:670:23: Error: Syntax error in IF-expression at (1)
mpc.f:671:25: Error: Syntax error in IF-expression at (1)
mpc.f:672:20:

str(m )='D'
1
Error: Unclassifiable statement at (1)
mpc.f:673:20:

str(m+1)='0'
1
Error: Unclassifiable statement at (1)
mpc.f:676:22:

str(i)=str(i+1)
1
Error: Unclassifiable statement at (1)
mpc.f:678:24:

elseif (str(m+1) == 'e') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:679:20:

str(m)='D'
1
Error: Unclassifiable statement at (1)
mpc.f:682:22:

str(i)=str(i+2)
1
Error: Unclassifiable statement at (1)
mpc.f:685:19:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:686:20:

elseif ( str(m) < 'A' .or. ( str(m) > 'Z'. and.
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:689:16:

do while(str(m-1) == ' ')
1
Error: Unclassifiable statement at (1)
mpc.f:693:18:

str(i+2)=str(i)
1
Error: Unclassifiable statement at (1)
mpc.f:695:16:

str(m)='_'
1
Error: Unclassifiable statement at (1)
mpc.f:696:16:

str(m+1)='8'
1
Error: Unclassifiable statement at (1)
mpc.f:698:17:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:699:15:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:700:13:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:701:11:

enddo
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:706:17: Error: Syntax error in IF-expression at (1)
mpc.f:707:39:

scratch(i:i)=char(ichar(str(i))+case_fold)
1
Error: Syntax error in argument list at (1)
mpc.f:708:72: Error: Unexpected ELSE statement at (1)
mpc.f:709:12:

scratch(i:i)=str(i)
1
Error: Unclassifiable statement at (1)
mpc.f:710:13:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:794:15: Error: Syntax error in IF-expression at (1)
mpc.f:796:10:

do while (str(i) == ' ' .and. i < length)
1
Error: Unclassifiable statement at (1)
mpc.f:798:13:

enddo
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:799:17: Error: Syntax error in IF-expression at (1)
mpc.f:802:12:

do while (str(i) == ' ' .and. i < length)
1
Error: Unclassifiable statement at (1)
mpc.f:804:15:

enddo
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:805:19: Error: Syntax error in IF-expression at (1)
mpc.f:807:14:

do while (str(i) == ' ' .and. i < length)
1
Error: Unclassifiable statement at (1)
mpc.f:809:17:

enddo
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:811:21: Error: Syntax error in IF-expression at (1)
mpc.f:820:18:

str(i+j-1)=scratch(j:j)
1
Error: Unclassifiable statement at (1)
mpc.f:823:17:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:824:15:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:825:13:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:826:11:

endif
1
Error: Expecting END PROGRAM statement at (1)
mpc.f:842:37: Error: Expected a right parenthesis in expression at (1)
mpc.f:844:37: Error: Expected a right parenthesis in expression at (1)
mpc.f:855:19: Error: Syntax error in IF-expression at (1)
mpc.f:857:18:

elseif (str(k) == ',') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:859:18:

elseif (str(k) == '=') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:861:18:

elseif (str(k) == '/') then
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:863:18:

elseif (str(k) == '+' .or.
1
Error: Unexpected junk after ELSE statement at (1)
mpc.f:867:15:

endif
1
Error: Expecting END DO statement at (1)
mpc.f:909:37: Error: Expected a right parenthesis in expression at (1)
mpc.f:911:38: Error: Expected a right parenthesis in expression at (1)
mpc.f:914:12:

str(i)=' '
1
Error: Unclassifiable statement at (1)
mpc.f:916:10:

str(6)='&'
1
Error: Unclassifiable statement at (1)
mpc.f:919:12:

str(i-m)=str(i)
1
Error: Unclassifiable statement at (1)
mpc.f:922:37: Error: Expected a right parenthesis in expression at (1)
mpc.f:924:37: Error: Expected a right parenthesis in expression at (1)
make: *** [mpc] Error 1


Why do I get this error?
Thanks in advance for your help.

Mar.Mo.


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 14, 2018 11:25 pm 
Offline

Joined: Fri Nov 14, 2003 4:57 pm
Posts: 176
Location: UCLA, USA
The reason why you have these compiling problems is a faulty version of mpc.F supplied
with the package at some point in the past. This was corrected, but it appears that the
old version came back because at some point the web page was restored from the backup
after disk failure and I did not realize that this happened. At this moment I do not
have access to the web server to replace tar file, so use file "tools.tar" attached to
this response.

Note that a Matlab grid generation tool which was used to make the grid in the previous
post is also available from the same web suite
http://people.atmos.ucla.edu/alex/ROMS/grid_gui.tar
although it is relatively new and lacks instructions - a README file is being written,
but not included into the package yet. It is basically a tool to create analytical
grid using staged conformal transformations. Setting all weird parameters to zero

cent_lat = EWtpr = NStpr = cushn1 = cushn2 = cushn3 = cushn4 = 0

reverts it to easy_grid type of tool: it creates a patch of Mercator grid transferred
to user-specified location and rotated by user-specified azimuth angle.

Optionally the initial rectangular patch on Mercator plane can be deformed into
a desired shape by two kind of transforms:

(i) "tapering" in either direction - rectangle turns into a sector of polar coordinates
with simultaneous exponential stretching along the radial direction (delta r is
proportional to r), and

(ii) "cushioning" - rectangle becomes convex in one direction, concave in the other
(or vice versa, depending whether parameter cushn is positive or negative).
This is actually transform into elliptic coordinates: imagine a family of confocal ellipses
and a family of hyperbolae with the same foci. It can be proven that ellipses and
hyperbolae intersect each other at right angle. This is the basis.

Parameter cushn controls the location of foci:

cushn=0 means that they are infinitely
far away - rectangle remains rectangle and nothing happens;

cushn > 0 makes them approach from infinity along x-axis - actually places the foci
on the horizontal line passing through point (xctr,yctr) and at equal distance from
the point, so the rectangle become concave in eastern and western side (they become
hyperbolae) and convex on northen and southern (they become cutoffs of ellipses).
Now exactly depends on (xctr,yctr).

cushn < 0 along y-axis -- similarly, but everything is rotated
90 degrees.

It is a bit tricky to control, but after some practice you can fit very weird shapes.

Couple tips:

1. The boundaries of the map are determined automatically based on current grid
configuration. Once the desired geographical region is captured unclick the "redraw map"
box on top -- this would speed up the drawing by a factor of 100 LITERALLY(!) because
map does not need to be redrawn every time when you hit "update" button.

2. Leaving one of the four boxes, nx, ny, size_x, size_y, blank makes the tool to calculate
the missing value from the condition of isotropy of the grid: dx = dy EVERYWHERE (same
as pm == pn EVERYWHERE). This is very useful. Of course, if size_x, size_y are both
specified, but one of nx,ny is not, then isotropy is not exact because of rounding
to the nearest integer; but is nx,ny are both specified, while one of size_x,size_y left
blank, then isotropy is perfect. THIS IS HOW I ALWAYS RECOMMEND to do it at the end:
at first specify both size_x,size_y, and leave nx blank, play with setting until
you like it, then see Matlab command window to figure nx (the tool always prints the
computed value), put nx into the box, but erase size_x or size_y -- the tool will
adjust its value to make the grid be perfectly isotropic.

3. UPDATE button draws the new contour on top of the old (alternating between red and
magenta colors). This is useful to visualize incremental change, so you can accept or
reverse it. Hitting UPDATE button second time without changing any of the parameters
makes single contour.

4. The contours are actually double lines exactly 1dx or 1dy apart from each other.
this is useful because one can use Matlab zoom facility to check how the edge of
the grid is placed relative to the coastline: ideally the coastline should be in
between the double lines - in this case there will be EXACTLY 1 row of mask points.

5. BREXIT means "Break and Exit" this button just quits the tool without doing anything
else, i.e., it does not trigger saving into the file.


Attachments:
File comment: source code
tools.tar [1.48 MiB]
Downloaded 15 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 14, 2018 11:35 pm 
Offline

Joined: Fri Nov 14, 2003 4:57 pm
Posts: 176
Location: UCLA, USA
you can fit weird shapes after some practice...


Attachments:
File comment: Gulf of Mexico grid optimized to receive Gulf Stream inflow from a model of lower resolution.
GOM_curv1_grid.png
GOM_curv1_grid.png [ 63.53 KiB | Viewed 351 times ]
File comment: Black Sea
black_sea_conf5.jpg
black_sea_conf5.jpg [ 129.88 KiB | Viewed 351 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 15, 2018 7:21 pm 
Offline

Joined: Tue Aug 04, 2015 4:42 pm
Posts: 30
Location: UMAR, Mexico
Dear Alexander:
Thanks a lot for your help, it was and will be so helpful.
Already with the new tools, I could compile mpc. But now when I type make, I get:
--------------------------------------------------------------
[ahumada@master tools]$ make
gfortran -fopenmp -fno-second-underscore -c -I/usr/local/lib -O3 def_clim_file.f
def_clim_file.f:538:40:

ierr=nf_create(trgfile, nf_netcdf4, nctarg)
1
Error: Symbol ‘nf_netcdf4’ at (1) has no IMPLICIT type
make: *** [def_clim_file.o] Error 1
--------------------------------------------------------------
I don't konow if is cause by my netcdf libreries or if is def_clim_file.f file problem.
How can I solve this problem?. Thanks in advance.
Best regards.

Scarlett


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 16, 2018 9:24 am 
Offline

Joined: Fri Nov 14, 2003 4:57 pm
Posts: 176
Location: UCLA, USA
Quote:
Error: Symbol ‘nf_netcdf4’ at (1) has no IMPLICIT type


This one you should be able to overcome yourself. At first, my package comes with several
README.something files: just look through them. Among them is README.compiling which
tells what to do.

Then, it is quite obvious that your netcdf.inc file does not contain definitions for netCDF 4
functions, so you can either

(i) preferred way, install and use netCDF library with full netDF4/hdf5 capabilities, or

(ii) handicapped way (ok as a temporary fix): exclude all functionality from the package
which requires netCDF4 - basically keep trying to compile everything by "make", see which
ones do not compile with errors line this, and exclude them from INST_LIST in Makefile.

Some people find compiling netCDF 4 with hdf5 and zlib too tedious. In reality it takes
about 20 minutes, using mostly computer mouse for copy-pasting and almost without
ever touching keyboard. See README.compiling_sequence inside the attached
netcdf4_help.tar.


Attachments:
File comment: help for zlib-hdf5-netcdf compiling
netcdf4_help.tar [20 KiB]
Downloaded 15 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group