forked from 3rdparty/wrf-python
29 changed files with 5953 additions and 6039 deletions
@ -1,265 +1,254 @@
@@ -1,265 +1,254 @@
|
||||
from __future__ import (absolute_import, division, print_function) |
||||
|
||||
from .py3compat import py2round |
||||
|
||||
|
||||
|
||||
|
||||
def _binary_operator(operator): |
||||
"""Function wrapper for binary operators. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
operator (method): The operator to wrap. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
method: An implementation for the *operator* type. |
||||
|
||||
|
||||
""" |
||||
def func(self, other): |
||||
"""Operator implementation. |
||||
|
||||
Operator action is performed across the same class attributes when |
||||
|
||||
Operator action is performed across the same class attributes when |
||||
the *other* object is a :class:`CoordPair`. If the *other* object is |
||||
a scalar value, the operator action is performed across all |
||||
a scalar value, the operator action is performed across all |
||||
attributes with the scalar value. |
||||
|
||||
|
||||
Args: |
||||
|
||||
other (:class:`CoordPair` or scalar): A separate :class:`CoordPair` |
||||
|
||||
other (:class:`CoordPair` or scalar): A separate :class:`CoordPair` |
||||
object or scalar value. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
:class:`CoordPair`: A new :class:`CoordPair` object that is the |
||||
|
||||
:class:`CoordPair`: A new :class:`CoordPair` object that is the |
||||
result of the operator action. |
||||
|
||||
|
||||
""" |
||||
if isinstance(other, CoordPair): |
||||
args = [ |
||||
None if getattr(self, attr) is None or getattr(other, attr) is None |
||||
else getattr(getattr(self, attr), operator)(getattr(other, attr)) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
args = [None if getattr(self, attr) is None or |
||||
getattr(other, attr) is None else |
||||
getattr(getattr(self, attr), operator)(getattr(other, |
||||
attr)) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
else: |
||||
args = [ |
||||
None if getattr(self, attr) is None |
||||
else getattr(getattr(self, attr), operator)(other) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
args = [None if getattr(self, attr) is None |
||||
else getattr(getattr(self, attr), operator)(other) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
return CoordPair(*args) |
||||
|
||||
|
||||
return func |
||||
|
||||
|
||||
def _unary_operator(operator): |
||||
"""Function wrapper for unary operators. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
operator (method): The operator to wrap. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
method: An implementation for the *operator* type. |
||||
|
||||
|
||||
""" |
||||
def func(self): |
||||
"""Operator implementation. |
||||
|
||||
|
||||
Operator action is performed across all class attributes. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
:class:`CoordPair`: A new :class:`CoordPair` object that is the |
||||
|
||||
:class:`CoordPair`: A new :class:`CoordPair` object that is the |
||||
result of the operator action. |
||||
|
||||
|
||||
""" |
||||
args = [None if getattr(self, attr) is None |
||||
else getattr(getattr(self, attr), operator)() |
||||
else getattr(getattr(self, attr), operator)() |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
|
||||
return CoordPair(*args) |
||||
|
||||
|
||||
return func |
||||
|
||||
|
||||
def _cmp_operator(operator): |
||||
"""Function wrapper for comparison operators. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
operator (method): The operator to wrap. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
method: An implementation for the *operator* type. |
||||
|
||||
|
||||
""" |
||||
|
||||
|
||||
def func(self, other): |
||||
"""Operator implementation. |
||||
|
||||
Performs a comparison operation across all of the same class |
||||
attributes, and returns True if all these operations are True. |
||||
|
||||
|
||||
Performs a comparison operation across all of the same class |
||||
attributes, and returns True if all these operations are True. |
||||
|
||||
Returns: |
||||
|
||||
:obj:`boot`: Returns True if all comparisons across class |
||||
|
||||
:obj:`boot`: Returns True if all comparisons across class |
||||
attributes returns True, otherwise False. |
||||
|
||||
|
||||
""" |
||||
vals = [getattr(getattr(self, attr), operator)(getattr(other, attr)) |
||||
for attr in ("x", "y", "lat", "lon") |
||||
for attr in ("x", "y", "lat", "lon") |
||||
if getattr(self, attr) is not None] |
||||
|
||||
|
||||
return all(vals) |
||||
|
||||
|
||||
return func |
||||
|
||||
|
||||
|
||||
|
||||
class CoordPair(object): |
||||
"""A class that stores (x, y) and/or (latitude, longitude) |
||||
"""A class that stores (x, y) and/or (latitude, longitude) |
||||
coordinate pairs. |
||||
|
||||
Most math operators are supplied. When the other operand is a |
||||
:class:`CoordPair`, the operation is performed with the same attribute. |
||||
When a math operation uses a scalar as the other operand, the |
||||
operation is applied across all attributes. |
||||
|
||||
|
||||
Most math operators are supplied. When the other operand is a |
||||
:class:`CoordPair`, the operation is performed with the same attribute. |
||||
When a math operation uses a scalar as the other operand, the |
||||
operation is applied across all attributes. |
||||
|
||||
Attributes: |
||||
|
||||
|
||||
x (:obj:`float`): The x-coordinate. |
||||
y (:obj:`float`): The y-coordinate. |
||||
lat (:obj:`float`): The latitude coordinate. |
||||
lon (:obj:`float`): The longitude coordinate. |
||||
|
||||
|
||||
|
||||
|
||||
""" |
||||
def __init__(self, x=None, y=None, lat=None, lon=None): |
||||
"""Initialize a :class:`CoordPair` object. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
x (:obj:`float`, optional): The x-coordinate. |
||||
y (:obj:`float`, optional): The y-coordinate. |
||||
lat (:obj:`float`, optional): The latitude coordinate. |
||||
lon (:obj:`float`, optional): The longitude coordinate. |
||||
|
||||
|
||||
|
||||
|
||||
""" |
||||
self.x = x |
||||
self.y = y |
||||
self.lat = lat |
||||
self.lon = lon |
||||
|
||||
|
||||
|
||||
def __repr__(self): |
||||
args = [] |
||||
if self.x is not None: |
||||
args.append("x={}".format(self.x)) |
||||
args.append("y={}".format(self.y)) |
||||
|
||||
|
||||
if self.lat is not None: |
||||
args.append("lat={}".format(self.lat)) |
||||
args.append("lon={}".format(self.lon)) |
||||
|
||||
|
||||
argstr = ", ".join(args) |
||||
|
||||
|
||||
return "{}({})".format(self.__class__.__name__, argstr) |
||||
|
||||
|
||||
|
||||
def __str__(self): |
||||
return self.__repr__() |
||||
|
||||
|
||||
|
||||
def xy_str(self, fmt="{:.4f}, {:.4f}"): |
||||
"""Return a :obj:`str` for the (x,y) coordinate pair. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
fmt (:obj:`str`): The format string. Default is '{:.4f}, {:.4f}' |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
:obj:`str`: A string for the (x,y) coordinate pair |
||||
|
||||
|
||||
""" |
||||
if self.x is None or self.y is None: |
||||
return None |
||||
|
||||
|
||||
return fmt.format(self.x, self.y) |
||||
|
||||
|
||||
|
||||
def latlon_str(self, fmt="{:.4f}, {:.4f}"): |
||||
"""Return a :obj:`str` for the (latitude, longitude) coordinate pair. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
fmt (:obj:`str`): The format string. Default is '{:.4f}, {:.4f}' |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
:obj:`str`: A string for the (latitude, longitude) coordinate pair |
||||
|
||||
|
||||
""" |
||||
if self.lat is None or self.lon is None: |
||||
return None |
||||
|
||||
|
||||
return fmt.format(self.lat, self.lon) |
||||
|
||||
|
||||
|
||||
def __round__(self, ndigits=None): |
||||
"""Return a new :class:`CoordPair` object with all coordinate values |
||||
rounded to the nearest integer. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
ndigits (:obj:`int`): The number of digits. |
||||
|
||||
|
||||
Returns: |
||||
|
||||
|
||||
:class:`CoordPair`: A CoordPair object. |
||||
|
||||
|
||||
""" |
||||
args = [None if getattr(self, attr) is None |
||||
else py2round(getattr(self, attr), ndigits) |
||||
else py2round(getattr(self, attr), ndigits) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
|
||||
return CoordPair(*args) |
||||
|
||||
|
||||
|
||||
def __pow__(self, other, modulo=None): |
||||
if isinstance(other, CoordPair): |
||||
args = [ |
||||
None if getattr(self, attr) is None or getattr(other, attr) is None |
||||
else getattr(getattr(self, attr), "__pow__")(getattr(other, attr), |
||||
modulo) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
args = [None if getattr(self, attr) is None or |
||||
getattr(other, attr) is None |
||||
else getattr(getattr(self, attr), "__pow__")( |
||||
getattr(other, attr), modulo) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
else: |
||||
args = [ |
||||
None if getattr(self, attr) is None |
||||
else getattr(getattr(self, attr), "__pow__")(other, modulo) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
args = [None if getattr(self, attr) is None |
||||
else getattr(getattr(self, attr), "__pow__")(other, modulo) |
||||
for attr in ("x", "y", "lat", "lon")] |
||||
|
||||
return CoordPair(*args) |
||||
|
||||
|
||||
|
||||
def __rpow__(self, other): |
||||
return self.__pow__(other) |
||||
|
||||
|
||||
for operator in ("__add__", "__divmod__", "__floordiv__", "__mod__", |
||||
"__mul__", "__sub__", "__truediv__", "__radd__", |
||||
"__rdivmod__", "__rsub__", "__rmul__", "__rtruediv__", |
||||
|
||||
for operator in ("__add__", "__divmod__", "__floordiv__", "__mod__", |
||||
"__mul__", "__sub__", "__truediv__", "__radd__", |
||||
"__rdivmod__", "__rsub__", "__rmul__", "__rtruediv__", |
||||
"__rfloordiv__", "__rmod__"): |
||||
setattr(CoordPair, operator, _binary_operator(operator)) |
||||
|
||||
|
||||
|
||||
for operator in ("__neg__", "__pos__", "__abs__", "__invert__"): |
||||
setattr(CoordPair, operator, _unary_operator(operator)) |
||||
|
||||
|
||||
|
||||
for operator in ("__lt__", "__le__", "__eq__", "__ne__", "__gt__", "__ge__"): |
||||
setattr(CoordPair, operator, _cmp_operator(operator)) |
||||
|
||||
|
||||
|
@ -1,164 +1,163 @@
@@ -1,164 +1,163 @@
|
||||
from __future__ import (absolute_import, division, print_function) |
||||
|
||||
#from .extension import computetd |
||||
from .extension import _td |
||||
from .decorators import convert_units |
||||
from .metadecorators import copy_and_set_metadata |
||||
from .util import extract_vars |
||||
|
||||
|
||||
@copy_and_set_metadata(copy_varname="QVAPOR", name="td", |
||||
@copy_and_set_metadata(copy_varname="QVAPOR", name="td", |
||||
description="dew point temperature") |
||||
@convert_units("temp", "c") |
||||
def get_dp(wrfin, timeidx=0, method="cat", squeeze=True, |
||||
def get_dp(wrfin, timeidx=0, method="cat", squeeze=True, |
||||
cache=None, meta=True, _key=None, units="degC"): |
||||
"""Return the dewpoint temperature. |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
object in order to perform the calculation. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
or an iterable sequence of the aforementioned types. |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
all times in the file or sequence. The default is 0. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
The default is 'cat'. |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
of the output. Default is True. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
Default is None. |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
:class:`xarray.DataArray`. Default is True. |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
purposes only. Default is None. |
||||
|
||||
units (:obj:`str`): The desired units. Refer to the :meth:`getvar` |
||||
product table for a list of available units for 'td'. Default |
||||
|
||||
units (:obj:`str`): The desired units. Refer to the :meth:`getvar` |
||||
product table for a list of available units for 'td'. Default |
||||
is 'degC'. |
||||
|
||||
|
||||
Returns: |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The |
||||
dewpoint temperature. |
||||
If xarray is enabled and the *meta* parameter is True, then the result |
||||
will be a :class:`xarray.DataArray` object. Otherwise, the result will |
||||
If xarray is enabled and the *meta* parameter is True, then the result |
||||
will be a :class:`xarray.DataArray` object. Otherwise, the result will |
||||
be a :class:`numpy.ndarray` object with no metadata. |
||||
|
||||
|
||||
""" |
||||
|
||||
varnames=("P", "PB", "QVAPOR") |
||||
|
||||
varnames = ("P", "PB", "QVAPOR") |
||||
ncvars = extract_vars(wrfin, timeidx, varnames, method, squeeze, cache, |
||||
meta=False, _key=_key) |
||||
|
||||
|
||||
p = ncvars["P"] |
||||
pb = ncvars["PB"] |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# break with every release |
||||
qvapor = ncvars["QVAPOR"].copy() |
||||
|
||||
|
||||
# Algorithm requires hPa |
||||
full_p = .01*(p + pb) |
||||
qvapor[qvapor < 0] = 0 |
||||
|
||||
|
||||
td = _td(full_p, qvapor) |
||||
return td |
||||
|
||||
@copy_and_set_metadata(copy_varname="Q2", name="td2", |
||||
|
||||
@copy_and_set_metadata(copy_varname="Q2", name="td2", |
||||
description="2m dew point temperature") |
||||
@convert_units("temp", "c") |
||||
def get_dp_2m(wrfin, timeidx=0, method="cat", squeeze=True, |
||||
def get_dp_2m(wrfin, timeidx=0, method="cat", squeeze=True, |
||||
cache=None, meta=True, _key=None, units="degC"): |
||||
"""Return the 2m dewpoint temperature. |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
object in order to perform the calculation. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
or an iterable sequence of the aforementioned types. |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
all times in the file or sequence. The default is 0. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
The default is 'cat'. |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
of the output. Default is True. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
Default is None. |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
:class:`xarray.DataArray`. Default is True. |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
purposes only. Default is None. |
||||
|
||||
units (:obj:`str`): The desired units. Refer to the :meth:`getvar` |
||||
product table for a list of available units for 'td2'. Default |
||||
|
||||
units (:obj:`str`): The desired units. Refer to the :meth:`getvar` |
||||
product table for a list of available units for 'td2'. Default |
||||
is 'degC'. |
||||
|
||||
|
||||
Returns: |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The |
||||
2m dewpoint temperature. |
||||
If xarray is enabled and the *meta* parameter is True, then the result |
||||
will be a :class:`xarray.DataArray` object. Otherwise, the result will |
||||
If xarray is enabled and the *meta* parameter is True, then the result |
||||
will be a :class:`xarray.DataArray` object. Otherwise, the result will |
||||
be a :class:`numpy.ndarray` object with no metadata. |
||||
|
||||
|
||||
""" |
||||
varnames=("PSFC", "Q2") |
||||
varnames = ("PSFC", "Q2") |
||||
ncvars = extract_vars(wrfin, timeidx, varnames, method, squeeze, cache, |
||||
meta=False, _key=_key) |
||||
|
||||
# Algorithm requires hPa |
||||
psfc = .01*(ncvars["PSFC"]) |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# break with every release |
||||
q2 = ncvars["Q2"].copy() |
||||
q2[q2 < 0] = 0 |
||||
|
||||
|
||||
td = _td(psfc, q2) |
||||
|
||||
return td |
||||
|
||||
return td |
||||
|
@ -1,91 +1,86 @@
@@ -1,91 +1,86 @@
|
||||
from __future__ import (absolute_import, division, print_function) |
||||
|
||||
#from .extension import computepw,computetv,computetk |
||||
from .extension import _pw, _tv, _tk |
||||
from .constants import Constants |
||||
from .util import extract_vars |
||||
from .metadecorators import copy_and_set_metadata |
||||
|
||||
|
||||
@copy_and_set_metadata(copy_varname="T", name="pw", |
||||
@copy_and_set_metadata(copy_varname="T", name="pw", |
||||
remove_dims=("bottom_top",), |
||||
description="precipitable water", |
||||
MemoryOrder="XY", |
||||
units="kg m-2") |
||||
def get_pw(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, |
||||
def get_pw(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, |
||||
meta=True, _key=None): |
||||
"""Return the preciptiable water. |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
object in order to perform the calculation. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
or an iterable sequence of the aforementioned types. |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
all times in the file or sequence. The default is 0. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
The default is 'cat'. |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
of the output. Default is True. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
Default is None. |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
:class:`xarray.DataArray`. Default is True. |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
purposes only. Default is None. |
||||
|
||||
|
||||
Returns: |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The preciptable |
||||
water. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The preciptable |
||||
water. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
:class:`numpy.ndarray` object with no metadata. |
||||
|
||||
|
||||
""" |
||||
varnames=("T", "P", "PB", "PH", "PHB", "QVAPOR") |
||||
varnames = ("T", "P", "PB", "PH", "PHB", "QVAPOR") |
||||
ncvars = extract_vars(wrfin, timeidx, varnames, method, squeeze, cache, |
||||
meta=False, _key=_key) |
||||
|
||||
|
||||
t = ncvars["T"] |
||||
p = ncvars["P"] |
||||
pb = ncvars["PB"] |
||||
ph = ncvars["PH"] |
||||
phb = ncvars["PHB"] |
||||
qv = ncvars["QVAPOR"] |
||||
|
||||
|
||||
full_p = p + pb |
||||
ht = (ph + phb)/Constants.G |
||||
full_t = t + Constants.T_BASE |
||||
|
||||
|
||||
tk = _tk(full_p, full_t) |
||||
tv = _tv(tk, qv) |
||||
|
||||
|
||||
return _pw(full_p, tv, qv, ht) |
||||
|
||||
|
||||
|
||||
|
@ -1,156 +1,154 @@
@@ -1,156 +1,154 @@
|
||||
from __future__ import (absolute_import, division, print_function) |
||||
|
||||
from .constants import Constants |
||||
#from .extension import computerh, computetk |
||||
from .constants import Constants |
||||
from .extension import _rh, _tk |
||||
from .util import extract_vars |
||||
from .metadecorators import copy_and_set_metadata |
||||
|
||||
|
||||
@copy_and_set_metadata(copy_varname="T", name="rh", |
||||
@copy_and_set_metadata(copy_varname="T", name="rh", |
||||
description="relative humidity", |
||||
units="%") |
||||
def get_rh(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, |
||||
def get_rh(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, |
||||
meta=True, _key=None): |
||||
"""Return the relative humidity. |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
object in order to perform the calculation. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
or an iterable sequence of the aforementioned types. |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
all times in the file or sequence. The default is 0. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
The default is 'cat'. |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
of the output. Default is True. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
Default is None. |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
:class:`xarray.DataArray`. Default is True. |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
purposes only. Default is None. |
||||
|
||||
|
||||
Returns: |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The relative |
||||
humidity. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The relative |
||||
humidity. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
:class:`numpy.ndarray` object with no metadata. |
||||
|
||||
|
||||
""" |
||||
varnames=("T", "P", "PB", "QVAPOR") |
||||
varnames = ("T", "P", "PB", "QVAPOR") |
||||
ncvars = extract_vars(wrfin, timeidx, varnames, method, squeeze, cache, |
||||
meta=False, _key=_key) |
||||
t = ncvars["T"] |
||||
p = ncvars["P"] |
||||
pb = ncvars["PB"] |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# break with every release |
||||
qvapor = ncvars["QVAPOR"].copy() |
||||
|
||||
|
||||
full_t = t + Constants.T_BASE |
||||
full_p = p + pb |
||||
qvapor[qvapor < 0] = 0 |
||||
tk = _tk(full_p, full_t) |
||||
rh = _rh(qvapor, full_p, tk) |
||||
|
||||
|
||||
return rh |
||||
|
||||
|
||||
@copy_and_set_metadata(copy_varname="T2", name="rh2", |
||||
@copy_and_set_metadata(copy_varname="T2", name="rh2", |
||||
description="2m relative humidity", |
||||
units="%") |
||||
def get_rh_2m(wrfin, timeidx=0, method="cat", squeeze=True, cache=None, |
||||
meta=True, _key=None): |
||||
"""Return the 2m relative humidity. |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
|
||||
This functions extracts the necessary variables from the NetCDF file |
||||
object in order to perform the calculation. |
||||
|
||||
|
||||
Args: |
||||
|
||||
|
||||
wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
iterable): WRF-ARW NetCDF |
||||
data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` |
||||
or an iterable sequence of the aforementioned types. |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
|
||||
timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The |
||||
desired time index. This value can be a positive integer, |
||||
negative integer, or |
||||
:data:`wrf.ALL_TIMES` (an alias for None) to return |
||||
all times in the file or sequence. The default is 0. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
|
||||
method (:obj:`str`, optional): The aggregation method to use for |
||||
sequences. Must be either 'cat' or 'join'. |
||||
'cat' combines the data along the Time dimension. |
||||
'join' creates a new dimension for the file index. |
||||
The default is 'cat'. |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
|
||||
squeeze (:obj:`bool`, optional): Set to False to prevent dimensions |
||||
with a size of 1 from being automatically removed from the shape |
||||
of the output. Default is True. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
|
||||
cache (:obj:`dict`, optional): A dictionary of (varname, ndarray) |
||||
that can be used to supply pre-extracted NetCDF variables to the |
||||
computational routines. It is primarily used for internal |
||||
purposes, but can also be used to improve performance by |
||||
eliminating the need to repeatedly extract the same variables |
||||
used in multiple diagnostics calculations, particularly when using |
||||
large sequences of files. |
||||
Default is None. |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
|
||||
meta (:obj:`bool`, optional): Set to False to disable metadata and |
||||
return :class:`numpy.ndarray` instead of |
||||
:class:`xarray.DataArray`. Default is True. |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
|
||||
_key (:obj:`int`, optional): A caching key. This is used for internal |
||||
purposes only. Default is None. |
||||
|
||||
|
||||
Returns: |
||||
:class:`xarray.DataArray` or :class:`numpy.ndarray`: The 2m relative |
||||
humidity. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
humidity. If xarray is |
||||
enabled and the *meta* parameter is True, then the result will be a |
||||
:class:`xarray.DataArray` object. Otherwise, the result will be a |
||||
:class:`numpy.ndarray` object with no metadata. |
||||
|
||||
|
||||
""" |
||||
varnames=("T2", "PSFC", "Q2") |
||||
varnames = ("T2", "PSFC", "Q2") |
||||
ncvars = extract_vars(wrfin, timeidx, varnames, method, squeeze, cache, |
||||
meta=False, _key=_key) |
||||
t2 = ncvars["T2"] |
||||
psfc = ncvars["PSFC"] |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# Copy needed for the mmap nonsense of scipy.io.netcdf, which seems to |
||||
# break with every release |
||||
q2 = ncvars["Q2"].copy() |
||||
|
||||
|
||||
q2[q2 < 0] = 0 |
||||
rh = _rh(q2, psfc, t2) |
||||
|
||||
return rh |
||||
|
||||
return rh |
||||
|
Loading…
Reference in new issue