简体   繁体   English

在python np.array中对连续值进行分组

[英]grouping consecutive values in python np.array

I have got an array (500*490) long with data. 我有一个数组(500 * 490),长有数据。 It's actually raw data from a radar. 它实际上是来自雷达的原始数据。 I am planning on creating some sort of tracking, which finds showers & thunderstorms, based on their value in the array. 我计划创建某种跟踪,根据阵雨和雷暴在数组中的值来查找阵雨和雷暴。 The values range from 0 tot 75. 取值范围是0到75。

In order to find the showers & thunderstorms based on a treshold value, I have created an array from a raw h5 image, using h5py to read the file & then create an array out of it. 为了找到基于阈值的阵雨和雷暴,我从原始的h5图像创建了一个数组,使用h5py读取文件,然后从中创建一个数组。

import numpy as np
from numpy import inf
import pylab as pl
import math
import h5py
import scipy
import scipy.spatial

np.set_printoptions(threshold=10)

# read data
# *********
print "Reading & converting data data (mm/u - dbz)"
f = h5py.File('test.h5','r')
data = f.get('image1/image_data')
data_as_array = np.array(data)
datadbz = 20 * np.ma.log10(data_as_array)
print "*** Data read & converted"
print "raw array data = 'data_as_array'"
print "dbz array data = 'datadbz'"
print ""

# print raw data
# **************
print "Array from h5-file"
print "******************"
print data_as_array
print "*"
print ""

datadbz[datadbz == -inf] = 0
datadbz[datadbz == 96.32946777] = 0
datadbz[datadbz < 40] = 0

print "Array in dbz"
print "************"
print datadbz
print ""

# > 40 dbz
pixelarray = np.array(zip(*np.where(datadbz > 40)))
print "Array wich cores (> 40 dbz)"
print "***************************"
print pixelarray
print "*"
print ""

# > 55 dbz
hailarray = np.array(zip(*np.where(datadbz > 55)))
print "Array with cores (> 55 dbz)"
print "***************************"
print hailarray
print "*"
print ""

The 2 arrays I need to use are the array "pixelarray", which looks like the following snippet in the python shell 我需要使用的2个数组是数组“ pixelarray”,它看起来像python shell中的以下代码片段

Array wich cores (> 40 dbz)
***************************
[[  5 106]
 [  5 107]
 [  6 105]
 ..., 
 [440 270]
 [440 271]
 [489 151]]
*

and the other one is "hailarray", looking like this in the python shell 另一个是“ hailarray”,在python shell中看起来像这样

Array with cores (> 55 dbz)
***************************
[[  7 104]
 [  8 103]
 [ 27 194]
 ..., 
 [433 272]
 [435 272]
 [438 271]]
*

The point where I am stuck is the following... 我遇到的问题是...

Provided this is the radar image in question: 如果这是有问题的雷达图像:

radarimage 雷达图像

The array contains clutter, which should be discarded & ignored. 该数组包含杂波,应将其丢弃并忽略。 Those are the little splots & dots on the image. 这些是图像上的小斑点和点。 What I do need however, are the storms / showers. 但是,我需要的是暴风雨/阵雨。

In order to do that I need to figure out how to distinguish the clutter (random spots (values in the array) from the real echo's in the image (data ranges in the array) 为此,我需要弄清楚如何将杂波(随机斑点(数组中的值))与图像中的实际回声(数组中的数据范围)区分开来

Since the array I use looks like this, where each duo of values represent ax pixel & y pixel of the detection 由于我使用的数组看起来像这样,所以每个值的二重奏分别代表检测的x像素和y像素

[[  5 106]
 [  5 107]
 [  6 105]
 ..., 
 [440 270]
 [440 271]
 [489 151]]
*

I was thinking about grouping the pixelranges together. 我正在考虑将pixelranges分组在一起。 I know of a possibility to use "consecutive values" in an array and group them together, but I havent found a way to do that properly, because my array looks more like a matrix of some kind. 我知道有可能在数组中使用“连续值”并将它们分组在一起,但是我还没有找到正确执行此方法的方法,因为我的数组看起来更像某种矩阵。

Since I am not an expert in python I would have like to be pointed in the right direction as to how I can go about this. 由于我不是python专家,因此我想向正确的方向指出如何解决这个问题。 Once I have done this It's "only" a matter of finding which groups have a larger dimension than a certain treshold value, so I can get rid of the litte clutter spots & just be left with the storms themselves. 一旦完成此操作,这就是“仅”一个问题,即找出哪些组的维数大于某个阈值,这样我就可以摆脱杂乱的斑点,而只剩下暴风雨了。

I can then use the center of those larger groups as the center of the storms & the tracking should be complete. 然后,我可以将这些较大的组的中心用作风暴的中心,并完成跟踪。

So if anybody could help me set up the search for consecutive pixel ranges in the detection arrays I would be forever grateful, because I can't help the feeling of trying to invent the wheel here. 因此,如果有人可以帮助我在检测阵列中设置连续像素范围的搜索功能,我将永远感激不已,因为我无法忍受尝试在这里发明轮子的感觉。

If you have enough memory, you can build a dense representation of the image, and use you arrays to set the corresponding pixels there. 如果您有足够的内存,则可以构建图像的密集表示,并使用数组在此处设置相应的像素。 Then you can use an erosion filter on the image to eliminate the noise (like SciPy's binary_erosion ) 然后,您可以在图像上使用腐蚀滤镜以消除噪声(例如SciPy的binary_erosion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM