- 积分
- 2572
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2020-11-22
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 wudi129 于 2022-3-10 10:41 编辑
- import numpy as np
- import matplotlib.pyplot as plt
- import netCDF4 as nc
- from netCDF4 import num2date
- import pandas as pd
- import datetime
- file = 'F:/data/HadCRUT.nc'
- data = nc.Dataset(file)
- lat = np.array(data.variables['latitude'])
- lon = np.array(data.variables['longitude'])
- t = np.array(data.variables['time'])
- tas_mean = np.array(data.variables['tas_mean'])
- tas_mean[tas_mean == -1.e+30] = np.nan
- def cftime2datetime(cftime, units, format='%Y-%m-%d %H:%M:%S'):
- """
- 将nc文件里面的时间格式 从cftime 转换到 datetime格式
- :param cftime:
- :param units:
- :param format:
- :return:
- """
- return datetime.datetime.strptime(num2date(times=cftime, units=units).strftime(format), format)
- clean_time_data = pd.Series([cftime2datetime(i, units='days since 1850-01-01 00:00:00') for i in t])
- def y_m(year):
- v = np.nanmean(tas_mean[clean_time_data.dt.year == year,:,:].flatten())
- return v
- year = np.arange(start = 1979,stop = np.max(clean_time_data.dt.year) + 1)
- need = pd.DataFrame({'year': year})
- need['tas_mean'] = need['year'].apply(lambda x: y_m(year = x))
- fig , ax = plt.subplots(figsize = (10,4),dpi = 150)
- ax.plot(need['year'],need['tas_mean'],linestyle = '-',marker = 'o')
- plt.show()
复制代码
|
评分
-
查看全部评分
|