@@ -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