Get grid#

The get_grid method returns an xarray.Dataset containing grid variables for a given model grid. It relies on a checkout of binary horizontal grid and topography files from the CESM inputdata repository. The vertical grid files are in the POP2-CESM repository in the input_templates directory; they are maintained separately as part of the pop-tools repository.

%matplotlib inline
import xarray as xr

import pop_tools

Get a dataset for the POP_tx0.v3 tripole grid.

ds = pop_tools.get_grid('POP_tx0.1v3')
ds.info()
Downloading file 'inputdata/ocn/pop/tx0.1v3/grid/horiz_grid_200709.ieeer8' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/tx0.1v2/grid/horiz_grid_200709.ieeer8' to '/home/docs/.pop_tools'.
/home/docs/checkouts/readthedocs.org/user_builds/pop-tools/conda/latest/lib/python3.9/site-packages/urllib3/connectionpool.py:1095: InsecureRequestWarning: Unverified HTTPS request is being made to host 'svn-ccsm-inputdata.cgd.ucar.edu'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
  0%|                                       | 66.6k/484M [00:00<14:37, 551kB/s]
  0%|                                       | 509k/484M [00:00<03:25, 2.36MB/s]
  1%|▏                                     | 3.18M/484M [00:00<00:39, 12.3MB/s]
  1%|▌                                     | 6.46M/484M [00:00<00:24, 19.5MB/s]
  2%|▊                                     | 10.4M/484M [00:00<00:18, 26.3MB/s]
  3%|█                                     | 13.4M/484M [00:00<00:17, 27.0MB/s]
  4%|█▎                                    | 17.2M/484M [00:00<00:15, 30.6MB/s]
  4%|█▌                                    | 20.5M/484M [00:00<00:15, 30.9MB/s]
  5%|█▉                                    | 24.5M/484M [00:00<00:13, 33.5MB/s]
  6%|██▏                                   | 27.8M/484M [00:01<00:13, 32.7MB/s]
  7%|██▌                                   | 31.9M/484M [00:01<00:12, 35.1MB/s]
  7%|██▊                                   | 35.5M/484M [00:01<00:13, 34.3MB/s]
  8%|███                                   | 39.2M/484M [00:01<00:13, 33.8MB/s]
  9%|███▍                                  | 43.1M/484M [00:01<00:12, 35.3MB/s]
 10%|███▋                                  | 46.7M/484M [00:01<00:12, 34.3MB/s]
 10%|███▉                                  | 50.6M/484M [00:01<00:12, 34.1MB/s]
 11%|████▎                                 | 54.5M/484M [00:01<00:12, 35.6MB/s]
 12%|████▌                                 | 58.1M/484M [00:01<00:12, 34.7MB/s]
 13%|████▉                                 | 62.2M/484M [00:02<00:12, 34.8MB/s]
 14%|█████▏                                | 66.2M/484M [00:02<00:11, 36.2MB/s]
 14%|█████▍                                | 69.8M/484M [00:02<00:11, 35.2MB/s]
 15%|█████▊                                | 74.0M/484M [00:02<00:11, 35.2MB/s]
 16%|██████                                | 78.0M/484M [00:02<00:11, 36.5MB/s]
 17%|██████▍                               | 81.6M/484M [00:02<00:11, 35.7MB/s]
 18%|██████▋                               | 85.9M/484M [00:02<00:10, 37.6MB/s]
 19%|███████                               | 89.7M/484M [00:02<00:10, 36.3MB/s]
 19%|███████▎                              | 93.5M/484M [00:02<00:10, 35.8MB/s]
 20%|███████▋                              | 97.4M/484M [00:03<00:10, 36.6MB/s]
 21%|████████▏                              | 101M/484M [00:03<00:10, 35.6MB/s]
 22%|████████▍                              | 105M/484M [00:03<00:10, 35.3MB/s]
 23%|████████▊                              | 109M/484M [00:03<00:10, 36.8MB/s]
 23%|█████████                              | 113M/484M [00:03<00:10, 35.9MB/s]
 24%|█████████▍                             | 117M/484M [00:03<00:09, 37.7MB/s]
 25%|█████████▋                             | 121M/484M [00:03<00:09, 36.5MB/s]
 26%|██████████                             | 125M/484M [00:03<00:09, 36.3MB/s]
 27%|██████████▍                            | 129M/484M [00:03<00:09, 37.7MB/s]
 27%|██████████▋                            | 133M/484M [00:03<00:09, 36.9MB/s]
 28%|███████████                            | 137M/484M [00:04<00:09, 38.5MB/s]
 29%|███████████▎                           | 141M/484M [00:04<00:09, 37.6MB/s]
 30%|███████████▋                           | 145M/484M [00:04<00:09, 37.5MB/s]
 31%|████████████                           | 149M/484M [00:04<00:08, 38.7MB/s]
 32%|████████████▎                          | 153M/484M [00:04<00:08, 37.7MB/s]
 33%|████████████▋                          | 158M/484M [00:04<00:08, 39.4MB/s]
 33%|█████████████                          | 162M/484M [00:04<00:08, 38.1MB/s]
 34%|█████████████▎                         | 166M/484M [00:04<00:08, 37.8MB/s]
 35%|█████████████▋                         | 170M/484M [00:04<00:08, 38.8MB/s]
 36%|██████████████                         | 174M/484M [00:05<00:08, 37.8MB/s]
 37%|██████████████▎                        | 178M/484M [00:05<00:07, 39.3MB/s]
 38%|██████████████▋                        | 182M/484M [00:05<00:07, 38.0MB/s]
 38%|███████████████                        | 186M/484M [00:05<00:07, 38.0MB/s]
 39%|███████████████▎                       | 190M/484M [00:05<00:07, 39.3MB/s]
 40%|███████████████▋                       | 194M/484M [00:05<00:07, 38.3MB/s]
 41%|████████████████                       | 199M/484M [00:05<00:07, 39.8MB/s]
 42%|████████████████▎                      | 203M/484M [00:05<00:07, 38.7MB/s]
 43%|████████████████▋                      | 207M/484M [00:05<00:07, 38.4MB/s]
 44%|█████████████████                      | 211M/484M [00:05<00:06, 39.5MB/s]
 44%|█████████████████▎                     | 215M/484M [00:06<00:06, 38.6MB/s]
 45%|█████████████████▋                     | 219M/484M [00:06<00:06, 39.9MB/s]
 46%|██████████████████                     | 223M/484M [00:06<00:06, 38.7MB/s]
 47%|██████████████████▎                    | 228M/484M [00:06<00:06, 38.6MB/s]
 48%|██████████████████▋                    | 232M/484M [00:06<00:06, 39.6MB/s]
 49%|███████████████████                    | 236M/484M [00:06<00:06, 39.1MB/s]
 50%|███████████████████▎                   | 240M/484M [00:06<00:06, 39.6MB/s]
 50%|███████████████████▋                   | 244M/484M [00:06<00:06, 39.4MB/s]
 51%|████████████████████                   | 248M/484M [00:06<00:05, 39.7MB/s]
 52%|████████████████████▎                  | 252M/484M [00:07<00:05, 39.6MB/s]
 53%|████████████████████▋                  | 256M/484M [00:07<00:05, 39.8MB/s]
 54%|█████████████████████                  | 261M/484M [00:07<00:05, 39.9MB/s]
 55%|█████████████████████▎                 | 265M/484M [00:07<00:05, 39.8MB/s]
 56%|█████████████████████▋                 | 269M/484M [00:07<00:05, 40.0MB/s]
 56%|█████████████████████▉                 | 273M/484M [00:07<00:05, 39.8MB/s]
 57%|██████████████████████▎                | 277M/484M [00:07<00:05, 40.1MB/s]
 58%|██████████████████████▋                | 281M/484M [00:07<00:05, 39.9MB/s]
 59%|██████████████████████▉                | 285M/484M [00:07<00:04, 40.1MB/s]
 60%|███████████████████████▎               | 289M/484M [00:07<00:04, 39.7MB/s]
 61%|███████████████████████▋               | 293M/484M [00:08<00:04, 40.0MB/s]
 61%|███████████████████████▉               | 297M/484M [00:08<00:04, 39.9MB/s]
 62%|████████████████████████▎              | 302M/484M [00:08<00:04, 40.5MB/s]
 63%|████████████████████████▋              | 306M/484M [00:08<00:04, 39.7MB/s]
 64%|████████████████████████▉              | 310M/484M [00:08<00:04, 40.3MB/s]
 65%|█████████████████████████▎             | 314M/484M [00:08<00:04, 39.7MB/s]
 66%|█████████████████████████▋             | 318M/484M [00:08<00:04, 40.4MB/s]
 67%|█████████████████████████▉             | 322M/484M [00:08<00:04, 39.7MB/s]
 67%|██████████████████████████▎            | 326M/484M [00:08<00:03, 40.2MB/s]
 68%|██████████████████████████▋            | 330M/484M [00:08<00:03, 39.6MB/s]
 69%|██████████████████████████▉            | 335M/484M [00:09<00:03, 40.1MB/s]
 70%|███████████████████████████▎           | 339M/484M [00:09<00:03, 39.8MB/s]
 71%|███████████████████████████▋           | 343M/484M [00:09<00:03, 40.2MB/s]
 72%|███████████████████████████▉           | 347M/484M [00:09<00:03, 39.8MB/s]
 73%|████████████████████████████▎          | 351M/484M [00:09<00:03, 39.9MB/s]
 73%|████████████████████████████▋          | 355M/484M [00:09<00:03, 40.4MB/s]
 74%|████████████████████████████▉          | 360M/484M [00:09<00:03, 40.1MB/s]
 75%|█████████████████████████████▎         | 364M/484M [00:09<00:02, 40.6MB/s]
 76%|█████████████████████████████▋         | 368M/484M [00:09<00:02, 40.4MB/s]
 77%|█████████████████████████████▉         | 372M/484M [00:10<00:02, 40.8MB/s]
 78%|██████████████████████████████▎        | 376M/484M [00:10<00:02, 40.7MB/s]
 79%|██████████████████████████████▋        | 380M/484M [00:10<00:02, 40.4MB/s]
 80%|███████████████████████████████        | 385M/484M [00:10<00:02, 40.9MB/s]
 80%|███████████████████████████████▎       | 389M/484M [00:10<00:02, 40.9MB/s]
 81%|███████████████████████████████▋       | 393M/484M [00:10<00:02, 41.2MB/s]
 82%|████████████████████████████████       | 397M/484M [00:10<00:02, 40.8MB/s]
 83%|████████████████████████████████▍      | 402M/484M [00:10<00:01, 41.2MB/s]
 84%|████████████████████████████████▋      | 406M/484M [00:10<00:01, 40.9MB/s]
 85%|█████████████████████████████████      | 410M/484M [00:10<00:01, 41.7MB/s]
 86%|█████████████████████████████████▍     | 414M/484M [00:11<00:01, 40.8MB/s]
 87%|█████████████████████████████████▋     | 419M/484M [00:11<00:01, 41.5MB/s]
 87%|██████████████████████████████████     | 423M/484M [00:11<00:01, 41.0MB/s]
 88%|██████████████████████████████████▍    | 427M/484M [00:11<00:01, 40.9MB/s]
 89%|██████████████████████████████████▊    | 431M/484M [00:11<00:01, 41.4MB/s]
 90%|███████████████████████████████████    | 436M/484M [00:11<00:01, 41.3MB/s]
 91%|███████████████████████████████████▍   | 440M/484M [00:11<00:01, 41.4MB/s]
 92%|███████████████████████████████████▊   | 444M/484M [00:11<00:00, 41.4MB/s]
 93%|████████████████████████████████████▏  | 449M/484M [00:11<00:00, 41.7MB/s]
 94%|████████████████████████████████████▌  | 453M/484M [00:11<00:00, 41.6MB/s]
 94%|████████████████████████████████████▊  | 457M/484M [00:12<00:00, 41.3MB/s]
 95%|█████████████████████████████████████▏ | 461M/484M [00:12<00:00, 41.8MB/s]
 96%|█████████████████████████████████████▌ | 466M/484M [00:12<00:00, 41.4MB/s]
 97%|█████████████████████████████████████▉ | 470M/484M [00:12<00:00, 41.2MB/s]
 98%|██████████████████████████████████████▏| 474M/484M [00:12<00:00, 41.6MB/s]
 99%|██████████████████████████████████████▌| 479M/484M [00:12<00:00, 41.7MB/s]
100%|██████████████████████████████████████▉| 483M/484M [00:12<00:00, 41.3MB/s]
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
100%|████████████████████████████████████████| 484M/484M [00:00<00:00, 579GB/s]

Downloading file 'inputdata/ocn/pop/tx0.1v3/grid/topography_20170718.ieeei4' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/tx0.1v3/grid/topography_20170718.ieeei4' to '/home/docs/.pop_tools'.
/home/docs/checkouts/readthedocs.org/user_builds/pop-tools/conda/latest/lib/python3.9/site-packages/urllib3/connectionpool.py:1095: InsecureRequestWarning: Unverified HTTPS request is being made to host 'svn-ccsm-inputdata.cgd.ucar.edu'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
  0%|                                      | 66.6k/34.6M [00:00<01:03, 544kB/s]
  2%|▋                                     | 591k/34.6M [00:00<00:12, 2.73MB/s]
  9%|███▎                                 | 3.12M/34.6M [00:00<00:02, 11.9MB/s]
 18%|██████▋                              | 6.21M/34.6M [00:00<00:01, 18.5MB/s]
 29%|██████████▋                          | 10.0M/34.6M [00:00<00:00, 25.1MB/s]
 38%|█████████████▉                       | 13.1M/34.6M [00:00<00:00, 26.4MB/s]
 49%|██████████████████                   | 16.9M/34.6M [00:00<00:00, 30.1MB/s]
 58%|█████████████████████▍               | 20.0M/34.6M [00:00<00:00, 29.4MB/s]
 69%|█████████████████████████▌           | 23.8M/34.6M [00:00<00:00, 30.5MB/s]
 80%|█████████████████████████████▌       | 27.6M/34.6M [00:01<00:00, 32.6MB/s]
 89%|█████████████████████████████████    | 30.9M/34.6M [00:01<00:00, 31.5MB/s]
100%|████████████████████████████████████▉| 34.6M/34.6M [00:01<00:00, 31.4MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 20.5GB/s]

Downloading file 'inputdata/ocn/pop/tx0.1v3/grid/region_mask_20170718.ieeei4' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/tx0.1v3/grid/region_mask_20170718.ieeei4' to '/home/docs/.pop_tools'.
/home/docs/checkouts/readthedocs.org/user_builds/pop-tools/conda/latest/lib/python3.9/site-packages/urllib3/connectionpool.py:1095: InsecureRequestWarning: Unverified HTTPS request is being made to host 'svn-ccsm-inputdata.cgd.ucar.edu'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
  0%|                                      | 66.6k/34.6M [00:00<01:03, 546kB/s]
  2%|▋                                     | 591k/34.6M [00:00<00:12, 2.74MB/s]
  8%|██▉                                  | 2.75M/34.6M [00:00<00:03, 9.54MB/s]
 19%|███████                              | 6.65M/34.6M [00:00<00:01, 19.8MB/s]
 28%|██████████▌                          | 9.85M/34.6M [00:00<00:01, 23.4MB/s]
 39%|██████████████▌                      | 13.6M/34.6M [00:00<00:00, 26.1MB/s]
 51%|██████████████████▊                  | 17.6M/34.6M [00:00<00:00, 30.0MB/s]
 60%|██████████████████████▏              | 20.7M/34.6M [00:00<00:00, 30.1MB/s]
 71%|██████████████████████████▎          | 24.5M/34.6M [00:01<00:00, 30.5MB/s]
 82%|██████████████████████████████▍      | 28.4M/34.6M [00:01<00:00, 32.9MB/s]
 92%|██████████████████████████████████   | 31.8M/34.6M [00:01<00:00, 32.4MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 42.7GB/s]

xarray.Dataset {
dimensions:
	nlat = 2400 ;
	nlon = 3600 ;
	z_t = 62 ;
	z_w = 62 ;
	z_w_bot = 62 ;

variables:
	float64 TLAT(nlat, nlon) ;
		TLAT:units = degrees_north ;
		TLAT:long_name = T-grid latitude ;
	float64 TLONG(nlat, nlon) ;
		TLONG:units = degrees_east ;
		TLONG:long_name = T-grid longitude ;
	float64 ULAT(nlat, nlon) ;
		ULAT:units = degrees_north ;
		ULAT:long_name = U-grid latitude ;
	float64 ULONG(nlat, nlon) ;
		ULONG:units = degrees_east ;
		ULONG:long_name = U-grid longitude ;
	float64 DXT(nlat, nlon) ;
		DXT:units = cm ;
		DXT:long_name = x-spacing centered at T points ;
		DXT:coordinates = TLONG TLAT ;
	float64 DYT(nlat, nlon) ;
		DYT:units = cm ;
		DYT:long_name = y-spacing centered at T points ;
		DYT:coordinates = TLONG TLAT ;
	float64 DXU(nlat, nlon) ;
		DXU:units = cm ;
		DXU:long_name = x-spacing centered at U points ;
		DXU:coordinates = ULONG ULAT ;
	float64 DYU(nlat, nlon) ;
		DYU:units = cm ;
		DYU:long_name = y-spacing centered at U points ;
		DYU:coordinates = ULONG ULAT ;
	float64 TAREA(nlat, nlon) ;
		TAREA:units = cm^2 ;
		TAREA:long_name = area of T cells ;
		TAREA:coordinates = TLONG TLAT ;
	float64 UAREA(nlat, nlon) ;
		UAREA:units = cm^2 ;
		UAREA:long_name = area of U cells ;
		UAREA:coordinates = ULONG ULAT ;
	int32 KMT(nlat, nlon) ;
		KMT:long_name = k Index of Deepest Grid Cell on T Grid ;
		KMT:coordinates = TLONG TLAT ;
	int32 REGION_MASK(nlat, nlon) ;
		REGION_MASK:long_name = basin index number (signed integers) ;
		REGION_MASK:coordinates = TLONG TLAT ;
	float64 z_t(z_t) ;
		z_t:units = cm ;
		z_t:long_name = depth from surface to midpoint of layer ;
		z_t:positive = down ;
	float64 dz(z_t) ;
		dz:units = cm ;
		dz:long_name = thickness of layer k ;
	float64 z_w(z_w) ;
		z_w:units = cm ;
		z_w:positive = down ;
		z_w:long_name = depth from surface to top of layer ;
	float64 z_w_bot(z_w_bot) ;
		z_w_bot:units = cm ;
		z_w_bot:positive = down ;
		z_w_bot:long_name = depth from surface to bottom of layer ;

// global attributes:
	:lateral_dims = [2400, 3600] ;
	:vertical_dims = 62 ;
	:vert_grid_file = tx0.1v3_vert_grid ;
	:horiz_grid_fname = inputdata/ocn/pop/tx0.1v3/grid/horiz_grid_200709.ieeer8 ;
	:topography_fname = inputdata/ocn/pop/tx0.1v3/grid/topography_20170718.ieeei4 ;
	:region_mask_fname = inputdata/ocn/pop/tx0.1v3/grid/region_mask_20170718.ieeei4 ;
	:type = tripole ;
	:title = POP_tx0.1v3 grid ;
}

Visualize grid#

Take a quick look at KMT (k Index of Deepest Grid Cell on T Grid), applying a land-mask criterion along the way.

h = ds.KMT.where(ds.KMT > 0).plot()
../_images/4489aa8bd8ecfb8342bf4924c1d29d653e335d25dda52f8a2a926cf3b6e43969.png

And the coordinates: TLAT

h = ds.TLAT.where(ds.KMT > 0).plot()
../_images/bfe3ecf59515079109fbc7487dc5f21f5aa18a66d24078c0e66b1e63cfed8b43.png

and TLONG

h = ds.TLONG.where(ds.KMT > 0).plot()
../_images/3ecd8e460e2f3897aa1dcb0139426193cfd24bedab259bc658be8617bf1d7412.png

SCRIP format#

It is also possible to get the grid file in SCRIP format which is useful for regridding applications with ESMF.

ds = pop_tools.get_grid('POP_tx0.1v3', scrip=True)
ds.info()
xarray.Dataset {
dimensions:
	grid_rank = 2 ;
	grid_size = 8640000 ;
	grid_corners = 4 ;

variables:
	int32 grid_dims(grid_rank) ;
	float64 grid_center_lat(grid_size) ;
		grid_center_lat:units = degrees ;
	float64 grid_center_lon(grid_size) ;
		grid_center_lon:units = degrees ;
	float64 grid_corner_lat(grid_size, grid_corners) ;
		grid_corner_lat:units = degrees ;
	float64 grid_corner_lon(grid_size, grid_corners) ;
		grid_corner_lon:units = degrees ;
	int64 grid_imask(grid_size) ;
		grid_imask:units = unitless ;

// global attributes:
	:lateral_dims = [2400, 3600] ;
	:vertical_dims = 62 ;
	:vert_grid_file = tx0.1v3_vert_grid ;
	:horiz_grid_fname = inputdata/ocn/pop/tx0.1v3/grid/horiz_grid_200709.ieeer8 ;
	:topography_fname = inputdata/ocn/pop/tx0.1v3/grid/topography_20170718.ieeei4 ;
	:region_mask_fname = inputdata/ocn/pop/tx0.1v3/grid/region_mask_20170718.ieeei4 ;
	:type = tripole ;
	:title = POP_tx0.1v3 grid ;
	:conventions = SCRIP ;
}
%load_ext watermark
%watermark -d -iv -m -g
Compiler    : GCC 11.3.0
OS          : Linux
Release     : 5.15.0-1004-aws
Machine     : x86_64
Processor   : x86_64
CPU cores   : 2
Architecture: 64bit

Git hash: d3c80c0576ae4838c0e04a0157734eb0c977e613

xarray   : 2023.6.0
pop_tools: 2023.3.0.post2+dirty