Skip to content

Commit 5d94109

Browse files
committed
small bug fixes for MBL and plot2d edits
-small fixes to check if MBL is in dictionary before loading so that you can still load mooring types without an MBL -plot2d add setting for whether to show legend -get legend handles from ax instead of plt.gca()
1 parent fab48cd commit 5d94109

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

famodel/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,8 @@ def MooringProps(mCon, lineTypes, rho_water, g, checkType=1):
795795
# else:
796796
# d_vol = dd['d']
797797
dd['w'] = (dd['m']-np.pi/4*d_vol**2*rho_water)*g
798-
dd['MBL'] = float(dd['MBL'])
798+
if 'MBL' in dd:
799+
dd['MBL'] = float(dd['MBL'])
799800
if 'mooringFamily' in mCon:
800801
raise Exception('type and moorFamily listed in yaml - use type to reference a mooring type in the mooring_line_types section of the yaml and mooringFamily to obtain mooring properties from MoorProps_default.yaml')
801802
elif 'mooringFamily' in mCon:
@@ -862,7 +863,8 @@ def getMoorings(lcID, lineConfigs, connectorTypes, pfID, proj):
862863
config[-1]['type']['name'] = str(ct)+'_'+str(lt['name'])
863864
# make EA a float not a string
864865
config[-1]['type']['EA'] = float(lt['EA'])
865-
config[-1]['type']['MBL'] = float(lt['MBL'])
866+
if 'MBL' in lt:
867+
config[-1]['type']['MBL'] = float(lt['MBL'])
866868
# set line length
867869
config[-1]['L'] = lc['length']
868870

famodel/project.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ def loadSite(self, site, dir=''):
986986
self.rho_air = getFromDict(site['general'], 'rho_air', default=1.225)
987987
self.mu_air = getFromDict(site['general'], 'mu_air', default=1.81e-5)
988988

989+
989990
# load bathymetry information, if provided
990991
if 'bathymetry' in site and site['bathymetry']:
991992
if 'file' in site['bathymetry'] and site['bathymetry']['file']: # make sure there was a file provided even if the key is there
@@ -2179,6 +2180,7 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
21792180
depth_vmin = kwargs.get('depth_vmin', None)
21802181
depth_vmax = kwargs.get('depth_vmax', None)
21812182
bath_levels = kwargs.get('bath_levels', None)
2183+
show_legend = kwargs.get('show_legend', True)
21822184

21832185

21842186
# if axes not passed in, make a new figure
@@ -2383,12 +2385,14 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
23832385
if axis_equal:
23842386
ax.set_aspect('equal',adjustable='box')
23852387

2386-
handles, labels = plt.gca().get_legend_handles_labels()
2388+
handles, labels = ax.get_legend_handles_labels()
23872389
if plot_seabed:
23882390
handles += soil_handles
23892391
labels += [h.get_label() for h in soil_handles]
23902392
by_label = dict(zip(labels, handles)) # Removing duplicate labels
2391-
ax.legend(by_label.values(), by_label.keys(),loc='upper center',bbox_to_anchor=(0.5, -0.1), fancybox=True, ncol=4)
2393+
2394+
if show_legend:
2395+
ax.legend(by_label.values(), by_label.keys(),loc='upper center',bbox_to_anchor=(0.5, -0.1), fancybox=True, ncol=4)
23922396
if save:
23932397
plt.savefig('2dfarm.png', dpi=600, bbox_inches='tight') # Adjust the dpi as needed
23942398

0 commit comments

Comments
 (0)