for index_lat in tqdm(range(raw_lat_data.shape[0])): for index_lon in range(raw_lon_data.shape[0]): point = (raw_lon_data[index_lon], raw_lat_data[index_lat]) mask_for_china[index_lat, index_lon] = pic(point[0], point[1])
def smooth_data(y_value, deg=4): x_new = np.arange(y_value.shape[0]) new_param = np.polyfit(x_new, y_value, deg=deg) value = np.zeros_like(x_new) for index, param in enumerate(new_param[::-1]): value = value + param * x_new ** index return value
ax.set_title("每年平均气温") ax.legend() ax.set_xlabel("年份") ax.set_ylabel("温度平均数$ ^\circ C $") plt.tight_layout() fig.savefig("结果/每年平均气温.png")
需求5和6
全世界每一年的平均数保存为tiff文件;
中国每一年的平均数保存为tiff文件;
def cal_need56(year, type): out = np.nanmean(raw_tmp_data[clean_time_data.dt.year == year, :, :], axis=0) iftype == 'world': value = out eliftype == 'china': out[~mask_for_china] = np.nan value = out else: value = None return value
out = cal_need56(year=2000, type='china') array2gtiff(array=out[::-1, :], filename="结果/year2000.tiff")
out = cal_need56(year=2000, type='world') array2gtiff(array=out[::-1, :], filename="结果/year2000_world.tiff")
#%%
for temp_year in tqdm(range(np.min(clean_time_data.dt.year), np.max(clean_time_data.dt.year) + 1)): out = cal_need56(year=temp_year, type='china') array2gtiff(array=out[::-1, :], filename=f"结果/year_{temp_year}_china.tiff")
out = cal_need56(year=temp_year, type='world') array2gtiff(array=out[::-1, :], filename=f"结果/year_{temp_year}_world.tiff")
需求7
特定时间范围内的数据保存为tiff文件(包括中国和全世界两种)
def cal_need7(start_date, end_date, type): out = np.nanmean(raw_tmp_data[(start_date <= clean_time_data) & (clean_time_data <= end_date), :, :], axis=0) iftype == 'world': value = out eliftype == 'china': out[~mask_for_china] = np.nan value = out else: value = None return value
out = cal_need7(start_date='1902-01', end_date='2020-01', type='world') array2gtiff(array=out[::-1, :], filename="结果/data190201_202001_world.tiff")
out = cal_need7(start_date='1902-01', end_date='2020-01', type='china') array2gtiff(array=out[::-1, :], filename="结果/data190201_202001_china.tiff")