Python NetCDF 本初子午线空白

问题描述 投票:0回答:1

我正在尝试绘制 GPCC 降水气候图。

但是我发现本初子午线有一个空白(数据剪切)。

我该如何解决这个问题?我可以使用 CDO、NCO、Python。

我也分享代码和数据。

(数据) https://drive.google.com/drive/folders/1rEHKz5GQlvC3m_Cfzx48cTrPZPU0qAar?usp=sharing

(GPCC 元数据) https://opendata.dwd.de/climate_environment/GPCC/html/fulldata-monthly_v2022_doi_download.html

enter image description here

enter image description here

type here

from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

import xarray as xr
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import calendar

import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.feature as cfeature
import cftime
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
%matplotlib inline

mpl.rcParams['figure.figsize'] = [8., 6.]

filename = 'D:/ERA5/precip.nc'
ds = xr.open_dataset(filename)
ds

da = ds['precip']
da

def is_jjas(month):
    return (month >= 6) & (month <= 9)

dd = da.sel(time=is_jjas(da['time.month']))

def is_1982(year):
    return (year> 1981)

dn = dd.sel(time=is_1982(dd['time.year']))
dn

JJAS= dn.groupby('time.year').mean('time')

JJAS2 = JJAS.mean(dim='year', keep_attrs=True)
JJAS2

fig, ax = plt.subplots(1, 1, figsize = (16, 8), subplot_kw={'projection': ccrs.PlateCarree()})

cs = plt.contourf(JJAS2.lon, JJAS2.lat, JJAS2, levels=[0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500],
                  vmin=0, vmax=500, cmap='Blues', extend='both')

# Set the figure title, add lat/lon grid and coastlines
ax.set_title('', fontsize=16)
ax.gridlines(draw_labels=True, linewidth=1, color='gray', alpha=0.5, linestyle='--') 
ax.coastlines(color='black')
ax.set_extent([-20, 30, 0, 30], crs=ccrs.PlateCarree())

cbar = plt.colorbar(cs,fraction=0.05, pad=0.04, extend='both', orientation='horizontal')

我尝试搜索Google并找到CDO方法。 如果我对数据进行插值,其分辨率可能会改变。 我想使用具有相同分辨率但没有任何空白的 GPCC 数据。

numpy python-xarray netcdf matplotlib-basemap cdo-climate
1个回答
0
投票

一个有用的函数是

add_cyclic
,它为 0 -> 360 经度添加重复点。尝试这样的事情:

import cartopy.util as cutil
lon2d, lat2d = np.meshgrid(JJAS2.lon,JJAS2.lat)
cdata, clon2d, clat2d = cutil.add_cyclic(JJAS2, lon2d, lat2d)

然后将它们用于情节...

© www.soinside.com 2019 - 2024. All rights reserved.