如何在每个网格IE处按时间轴对气候数据集的特定纬度和经度上的时间轴进行排序
我有一个气候数据集的NetCDF文件,其形状为20 * 445 * 445 AS(时间,纬度,经度),
我已将其读为 numpy.ma.core.maskedarray
使用 > netcdf4
库
array 在时间轴上的数据
我想对此 numpy 3D -
(纬度,经度)
该值应为上升或降序,
我尝试了
import netCDF4 as nc
from netCDF4 import Dataset,num2date,date2num
import sys,os,numpy as np,logging
from datetime import date, datetime, timedelta
import matplotlib.pyplot as plt
fileName = 'some_file'
data = Dataset(fileName, 'r')
temp_data = data.variables['Band1'][:,:,:]
数据集的原始数据集图
for i in range(0,20):
data_to_plot = temp_data[i]
fig, ax = plt.subplots(figsize = (4,4))
ax.set_title('Layer '+ str(i))
cax = ax.imshow(data_to_plot, cmap = plt.cm.Accent)
cbar = plt.colorbar(cax,
orientation='vertical',
fraction=0.045,
pad=0.05)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
sorted_temp_data = np.argsort(temp_data, axis=0)
排序
for i in range(0,20):
data_to_plot = sorted_temp_data[i]
fig, ax = plt.subplots(figsize = (4,4))
ax.set_title('Layer '+ str(i))
cax = ax.imshow(data_to_plot, cmap = plt.cm.Accent)
cbar = plt.colorbar(cax,
orientation='vertical',
fraction=0.045,
pad=0.05)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
如何做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
numpy的
argsort
函数不返回排序的数组。它返回排序的数组的索引。您可以直接沿时间轴(假设时间轴为0轴)直接对数组进行排序,如下所示:如果要使用ArgSort,则代码应该是这样:
Numpy's
argsort
function doesnt return sorted array. It returns the index of sorted array. You can directly sort the array along the time axis (assuming time axis is the 0th axis) as follows:If you want to use argsort the code should be like this: