Source code for pycif.plugins.domains.dummy.create_domain
import numpy as np
from ....utils.path import init_dir
[docs]
def create_domain(domain, **kwargs):
"""Build a uniform Cartesian dummy domain from YAML parameters.
Generates equally-spaced corner (``lonc``, ``latc``) and centre
(``lon``, ``lat``) coordinate arrays over the rectangle
[``xmin``, ``xmax``] × [``ymin``, ``ymax``] with ``nlon`` × ``nlat``
cells, builds 2-D meshgrids, and writes the 1-D arrays to text files
under ``{workdir}/domain/``.
Sets on *domain*: ``zlon``, ``zlat``, ``zlonc``, ``zlatc``.
Args:
domain: dummy domain plugin instance with ``nlon``, ``nlat``,
``xmin``, ``xmax``, ``ymin``, ``ymax``, and ``workdir`` set.
**kwargs: unused.
"""
nlon = domain.nlon
nlat = domain.nlat
lonc = np.linspace(domain.xmin, domain.xmax, nlon + 1)
latc = np.linspace(domain.ymin, domain.ymax, nlat + 1)
lon = 0.5 * (lonc[1:] + lonc[:-1])
lat = 0.5 * (latc[1:] + latc[:-1])
# Meshgrids
zlon, zlat = np.meshgrid(lon, lat)
zlonc, zlatc = np.meshgrid(lonc, latc)
domain.zlon = zlon
domain.zlat = zlat
domain.zlonc = zlonc
domain.zlatc = zlatc
# Dump coordinates for later use
init_dir(f"{domain.workdir}/domain")
np.savetxt(f"{domain.workdir}/domain/lonc.txt", lonc)
np.savetxt(f"{domain.workdir}/domain/latc.txt", latc)
np.savetxt(f"{domain.workdir}/domain/lon.txt", lon)
np.savetxt(f"{domain.workdir}/domain/lat.txt", lat)