當前位置: 首頁>>代碼示例>>Python>>正文


Python xarray.set_options方法代碼示例

本文整理匯總了Python中xarray.set_options方法的典型用法代碼示例。如果您正苦於以下問題:Python xarray.set_options方法的具體用法?Python xarray.set_options怎麽用?Python xarray.set_options使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xarray的用法示例。


在下文中一共展示了xarray.set_options方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_repr_html

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def test_repr_html(self):
        """Test if the function _repr_html is generating html."""
        idata = load_arviz_data("centered_eight")
        display_style = OPTIONS["display_style"]
        xr.set_options(display_style="html")
        html = idata._repr_html_()  # pylint: disable=protected-access

        assert html is not None
        assert "<div" in html
        for group in idata._groups:  # pylint: disable=protected-access
            assert group in html
            xr_data = getattr(idata, group)
            for item, _ in xr_data.items():
                assert item in html
        specific_style = ".xr-wrap{width:700px!important;}"
        assert specific_style in html

        xr.set_options(display_style="text")
        html = idata._repr_html_()  # pylint: disable=protected-access
        assert escape(idata.__repr__()) in html
        xr.set_options(display_style=display_style) 
開發者ID:arviz-devs,項目名稱:arviz,代碼行數:23,代碼來源:test_data.py

示例2: test_repr_HC

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def test_repr_HC(
    hind_ds_initialized_1d, hist_ds_uninitialized_1d, observations_ds_1d, display_style,
):
    """Test html repr."""
    with xr.set_options(display_style=display_style):
        he = HindcastEnsemble(hind_ds_initialized_1d)
        display(he)
        he = he.add_uninitialized(hist_ds_uninitialized_1d)
        display(he)
        he = he.add_observations(observations_ds_1d, 'OBS1')
        display(he)
        he = he.add_observations(observations_ds_1d, 'OBS2')
        display(he)
        # no uninit
        he = HindcastEnsemble(hind_ds_initialized_1d)
        he = he.add_observations(observations_ds_1d, 'OBS1')
        display(he) 
開發者ID:bradyrx,項目名稱:climpred,代碼行數:19,代碼來源:test_repr.py

示例3: __init__

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def __init__(self, **kwargs):
        self.old = xr.set_options(**kwargs).old 
開發者ID:NCAR,項目名稱:esmlab,代碼行數:4,代碼來源:common_utils.py

示例4: __exit__

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def __exit__(self, *exc):
        xr.set_options(**self.old)
        return 
開發者ID:NCAR,項目名稱:esmlab,代碼行數:5,代碼來源:common_utils.py

示例5: __init__

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def __init__(self, data):
        super().__init__()
        xr.set_options(display_style='html')
        pn.extension(raw_css=[CSS])
        self.data = data
        self.panel = pn.pane.HTML(min_width=500, max_height=250, css_classes=['xrviz-scroll'])
        self.panel.object = "Description Section"
        self.setup() 
開發者ID:intake,項目名稱:xrviz,代碼行數:10,代碼來源:describe.py

示例6: test_repr_PM

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def test_repr_PM(PM_da_initialized_1d, PM_da_control_1d, display_style):
    """Test html and text repr."""
    with xr.set_options(display_style=display_style):
        pm = PerfectModelEnsemble(PM_da_initialized_1d)
        display(pm)
        pm = pm.add_control(PM_da_control_1d)
        display(pm)
        pm = pm.generate_uninitialized()
        display(pm) 
開發者ID:bradyrx,項目名稱:climpred,代碼行數:11,代碼來源:test_repr.py

示例7: get_correction

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def get_correction(x: xr.DataArray, y: xr.DataArray, kind: str):
    """Return the additive or multiplicative correction/adjustment factors."""
    with xr.set_options(keep_attrs=True):
        if kind == ADDITIVE:
            out = y - x
        elif kind == MULTIPLICATIVE:
            out = y / x
        else:
            raise ValueError("kind must be + or *.")

    if isinstance(out, xr.DataArray):
        out.attrs["kind"] = kind
    return out 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:15,代碼來源:utils.py

示例8: apply_correction

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def apply_correction(x: xr.DataArray, factor: xr.DataArray, kind: Optional[str] = None):
    """Apply the additive or multiplicative correction/adjustment factors.

    If kind is not given, default to the one stored in the "kind" attribute of factor.
    """
    kind = kind or factor.get("kind", None)
    with xr.set_options(keep_attrs=True):
        if kind == ADDITIVE:
            out = x + factor
        elif kind == MULTIPLICATIVE:
            out = x * factor
        else:
            raise ValueError
    return out 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:16,代碼來源:utils.py

示例9: invert

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def invert(x: xr.DataArray, kind: Optional[str] = None):
    """Invert a DataArray either additively (-x) or multiplicatively (1/x).

    If kind is not given, default to the one stored in the "kind" attribute of x.
    """
    kind = kind or x.get("kind", None)
    with xr.set_options(keep_attrs=True):
        if kind == ADDITIVE:
            return -x
        if kind == MULTIPLICATIVE:
            return 1 / x
        raise ValueError 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:14,代碼來源:utils.py

示例10: _adjust

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def _adjust(self, sim, interp="linear"):
        sth = broadcast(self.ds.hist_thresh, sim, group=self.group, interp=interp)
        factor = broadcast(self.ds.af, sim, group=self.group, interp=interp)
        with xr.set_options(keep_attrs=True):
            scen = (factor * (sim - sth) + self.ds.ref_thresh).clip(min=0)
        return scen 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:8,代碼來源:adjustment.py

示例11: isothermality

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def isothermality(tasmin: xarray.DataArray, tasmax: xarray.DataArray, freq: str = "YS"):
    r"""Isothermality

    The mean diurnal range divided by the annual temperature range.

    Parameters
    ----------
    tasmin : xarray.DataArray
      Average daily minimum temperature [℃] or [K] at daily, weekly, or monthly frequency.
    tasmax : xarray.DataArray
      Average daily maximum temperature [℃] or [K] at daily, weekly, or monthly frequency.
    freq : str
      Resampling frequency; Defaults to "YS".

    Returns
    -------
    xarray.DataArray
      The isothermality value expressed as a percent.

    Notes
    -----
    According to the ANUCLIM user-guide https://fennerschool.anu.edu.au/files/anuclim61.pdf (ch. 6), input
    values should be at a weekly (or monthly) frequency.  However, the xclim.indices implementation here will calculate
    the output with input data with daily frequency as well. As such weekly or monthly input values, if desired, should
    be calculated prior to calling the function.
    """

    dtr = daily_temperature_range(tasmin=tasmin, tasmax=tasmax, freq=freq)
    etr = extreme_temperature_range(tasmin=tasmin, tasmax=tasmax, freq=freq)
    with xarray.set_options(keep_attrs=True):
        iso = dtr / etr * 100
        iso.attrs["units"] = "%"
    return iso 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:35,代碼來源:_anuclim.py

示例12: mon_series

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def mon_series(series, mon_triangular):
    def _mon_series(values, name):
        """Random time series whose mean varies over a monthly cycle."""
        x = series(values, name)
        m = mon_triangular
        factor = series(m[x.time.dt.month - 1], name)

        with xr.set_options(keep_attrs=True):
            return apply_correction(x, factor, x.kind)

    return _mon_series 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:13,代碼來源:conftest.py

示例13: cmip3_day_tas

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def cmip3_day_tas():
    # xr.set_options(enable_cftimeindex=False)
    ds = xr.open_dataset(
        os.path.join(TESTS_DATA, "cmip3", "tas.sresb1.giss_model_e_r.run1.atm.da.nc")
    )
    yield ds.tas
    ds.close() 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:9,代碼來源:test_indices.py

示例14: precip_seasonality

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def precip_seasonality(pr: xarray.DataArray,):
    r""" ANUCLIM Precipitation Seasonality (C of V)

    The annual precipitation Coefficient of Variation (C of V) expressed in percent. Calculated as the standard deviation
    of precipitation values for a given year expressed as a percentage of the mean of those values.


    Parameters
    ----------
    pr : xarray.DataArray
      Total precipitation rate at daily, weekly, or monthly frequency.
      Units need to be defined as a rate (e.g. mm d-1, mm week-1).

    Returns
    -------
    xarray.DataArray
      The coefficient of variation of precipitation values.

    Examples
    --------
    The following would compute for each grid cell of file `pr.day.nc` the annual precipitation seasonality:

    >>> import xclim.indices as xci
    >>> p = xr.open_dataset('pr.day.nc')
    >>> pday_seasonality = xci.precip_seasonality(p)

    >>> p_weekly = xci.precip_accumulation(p, freq='7D')
    >>> p_weekly.attrs['units'] = "mm/week" # input units need to be a rate
    >>> pweek_seasonality = xci.precip_seasonality(p_weekly)

    Notes
    -----
    According to the ANUCLIM user-guide https://fennerschool.anu.edu.au/files/anuclim61.pdf (ch. 6), input
    values should be at a weekly (or monthly) frequency.  However, the xclim.indices implementation here will calculate
    the result with input data with daily frequency as well. As such weekly or monthly input values, if desired,
    should be calculated prior to calling the function.

    If input units are in mm s-1 (or equivalent) values are converted to mm/day to avoid potentially small denominator
    values.

    """

    # If units in mm/sec convert to mm/days to avoid potentially small denominator
    if units2pint(pr) == units("mm / s"):
        pr = convert_units_to(pr, "mm d-1")

    with xarray.set_options(keep_attrs=True):
        seas = 100 * _anuclim_coeff_var(pr)

    seas.attrs["units"] = "percent"
    return seas 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:53,代碼來源:_anuclim.py

示例15: tg_mean_wetdry_quarter

# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import set_options [as 別名]
def tg_mean_wetdry_quarter(
    tas: xarray.DataArray,
    pr: xarray.DataArray,
    op: str = None,
    input_freq: str = None,
    freq: str = "YS",
):
    r""" ANUCLIM Mean temperature of wettest/driest quarter

    The wettest (or driest) quarter of the year is determined, and the mean temperature of this period is calculated.
    If the input data frequency is "daily" or "weekly" quarters are defined as 13 week periods, otherwise are 3 months.

    Parameters
    ----------
    tas : xarray.DataArray
      Mean temperature [℃] or [K] at daily, weekly, or monthly frequency.
    pr : xarray.DataArray
      Total precipitation rate at daily, weekly, or monthly frequency.
    op : str {'wettest', 'driest'}
      Operation to perform: 'wettest' calculate for the wettest quarter; 'driest' calculate for the driest quarter.
    input_freq : str
      Input data time frequency - One of 'daily', 'weekly' or 'monthly'.
    freq : str
      Resampling frequency; Defaults to "YS".

    Returns
    -------
    xarray.DataArray
       Mean temperature values of the wettest/driest quarter of each year.

    Notes
    -----
    According to the ANUCLIM user-guide https://fennerschool.anu.edu.au/files/anuclim61.pdf (ch. 6), input
    values should be at a weekly (or monthly) frequency.  However, the xclim.indices implementation here will calculate
    the result with input data with daily frequency as well. As such weekly or monthly input values, if desired,
    should be calculated prior to calling the function.

    """
    tas_qrt = _to_quarter(input_freq, tas=tas)
    pr_qrt = _to_quarter(input_freq, pr=pr)

    xr_op = _xr_argops[op]
    with xarray.set_options(keep_attrs=True):
        out = _from_other_arg(criteria=pr_qrt, output=tas_qrt, op=xr_op, freq=freq)
        out.attrs = tas.attrs
        return out 
開發者ID:Ouranosinc,項目名稱:xclim,代碼行數:48,代碼來源:_anuclim.py


注:本文中的xarray.set_options方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。