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/stable/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<15:08, 533kB/s]
  0%|                                       | 722k/484M [00:00<02:27, 3.26MB/s]
  1%|▏                                     | 3.18M/484M [00:00<00:40, 11.8MB/s]
  1%|▌                                     | 6.83M/484M [00:00<00:23, 19.9MB/s]
  2%|▊                                     | 10.5M/484M [00:00<00:18, 25.5MB/s]
  3%|█                                     | 13.3M/484M [00:00<00:18, 25.5MB/s]
  4%|█▎                                    | 17.0M/484M [00:00<00:16, 28.9MB/s]
  4%|█▌                                    | 20.5M/484M [00:00<00:15, 29.7MB/s]
  5%|█▉                                    | 24.2M/484M [00:00<00:14, 31.7MB/s]
  6%|██▏                                   | 27.4M/484M [00:01<00:15, 30.2MB/s]
  6%|██▍                                   | 31.1M/484M [00:01<00:14, 32.3MB/s]
  7%|██▋                                   | 34.4M/484M [00:01<00:14, 31.5MB/s]
  8%|██▉                                   | 37.9M/484M [00:01<00:14, 30.5MB/s]
  9%|███▎                                  | 41.5M/484M [00:01<00:13, 32.0MB/s]
  9%|███▌                                  | 44.9M/484M [00:01<00:13, 31.7MB/s]
 10%|███▊                                  | 48.6M/484M [00:01<00:13, 33.3MB/s]
 11%|████                                  | 52.0M/484M [00:01<00:13, 31.4MB/s]
 12%|████▍                                 | 55.8M/484M [00:01<00:12, 33.1MB/s]
 12%|████▋                                 | 59.1M/484M [00:02<00:13, 32.3MB/s]
 13%|████▉                                 | 62.4M/484M [00:02<00:13, 30.8MB/s]
 14%|█████▏                                | 66.1M/484M [00:02<00:12, 32.6MB/s]
 14%|█████▍                                | 69.5M/484M [00:02<00:12, 32.0MB/s]
 15%|█████▊                                | 73.2M/484M [00:02<00:12, 33.4MB/s]
 16%|██████                                | 76.6M/484M [00:02<00:12, 31.4MB/s]
 17%|██████▎                               | 80.3M/484M [00:02<00:12, 33.0MB/s]
 17%|██████▌                               | 83.6M/484M [00:02<00:12, 32.2MB/s]
 18%|██████▊                               | 86.9M/484M [00:02<00:13, 30.3MB/s]
 19%|███████                               | 90.7M/484M [00:03<00:12, 32.4MB/s]
 19%|███████▍                              | 94.0M/484M [00:03<00:12, 31.8MB/s]
 20%|███████▋                              | 97.6M/484M [00:03<00:12, 30.9MB/s]
 21%|████████▏                              | 101M/484M [00:03<00:11, 32.4MB/s]
 22%|████████▍                              | 105M/484M [00:03<00:11, 32.0MB/s]
 22%|████████▋                              | 108M/484M [00:03<00:11, 33.3MB/s]
 23%|█████████                              | 112M/484M [00:03<00:11, 31.6MB/s]
 24%|█████████▎                             | 115M/484M [00:03<00:11, 33.2MB/s]
 25%|█████████▌                             | 119M/484M [00:03<00:11, 32.4MB/s]
 25%|█████████▉                             | 123M/484M [00:04<00:10, 35.7MB/s]
 26%|██████████▏                            | 127M/484M [00:04<00:09, 36.1MB/s]
 27%|██████████▌                            | 131M/484M [00:04<00:09, 38.3MB/s]
 28%|██████████▉                            | 136M/484M [00:04<00:09, 38.3MB/s]
 29%|███████████▎                           | 140M/484M [00:04<00:08, 40.0MB/s]
 30%|███████████▋                           | 145M/484M [00:04<00:08, 39.6MB/s]
 31%|████████████                           | 149M/484M [00:04<00:08, 40.7MB/s]
 32%|████████████▎                          | 153M/484M [00:04<00:07, 41.8MB/s]
 33%|████████████▋                          | 158M/484M [00:04<00:07, 40.9MB/s]
 33%|█████████████                          | 162M/484M [00:04<00:07, 41.4MB/s]
 34%|█████████████▍                         | 166M/484M [00:05<00:07, 40.9MB/s]
 35%|█████████████▋                         | 170M/484M [00:05<00:07, 41.3MB/s]
 36%|██████████████                         | 175M/484M [00:05<00:07, 42.6MB/s]
 37%|██████████████▍                        | 179M/484M [00:05<00:07, 41.7MB/s]
 38%|██████████████▊                        | 184M/484M [00:05<00:07, 42.5MB/s]
 39%|███████████████▏                       | 188M/484M [00:05<00:07, 42.0MB/s]
 40%|███████████████▍                       | 192M/484M [00:05<00:06, 42.3MB/s]
 41%|███████████████▊                       | 197M/484M [00:05<00:06, 43.2MB/s]
 42%|████████████████▏                      | 201M/484M [00:05<00:06, 42.2MB/s]
 42%|████████████████▌                      | 205M/484M [00:06<00:06, 43.1MB/s]
 43%|████████████████▉                      | 210M/484M [00:06<00:06, 42.2MB/s]
 44%|█████████████████▎                     | 214M/484M [00:06<00:06, 42.9MB/s]
 45%|█████████████████▋                     | 219M/484M [00:06<00:06, 43.6MB/s]
 46%|█████████████████▉                     | 223M/484M [00:06<00:06, 43.0MB/s]
 47%|██████████████████▍                    | 228M/484M [00:06<00:05, 44.1MB/s]
 48%|██████████████████▋                    | 232M/484M [00:06<00:05, 43.3MB/s]
 49%|███████████████████                    | 237M/484M [00:06<00:05, 44.4MB/s]
 50%|███████████████████▍                   | 242M/484M [00:06<00:05, 44.0MB/s]
 51%|███████████████████▊                   | 246M/484M [00:06<00:05, 43.9MB/s]
 52%|████████████████████▏                  | 251M/484M [00:07<00:05, 45.2MB/s]
 53%|████████████████████▌                  | 255M/484M [00:07<00:05, 44.0MB/s]
 54%|████████████████████▉                  | 260M/484M [00:07<00:04, 44.9MB/s]
 55%|█████████████████████▎                 | 265M/484M [00:07<00:04, 43.9MB/s]
 56%|█████████████████████▋                 | 269M/484M [00:07<00:04, 44.4MB/s]
 57%|██████████████████████                 | 274M/484M [00:07<00:04, 45.7MB/s]
 58%|██████████████████████▍                | 279M/484M [00:07<00:04, 44.5MB/s]
 59%|██████████████████████▊                | 283M/484M [00:07<00:04, 45.7MB/s]
 60%|███████████████████████▏               | 288M/484M [00:07<00:04, 44.7MB/s]
 61%|███████████████████████▌               | 293M/484M [00:07<00:04, 45.5MB/s]
 61%|███████████████████████▉               | 297M/484M [00:08<00:04, 45.3MB/s]
 62%|████████████████████████▎              | 302M/484M [00:08<00:04, 45.2MB/s]
 63%|████████████████████████▋              | 307M/484M [00:08<00:03, 46.1MB/s]
 64%|█████████████████████████              | 311M/484M [00:08<00:03, 44.9MB/s]
 65%|█████████████████████████▍             | 316M/484M [00:08<00:03, 46.0MB/s]
 66%|█████████████████████████▊             | 321M/484M [00:08<00:03, 45.0MB/s]
 67%|██████████████████████████▏            | 325M/484M [00:08<00:03, 45.5MB/s]
 68%|██████████████████████████▌            | 330M/484M [00:08<00:03, 46.1MB/s]
 69%|██████████████████████████▉            | 335M/484M [00:08<00:03, 45.5MB/s]
 70%|███████████████████████████▍           | 340M/484M [00:08<00:03, 46.4MB/s]
 71%|███████████████████████████▊           | 344M/484M [00:09<00:03, 45.4MB/s]
 72%|████████████████████████████▏          | 349M/484M [00:09<00:02, 46.1MB/s]
 73%|████████████████████████████▌          | 354M/484M [00:09<00:02, 45.9MB/s]
 74%|████████████████████████████▉          | 359M/484M [00:09<00:02, 46.3MB/s]
 75%|█████████████████████████████▎         | 364M/484M [00:09<00:02, 47.3MB/s]
 76%|█████████████████████████████▋         | 368M/484M [00:09<00:02, 46.2MB/s]
 77%|██████████████████████████████         | 373M/484M [00:09<00:02, 46.8MB/s]
 78%|██████████████████████████████▍        | 378M/484M [00:09<00:02, 47.0MB/s]
 79%|██████████████████████████████▊        | 383M/484M [00:09<00:02, 46.9MB/s]
 80%|███████████████████████████████▏       | 388M/484M [00:10<00:02, 47.8MB/s]
 81%|███████████████████████████████▋       | 392M/484M [00:10<00:01, 46.7MB/s]
 82%|████████████████████████████████       | 397M/484M [00:10<00:01, 47.4MB/s]
 83%|████████████████████████████████▍      | 402M/484M [00:10<00:01, 46.7MB/s]
 84%|████████████████████████████████▊      | 407M/484M [00:10<00:01, 47.2MB/s]
 85%|█████████████████████████████████▏     | 412M/484M [00:10<00:01, 48.0MB/s]
 86%|█████████████████████████████████▌     | 417M/484M [00:10<00:01, 46.9MB/s]
 87%|█████████████████████████████████▉     | 422M/484M [00:10<00:01, 47.7MB/s]
 88%|██████████████████████████████████▎    | 426M/484M [00:10<00:01, 46.6MB/s]
 89%|██████████████████████████████████▊    | 431M/484M [00:10<00:01, 47.4MB/s]
 90%|███████████████████████████████████▏   | 436M/484M [00:11<00:00, 47.9MB/s]
 91%|███████████████████████████████████▌   | 441M/484M [00:11<00:00, 47.1MB/s]
 92%|███████████████████████████████████▉   | 446M/484M [00:11<00:00, 47.8MB/s]
 93%|████████████████████████████████████▎  | 451M/484M [00:11<00:00, 46.8MB/s]
 94%|████████████████████████████████████▋  | 456M/484M [00:11<00:00, 47.7MB/s]
 95%|█████████████████████████████████████▏ | 461M/484M [00:11<00:00, 47.9MB/s]
 96%|█████████████████████████████████████▌ | 466M/484M [00:11<00:00, 47.4MB/s]
 97%|█████████████████████████████████████▉ | 471M/484M [00:11<00:00, 48.6MB/s]
 98%|██████████████████████████████████████▎| 476M/484M [00:11<00:00, 47.6MB/s]
 99%|██████████████████████████████████████▋| 481M/484M [00:11<00:00, 48.6MB/s]
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
100%|████████████████████████████████████████| 484M/484M [00:00<00:00, 645GB/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/stable/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, 540kB/s]
  0%|▏                                      | 121k/34.6M [00:00<02:08, 267kB/s]
  1%|▌                                     | 476k/34.6M [00:00<00:31, 1.10MB/s]
  8%|██▊                                  | 2.67M/34.6M [00:00<00:04, 6.70MB/s]
 18%|██████▌                              | 6.16M/34.6M [00:00<00:01, 14.2MB/s]
 29%|██████████▋                          | 10.0M/34.6M [00:00<00:01, 20.9MB/s]
 38%|██████████████                       | 13.2M/34.6M [00:00<00:00, 23.6MB/s]
 49%|██████████████████                   | 16.9M/34.6M [00:01<00:00, 27.4MB/s]
 59%|█████████████████████▊               | 20.3M/34.6M [00:01<00:00, 28.8MB/s]
 70%|█████████████████████████▉           | 24.2M/34.6M [00:01<00:00, 31.8MB/s]
 80%|█████████████████████████████▍       | 27.5M/34.6M [00:01<00:00, 31.1MB/s]
 92%|██████████████████████████████████   | 31.8M/34.6M [00:01<00:00, 34.4MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 42.2GB/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/stable/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:05, 524kB/s]
  2%|▋                                     | 607k/34.6M [00:00<00:12, 2.71MB/s]
  9%|███▍                                 | 3.18M/34.6M [00:00<00:02, 11.8MB/s]
 19%|███████▏                             | 6.72M/34.6M [00:00<00:01, 19.4MB/s]
 30%|███████████                          | 10.3M/34.6M [00:00<00:00, 24.8MB/s]
 39%|██████████████▌                      | 13.6M/34.6M [00:00<00:00, 26.2MB/s]
 50%|██████████████████▎                  | 17.2M/34.6M [00:00<00:00, 29.1MB/s]
 59%|█████████████████████▉               | 20.5M/34.6M [00:00<00:00, 29.2MB/s]
 69%|█████████████████████████▋           | 24.0M/34.6M [00:00<00:00, 30.8MB/s]
 79%|█████████████████████████████▎       | 27.3M/34.6M [00:01<00:00, 30.3MB/s]
 89%|█████████████████████████████████    | 30.9M/34.6M [00:01<00:00, 31.8MB/s]
 99%|████████████████████████████████████▋| 34.3M/34.6M [00:01<00:00, 31.3MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 51.8GB/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: 97ccdd4eb9f590e82d9e008d8133eeb875bf0b3c

pop_tools: 2023.6.0.post0+dirty
xarray   : 2023.6.0