Lateral fill on model gridΒΆ

This example shows how to apply lateral_fill() on a model dataset. We use a model grid dataset for illustration purposes.

Import packagesΒΆ

%matplotlib inline
import numpy as np
import xarray as xr

import pop_tools
ds = pop_tools.get_grid('POP_gx3v7')
ds
Downloading file 'inputdata/ocn/pop/gx3v7/grid/horiz_grid_20030806.ieeer8' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/gx3v7/grid/horiz_grid_20030806.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/650k [00:00<?, ?B/s]
 13%|β–ˆβ–ˆβ–ˆβ–ˆβ–‰                                  | 82.9k/650k [00:00<00:00, 668kB/s]
  0%|                                               | 0.00/650k [00:00<?, ?B/s]
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 650k/650k [00:00<00:00, 628MB/s]

Downloading file 'inputdata/ocn/pop/gx3v7/grid/topography_20100105.ieeei4' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/gx3v7/grid/topography_20100105.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/46.4k [00:00<?, ?B/s]
  0%|                                              | 0.00/46.4k [00:00<?, ?B/s]
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 46.4k/46.4k [00:00<00:00, 51.8MB/s]
Downloading file 'inputdata/ocn/pop/gx3v7/grid/region_mask_20090831.ieeei4' from 'https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/ocn/pop/gx3v7/grid/region_mask_20090831.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/46.4k [00:00<?, ?B/s]
  0%|                                              | 0.00/46.4k [00:00<?, ?B/s]
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 46.4k/46.4k [00:00<00:00, 32.7MB/s]

<xarray.Dataset>
Dimensions:      (nlat: 116, nlon: 100, z_t: 60, z_w: 60, z_w_bot: 60)
Coordinates:
  * z_t          (z_t) float64 500.0 1.5e+03 2.5e+03 ... 5.125e+05 5.375e+05
  * z_w          (z_w) float64 0.0 1e+03 2e+03 3e+03 ... 4.75e+05 5e+05 5.25e+05
  * z_w_bot      (z_w_bot) float64 1e+03 2e+03 3e+03 ... 5e+05 5.25e+05 5.5e+05
Dimensions without coordinates: nlat, nlon
Data variables: (12/13)
    TLAT         (nlat, nlon) float64 -79.5 -79.5 -79.5 ... 68.36 68.26 68.21
    TLONG        (nlat, nlon) float64 323.3 326.9 330.5 ... 317.8 319.3 320.8
    ULAT         (nlat, nlon) float64 -78.73 -78.73 -78.73 ... 68.49 68.42 68.4
    ULONG        (nlat, nlon) float64 325.1 328.7 332.3 ... 318.7 320.1 321.5
    DXT          (nlat, nlon) float64 6.842e+06 6.828e+06 ... 6.129e+06
    DYT          (nlat, nlon) float64 1.686e+07 1.686e+07 ... 4.524e+06
    ...           ...
    DYU          (nlat, nlon) float64 1.686e+07 1.686e+07 ... 1.069e+07
    TAREA        (nlat, nlon) float64 1.154e+14 1.151e+14 ... 2.773e+13
    UAREA        (nlat, nlon) float64 1.318e+14 1.318e+14 ... 6.256e+13 6.27e+13
    KMT          (nlat, nlon) int32 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
    REGION_MASK  (nlat, nlon) int32 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
    dz           (z_t) float64 1e+03 1e+03 1e+03 ... 2.499e+04 2.5e+04 2.5e+04
Attributes:
    lateral_dims:       [116, 100]
    vertical_dims:      60
    vert_grid_file:     gx3v7_vert_grid
    horiz_grid_fname:   inputdata/ocn/pop/gx3v7/grid/horiz_grid_20030806.ieeer8
    topography_fname:   inputdata/ocn/pop/gx3v7/grid/topography_20100105.ieeei4
    region_mask_fname:  inputdata/ocn/pop/gx3v7/grid/region_mask_20090831.ieeei4
    type:               dipole
    title:              POP_gx3v7 grid

Generate a field with some missing valuesΒΆ

field = ds.KMT.copy() * 1.0
field = field.where(ds.KMT > 0)
field.values[20:40, :] = np.nan
field.plot()
<matplotlib.collections.QuadMesh at 0x7f0eda017430>
../_images/lateral-fill-model-grid_5_1.png

Fill the missing valuesΒΆ

field_filled = pop_tools.lateral_fill(field, isvalid_mask=(ds.KMT > 0))
h = field_filled.plot()
../_images/lateral-fill-model-grid_7_0.png
%load_ext watermark
%watermark -d -iv -m -g -h
Compiler    : GCC 9.4.0
OS          : Linux
Release     : 5.11.0-1019-aws
Machine     : x86_64
Processor   : x86_64
CPU cores   : 2
Architecture: 64bit

Hostname: build-15808828-project-451810-pop-tools

Git hash: 6562432b7c2246654aef0997a6318cdb0122d10b

xarray   : 0.20.2
numpy    : 1.21.5
pop_tools: 2021.5.28.post26+dirty