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:1043: 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%|                                       | 66.6k/484M [00:00<14:16, 565kB/s]
  0%|                                       | 591k/484M [00:00<02:51, 2.82MB/s]
  1%|▎                                     | 3.95M/484M [00:00<00:30, 15.5MB/s]
  1%|▌                                     | 6.92M/484M [00:00<00:22, 20.8MB/s]
  2%|▊                                     | 10.9M/484M [00:00<00:18, 25.6MB/s]
  3%|█▏                                    | 15.2M/484M [00:00<00:15, 31.1MB/s]
  4%|█▍                                    | 18.3M/484M [00:00<00:15, 30.7MB/s]
  4%|█▋                                    | 21.7M/484M [00:00<00:15, 30.3MB/s]
  5%|██                                    | 26.6M/484M [00:00<00:12, 35.7MB/s]
  6%|██▎                                   | 30.2M/484M [00:01<00:12, 35.6MB/s]
  7%|██▊                                   | 35.1M/484M [00:01<00:11, 37.6MB/s]
  8%|███▏                                  | 39.9M/484M [00:01<00:10, 40.5MB/s]
  9%|███▍                                  | 43.9M/484M [00:01<00:11, 39.7MB/s]
 10%|███▊                                  | 48.5M/484M [00:01<00:10, 40.0MB/s]
 11%|████▏                                 | 53.2M/484M [00:01<00:10, 42.0MB/s]
 12%|████▌                                 | 57.5M/484M [00:01<00:10, 41.1MB/s]
 13%|████▊                                 | 62.0M/484M [00:01<00:10, 40.9MB/s]
 14%|█████▏                                | 66.6M/484M [00:01<00:09, 42.3MB/s]
 15%|█████▌                                | 70.8M/484M [00:02<00:10, 41.2MB/s]
 16%|█████▉                                | 75.4M/484M [00:02<00:09, 41.4MB/s]
 16%|██████▎                               | 79.7M/484M [00:02<00:09, 42.0MB/s]
 17%|██████▌                               | 83.9M/484M [00:02<00:09, 41.4MB/s]
 18%|██████▉                               | 88.6M/484M [00:02<00:09, 42.9MB/s]
 19%|███████▎                              | 92.9M/484M [00:02<00:09, 41.7MB/s]
 20%|███████▋                              | 97.4M/484M [00:02<00:09, 41.8MB/s]
 21%|████████▏                              | 102M/484M [00:02<00:09, 41.9MB/s]
 22%|████████▌                              | 106M/484M [00:02<00:09, 41.8MB/s]
 23%|████████▉                              | 110M/484M [00:02<00:08, 42.6MB/s]
 24%|█████████▏                             | 115M/484M [00:03<00:08, 41.5MB/s]
 25%|█████████▋                             | 120M/484M [00:03<00:08, 43.7MB/s]
 26%|█████████▉                             | 124M/484M [00:03<00:08, 42.2MB/s]
 26%|██████████▎                            | 128M/484M [00:03<00:08, 41.2MB/s]
 27%|██████████▋                            | 133M/484M [00:03<00:08, 43.4MB/s]
 28%|███████████                            | 137M/484M [00:03<00:08, 42.1MB/s]
 29%|███████████▍                           | 142M/484M [00:03<00:08, 41.7MB/s]
 30%|███████████▊                           | 147M/484M [00:03<00:07, 43.3MB/s]
 31%|████████████▏                          | 151M/484M [00:03<00:07, 42.1MB/s]
 32%|████████████▌                          | 156M/484M [00:04<00:07, 42.4MB/s]
 33%|████████████▉                          | 160M/484M [00:04<00:07, 43.5MB/s]
 34%|█████████████▎                         | 165M/484M [00:04<00:07, 42.4MB/s]
 35%|█████████████▋                         | 169M/484M [00:04<00:07, 43.5MB/s]
 36%|██████████████                         | 174M/484M [00:04<00:07, 43.4MB/s]
 37%|██████████████▎                        | 178M/484M [00:04<00:07, 43.4MB/s]
 38%|██████████████▋                        | 183M/484M [00:04<00:06, 43.5MB/s]
 39%|███████████████                        | 187M/484M [00:04<00:06, 43.3MB/s]
 40%|███████████████▍                       | 191M/484M [00:04<00:06, 43.6MB/s]
 40%|███████████████▊                       | 196M/484M [00:04<00:06, 42.5MB/s]
 41%|████████████████▏                      | 201M/484M [00:05<00:06, 44.5MB/s]
 42%|████████████████▌                      | 205M/484M [00:05<00:06, 43.3MB/s]
 43%|████████████████▉                      | 210M/484M [00:05<00:06, 43.3MB/s]
 44%|█████████████████▎                     | 214M/484M [00:05<00:06, 44.4MB/s]
 45%|█████████████████▋                     | 219M/484M [00:05<00:06, 43.4MB/s]
 46%|██████████████████                     | 224M/484M [00:05<00:05, 45.2MB/s]
 47%|██████████████████▍                    | 228M/484M [00:05<00:05, 44.2MB/s]
 48%|██████████████████▊                    | 233M/484M [00:05<00:05, 43.1MB/s]
 49%|███████████████████▏                   | 238M/484M [00:05<00:05, 45.2MB/s]
 50%|███████████████████▌                   | 242M/484M [00:06<00:05, 44.1MB/s]
 51%|███████████████████▉                   | 247M/484M [00:06<00:05, 44.8MB/s]
 52%|████████████████████▎                  | 252M/484M [00:06<00:05, 44.3MB/s]
 53%|████████████████████▋                  | 256M/484M [00:06<00:05, 44.0MB/s]
 54%|█████████████████████                  | 261M/484M [00:06<00:04, 45.2MB/s]
 55%|█████████████████████▍                 | 266M/484M [00:06<00:04, 44.4MB/s]
 56%|█████████████████████▊                 | 271M/484M [00:06<00:04, 46.4MB/s]
 57%|██████████████████████▏                | 275M/484M [00:06<00:04, 44.8MB/s]
 58%|██████████████████████▌                | 280M/484M [00:06<00:04, 44.5MB/s]
 59%|██████████████████████▉                | 285M/484M [00:06<00:04, 46.3MB/s]
 60%|███████████████████████▎               | 290M/484M [00:07<00:04, 45.4MB/s]
 61%|███████████████████████▊               | 295M/484M [00:07<00:04, 46.1MB/s]
 62%|████████████████████████▏              | 300M/484M [00:07<00:03, 46.2MB/s]
 63%|████████████████████████▌              | 304M/484M [00:07<00:03, 46.2MB/s]
 64%|████████████████████████▉              | 309M/484M [00:07<00:03, 47.5MB/s]
 65%|█████████████████████████▎             | 314M/484M [00:07<00:03, 46.3MB/s]
 66%|█████████████████████████▋             | 319M/484M [00:07<00:03, 46.6MB/s]
 67%|██████████████████████████             | 324M/484M [00:07<00:03, 46.7MB/s]
 68%|██████████████████████████▍            | 328M/484M [00:07<00:03, 47.0MB/s]
 69%|██████████████████████████▊            | 333M/484M [00:07<00:03, 46.9MB/s]
 70%|███████████████████████████▏           | 338M/484M [00:08<00:03, 47.4MB/s]
 71%|███████████████████████████▋           | 343M/484M [00:08<00:02, 47.2MB/s]
 72%|████████████████████████████           | 348M/484M [00:08<00:02, 47.4MB/s]
 73%|████████████████████████████▍          | 352M/484M [00:08<00:02, 47.5MB/s]
 74%|████████████████████████████▊          | 357M/484M [00:08<00:02, 47.2MB/s]
 75%|█████████████████████████████▏         | 362M/484M [00:08<00:02, 48.2MB/s]
 76%|█████████████████████████████▌         | 367M/484M [00:08<00:02, 47.3MB/s]
 77%|██████████████████████████████         | 373M/484M [00:08<00:02, 49.2MB/s]
 78%|██████████████████████████████▍        | 377M/484M [00:08<00:02, 47.8MB/s]
 79%|██████████████████████████████▊        | 382M/484M [00:09<00:02, 47.5MB/s]
 80%|███████████████████████████████▏       | 388M/484M [00:09<00:01, 48.4MB/s]
 81%|███████████████████████████████▋       | 392M/484M [00:09<00:01, 47.5MB/s]
 82%|████████████████████████████████       | 398M/484M [00:09<00:01, 49.0MB/s]
 83%|████████████████████████████████▍      | 403M/484M [00:09<00:01, 48.0MB/s]
 84%|████████████████████████████████▊      | 408M/484M [00:09<00:01, 48.5MB/s]
 85%|█████████████████████████████████▏     | 412M/484M [00:09<00:01, 48.4MB/s]
 86%|█████████████████████████████████▋     | 418M/484M [00:09<00:01, 48.2MB/s]
 87%|██████████████████████████████████     | 423M/484M [00:09<00:01, 49.0MB/s]
 88%|██████████████████████████████████▍    | 428M/484M [00:09<00:01, 47.8MB/s]
 89%|██████████████████████████████████▉    | 433M/484M [00:10<00:01, 49.2MB/s]
 90%|███████████████████████████████████▎   | 438M/484M [00:10<00:00, 48.5MB/s]
 92%|███████████████████████████████████▋   | 443M/484M [00:10<00:00, 50.4MB/s]
 93%|████████████████████████████████████▏  | 448M/484M [00:10<00:00, 49.1MB/s]
 94%|████████████████████████████████████▌  | 453M/484M [00:10<00:00, 49.0MB/s]
 95%|████████████████████████████████████▉  | 458M/484M [00:10<00:00, 49.4MB/s]
 96%|█████████████████████████████████████▎ | 463M/484M [00:10<00:00, 48.6MB/s]
 97%|█████████████████████████████████████▊ | 469M/484M [00:10<00:00, 50.1MB/s]
 98%|██████████████████████████████████████▏| 474M/484M [00:10<00:00, 49.2MB/s]
 99%|██████████████████████████████████████▌| 479M/484M [00:10<00:00, 50.9MB/s]
  0%|                                               | 0.00/484M [00:00<?, ?B/s]
100%|████████████████████████████████████████| 484M/484M [00:00<00:00, 590GB/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:1043: 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:01, 560kB/s]
  2%|▋                                     | 607k/34.6M [00:00<00:11, 2.89MB/s]
 11%|████▏                                | 3.94M/34.6M [00:00<00:01, 15.5MB/s]
 21%|███████▌                             | 7.10M/34.6M [00:00<00:01, 21.5MB/s]
 34%|████████████▍                        | 11.6M/34.6M [00:00<00:00, 29.7MB/s]
 43%|███████████████▉                     | 14.9M/34.6M [00:00<00:00, 30.5MB/s]
 56%|████████████████████▋                | 19.4M/34.6M [00:00<00:00, 33.2MB/s]
 69%|█████████████████████████▌           | 23.9M/34.6M [00:00<00:00, 36.9MB/s]
 80%|█████████████████████████████▌       | 27.6M/34.6M [00:00<00:00, 36.1MB/s]
 92%|██████████████████████████████████▏  | 31.9M/34.6M [00:01<00:00, 36.8MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 32.6GB/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:1043: 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:01, 562kB/s]
  2%|▋                                     | 607k/34.6M [00:00<00:11, 2.90MB/s]
 10%|███▌                                 | 3.34M/34.6M [00:00<00:02, 12.0MB/s]
 22%|████████                             | 7.57M/34.6M [00:00<00:01, 21.2MB/s]
 33%|████████████▎                        | 11.5M/34.6M [00:00<00:00, 25.4MB/s]
 45%|████████████████▊                    | 15.7M/34.6M [00:00<00:00, 30.4MB/s]
 54%|████████████████████                 | 18.8M/34.6M [00:00<00:00, 30.1MB/s]
 65%|███████████████████████▉             | 22.4M/34.6M [00:00<00:00, 30.6MB/s]
 77%|████████████████████████████▌        | 26.6M/34.6M [00:01<00:00, 34.0MB/s]
 87%|████████████████████████████████▏    | 30.1M/34.6M [00:01<00:00, 33.1MB/s]
 97%|███████████████████████████████████▊ | 33.4M/34.6M [00:01<00:00, 31.9MB/s]
  0%|                                              | 0.00/34.6M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 34.6M/34.6M [00:00<00:00, 35.5GB/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/d3918102395fd450bb39eacd9a5ed1c4c1af65ba948f228de8c27547f95eca54.png

And the coordinates: TLAT

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

and TLONG

h = ds.TLONG.where(ds.KMT > 0).plot()
../_images/e0c2e532d10f316aac987935c9e5a508815b075d2eb66baab184a6518d20e368.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 10.3.0
OS          : Linux
Release     : 5.15.0-1004-aws
Machine     : x86_64
Processor   : x86_64
CPU cores   : 2
Architecture: 64bit

Git hash: f8dc20b9962e0fdc7b9a1995503e368ff326e3e7

xarray   : 2022.3.0
pop_tools: 2021.5.28.post40+dirty