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: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/650k [00:00<?, ?B/s]
10%|███▉ | 66.6k/650k [00:00<00:01, 547kB/s]
88%|██████████████████████████████████▍ | 574k/650k [00:00<00:00, 2.66MB/s]
0%| | 0.00/650k [00:00<?, ?B/s]
100%|███████████████████████████████████████| 650k/650k [00:00<00:00, 1.01GB/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: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/46.4k [00:00<?, ?B/s]
0%| | 0.00/46.4k [00:00<?, ?B/s]
100%|█████████████████████████████████████| 46.4k/46.4k [00:00<00:00, 54.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: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/46.4k [00:00<?, ?B/s]
0%| | 0.00/46.4k [00:00<?, ?B/s]
100%|█████████████████████████████████████| 46.4k/46.4k [00:00<00:00, 39.0MB/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 0x7fa74d8880a0>

Fill the missing values#
field_filled = pop_tools.lateral_fill(field, isvalid_mask=(ds.KMT > 0))
h = field_filled.plot()

%load_ext watermark
%watermark -d -iv -m -g -h
Compiler : GCC 11.3.0
OS : Linux
Release : 5.15.0-1004-aws
Machine : x86_64
Processor : x86_64
CPU cores : 2
Architecture: 64bit
Hostname: build-21213814-project-451810-pop-tools
Git hash: d3c80c0576ae4838c0e04a0157734eb0c977e613
xarray : 2023.6.0
numpy : 1.24.4
pop_tools: 2023.3.0.post2+dirty