mom6_bathy.topo module

class mom6_bathy.topo.Topo(grid, min_depth, version_control_dir='TopoLibrary')

Bases: object

Bathymetry Generator for MOM6 grids (mom6_bathy.grid.Grid).

MOM6 Simpler Models bathymetry constructor.

Parameters:
  • grid (mom6_bathy.grid.Grid) – horizontal grid instance for which the bathymetry is to be created.

  • min_depth (float) – Minimum water column depth. Columns with shallow depths are to be masked out.

apply_land_frac(landfrac_filepath, landfrac_name, xcoord_name, ycoord_name, depth_fillval=0.0, cutoff_frac=0.5, method='bilinear')

Given a dataset containing land fraction, generate and apply ocean mask.

Parameters:
  • landfrac_filepath (str) – Path the netcdf file containing the land fraction field.

  • landfrac_name (str) – The field name corresponding to the land fraction (e.g., “landfrac”).

  • xcoord_name (str) – The name of the x coordinate of the landfrac dataset (e.g., “lon”).

  • ycoord_name (str) – The name of the y coordinate of the landfrac dataset (e.g., “lat”).

  • depth_fillval (float) – The depth value for dry cells.

  • cutoff_frac (float) – Cells with landfrac > cutoff_frac are deemed land cells.

  • method (str) – Mapping method for determining the ocean mask (lnd -> ocn)

apply_ridge(height, width, lon, ilat)

Apply a ridge to the bathymetry.

Parameters:
  • height (float) – Height of the ridge to be added.

  • width (float) – Width of the ridge to be added.

  • lon (float) – Longitude where the ridge is to be centered.

  • ilat (pair of integers) – Initial and final latitude indices for the ridge.

property basintmask

Ocean domain mask at T grid. Seperate number for each connected water cell, 0 if land.

config_dataset(bathymetry_path, longitude_coordinate_name, latitude_coordinate_name, vertical_coordinate_name, fill_channels=False, positive_down=False, output_dir=PosixPath('.'), write_to_file=True)

Sets up necessary objects/files for regridding bathymetry. Can be flexibly used with mapping.regrid_bathy_dataset() or user can manually regrid with ESMF_regrid.

If manual regridding is necessary, write_to_file must be set to True.

Parameters:
  • bathymetry_path (str) – Path to netCDF file with bathymetry data.

  • longitude_coordinate_name (Optional[str]) – The name of the longitude coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'lon' (default).

  • latitude_coordinate_name (Optional[str]) – The name of the latitude coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'lat' (default).

  • vertical_coordinate_name (Optional[str]) – The name of the vertical coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'elevation' (default).

  • output_dir – str | Path The str or Path the write to file should write to. Defaults to the directory the script is running in.

  • write_to_file (Optional[bool]) – Files saved to output_dir. Defaults to True. Must be set to true if using manual regridding methods with ESMF_regrid.

Returns:

where bathymetry_output is the original bathymetry data with proper metadata and attributes and empty_bathy is a template for the regridder.

Return type:

(bathymetry_output,``empty_bathy``) (tuple of Datasets)

property depth

MOM6 grid depth array (m). Positive below MSL.

erase_disconnected_basin(i, j)
erase_selected_basin(i, j)
classmethod from_topo_file(grid, topo_file_path, min_depth=0.0, version_control_dir='TopoLibrary')

Create a bathymetry object from an existing topog file.

Parameters:
  • grid (mom6_bathy.grid.Grid) – horizontal grid instance for which the bathymetry is to be created.

  • topo_file_path (str) – Path to an existing MOM6 topog file.

  • min_depth (float, optional) – Minimum water column depth (m). Columns with shallower depths are to be masked out.

classmethod from_version_control(folder_path: str | Path)

Create a bathymetry object from an existing version-controlled bathymetry folder.

Parameters:

folder_path (str | Path) – Path to an existing bathymetry folder created by mom6_bathy with version control enabled.

gen_topo_ds(title=None)

Write the TOPO_FILE (bathymetry file) in xarray Dataset.

Parameters:

title (str, optional) – File title.

property max_depth

Maximum water column depth.

property min_depth

Minimum water column depth. Columns with shallow depths are to be masked out.

mpi_set_from_dataset(*, bathymetry_path, longitude_coordinate_name, latitude_coordinate_name, vertical_coordinate_name, fill_channels=False, positive_down=False, output_dir=PosixPath('.'), write_to_file=True, verbose=True)
point_is_ocean(lons, lats)

Given a list of coordinates, return a list of booleans indicating if the coordinates are in the ocean (True) or land (False)

property qmask

Ocean domain mask on Q grid. 1 if ocean, 0 if land.

save()

Save the TOPO_FILE (bathymetry file) in netcdf format to version control

send_entire_depth_change_to_tcm(depth, quietly=False)

This function takes an entire depth change and adds it through the TopoCommandManager (TCM) or directly if quietly is enabled.

set_bowl(max_depth, dedge, rad_earth=6378000.0, expdecay=400000.0)

Create a bowl-shaped bathymetry. Same effect as setting the TOPO_CONFIG parameter to “bowl”.

Parameters:
  • max_depth (float) – Maximum depth of model in the units of D.

  • dedge (float) – The depth [Z ~> m], at the basin edge

  • rad_earth (float, optional) – Radius of earth

  • expdecay (float, optional) – A decay scale of associated with the sloping boundaries [m]

set_depth_via_topog_file(topog_file_path, quietly=False)

Apply a bathymetry read from an existing topog file

Parameters:

topog_file_path (str) – absolute path to an existing MOM6 topog file

set_flat(D)

Create a flat bottom bathymetry with a given depth D.

Parameters:

D (float) – Bathymetric depth of the flat bottom to be generated.

set_from_dataset(bathymetry_path, longitude_coordinate_name, latitude_coordinate_name, vertical_coordinate_name, fill_channels=False, positive_down=False, output_dir=PosixPath('.'), write_to_file=True, regridding_method='bilinear', run_config_dataset=True, run_regrid_dataset=True, run_tidy_dataset=True)

This code was originally written by Ashley Barnes in regional_mom6(https://github.com/COSIMA/regional-mom6) and adapted for this package.

Cut out and interpolate the chosen bathymetry and then fill inland lakes.

Users can optionally fill narrow channels (see fill_channels keyword argument below). Note, however, that narrow channels are less of an issue for models that are discretized on an Arakawa C grid, like MOM6.

Output is saved in the output_dir.

Parameters:
  • bathymetry_path (str) – Path to the netCDF file with the bathymetry.

  • longitude_coordinate_name (Optional[str]) – The name of the longitude coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'lon' (default).

  • latitude_coordinate_name (Optional[str]) – The name of the latitude coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'lat' (default).

  • vertical_coordinate_name (Optional[str]) – The name of the vertical coordinate in the bathymetry dataset at bathymetry_path. For example, for GEBCO bathymetry: 'elevation' (default).

  • fill_channels (Optional[bool]) – Whether or not to fill in diagonal channels. This removes more narrow inlets, but can also connect extra islands to land. Default: False.

  • positive_down (Optional[bool]) – If True, it assumes that the bathymetry vertical coordinate is positive downwards. Default: False.

  • write_to_file (Optional[bool]) – Whether to write the bathymetry to a file. Default: True.

  • regridding_method (Optional[str]) – The type of regridding method to use. Defaults to self.regridding_method

  • run_* (Optional[bool]) – Whether to run the respective step in the bathymetry processing. Default: True.

set_spoon(max_depth, dedge, rad_earth=6378000.0, expdecay=400000.0)

Create a spoon-shaped bathymetry. Same effect as setting the TOPO_CONFIG parameter to “spoon”.

Parameters:
  • max_depth (float) – Maximum depth of model in the units of D.

  • dedge (float) – The depth [Z ~> m], at the basin edge

  • rad_earth (float, optional) – Radius of earth

  • expdecay (float, optional) – A decay scale of associated with the sloping boundaries [m]

property supergridmask

Ocean domain mask on supergrid. 1 if ocean, 0 if land.

tidy_dataset(fill_channels=False, positive_down=False, vertical_coordinate_name='depth', bathymetry=None, output_dir=PosixPath('.'), write_to_file=True, longitude_coordinate_name='lon', latitude_coordinate_name='lat')

An auxiliary method for bathymetry used to fix up the metadata and remove inland lakes after regridding the bathymetry. Having tidy_dataset() as a separate method from setup_bathymetry() allows for the regridding to be done separately, since regridding can be really expensive for large domains.

If the bathymetry is already regridded and what is left to be done is fixing the metadata or fill in some channels, then tidy_dataset() directly can read the existing bathymetry_unfinished.nc file that should be in the input directory.

Parameters:
  • fill_channels (Optional[bool]) – Whether to fill in diagonal channels. This removes more narrow inlets, but can also connect extra islands to land. Default: False.

  • positive_down (Optional[bool]) – If False (default), assume that bathymetry vertical coordinate is positive down, as is the case in GEBCO for example.

  • bathymetry (Optional[xr.Dataset]) – The bathymetry dataset to tidy up. If not provided, it will read the bathymetry from the file bathymetry_unfinished.nc in the input directory that was created by config/regrid_dataset().

property tmask

Ocean domain mask at T grid. 1 if ocean, 0 if land.

property umask

Ocean domain mask on U grid. 1 if ocean, 0 if land.

property vmask

Ocean domain mask on V grid. 1 if ocean, 0 if land.

write_cice_grid(file_path)

Write the CICE grid file in netcdf format. The written file is to be read in by CICE during runtime.

Parameters:

file_path (str) – Path to CICE grid file to be written.

write_esmf_mesh(file_path, title=None)

Write the ESMF mesh file

Parameters:
  • file_path (str) – Path to ESMF mesh file to be written.

  • title (str, optional) – File title.

write_scrip_grid(file_path, title=None)

Write the SCRIP grid file. In latest CESM versions, SCRIP grid files are no longer required and are replaced by ESMF mesh files. However, SCRIP files are still needed to generate custom ocean-runoff mapping files.

Parameters:
  • file_path (str) – Path to SCRIP file to be written.

  • title (str, optional) – File title.

write_topo(file_path, title=None)

Write the TOPO_FILE (bathymetry file) in netcdf format. The written file is to be read in by MOM6 during runtime.

Parameters:
  • file_path (str) – Path to TOPO_FILE to be written.

  • title (str, optional) – File title.