#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import logging
import xarray as xr
LOGGER = logging.getLogger(__name__)
[docs]def celsius2kelvin(ds):
"""Convert Celsius degree to Kelvin
Parameters
----------
dai : xarray.DataArray
Single variable to regrid.
Returns
-------
xarray.DataArray
Regridded variable.
"""
LOGGER.info("Convert temperature from Celsius to Kelvin degrees")
ds['t2m'] -= 273.15
return ds
[docs]def windstress(ds, method=None):
"""Compute wind stress
Parameters
----------
ds : xarray.Dataset
method : str
Returns
-------
xarray.Dataset
"""
LOGGER.info("Compute the wind stress following the "
"{method} method")
if method == 'Speich':
rhocd = 1.3*(0.61+0.063*ds.si10)*1e-3
taux = rhocd * ds.si10 * ds.u10
tauy = rhocd * ds.si10 * ds.v10
taux.name = 'ewss'
tauy.name = 'nsss'
return xr.merge([ds, taux, tauy], compat='override')
[docs]def radiativeflux(ds):
"""Compute radiative flux
Parameters
----------
ds : xarray.Dataset
Returns
-------
xarray.Dataset
"""
LOGGER.info("Compute the radiative flux")
ds['radflx'] = ds.ssr + ds.str
return ds
[docs]def watervapormixingratio(ds):
"""Compute water vapor mixing ratio
Parameters
----------
ds : xarray.Dataset
Returns
-------
xarray.Dataset
"""
LOGGER.info("Compute the water vapor mixing ratio")
t = ds.t2m
qsatur =.622e-3*(6.107799961e+00+t*(4.436518521e-01
+t*(1.428945805e-02+t*(2.650648471e-04
+t*(3.031240396e-06+t*(2.034080948e-08
+t* 6.136820929e-11))))))
ds['vapmix'] = qsatur * ds.r2 * 0.01
return ds