generating nested grid contacts

Discussion of how to use ROMS on different regional and basin scale applications.

Moderators: arango, robertson

Post Reply
Message
Author
undave
Posts: 11
Joined: Mon Jul 16, 2007 5:30 pm
Location: Florida Gulf Coast University

generating nested grid contacts

#1 Unread post by undave »

I am having problems generating the contact points for nested grids. I tried many approaches. I included the matlab script below for a simplified version following the approach given in the COAWST manual. I have been able to generate a nested grid and contacts from an old Seagrid created grid, but not from new donor and recipient grids. The new donor grid and recipient grid look good, i.e. no missing values or other obvious problems, but when trying to generate the contacts, I get the error:
Reference to non-existent field 'contact'.

Error in contact (line 316)
dg = S.contact(cr).donor_grid;

I could not find a reference to the contact field in either the procedure outlined in the COAWST manual, nor was it created when I used the c_contact.m script to create the contact file first. I checked the old grid that was created from Seagrid, and there is no contact field. I wonder if someone could give me some advice as to what I am doing wrong?

Also, when using fine2coarse.m from a recent COAWST/Tools checkout, the command fails when trying to write the field 'x_psi' and I am not able to figure out why (see error message below). However, if I use fine2coarse.m from a checkout of ROMS from last year, the command works. I switched to the ROMSMatlab routines for the procedures in the matlab script below.

Error using netcdflib
The number of elements implied by the count argument (63984) does not
equal the number of data elements (64491).

Error in netcdf.putVar (line 84)
netcdflib(funcstr,ncid,varid,varargin{:});

Error in nc_write>nc_write_matlab (line 247)
netcdf.putVar(ncid, varid, start, count, f)

Error in nc_write (line 68)
status = nc_write_matlab(ncfile, Vname, f, Tindex, Info);

Error in fine2coarse (line 366)
status = nc_write (Gout, field, C.(field));

Error in makecoarse (line 11)
F=fine2coarse(fu,'Calusa_grid_donor_COAWST.nc',ref,3,1293,3,1243);


%Matlab script to generate user grid, donor grid, and refined grid

%use mask and bathymetry from a grid made with Gridbuilder

fug='user_grid_from_gridbuilder - Copy.nc';
netcdf_load(fug);

lon_rhoGB=lon_rho;
lat_rhoGB=lat_rho;
h_GB=h;
mask_rhoGB=mask_rho;

clearvars -EXCEPT lon_rhoGB lat_rhoGB h_GB mask_rhoGB;

%new grid to be created
roms_grid='swf_user_grid.nc';


xl=min(lon_rhoGB(:));
xr=max(lon_rhoGB(:));
yb=min(lat_rhoGB(:));
yt=max(lat_rhoGB(:));

numx=1250-1;
numy=1300-1;

dx=(xr-xl)/numx; dy=(yt-yb)/numy;
[lon, lat]=meshgrid(xl:dx:xr, yb:dy:yt);


rho.lon=lon;
rho.lat=lat;
rho.mask=zeros(size(rho.lon)); %this will be set later, as in the COAWST MANUAL
rho.depth=zeros(size(rho.lon))+100; %this will be set later, as in the COAWST MANUAL
spherical='T';
projection.name='mercator';
m_proj('Mercator')

save tempgrid rho spherical projection
eval(['mat2roms_mw(''tempgrid.mat'',''',roms_grid,''');'])



% I could not get scatteredInterpolant.m to work, keep getting error that
%The input points must be specified in column-vector format, although they seem to be
%in column format, so I used griddata instead

% F=scatteredInterpolant(double(lon_rhoGB(:)),double(lat_rhoGB(:)),...
% double(mask_rhoGB),'nearest');
% roms_mask=F(lon,lat);

roms_mask=griddata(lon_rhoGB(:),lat_rhoGB(:),mask_rhoGB(:),lon,lat,'nearest');

% figure
% pcolorjw(lon,lat,roms_mask)
% shading flat
% xlabel('longitude')
% ylabel('latitude')

water = double(roms_mask);
u_mask = water(1:end-1,:) & water(2:end,:);
v_mask= water(:,1:end-1) & water(:,2:end);
psi_mask= water(1:end-1,1:end-1) & water(1:end-1,2:end) & water(2:end,1:end-1) & water(2:end,2:end);
ncwrite(roms_grid,'mask_rho',roms_mask);
ncwrite(roms_grid,'mask_u',double(u_mask));
ncwrite(roms_grid,'mask_v',double(v_mask));
ncwrite(roms_grid,'mask_psi',double(psi_mask));



h=griddata(lon_rhoGB,lat_rhoGB,h_GB,lon,lat);
h(isnan(h))=5;
%smooth h a little
h(2:end-1,2:end-1)=0.2*(h(1:end-2,2:end-1)+h(2:end-1,2:end-1)+h(3:end,2:end-1)+h(2:end-1,1:end-2)+h(2:end-1,3:end));


ncwrite(roms_grid,'h',h);

%I then edited the mask in editmask


%create donor grid
ref=5;

fu='swf_user_grid.nc';

F=fine2coarse(fu,'Calusa_grid_donor.nc',ref,3,1293,3,1243);

%create recipient grid

F=grid_extract('swf_user_grid.nc','Calusa_grid_ref.nc',521,775,914,1231);

%create contacts

Gnames={'Calusa_grid_donor.nc','Calusa_grid_ref.nc'}
% c_contact('Calusa_contact.nc',true,2)
[S,G]=contact(Gnames,'Calusa_contact.nc');






Thanks for any help or advice,

David

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

Re: generating nested grid contacts

#2 Unread post by jcwarner »

so i know that we tested all this stuff before the workshop in Feb, but maybe we missed something. I dont do the exact procedure you show, i dont use the F=grid_extract.. command. so i am not sure if that is the problem. but here is what worked for our H Sandy test case.

after you make the parent grid, you need to select the 4 corners for the child child.
these are Istr, Iend, Jstr, Jend.
then set ref_ratio=3;
roms_child_grid='Sandy_roms_grid_ref3.nc';
F=coarse2fine('Sandy_roms_grid.nc','Sandy_roms_grid_ref3.nc', ...
ref_ratio,Istr,Iend,Jstr,Jend);
Gnames={'Sandy_roms_grid.nc','Sandy_roms_grid_ref3.nc'};
[S,G]=contact(Gnames,'Sandy_roms_contact.nc');
and that worked.


my Gnames used (), not {} . maybe that did it?
-j

undave
Posts: 11
Joined: Mon Jul 16, 2007 5:30 pm
Location: Florida Gulf Coast University

Re: generating nested grid contacts

#3 Unread post by undave »

John, thanks for your response. I redid the grids, creating a coarse grid first, then using coarse2fine.m to make the refined grid and was able to successfully make the contact file. Before I had created the high resolution "user" grid first because that was suggested at the COAWST workshop. For other users info, I did have to edit the write_contact.m to comment out the check for 'S.contact.hybrid' and just left
hybrid_nesting = false;
and then it created the contact file.

Thanks!
David

Post Reply