Skip to content

Commit 743aae4

Browse files
committed
Merge remote-tracking branch 'origin/main' into new_base
2 parents 52908f8 + ba4fe27 commit 743aae4

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

famodel/geography.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def writeBathymetryFile(moorpy_bathymetry_filename, bathXs, bathYs, bath_depths,
357357

358358

359359

360-
def getLeaseAndBathymetryInfo(lease_name, gebco_file, bath_ncols=100, bath_nrows=100):
360+
def getLeaseAndBathymetryInfo(lease_name, bathymetry_file, bath_ncols=100, bath_nrows=100, write_bathymetry=True):
361361

362362
# initialize the conventional lat/long CRS
363363
latlong_crs = getLatLongCRS()
@@ -371,25 +371,35 @@ def getLeaseAndBathymetryInfo(lease_name, gebco_file, bath_ncols=100, bath_nrows
371371
# convert the lease boundary to meters
372372
lease_xs, lease_ys, centroid_utm = convertLatLong2Meters(lease_longs, lease_lats, centroid, latlong_crs, custom_crs, return_centroid=True)
373373

374-
# get bathymetry information from a GEBCO file (or other)
375-
bath_longs, bath_lats, bath_depths, ncols, nrows = getMapBathymetry(gebco_file)
376-
# convert bathymetry to meters
377-
bath_xs, bath_ys, bath_depths = convertBathymetry2Meters(bath_longs, bath_lats, bath_depths, centroid, centroid_utm, latlong_crs, custom_crs, bath_ncols, bath_nrows)
378-
# export to MoorPy-readable file
379-
bathymetryfile = f'bathymetry_{bath_ncols}x{bath_nrows}.txt'
380-
writeBathymetryFile(bathymetryfile, bath_xs, bath_ys, bath_depths)
374+
if write_bathymetry:
375+
# get bathymetry information from a GEBCO file (or other)
376+
bath_longs, bath_lats, bath_depths, ncols, nrows = getMapBathymetry(bathymetry_file)
377+
# convert bathymetry to meters
378+
bath_xs, bath_ys, bath_depths = convertBathymetry2Meters(bath_longs, bath_lats, bath_depths, centroid, centroid_utm, latlong_crs, custom_crs, bath_ncols, bath_nrows)
379+
# export to MoorPy-readable file
380+
bathymetry_file = f'bathymetry_{bath_ncols}x{bath_nrows}.txt'
381+
writeBathymetryFile(bathymetry_file, bath_xs, bath_ys, bath_depths)
382+
383+
ms = mp.System(bathymetry=bathymetry_file)
381384

382385
info = {}
383386
info['lease_longs'] = lease_longs
384387
info['lease_lats'] = lease_lats
385388
info['lease_centroid'] = centroid
389+
info['centroid_utm'] = centroid_utm
386390
info['lease_xs'] = lease_xs
387391
info['lease_ys'] = lease_ys
388-
info['bath_longs'] = bath_longs
389-
info['bath_lats'] = bath_lats
390-
info['bath_xs'] = bath_xs
391-
info['bath_ys'] = bath_ys
392-
info['bath_depths'] = bath_depths
392+
if write_bathymetry:
393+
info['bath_longs'] = bath_longs
394+
info['bath_lats'] = bath_lats
395+
info['bath_xs'] = bath_xs
396+
info['bath_ys'] = bath_ys
397+
info['bath_depths'] = bath_depths
398+
else:
399+
info['bath_xs'] = ms.bathGrid_Xs
400+
info['bath_ys'] = ms.bathGrid_Ys
401+
info['bath_depths'] = ms.bathGrid
402+
393403

394404
return info
395405

@@ -941,7 +951,7 @@ def addState(self, ax, states=[], kwargs={}):
941951
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
942952
lease_name = 'GulfofMaine_ResearchArray'
943953
gebco_file = __location__+'\\..\\geography\\gebco_2024_n44.1458_s41.4761_w-70.9497_e-66.2146.asc'
944-
info = getLeaseAndBathymetryInfo(lease_name, gebco_file)
954+
info = getLeaseAndBathymetryInfo(lease_name, bathymetry_file)
945955

946956

947957
plt.show()

famodel/project.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ def updatePositions(self):
21522152
platform.r[1] = platform.body.r6[1]
21532153

21542154

2155-
def plot2d(self, ax=None, plot_seabed=True,plot_bathymetry=True, plot_boundary=True, bare=False, axis_equal=True,save=False,**kwargs):
2155+
def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True, plot_boundary=True, bare=False, axis_equal=True,save=False,**kwargs):
21562156
'''Plot aspects of the Project object in matplotlib in 3D.
21572157
21582158
TODO - harmonize a lot of the seabed stuff with MoorPy System.plot...
@@ -2176,6 +2176,9 @@ def plot2d(self, ax=None, plot_seabed=True,plot_bathymetry=True, plot_boundary=T
21762176
plot_moorings = kwargs.get('plot_moorings',True)
21772177
plot_cables = kwargs.get('plot_cables',True)
21782178
cable_labels = kwargs.get('cable_labels', False)
2179+
depth_vmin = kwargs.get('depth_vmin', None)
2180+
depth_vmax = kwargs.get('depth_vmax', None)
2181+
bath_levels = kwargs.get('bath_levels', None)
21792182

21802183

21812184
# if axes not passed in, make a new figure
@@ -2187,21 +2190,41 @@ def plot2d(self, ax=None, plot_seabed=True,plot_bathymetry=True, plot_boundary=T
21872190

21882191
# Bathymetry
21892192
if plot_bathymetry:
2193+
if plot_seabed:
2194+
raise ValueError('The bathymetry grid and soil grid cannot yet be plotted at the same time')
21902195
if len(self.grid_x) > 1 and len(self.grid_y) > 1:
2191-
num_levels = 100 # Adjust this value as needed
2192-
X, Y = np.meshgrid(self.grid_x, self.grid_y)
21932196

2194-
contourf = ax.contourf(X, Y, self.grid_depth, num_levels, cmap='Blues', vmin=np.min(self.grid_depth), vmax=np.max(self.grid_depth))
2195-
#contourf = ax.contourf(X, Y, self.grid_depth, num_levels, cmap='Blues', vmin=500, vmax=1300)
2196-
# >>>> TODO: Update the above to add optional inputs for bounds (vmin/vmax) on contour plot colors for bathymetry <<<<
2197-
2197+
X, Y = np.meshgrid(self.grid_x, self.grid_y)
2198+
2199+
num_levels = bath_levels if bath_levels is not None else 50
2200+
vmin = depth_vmin if depth_vmin is not None else np.min(self.grid_depth)
2201+
vmax = depth_vmax if depth_vmax is not None else np.max(self.grid_depth)
2202+
grid_depth = np.clip(self.grid_depth, vmin, vmax)
2203+
2204+
contourf = ax.contourf(X, Y, grid_depth, num_levels, cmap='Blues', vmin=np.min(self.grid_depth), vmax=np.max(self.grid_depth))
2205+
2206+
contourf.set_clim(depth_vmin, depth_vmax)
2207+
21982208
if not bare: # Add colorbar with label
21992209
import matplotlib.ticker as tkr
22002210
cbar = plt.colorbar(contourf, ax=ax, fraction=0.04, label='Water Depth (m)', format=tkr.FormatStrFormatter('%.0f'))
2201-
# if plot_seabed:
2202-
# if len(self.soil_x) > 1 and len(self.soil_y) > 1:
2203-
# sX, sY = np.meshgrid(self.soil_x, self.soil_y)
2204-
# ax.scatter(sX, sY, self.soil_names)
2211+
2212+
2213+
if plot_seabed:
2214+
if plot_bathymetry:
2215+
raise ValueError('The bathymetry grid and soil grid cannot yet be plotted at the same time')
2216+
import matplotlib.colors as mcolors
2217+
soil_types = np.unique(self.soil_names)
2218+
soil_type_to_int = {name: i for i,name in enumerate(soil_types)}
2219+
soil_colors = {'mud':'green', 'hard':'brown'}
2220+
soil_int = np.vectorize(soil_type_to_int.get)(self.soil_names)
2221+
cmap = mcolors.ListedColormap([soil_colors.get(name, 'white') for name in soil_types])
2222+
2223+
X, Y = np.meshgrid(self.soil_x, self.soil_y)
2224+
ax.pcolormesh(X, Y, soil_int, cmap=cmap, shading='auto')
2225+
2226+
soil_handles = [plt.Line2D([0], [0], marker='s', color='w', label=name, markerfacecolor=soil_colors.get(name, 'white'), markersize=10) for name in soil_types if name != '0' ]
2227+
22052228

22062229
if plot_boundary:
22072230
if len(self.boundary) > 1:
@@ -2361,6 +2384,9 @@ def plot2d(self, ax=None, plot_seabed=True,plot_bathymetry=True, plot_boundary=T
23612384
ax.set_aspect('equal',adjustable='box')
23622385

23632386
handles, labels = plt.gca().get_legend_handles_labels()
2387+
if plot_seabed:
2388+
handles += soil_handles
2389+
labels += [h.get_label() for h in soil_handles]
23642390
by_label = dict(zip(labels, handles)) # Removing duplicate labels
23652391
ax.legend(by_label.values(), by_label.keys(),loc='upper center',bbox_to_anchor=(0.5, -0.1), fancybox=True, ncol=4)
23662392
if save:
@@ -4834,17 +4860,10 @@ def FFarmCompatibleMDOutput(self, filename, MDoptionsDict=None, **kwargs):
48344860
else:
48354861
phi = None
48364862

4837-
# Setup nNodes of lines manually <<< TODO: Need to figure out a more automatic way of signing those numbers
4838-
for line in ms_temp.lineList:
4839-
if 0 < line.L < 20:
4840-
line.nNodes = 3
4841-
elif 20 <= line.L < 100:
4842-
line.nNodes = 6
4843-
elif 100 <= line.L < 700:
4844-
line.nNodes = 11
4845-
elif line.L >= 700:
4846-
line.nNodes = 16
4847-
4863+
# Setup nNodes of lines manually based on the segment length desired.
4864+
from moorpy.helpers import lengthAwareSegmentation
4865+
4866+
lengthAwareSegmentation(ms_temp.lineList)
48484867
ms_temp.unload(fileName=filename, phi=phi, MDoptionsDict=MDoptionsDict, outputList=outputList, flag=flag)
48494868

48504869
# rename Body to Turbine if needed

0 commit comments

Comments
 (0)