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:1045: 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/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
  0%|                                       | 99.3k/484M [00:00<10:00, 806kB/s]
  0%|                                       | 919k/484M [00:00<01:55, 4.20MB/s]
  1%|▎                                     | 4.49M/484M [00:00<00:31, 15.3MB/s]
  2%|▋                                     | 8.42M/484M [00:00<00:20, 23.5MB/s]
  2%|▉                                     | 11.4M/484M [00:00<00:18, 25.0MB/s]
  3%|█▏                                    | 15.3M/484M [00:00<00:17, 27.1MB/s]
  4%|█▌                                    | 19.2M/484M [00:00<00:15, 30.6MB/s]
  5%|█▊                                    | 22.4M/484M [00:00<00:15, 30.1MB/s]
  5%|██                                    | 26.2M/484M [00:01<00:15, 30.3MB/s]
  6%|██▎                                   | 30.1M/484M [00:01<00:13, 32.6MB/s]
  7%|██▌                                   | 33.4M/484M [00:01<00:14, 31.6MB/s]
  8%|██▉                                   | 37.0M/484M [00:01<00:13, 32.9MB/s]
  8%|███▏                                  | 40.4M/484M [00:01<00:13, 31.8MB/s]
  9%|███▍                                  | 44.4M/484M [00:01<00:13, 32.5MB/s]
 10%|███▊                                  | 48.5M/484M [00:01<00:12, 34.8MB/s]
 11%|████                                  | 52.0M/484M [00:01<00:12, 33.6MB/s]
 12%|████▍                                 | 56.2M/484M [00:01<00:11, 36.0MB/s]
 12%|████▋                                 | 59.9M/484M [00:02<00:12, 34.7MB/s]
 13%|█████                                 | 63.9M/484M [00:02<00:12, 34.8MB/s]
 14%|█████▎                                | 68.0M/484M [00:02<00:11, 36.5MB/s]
 15%|█████▋                                | 71.7M/484M [00:02<00:11, 35.3MB/s]
 16%|█████▉                                | 75.8M/484M [00:02<00:11, 36.8MB/s]
 16%|██████▏                               | 79.5M/484M [00:02<00:11, 35.4MB/s]
 17%|██████▌                               | 83.3M/484M [00:02<00:11, 34.5MB/s]
 18%|██████▊                               | 87.2M/484M [00:02<00:11, 35.8MB/s]
 19%|███████▏                              | 90.8M/484M [00:02<00:11, 34.6MB/s]
 20%|███████▍                              | 95.0M/484M [00:03<00:11, 34.6MB/s]
 20%|███████▊                              | 99.2M/484M [00:03<00:10, 36.4MB/s]
 21%|████████▎                              | 103M/484M [00:03<00:10, 35.2MB/s]
 22%|████████▋                              | 107M/484M [00:03<00:10, 37.3MB/s]
 23%|████████▉                              | 111M/484M [00:03<00:10, 35.8MB/s]
 24%|█████████▎                             | 115M/484M [00:03<00:10, 35.3MB/s]
 25%|█████████▌                             | 119M/484M [00:03<00:09, 37.0MB/s]
 25%|█████████▉                             | 123M/484M [00:03<00:10, 35.7MB/s]
 26%|██████████▏                            | 127M/484M [00:03<00:10, 35.0MB/s]
 27%|██████████▌                            | 131M/484M [00:03<00:09, 36.1MB/s]
 28%|██████████▊                            | 134M/484M [00:04<00:10, 34.9MB/s]
 29%|███████████▏                           | 138M/484M [00:04<00:09, 36.7MB/s]
 29%|███████████▍                           | 142M/484M [00:04<00:09, 35.0MB/s]
 30%|███████████▊                           | 146M/484M [00:04<00:09, 34.5MB/s]
 31%|████████████                           | 150M/484M [00:04<00:09, 36.2MB/s]
 32%|████████████▍                          | 154M/484M [00:04<00:09, 35.1MB/s]
 33%|████████████▋                          | 158M/484M [00:04<00:08, 37.1MB/s]
 33%|█████████████                          | 162M/484M [00:04<00:09, 35.6MB/s]
 34%|█████████████▎                         | 166M/484M [00:04<00:09, 35.0MB/s]
 35%|█████████████▋                         | 170M/484M [00:05<00:08, 36.3MB/s]
 36%|█████████████▉                         | 173M/484M [00:05<00:08, 35.2MB/s]
 37%|██████████████▎                        | 177M/484M [00:05<00:08, 37.2MB/s]
 37%|██████████████▌                        | 181M/484M [00:05<00:08, 36.3MB/s]
 38%|██████████████▉                        | 186M/484M [00:05<00:07, 38.7MB/s]
 39%|███████████████▎                       | 190M/484M [00:05<00:07, 37.5MB/s]
 40%|███████████████▋                       | 194M/484M [00:05<00:07, 39.9MB/s]
 41%|███████████████▉                       | 198M/484M [00:05<00:07, 38.5MB/s]
 42%|████████████████▎                      | 203M/484M [00:05<00:07, 38.4MB/s]
 43%|████████████████▋                      | 207M/484M [00:06<00:06, 39.6MB/s]
 44%|████████████████▉                      | 211M/484M [00:06<00:07, 38.7MB/s]
 44%|█████████████████▎                     | 215M/484M [00:06<00:06, 39.7MB/s]
 45%|█████████████████▋                     | 219M/484M [00:06<00:06, 39.0MB/s]
 46%|██████████████████                     | 224M/484M [00:06<00:06, 40.2MB/s]
 47%|██████████████████▎                    | 228M/484M [00:06<00:06, 39.3MB/s]
 48%|██████████████████▋                    | 232M/484M [00:06<00:06, 40.2MB/s]
 49%|███████████████████                    | 236M/484M [00:06<00:06, 39.5MB/s]
 50%|███████████████████▎                   | 240M/484M [00:06<00:06, 40.2MB/s]
 51%|███████████████████▋                   | 244M/484M [00:06<00:06, 39.6MB/s]
 51%|████████████████████                   | 249M/484M [00:07<00:05, 40.7MB/s]
 52%|████████████████████▍                  | 253M/484M [00:07<00:05, 40.3MB/s]
 53%|████████████████████▋                  | 257M/484M [00:07<00:05, 40.3MB/s]
 54%|█████████████████████                  | 262M/484M [00:07<00:05, 40.3MB/s]
 55%|█████████████████████▍                 | 266M/484M [00:07<00:05, 40.6MB/s]
 56%|█████████████████████▊                 | 270M/484M [00:07<00:05, 40.7MB/s]
 57%|██████████████████████                 | 274M/484M [00:07<00:05, 40.7MB/s]
 58%|██████████████████████▍                | 279M/484M [00:07<00:04, 41.3MB/s]
 59%|██████████████████████▊                | 283M/484M [00:07<00:04, 41.0MB/s]
 59%|███████████████████████▏               | 288M/484M [00:08<00:04, 41.0MB/s]
 60%|███████████████████████▌               | 292M/484M [00:08<00:04, 41.7MB/s]
 61%|███████████████████████▉               | 296M/484M [00:08<00:04, 41.5MB/s]
 62%|████████████████████████▏              | 301M/484M [00:08<00:04, 42.0MB/s]
 63%|████████████████████████▌              | 305M/484M [00:08<00:04, 41.8MB/s]
 64%|████████████████████████▉              | 310M/484M [00:08<00:04, 42.0MB/s]
 65%|█████████████████████████▎             | 314M/484M [00:08<00:03, 42.7MB/s]
 66%|█████████████████████████▋             | 318M/484M [00:08<00:03, 42.0MB/s]
 67%|██████████████████████████             | 323M/484M [00:08<00:03, 41.8MB/s]
 68%|██████████████████████████▍            | 327M/484M [00:08<00:03, 42.2MB/s]
 69%|██████████████████████████▊            | 332M/484M [00:09<00:03, 42.7MB/s]
 70%|███████████████████████████            | 336M/484M [00:09<00:03, 42.1MB/s]
 70%|███████████████████████████▍           | 341M/484M [00:09<00:03, 42.3MB/s]
 71%|███████████████████████████▊           | 345M/484M [00:09<00:03, 42.5MB/s]
 72%|████████████████████████████▏          | 350M/484M [00:09<00:03, 42.7MB/s]
 73%|████████████████████████████▌          | 354M/484M [00:09<00:03, 42.7MB/s]
 74%|████████████████████████████▉          | 359M/484M [00:09<00:02, 42.9MB/s]
 75%|█████████████████████████████▎         | 363M/484M [00:09<00:02, 43.2MB/s]
 76%|█████████████████████████████▋         | 368M/484M [00:09<00:02, 43.6MB/s]
 77%|██████████████████████████████         | 373M/484M [00:10<00:02, 42.9MB/s]
 78%|██████████████████████████████▍        | 377M/484M [00:10<00:02, 43.7MB/s]
 79%|██████████████████████████████▊        | 382M/484M [00:10<00:02, 43.4MB/s]
 80%|███████████████████████████████▏       | 387M/484M [00:10<00:02, 44.8MB/s]
 81%|███████████████████████████████▌       | 391M/484M [00:10<00:02, 43.2MB/s]
 82%|███████████████████████████████▉       | 396M/484M [00:10<00:02, 44.0MB/s]
 83%|████████████████████████████████▎      | 400M/484M [00:10<00:01, 43.1MB/s]
 84%|████████████████████████████████▋      | 405M/484M [00:10<00:01, 43.5MB/s]
 85%|█████████████████████████████████      | 409M/484M [00:10<00:01, 43.6MB/s]
 86%|█████████████████████████████████▍     | 414M/484M [00:10<00:01, 45.0MB/s]
 87%|█████████████████████████████████▊     | 419M/484M [00:11<00:01, 43.4MB/s]
 88%|██████████████████████████████████▏    | 424M/484M [00:11<00:01, 43.5MB/s]
 88%|██████████████████████████████████▌    | 428M/484M [00:11<00:01, 43.7MB/s]
 89%|██████████████████████████████████▉    | 433M/484M [00:11<00:01, 44.8MB/s]
 90%|███████████████████████████████████▎   | 437M/484M [00:11<00:01, 43.9MB/s]
 91%|███████████████████████████████████▋   | 442M/484M [00:11<00:00, 44.2MB/s]
 92%|████████████████████████████████████   | 447M/484M [00:11<00:00, 44.1MB/s]
 93%|████████████████████████████████████▍  | 452M/484M [00:11<00:00, 45.2MB/s]
 94%|████████████████████████████████████▊  | 456M/484M [00:11<00:00, 44.0MB/s]
 95%|█████████████████████████████████████▏ | 461M/484M [00:12<00:00, 44.7MB/s]
 96%|█████████████████████████████████████▌ | 465M/484M [00:12<00:00, 44.0MB/s]
 97%|█████████████████████████████████████▉ | 470M/484M [00:12<00:00, 45.4MB/s]
 98%|██████████████████████████████████████▎| 475M/484M [00:12<00:00, 44.2MB/s]
 99%|██████████████████████████████████████▋| 480M/484M [00:12<00:00, 45.2MB/s]
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
100%|████████████████████████████████████████| 484M/484M [00:00<00:00, 477GB/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:1045: 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/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
  0%|                                      | 66.6k/34.6M [00:00<01:25, 401kB/s]
  0%|                                       | 108k/34.6M [00:00<02:24, 239kB/s]
  0%|▏                                      | 134k/34.6M [00:00<03:02, 189kB/s]
  1%|▏                                      | 214k/34.6M [00:00<01:49, 314kB/s]
  4%|█▎                                   | 1.26M/34.6M [00:00<00:12, 2.60MB/s]
 15%|█████▍                               | 5.03M/34.6M [00:01<00:02, 10.5MB/s]
 25%|█████████▍                           | 8.77M/34.6M [00:01<00:01, 17.2MB/s]
 35%|████████████▊                        | 12.0M/34.6M [00:01<00:01, 20.6MB/s]
 44%|████████████████▍                    | 15.3M/34.6M [00:01<00:00, 24.1MB/s]
 53%|███████████████████▋                 | 18.4M/34.6M [00:01<00:00, 25.3MB/s]
 65%|███████████████████████▉             | 22.3M/34.6M [00:01<00:00, 29.1MB/s]
 73%|███████████████████████████▏         | 25.4M/34.6M [00:01<00:00, 28.9MB/s]
 85%|███████████████████████████████▍     | 29.3M/34.6M [00:01<00:00, 29.7MB/s]
 96%|███████████████████████████████████▌ | 33.2M/34.6M [00:01<00:00, 32.3MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 39.3GB/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:1045: 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/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
  0%|                                      | 66.6k/34.6M [00:00<01:04, 536kB/s]
  2%|▋                                     | 607k/34.6M [00:00<00:12, 2.77MB/s]
 11%|███▉                                 | 3.68M/34.6M [00:00<00:02, 14.0MB/s]
 19%|███████                              | 6.62M/34.6M [00:00<00:01, 19.0MB/s]
 30%|███████████▎                         | 10.5M/34.6M [00:00<00:01, 23.7MB/s]
 42%|███████████████▌                     | 14.5M/34.6M [00:00<00:00, 28.6MB/s]
 51%|██████████████████▋                  | 17.5M/34.6M [00:00<00:00, 28.0MB/s]
 61%|██████████████████████▋              | 21.2M/34.6M [00:00<00:00, 28.8MB/s]
 73%|██████████████████████████▉          | 25.2M/34.6M [00:01<00:00, 31.9MB/s]
 82%|██████████████████████████████▍      | 28.5M/34.6M [00:01<00:00, 31.1MB/s]
 93%|██████████████████████████████████▏  | 32.0M/34.6M [00:01<00:00, 30.3MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 23.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: fc1df4a99b6a6bde0f607865d6a81515674b85a2

xarray   : 2023.3.0
pop_tools: 2023.3.0.post1+dirty