【发布时间】:2015-01-25 04:30:42
【问题描述】:
我有一个数据集 here,它是特定的 latitude 和 longitude
import numpy as np
f = open('bt_20130221_f17_v02_s.bin', 'rb')
data = np.fromfile(f, dtype=np.uint16).reshape(332, 316)
f.close()
raw_lat = open('pss25lats_v3.dat', 'rb')
lats = np.fromfile(raw_lat, dtype='<i4').reshape(332,316) / 100000.
raw_lat.close()
raw_lon = open('pss12lons_v3.dat', 'rb')
lons = np.fromfile(raw_lat, dtype='<i4').reshape(332,316) / 100000.
raw_lon.close()
数据值在此处显示为:
import matplotlib.pyplot as plt
plt.imshow(data)
基于这些值,我希望过滤这些数据的常规部分。 如:
north = -59.7183
south = -65.3099
west = -65.743
east = -48.55
mask_lons = np.ma.masked_where(((lons > east) | (lons < west)), lons)
mask_lats = np.ma.masked_where(((lats < south) | (lats > north)), lats)
data_filtered = np.where(((lats == mask_lats) & (lons == mask_lons)),
data, 999)
这是生成的图像:
第一个问题: 如何切片此 data_filtered 以仅获取有效值(即仅包含值的矩阵!= 999)?
第二个问题: 我如何对 lats 和 lons 做同样的事情?我应该如何仅将非屏蔽值作为每个变量的单个 2D 数组获取? 因为 mask_lons 是:
In [176]: mask_lons
Out[176]:
masked_array(data =
[[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
...,
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]],
mask =
[[ True True True ..., True True True]
[ True True True ..., True True True]
[ True True True ..., True True True]
...,
[ True True True ..., True True True]
[ True True True ..., True True True]
[ True True True ..., True True True]],
fill_value = 1e+20)
【问题讨论】:
-
您的帖子链接到 pss12lons 而不是 pss25lons,因此重塑不起作用
-
对此感到抱歉。我会解决的
标签: python python-2.7 numpy latitude-longitude slice