Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to read geom_file and improvements in tao_mooring_comparison.py #47

Merged
merged 3 commits into from
May 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Option to read geom_file
If geom_file is provided, override the coordinates in grd_file
using those from this file. This is necessary when
land-block elimination is enabled, which leads to NaNs in the
coordinates in grd_file.
  • Loading branch information
gustavo-marques committed May 29, 2024
commit dfce031b10c8cf7ba03439f2dd859975ec76cd64
14 changes: 13 additions & 1 deletion mom6_tools/MOM6grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import xarray as xr

# -- return MOM6 grid object
def MOM6grid(grd_file, xrformat=False):
def MOM6grid(grd_file, geom_file=None, xrformat=False):
"""
Return an object or xarray Dataset with the MOM6 grid data.

Expand All @@ -10,6 +10,10 @@ def MOM6grid(grd_file, xrformat=False):
grd_file : str
Path to the static file.

geom_file : str, optional
If provided, override the coordinates in grd_file using those from this file. This is necessary when
land-block elimination is enabled, which leads to NaNs in grd_file.

xrformat : boolean, optional
If True, returns an xarray Dataset. Otherwise (default), returns an
object with numpy arrays.
Expand All @@ -27,6 +31,14 @@ def MOM6grid(grd_file, xrformat=False):
mgeolon_c = mgeolon_u.rename({'mgeolon_c'})
mgeolon_v = mgeolon.rename({'mgeolon_v'})

if geom_file:
try: geom = xr.open_dataset(geom_file, decode_times=False)
except: raise Exception('Could not find file', geom_file)
nc['geolat'].values = geom.geolat.values
nc['geolon'].values = geom.geolon.values
nc['geolat_c'].values = geom.geolatb.values
nc['geolon_c'].values = geom.geolonb.values

if xrformat:
nc['mgeolon'] = mgeolon
nc['mgeolon_c'] = mgeolon_c
Expand Down