CHLNDDEV / OceanMesh2D

A two-dimensional triangular mesh generator with pre- and post-processing utilities written in pure MATLAB (no toolboxes required) designed specifically to build models that solve shallow-water equations or wave equations in a coastal environment (ADCIRC, FVCOM, WaveWatch3, SWAN, SCHISM, Telemac, etc.).
https://github.com/sponsors/krober10nd
GNU General Public License v3.0
179 stars 65 forks source link

How do I run example 1 without errors? #192

Closed tng17 closed 3 years ago

tng17 commented 3 years ago

Hi,

I am a newbie to using the mesh generator and was wondering why I get the following errors when I run Example 1.

Reading shapefile with m_shaperead Error using m_shaperead (line 69) Cannot file filename: GSHHS_f_L1.shx

Error in Read_shapefile (line 62) S = m_shaperead(fname{1},reshape(bboxt',4,1));

Error in geodata/ParseShoreline (line 326) polygon_struct = Read_shapefile( obj.contourfile, [], ...

Error in geodata (line 288) obj = ParseShoreline(obj) ;

Error in Example_1_NZ (line 20) gdat = geodata('shp',coastline,'bbox',bbox,'h0',min_el);

I have not changed the structure of the repository, just unzipped it and stored in one of my folders and then ran setup.sh. I also downloaded the m_map package separately and stored it in the OceanMesh2D-Projection folder. GSHHS_f_L1.shx is in a GSHHS folder within the 'utilities' folder. Any help would be much appreciated.

krober10nd commented 3 years ago

Hello! Sounds like the utilities file isn’t added to the general Matlab path. Could you right click on the utilities folder and add this to the genpath?

tng17 commented 3 years ago

@krober10nd Thank you for the quick response. I think I have added to the general MATLAB path. This is my code: % Example_1_NZ: Mesh the South Island of New Zealand clearvars; clc;

addpath('..') addpath(genpath('../utilities/')) addpath(genpath('../datasets/')) addpath(genpath('../m_map/'))

%% STEP 1: set mesh extents and set parameters for mesh. bbox = [166 176; % lon_min lon_max -48 -40]; % lat_min lat_max min_el = 1e3; % minimum resolution in meters. max_el = 100e3; % maximum resolution in meters. max_el_ns = 5e3; % maximum resolution nearshore in meters. grade = 0.35; % mesh grade in decimal percent. R = 3; % number of elements to resolve feature width. %% STEP 2: specify geographical datasets and process the geographical data %% to be used later with other OceanMesh classes... coastline = 'GSHHS_f_L1'; gdat = geodata('shp',coastline,'bbox',bbox,'h0',min_el); %% STEP 3: create an edge function class fh = edgefx('geodata',gdat,... 'fs',R,'max_el_ns',max_el_ns,... 'max_el',max_el,'g',grade); %% STEP 4: Pass your edgefx class object along with some meshing options and % build the mesh... mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1,'nscreen',5,'proj','trans'); mshopts = mshopts.build;

%% STEP 5: Plot it and write a triangulation fort.14 compliant file to disk. % Get out the msh class and put on nodestrings m = mshopts.grd; m = make_bc(m,'auto',gdat,'distance'); % make the boundary conditions plot(m,'type','bd'); % if you want to write into fort.14... % write(m,'South_Island_NZ');

%% STEP 6: Example of plotting a subdomain with bcs bbox_s = [172 176; -42 -39]; plot(m,'type','bd','subdomain',bbox_s)

I have not changed the code at all. And when I right click on the utilities folder, It gives the option to only remove from the path. Do you know what else I could be doing wrong?

tng17 commented 3 years ago

Actually when I changed the filename from GSHHS_f_L1 to GSHHS_l_L1, it worked. For some reason, GSHHS_f_L1 does not exist for me. Do you know why this might be?

krober10nd commented 3 years ago

Hm not sure. Can you try putting the gshhs_f files in a dataset folder instead and then add that dataset folder to the path? Note that by add to path I mean click “add folders and subfolders”button

tng17 commented 3 years ago

Thanks for your reply, I understood what you were saying. I spotted that the name of the files in the GSHHS folder are actually named GSHHS_l_L1 rather than GSHHS_f_L1 (there are 4 files in total in this folder). So, I just edited the example 1 script file and changed the the 'f' to an 'l' and it worked. I guess I haven't done anything wrong, it's just a typo in the script?

krober10nd commented 3 years ago

Actually there should be several instances of GSHHS in the unzipped archive. The "l" or the "f" or the "c" etc. indicates the fidelity of the shoreline. The "f" has the most detail so we put that in there. These files aren't present in your zipped GSHHS?

tng17 commented 3 years ago

Oh I see, thank you. For some reason I have only ''I''. How can I get the other 2 you mentioned?

krober10nd commented 3 years ago

Okay lets redownload this

 wget "http://www.soest.hawaii.edu/pwessel/gshhg/gshhg-shp-2.3.7.zip" -O gshhs.zip
 unzip gshhs.zip

and then add the gshhs folder to the path (with folders and subfolders).

ghss_l is included internally in OM to perform various tests.

tng17 commented 3 years ago

Yes it works now. Thank you so much, legend!

krober10nd commented 3 years ago

@WPringle might want to investigate more as the setup.sh script didn't appear to download the GSHHS files in this case. Perhaps they were already downloaded somewhere else on @tng17 computer?

WPringle commented 3 years ago

Was the setup.sh script run? It should only check for existence inside the datasets directory, or if it happened to be in the path elsewhere.

tng17 commented 3 years ago

Yes I ran the setup,sh script. However, it downloaded only 4 GSHHS files. The GSHHS folder was within the utilities folder.

WPringle commented 3 years ago

Something wrong, maybe the downloading stopped halfway through. Should produce: GSHHS_shp: c f h i l README.TXT [c f h I l are directories]

WPringle commented 3 years ago

Oh yeah the GSHSS folder inside utilities is a different one. Was there anything in datasets directory? If not, then need to check error messages when downloading or maybe the "unzip" command didn't work correctly etc.

tng17 commented 3 years ago

There were 3 files in 'datasets': ak_outerpoly.mat SRTM15+V2.1.nc weir_struct.mat

tng17 commented 3 years ago

Also can I ask, how do you change the dataset and use the same example (Example 2 or 3 in my case)? I have a NetCDF file (.nc) downloaded from the following website: https://portal.emodnet-bathymetry.eu/?menu=19 It seems like I do not have a .shp file, only a .nc file? Do you know how to resolve this?

WPringle commented 3 years ago

just try run setup.sh again. and see what error messages or display messages come up for downloading the GSHSS shoreline

WPringle commented 3 years ago

Also can I ask, how do you change the dataset and use the same example (Example 2 or 3 in my case)? I have a NetCDF file (.nc) downloaded from the following website: https://portal.emodnet-bathymetry.eu/?menu=19 It seems like I do not have a .shp file, only a .nc file? Do you know how to resolve this?

If you want to try a different bathymetry product (seems like you want to use the European emod one) then just switch the .nc file DEM out. You can keep the same GSHSS_f_L1 shape file. Alternatively, you can generate a contour from the DEM and use that as the geodata input

tng17 commented 3 years ago

This is what came up:

Reading shapefile with m_shaperead 179837 Records in file, by 500:

.......................................................................................................................................................................................................................................................................................................................................................................Partitioning the boundary into islands, mainland, ocean Smoothing coastline with 5 point window Reading shapefile with m_shaperead 5707 Records in file, by 500:

...........Partitioning the boundary into islands, mainland, ocean {'Read in meshing boundary: '} {'GSHHS_f_L1'}

Error using internal.matlab.imagesci.nc/openToRead (line 1272) Could not open E42020.nc for reading.

Error in internal.matlab.imagesci.nc (line 121) this.openToRead();

Error in ncinfo (line 88) ncObj = internal.matlab.imagesci.nc(ncFile);

Error in geodata/ParseDEM/getdemvarnames (line 610) finfo = ncinfo(fname);

Error in geodata/ParseDEM (line 458) [xvn, yvn, zvn] = getdemvarnames(fname);

Error in geodata (line 312) obj = ParseDEM(obj) ;

Error in England_fyp_V1 (line 21) gdat = geodata('shp',coastline,'dem',dem,'h0',min_el,...

WPringle commented 3 years ago

So this means your dem: "E42020.nc" does not exist or is not in your path. It read the shape file correctly.

krober10nd commented 3 years ago

I would recommend heading over to the slack channel to discuss this further.

tng17 commented 3 years ago

Thank you for your quick responses @WPringle. Sorry I didn't fully understand what I am meant to do. So if these were my steps (2-3) following Example 1, what would you change so that it would work? (I have added the netCDF file to path).

%% STEP 2: specify geographical datasets and process the geographical data %% to be used later with other OceanMesh classes... dem = 'E42020.nc'; coastline = 'GSHHS_f_L1'; gdat = geodata('dem',dem,'shp',coastline,'h0',min_el,... 'bbox',bbox); %% STEP 3: create an edge function class fh = edgefx('geodata',gdat,... 'fs',R,'max_el_ns',max_el_ns,... 'max_el',max_el,'g',grade);

@krober10nd where can I find this slack channel you mentioned? Apologies, I'm new to all these stuff.

krober10nd commented 3 years ago

Let’s work together in Slack! It’s a faster, simpler way to talk shop, share files, and get work done. Join here: https://join.slack.com/t/oceanmesh2d/shared_invite/zt-mxlhj1cl-i2TBm2SkBcCnDCTHJ9BgTw