Search code examples
pythonpandasazimuth

Calculate difference in positions in Azumith measurement


I am working with azimuth and elevation data in a pandas dataframe. In this reference frame, measurements are specified from -180 to 180 in azimuth and 0 to 90 in elevation. My data points are hovering around the 180 degree mark so it also registers -180 sometimes because in that frame of reference, they are right next to each other.

Here is my dataframe

Az      El
-179.90 2.43    
179.85  2.30
179.95  2.33
-179.99 2.40    
179.98  2.63    
-179.92 2.67

I am trying to find the maximum distance between any value in the az column. If I look for the min and max, and find the difference I will get 359.97 even though the true largest difference should be .25.

Does anyone know an algorithm that will work?

Here is my current code:

def findMaxDistanceInColumn(dataframe,dimension):
    array = dataframe[dimension].to_numpy().astype(np.float)
    min = np.min(array)
    max = np.max(array)
    difference = max-min
    return difference

Solution

  • You seem to have reversed the calculations: you need the lowest absolution value on each side of the 180 split: take the minimum of the positive values, 179.85, and the maximum of the negative values, -179.90. Now do the math:

    neg_dist = neg_max + 180
    pos_dist = 180 - pos_min
    final = neg_dist + pos_dist
    

    Can you finish from there?