Skip to content

Commit c552f27

Browse files
committed
Added an option to main geography function to create a bathymetry file or not
- the input 'bathymetry_file' can now either be a GEBCO.asc file (for example), or a MoorPy/MoorDyn-readable text file. If it's the latter, the write_bathymetry option should be set to False
1 parent 478dcd3 commit c552f27

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

famodel/geography.py

Lines changed: 23 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,34 @@ 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
386389
info['lease_xs'] = lease_xs
387390
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
391+
if write_bathymetry:
392+
info['bath_longs'] = bath_longs
393+
info['bath_lats'] = bath_lats
394+
info['bath_xs'] = bath_xs
395+
info['bath_ys'] = bath_ys
396+
info['bath_depths'] = bath_depths
397+
else:
398+
info['bath_xs'] = ms.bathGrid_Xs
399+
info['bath_ys'] = ms.bathGrid_Ys
400+
info['bath_depths'] = ms.bathGrid
401+
393402

394403
return info
395404

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

946955

947956
plt.show()

0 commit comments

Comments
 (0)