當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。