经度坐标系-180°180°和0°360°的相互转换。
-180° — 180° 到 0° — 360°
假使数据默认经度坐标系为-180°~180°
1 2 3 4 5 6 7
| <xarray.Dataset> Dimensions: (lat: 181, lon: 360) Coordinates: * lat (lat) int64 90 89 88 87 86 85 84 83 ... -84 -85 -86 -87 -88 -89 -90 * lon (lon) int64 -180 -179 -178 -177 -176 -175 ... 175 176 177 178 179 Data variables: pop (lat, lon) float64 ...
|
对其进行坐标系变换:
1 2 3 4
| f = xr.open_dataset("./pop_1x1_2000.nc") f.coords['lon'] = np.mod(f['lon'], 360) f = f.reindex({ 'lon' : np.sort(f['lon'])}) print(f)
|
输出结果为:
1 2 3 4 5 6 7
| <xarray.Dataset> Dimensions: (lat: 181, lon: 360) Coordinates: * lon (lon) int64 0 1 2 3 4 5 6 7 8 ... 352 353 354 355 356 357 358 359 * lat (lat) int64 90 89 88 87 86 85 84 83 ... -84 -85 -86 -87 -88 -89 -90 Data variables: pop (lat, lon) float64 ...
|
0° — 360° 到 -180° — 180°
假使数据默认经度坐标系为0°~360°
1 2 3 4 5 6 7
| <xarray.Dataset> Dimensions: (lat: 720, lon: 1440) Coordinates: * lat (lat) float64 89.88 89.62 89.38 89.12 ... -89.38 -89.62 -89.88 * lon (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9 Data variables: pop (lat, lon) float64 ...
|
对其进行坐标系变换:
1 2 3 4
| f = xr.open_dataset('./pop_025_2000.nc') f.coords['lon'] = f['lon'].where(f['lon'] <= 180, f['lon'] - 360) f = f.reindex({ 'lon' : np.sort(f['lon'])}) print(f)
|
输出结果为:
1 2 3 4 5 6 7
| <xarray.Dataset> Dimensions: (lon: 1440, lat: 720) Coordinates: * lon (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9 * lat (lat) float64 89.88 89.62 89.38 89.12 ... -89.38 -89.62 -89.88 Data variables: pop (lat, lon) float64 ...
|