How to Create a Surface from a grid file

Hi, I have a problem, I tried to generate a surface from a gridded data (bathymetry from GEBCO *nc file), interpolating the grid to construct lines, but it results kind impossible. I appreciate your help.

Hi,

I’m not familiar with the details of the format but standard geologic data will be Cartesian coordinates or latitude, longitude, and height which can be mapped to Cartesian coordinates for Cubit. This stackoverflow answer netcdf - plot gebco data in python basemap - Stack Overflow seems like it could be a basis for python script to read the data.

Once you have the points in python you can loop through constant latitude values and create splines through the points. The format of the command is

create curve spline location position 0 0 0 position 1 1 0 position 2 0 0

The keyword position can be shortened to pos to reduce the command line length.
or in python something like:

all_curves_in_order = []
for constant_lat_values in model:
    coord_string = ""
    for coord in constant_lat_values:
        point = f" pos {coord[0]} {coord[1]} {coord[2]}"
        coord_string += point

      cubit.cmd( f"create curve spline location {coord_string}")
      last_curve = cubit.get_last_id("curve")
      all_curves_in_order.append(last_curve)

This avoids creating vertices which can be time consuming.

Then skin all the constant latitude curves to create a surface.

cubit.cmd( f"create surface skin curve {all_curves_in_order}")

This is just an outline. I have not tested any of this code but it should give you a starting direction.

1 Like

Thanks a lot, now I have a problem with “skin curve”, when I don’t have parallel curves, or semi-close curves.

Can you send a picture of the curves or save the .cub5 file and upload that to this forum post? I was assuming that the curves would be at a constant latitude or longitude value. Do you have any curves that intersect? That will be a problem. I wouldn’t think that near intersection should be a problem.

ContBathymetry .csv (477.5 KB)

Hi, I attached the ContBathymetry.csv file, separated by simple space, where the 1st column correspond to Longitude, 2nd column correspond to Latitude and the 3rd column correspond to Elevation. This file was shortened from gebco file, please your help of how can I generate a surface from these, the file is setting by latitude in descending order.

I wrote a small python script to create all the vertices. Looking at the cross-sectional data it looks like there are many interior loops and even self-intersections. It looks like this could represent multiple surfaces. You will need more information than is present in the CSV file to create surface data from these points.

cubit.cmd("reset")
with open("~/Downloads/ContBathymetry.csv", "r") as fp:
    line = fp.readline()
    while line:
        cubit.cmd(f"create vertex {line}")
        line = fp.readline()
2 Likes