6

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 ?

4
  • 1
    I think you forgot to ask a question - what exactly do you need help with? Commented May 5, 2014 at 10:09
  • 1
    Sorry, i want to detect the clusters of higher values than 20dbz and make a colored square around them on the final product image. The detected clusters should get an ID or something that we can do other things with it later such as tracking and velocity speed of the movement of the cells. Thanks! Commented May 5, 2014 at 10:20
  • You can keep track of the particular cells with a masked array which gives them a kind of ID. I am not sure if it makes sense for your situation and what for tool you're using for plotting. Commented May 5, 2014 at 13:17
  • Thanks, we use wradlib for processing the raw radar data. Commented May 5, 2014 at 16:23

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Jaime, I got this response: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
scipy.ndimage.label returns two values, the array with the labels and the number of labels it found, that's probably what was tripping you, I corrected the code above. You can use num_labels to know beforehand how many different storms did the algorithm found.
Thank you, that worked, but i can't plot a rectangle on my existing figure. I had tried with this code: # draw your rectangle someX, someY = 0.5, 0.5 fig,ax = plt.subplots() currentAxis = plt.gca() currentAxis.add_patch(Rectangle((someX - .1, someY - .1), 0.2, 0.2, alpha=1, facecolor='none'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.