Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect high values from numpy array

Im working on a detecting alogrythm for detecting storm cells on a radar imagery. I have radar data in 2d numpy arrays that we plot on a basemap. We got azymuth and rangebins data that we put in a polargrid with lat/lon coordinates.

The values in our numpy array are based on dBZ height in range from zero till maximum 80.

Here a printout of our numpy array named data:

[[-31.5 -31.5  16.5 ..., -31.5 -31.5 -31.5]
[-31.5 -31.5 -31.5 ..., -31.5 -31.5 -31.5]
[-31.5 -31.5 -31.5 ..., -31.5 -31.5 -31.5]
...,
[-31.5 -31.5 -31.5 ..., -31.5 -31.5 -31.5]
[-31.5 -31.5 -31.5 ..., -31.5 -31.5 -31.5]
[-31.5  11.5 -31.5 ..., -31.5 -31.5 -31.5]]

While -31.5 stands for null or hidden values. We only need the positive values. Even decimals make no sense.

So what do we want to do:

Detect the clusters of high values, and make them a red square around that cell. I have tried something with a image mask but i got stuck there. Even i dont know if an image mask is a good solution for this issue.

Here is my code to process the data.

gain             = 0.5                                  
offset           = -31.5

az = np.arange(0.,360.,360./scan["scan_number_azim"])
r  = np.arange(scan["scan_start_azim"], (scan["scan_start_azim"] + scan["scan_number_range"] * rscale), rscale)
data = gain * raw["scan2/scan_Z_data"] + offset

So the count of the detections would fluctuate very often. Maybe i need something like DBscan also ?

Can someone help me up with this ?

like image 586
user3408380 Avatar asked May 05 '14 10:05

user3408380


People also ask

How do you find the highest value in an array in Python?

Python also has a built-in max() function that can calculate maximum values of iterables. You can use this built-in max() to find the maximum element in a one-dimensional NumPy array, but it has no support for arrays with more dimensions.

How do I find the most frequent value in a NumPy array?

Steps to find the most frequency value in a NumPy array:Create a NumPy array. Apply bincount() method of NumPy to get the count of occurrences of each element in the array. The n, apply argmax() method to get the value having a maximum number of occurrences(frequency).

Which of the following finds maximum numbers in NumPy array?

Here, we create a single-dimensional NumPy array of integers. Now try to find the maximum element. To do this we have to use numpy. max(“array name”) function.

Does MAX () work with arrays?

M = max( A ) returns the maximum elements of an array. If A is a vector, then max(A) returns the maximum of A . If A is a matrix, then max(A) is a row vector containing the maximum value of each column of A .


1 Answers

If you can use scipy, I think something like this will work:

import scipy.ndimage

mask = data > 20
labels, num_labels = scipy.ndimage.label(mask)
custers = scipy.ndimage.find_objects(labels)

And clusters will now be a list of tuples of slices, and you can get the starting and ending rows and columns of your rectangles as:

for row_slice, col_slice in clusters:
    start_row = row_slice.start
    end_row = row_slice.stop
    start_col = col_slice.start
    end_col = col_slice.stop
    # draw your rectangle
like image 163
Jaime Avatar answered Sep 28 '22 06:09

Jaime