本文整理汇总了Python中xarray.Dataset.attrs['geospatial_bounds']方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.attrs['geospatial_bounds']方法的具体用法?Python Dataset.attrs['geospatial_bounds']怎么用?Python Dataset.attrs['geospatial_bounds']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xarray.Dataset
的用法示例。
在下文中一共展示了Dataset.attrs['geospatial_bounds']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_spatial_attrs_impl
# 需要导入模块: from xarray import Dataset [as 别名]
# 或者: from xarray.Dataset import attrs['geospatial_bounds'] [as 别名]
def adjust_spatial_attrs_impl(ds: xr.Dataset, allow_point: bool) -> xr.Dataset:
"""
Adjust the global spatial attributes of the dataset by doing some
introspection of the dataset and adjusting the appropriate attributes
accordingly.
In case the determined attributes do not exist in the dataset, these will
be added.
For more information on suggested global attributes see
`Attribute Convention for Data Discovery
<http://wiki.esipfed.org/index.php/Attribute_Convention_for_Data_Discovery>`_
:param ds: Dataset to adjust
:param allow_point: Whether to accept single point cells
:return: Adjusted dataset
"""
copied = False
for dim in ('lon', 'lat'):
geo_spatial_attrs = _get_geo_spatial_cf_attrs_from_var(ds, dim, allow_point=allow_point)
if geo_spatial_attrs:
# Copy any new attributes into the shallow Dataset copy
for key in geo_spatial_attrs:
if geo_spatial_attrs[key] is not None:
if not copied:
ds = ds.copy()
copied = True
ds.attrs[key] = geo_spatial_attrs[key]
lon_min = ds.attrs.get('geospatial_lon_min')
lat_min = ds.attrs.get('geospatial_lat_min')
lon_max = ds.attrs.get('geospatial_lon_max')
lat_max = ds.attrs.get('geospatial_lat_max')
if lon_min is not None and lat_min is not None and lon_max is not None and lat_max is not None:
if not copied:
ds = ds.copy()
ds.attrs['geospatial_bounds'] = 'POLYGON(({} {}, {} {}, {} {}, {} {}, {} {}))'. \
format(lon_min, lat_min, lon_min, lat_max, lon_max, lat_max, lon_max, lat_min, lon_min, lat_min)
# Determination of the following attributes from introspection in a general
# way is ambiguous, hence it is safer to drop them than to risk preserving
# out of date attributes.
drop = ['geospatial_bounds_crs', 'geospatial_bounds_vertical_crs',
'geospatial_vertical_min', 'geospatial_vertical_max',
'geospatial_vertical_positive', 'geospatial_vertical_units',
'geospatial_vertical_resolution']
for key in drop:
ds.attrs.pop(key, None)
return ds