当前位置: 首页>>代码示例>>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;未经允许,请勿转载。