2014-11-26 2 views
1

나는 데이터 집합 here을 가지고 데이터 값을 여기에 제시 latitude과 특이하고 longitude데이터 필터링, - NumPy와

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) 

enter image description here

이러한 값을 기반으로이 데이터의 일정 부분을 필터링하려고합니다. 같은 :

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) 

이 결과 이미지 : enter image description here

첫 번째 질문 :이 data_filtered 슬라이스 어떻게 만 유효한 값을 획득하는 (! 즉, 단지 값을 포함하는 매트릭스 = 999) ?

두 번째 질문 : 어떻게하면 lats와 lons에도 동일한 작업을 수행 할 수 있습니까? 마스크되지 않은 값만 각 변수에 대한 sigle 2D 배열로 가져와야합니까? mask_lons 이후 은 다음과 같습니다

inside = np.logical_and(np.logical_and(lons >= west, 
             lons <= east), 
         np.logical_and(lats >= south, 
             lats <= north)) 

전체 노트북입니다 :

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) 
+0

게시물 링크를, 그래서 모양이 바뀌지 않아 – story645

+0

죄송합니다. 해결해 드리겠습니다. – arnaldo

답변

0
mask = (((south<=lats) & (lats<=north)) & ((west<=lons) & (lons<=east))) 
data = np.ma.masked_where(data, ~mask)