0

I'm in the process of identifying objects whose float value is greater than a certain threshold in a 2-D numpy array. I then need to determine the length of the major axis of each object and make sure that the object's major axis length satisfies a certain threshold in kilometers.

I am able to identify the objects I want in my 2-D numpy array by using the scipy.ndimage.measurements.label module. I then am able to determine the length of each object's major axis using the scikit-image regionprops module (skimage.measure.regionprops).

However, I am unsure about what the units of the object's length are as the 2-D numpy array by itself does not have any information about coordinates. The 2-D numpy array is essentially a dataset that maps to a subdomain on the surface of the globe. Additionally, I have two other 2-D numpy arrays that are the same size as my data array with one array containing the latitude coordinates for each grid point and the other containing the longitude coordinates. I believe I somehow need to use the lat/lon arrays to determine the length of the major axis of my objects but I have no idea how.

This is the code I have so far:

from scipy import ndimage
from skimage.measure import regionprops
import numpy as np

# 2-D numpy array with data.
data

# 2-D numpy arrays with latitude and longitude coordinates that are same grid as data array.
lat
lon

# Allow label module to have diagonal object matching.
struct = np.ones((3,3), dtype=bool)

# Find objects in data array.
labl, n_features = ndimage.measurements.label(data>=35,structure=struct)

# Find major axis length in labl array for each object found.
props = regionprops(labl)
# Loop through each object.
for p in props:

    # Find object's major axis length.
    length = p.major_axis_length

    (some code to compute major axis length in kilometers?)

    if length < 125: #(125 is in km)
        (keep object)

Any help would be greatly appreciated. Thanks!

Helicity
  • 35
  • 2
  • 7
  • There are a few Python packages that _speak_ lattitude/longitude, did you try any of them? – wwii May 11 '17 at 18:39
  • Possible duplicate of [Getting distance between two points based on latitude/longitude](http://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude) – wwii May 11 '17 at 18:40
  • The unit is pixel distance. I don't think you can easily translate a scalar value (p.major_axis_length) to a distance on a map. What you can do, however, is to find the two endpoints, extract their corresponding (lat, lon) coordinates, and use one of many libraries (e.g., basemap) to compute the distance between them. – Stefan van der Walt May 11 '17 at 18:56
  • I realized that I needed to calculate the two endpoints by using the centroid, orientation, and major_axis_length. – Helicity May 11 '17 at 20:01

0 Answers0