本文整理汇总了Python中xarray.Dataset.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.apply方法的具体用法?Python Dataset.apply怎么用?Python Dataset.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xarray.Dataset
的用法示例。
在下文中一共展示了Dataset.apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _resample_dataset
# 需要导入模块: from xarray import Dataset [as 别名]
# 或者: from xarray.Dataset import apply [as 别名]
def _resample_dataset(ds_master: xr.Dataset, ds_replica: xr.Dataset, method_us: int, method_ds: int, monitor: Monitor) -> xr.Dataset:
"""
Resample replica onto the grid of the master.
This does spatial resampling the whole dataset, e.g., all
variables in the replica dataset.
This method works only if both datasets have (time, lat, lon) dimensions.
Note that dataset attributes are not propagated due to currently undecided CDM attributes' set.
:param ds_master: xr.Dataset whose lat/lon coordinates are used as the resampling grid
:param ds_replica: xr.Dataset that will be resampled on the masters' grid
:param method_us: Interpolation method for upsampling, see resampling.py
:param method_ds: Interpolation method for downsampling, see resampling.py
:param monitor: a progress monitor.
:return: xr.Dataset The resampled replica dataset
"""
# Find lat/lon bounds of the intersection of master and replica grids. The
# bounds should fall on pixel boundaries for both spatial dimensions for
# both datasets
lat_min, lat_max = _find_intersection(ds_master['lat'].values,
ds_replica['lat'].values,
global_bounds=(-90, 90))
lon_min, lon_max = _find_intersection(ds_master['lon'].values,
ds_replica['lon'].values,
global_bounds=(-180, 180))
# Subset replica dataset and master grid. We're not using here the subset
# operation, because the subset operation may produce datasets that cross
# the anti-meridian by design. However, such a disjoint dataset can not be
# resampled using our current resampling methods.
lat_slice = slice(lat_min, lat_max)
lon_slice = slice(lon_min, lon_max)
lon = ds_master['lon'].sel(lon=lon_slice)
lat = ds_master['lat'].sel(lat=lat_slice)
ds_replica = ds_replica.sel(lon=lon_slice, lat=lat_slice)
# Don't do anything if datasets already have the same spatial definition
if _grids_equal(ds_master, ds_replica):
return ds_replica
with monitor.starting("coregister dataset", len(ds_replica.data_vars)):
kwargs = {'lon': lon, 'lat': lat, 'method_us': method_us, 'method_ds': method_ds, 'parent_monitor': monitor}
retset = ds_replica.apply(_resample_array, keep_attrs=True, **kwargs)
return adjust_spatial_attrs(retset)