当前位置: 首页>>代码示例>>Python>>正文


Python xarray.apply_ufunc方法代码示例

本文整理汇总了Python中xarray.apply_ufunc方法的典型用法代码示例。如果您正苦于以下问题:Python xarray.apply_ufunc方法的具体用法?Python xarray.apply_ufunc怎么用?Python xarray.apply_ufunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xarray的用法示例。


在下文中一共展示了xarray.apply_ufunc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _determine_input_core_dims

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def _determine_input_core_dims(dim, weights):
    """
    Determine input_core_dims based on type of dim and weights.

    Parameters
    ----------
    dim : str, list
        The dimension(s) to apply the correlation along.
    weights : xarray.Dataset or xarray.DataArray or None
        Weights matching dimensions of ``dim`` to apply during the function.

    Returns
    -------
    list of lists
        input_core_dims used for xr.apply_ufunc.
    """
    if not isinstance(dim, list):
        dim = [dim]
    # build input_core_dims depending on weights
    if weights is None:
        input_core_dims = [dim, dim, [None]]
    else:
        input_core_dims = [dim, dim, dim]
    return input_core_dims 
开发者ID:raybellwaves,项目名称:xskillscore,代码行数:26,代码来源:deterministic.py

示例2: windowed_run_events_ufunc

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def windowed_run_events_ufunc(x: Sequence[bool], window: int) -> xr.apply_ufunc:
    """Dask-parallel version of windowed_run_events_1d, ie the number of runs at least as long as given duration.

    Parameters
    ----------
    x : Sequence[bool]
      Input array (bool)
    window : int
      Minimum run length

    Returns
    -------
    out : func
      A function operating along the time dimension of a dask-array.
    """
    return xr.apply_ufunc(
        windowed_run_events_1d,
        x,
        input_core_dims=[["time"]],
        vectorize=True,
        dask="parallelized",
        output_dtypes=[np.int],
        keep_attrs=True,
        kwargs={"window": window},
    ) 
开发者ID:Ouranosinc,项目名称:xclim,代码行数:27,代码来源:run_length.py

示例3: longest_run_ufunc

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def longest_run_ufunc(x: Sequence[bool]) -> xr.apply_ufunc:
    """Dask-parallel version of longest_run_1d, ie the maximum number of consecutive true values in
    array.

    Parameters
    ----------
    x : Sequence[bool]
      Input array (bool)

    Returns
    -------
    out : func
      A function operating along the time dimension of a dask-array.
    """
    return xr.apply_ufunc(
        longest_run_1d,
        x,
        input_core_dims=[["time"]],
        vectorize=True,
        dask="parallelized",
        output_dtypes=[np.int],
        keep_attrs=True,
    ) 
开发者ID:Ouranosinc,项目名称:xclim,代码行数:25,代码来源:run_length.py

示例4: psd_fft

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def psd_fft(varr):
    _T = len(varr.coords['frame'])
    ns = _T // 2 + 1
    if _T % 2 == 0:
        freq_crd = np.linspace(0, 0.5, ns)
    else:
        freq_crd = np.linspace(0, 0.5 * (_T - 1) / _T, ns)
    print("computing psd of input")
    varr_fft = xr.apply_ufunc(
        fftw.rfft,
        varr.chunk(dict(frame=-1)),
        input_core_dims=[['frame']],
        output_core_dims=[['freq']],
        dask='allowed',
        output_sizes=dict(freq=ns),
        output_dtypes=[np.complex_])
    varr_fft = varr_fft.assign_coords(freq=freq_crd)
    varr_psd = 1 / _T * np.abs(varr_fft)**2
    return varr_psd 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:21,代码来源:cnmf.py

示例5: psd_welch

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def psd_welch(varr):
    _T = len(varr.coords['frame'])
    ns = _T // 2 + 1
    if _T % 2 == 0:
        freq_crd = np.linspace(0, 0.5, ns)
    else:
        freq_crd = np.linspace(0, 0.5 * (_T - 1) / _T, ns)
    varr_psd = xr.apply_ufunc(
            _welch,
            varr.chunk(dict(frame=-1)),
            input_core_dims=[['frame']],
            output_core_dims=[['freq']],
            dask='parallelized',
            vectorize=True,
            kwargs=dict(nperseg=_T),
            output_sizes=dict(freq=ns),
            output_dtypes=[varr.dtype])
    varr_psd = varr_psd.assign_coords(freq=freq_crd)
    return varr_psd 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:21,代码来源:cnmf.py

示例6: get_noise_welch

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def get_noise_welch(varr,
                    noise_range=(0.25, 0.5),
                    noise_method='logmexp',
                    compute=True):
    print("estimating noise")
    sn = xr.apply_ufunc(
        noise_welch,
        varr.chunk(dict(frame=-1)),
        input_core_dims=[['frame']],
        dask='parallelized',
        vectorize=True,
        kwargs=dict(noise_range=noise_range, noise_method=noise_method),
        output_dtypes=[varr.dtype])
    if compute:
        sn = sn.compute()
    return sn 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:18,代码来源:cnmf.py

示例7: ks_refine

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def ks_refine(varr, seeds, sig=0.05):
    print("selecting seeds")
    varr_sub = varr.sel(
        spatial=[tuple(hw) for hw in seeds[['height', 'width']].values])
    print("performing KS test")
    ks = xr.apply_ufunc(
        lambda x: kstest(zscore(x), 'norm')[1],
        varr_sub.chunk(dict(frame=-1, spatial='auto')),
        input_core_dims=[['frame']],
        vectorize=True,
        dask='parallelized',
        output_dtypes=[float])
    mask = ks < sig
    mask_df = mask.to_pandas().rename('mask_ks').reset_index()
    seeds = pd.merge(seeds, mask_df, on=['height', 'width'], how='left')
    return seeds 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:18,代码来源:initialization.py

示例8: __eq__

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def __eq__(self, other):
        if isinstance(other, Longitude):
            return (self.hemisphere == other.hemisphere and
                    self.longitude == other.longitude)
        else:
            return xr.apply_ufunc(np.equal, other, self) 
开发者ID:spencerahill,项目名称:aospy,代码行数:8,代码来源:longitude.py

示例9: __lt__

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def __lt__(self, other):
        if isinstance(other, Longitude):
            if self.hemisphere == 'W':
                if other.hemisphere == 'E':
                    return True
                else:
                    return self.longitude > other.longitude
            else:
                if other.hemisphere == 'W':
                    return False
                else:
                    return self.longitude < other.longitude
        else:
            return xr.apply_ufunc(np.greater, other, self) 
开发者ID:spencerahill,项目名称:aospy,代码行数:16,代码来源:longitude.py

示例10: __gt__

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def __gt__(self, other):
        if isinstance(other, Longitude):
            if self.hemisphere == 'W':
                if other.hemisphere == 'E':
                    return False
                else:
                    return self.longitude < other.longitude
            else:
                if other.hemisphere == 'W':
                    return True
                else:
                    return self.longitude > other.longitude
        else:
            return xr.apply_ufunc(np.less, other, self) 
开发者ID:spencerahill,项目名称:aospy,代码行数:16,代码来源:longitude.py

示例11: __le__

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def __le__(self, other):
        if isinstance(other, Longitude):
            return self < other or self == other
        else:
            return xr.apply_ufunc(np.greater_equal, other, self) 
开发者ID:spencerahill,项目名称:aospy,代码行数:7,代码来源:longitude.py

示例12: __ge__

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def __ge__(self, other):
        if isinstance(other, Longitude):
            return self > other or self == other
        else:
            return xr.apply_ufunc(np.less_equal, other, self) 
开发者ID:spencerahill,项目名称:aospy,代码行数:7,代码来源:longitude.py

示例13: xr_pearson_r

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def xr_pearson_r(x, y, dim):
    """pearson_r implementation using xarray and minimal numpy only."""
    return xr.apply_ufunc(
        pearson_correlation_gufunc,
        x,
        y,
        input_core_dims=[[dim], [dim]],
        dask='parallelized',
        output_dtypes=[float],
    ) 
开发者ID:raybellwaves,项目名称:xskillscore,代码行数:12,代码来源:xr_vs_xs.py

示例14: median_absolute_error

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def median_absolute_error(a, b, dim, skipna=False):
    """
    Median Absolute Error.

    Parameters
    ----------
    a : xarray.Dataset or xarray.DataArray
        Labeled array(s) over which to apply the function.
    b : xarray.Dataset or xarray.DataArray
        Labeled array(s) over which to apply the function.
    dim : str, list
        The dimension(s) to apply the median absolute error along.
    skipna : bool
        If True, skip NaNs when computing function.

    Returns
    -------
    xarray.Dataset or xarray.DataArray
        Median Absolute Error.

    See Also
    --------
    sklearn.metrics.median_absolute_error
    xarray.apply_ufunc
    xskillscore.core.np_deterministic._median_absolute_error

    """
    dim, axis = _preprocess_dims(dim)

    return xr.apply_ufunc(
        _median_absolute_error,
        a,
        b,
        input_core_dims=[dim, dim],
        kwargs={'axis': axis, 'skipna': skipna},
        dask='parallelized',
        output_dtypes=[float],
    ) 
开发者ID:raybellwaves,项目名称:xskillscore,代码行数:40,代码来源:deterministic.py

示例15: xr_crps_gaussian

# 需要导入模块: import xarray [as 别名]
# 或者: from xarray import apply_ufunc [as 别名]
def xr_crps_gaussian(observations, mu, sig):
    """
    xarray version of properscoring.crps_gaussian: Continuous Ranked
     Probability Score with a Gaussian distribution.
    Parameters
    ----------
    observations : xarray.Dataset or xarray.DataArray
        The observations or set of observations.
    mu : xarray.Dataset or xarray.DataArray
        The mean of the forecast normal distribution.
    sig : xarray.Dataset or xarray.DataArray
        The standard deviation of the forecast distribution.
    Returns
    -------
    xarray.Dataset or xarray.DataArray
    See Also
    --------
    properscoring.crps_gaussian
    xarray.apply_ufunc
    """
    # check if same dimensions
    if isinstance(mu, (int, float)):
        mu = xr.DataArray(mu)
    if isinstance(sig, (int, float)):
        sig = xr.DataArray(sig)
    if mu.dims != observations.dims:
        observations, mu = xr.broadcast(observations, mu)
    if sig.dims != observations.dims:
        observations, sig = xr.broadcast(observations, sig)
    return xr.apply_ufunc(
        crps_gaussian,
        observations,
        mu,
        sig,
        input_core_dims=[[], [], []],
        dask='parallelized',
        output_dtypes=[float],
    ) 
开发者ID:raybellwaves,项目名称:xskillscore,代码行数:40,代码来源:probabilistic.py


注:本文中的xarray.apply_ufunc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。