Source code for pycif.plugins.transforms.complex.diagmet.utils.uv_rotation

import numpy as np


[docs] def uv_rotation(transf, inout_datastore, ddi, mapper): """Rotate u/v wind components from the meteorological (lat/lon) grid to the model grid. The local grid-cell orientation :math:`(\\cos\\theta, \\sin\\theta)` is derived from the geographic coordinates of the grid-cell corners, and winds are rotated as :math:`u' = \\cos\\theta\\, u - \\sin\\theta\\, v`, :math:`v' = \\sin\\theta\\, u + \\cos\\theta\\, v`. See :doc:`/documentation/doc-models/chimere/diagmet` (section 3) for the full derivation. Args: transf (Plugin): diagmet transform instance. inout_datastore (dict): mutable datastore. ddi (datetime): current sub-simulation date. mapper (dict): transform mapper. """ # First compute sin/cos and grid centers domain = mapper["inputs"][("meteo", "winz")]["domain"] zlon = domain.zlon zlat = domain.zlat zlonc = domain.zlonc zlatc = domain.zlatc dx = np.degrees(np.unwrap(np.diff(np.radians( 0.5 * (zlonc[1:] + zlonc[:-1])), axis=1))) * np.cos(np.radians(zlat)) # dy = np.diff(0.5 * (zlatc[:, 1:] + zlatc[:, :-1]), axis=0) # dx = np.degrees(np.unwrap(np.diff(np.radians( # 0.5 * (zlonc[:, 1:] + zlonc[:, -1])), axis=0))) * np.cos(np.radians(zlat)) dy = np.diff(0.5 * (zlatc[1:] + zlatc[:-1]), axis=1) coso = dx / np.sqrt(dx ** 2 + dy ** 2) sino = dy / np.sqrt(dx ** 2 + dy ** 2) # Now rotate winds winx = inout_datastore["inputs"][("meteo", "winz")][ddi]["spec"] winy = inout_datastore["inputs"][("meteo", "winm")][ddi]["spec"] inout_datastore["outputs"][("meteo", "winz")][ddi]["spec"] = coso * winx - sino * winy inout_datastore["outputs"][("meteo", "winm")][ddi]["spec"] = sino * winx + coso * winy
# WARNING!!!!!!!!!!!!!!!!!!!!!!!! TEMPORARY TO FIX ROTATION MANUALLY!!!!!!!!! # inout_datastore["outputs"][("meteo", "winz")][ddi]["spec"] = -sino * winx - coso * winy # inout_datastore["outputs"][("meteo", "winm")][ddi]["spec"] = coso * winx - sino * winy