Skip to content

Commit 19aa6ab

Browse files
committed
A new feature to enable plot2d to show the line depth in 2D. This feature requires the updates in drawLine2d in subsystem.py in MoorPy to be integrated.
- The user can provide a set value of maximum depth to show the most transparent part of the line. By default, this is set to the water depth. But sometimes, we might be interested in limiting the depth to the first 200m for instance or to show the depth of which it can be affected by marine growth (e.g., -170m). This is added as a variable in kwargs called max_line_depth.
1 parent 166fa76 commit 19aa6ab

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

famodel/project.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,7 @@ def updatePositions(self):
21532153
platform.r[1] = platform.body.r6[1]
21542154

21552155

2156-
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):
2156+
def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True, plot_boundary=True, color_lineDepth=False, bare=False, axis_equal=True,save=False,**kwargs):
21572157
'''Plot aspects of the Project object in matplotlib in 3D.
21582158
21592159
TODO - harmonize a lot of the seabed stuff with MoorPy System.plot...
@@ -2182,6 +2182,7 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
21822182
bath_levels = kwargs.get('bath_levels', None)
21832183
show_legend = kwargs.get('show_legend', True)
21842184

2185+
max_line_depth = kwargs.get('max_line_depth', None) # max depth for line coloring if color_lineDepth is True
21852186

21862187
# if axes not passed in, make a new figure
21872188
if ax == None:
@@ -2250,6 +2251,17 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
22502251
ax.fill(env['x'], env['y'], edgecolor=edgecolor, facecolor='none', linestyle='dashed', lw=0.8, label='Platform Envelope')
22512252

22522253
if plot_moorings:
2254+
depth_cmap_settings = None
2255+
if color_lineDepth:
2256+
if max_line_depth is None:
2257+
bath_depth = True
2258+
if plot_bathymetry:
2259+
raise ValueError("Cannot use depth-based line coloring with plot_bathymetry=True. Disable bathymetry to avoid confusion.")
2260+
depth_cmap_settings = {
2261+
"cmap": "Blues",
2262+
"vmin": max_line_depth if max_line_depth else -np.max(self.grid_depth),
2263+
"vmax": 0
2264+
}
22532265
for mooring in self.mooringList.values():
22542266
for name, env in mooring.envelopes.items():
22552267
#if 'shape' in env: # if there's a shapely object
@@ -2284,16 +2296,27 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
22842296

22852297
if mooring.ss:
22862298
mooring.ss.drawLine2d(0, ax, color="self", endpoints=False,
2287-
Xuvec=[1,0,0], Yuvec=[0,1,0],label=labs)
2299+
Xuvec=[1,0,0], Yuvec=[0,1,0], depth_cmap_settings=depth_cmap_settings, label=labs)
22882300
elif mooring.parallels:
22892301
for i,line in enumerate(lineList):
22902302
line.drawLine2d(0, ax, color="self",
2291-
Xuvec=[1,0,0], Yuvec=[0,1,0],label=labs[i])
2303+
Xuvec=[1,0,0], Yuvec=[0,1,0], depth_cmap_settings=depth_cmap_settings, label=labs[i])
22922304

22932305
else: # simple line plot
22942306
ax.plot([mooring.rA[0], mooring.rB[0]],
22952307
[mooring.rA[1], mooring.rB[1]], 'k', lw=0.5, label='Mooring Line')
2296-
2308+
2309+
# ---- Add colorbar for line depth ----
2310+
if depth_cmap_settings is not None and not bare:
2311+
import matplotlib.cm as cm
2312+
import matplotlib.colors as mcolors
2313+
sm = cm.ScalarMappable(cmap=cm.get_cmap(depth_cmap_settings["cmap"]),
2314+
norm=mcolors.Normalize(vmin=depth_cmap_settings["vmin"],
2315+
vmax=depth_cmap_settings["vmax"]))
2316+
sm.set_array([])
2317+
cbar = plt.colorbar(sm, ax=ax, fraction=0.04)
2318+
cbar.set_label("Line Depth (m)")
2319+
22972320
if plot_anchors:
22982321
for anchor in self.anchorList.values():
22992322
ax.plot(anchor.r[0],anchor.r[1], 'mo',ms=2, label='Anchor')

0 commit comments

Comments
 (0)