I was trying to plot reflectivity data from a same nexrad level 2 file using both Metpy and pyart, and the result seems to be quite different, especially, I see that metpy and pyart calculate the coordinates very differently:
In MetPy, the coordinates are calculated as:
(from NEXRAD_Level_2_File sample)
xlocs = ref_range * np.sin(np.deg2rad(az[:, np.newaxis]))
ylocs = ref_range * np.cos(np.deg2rad(az[:, np.newaxis]))
In pyart, it's calculated as:
(antenna_to_cartesian method called by get_gate_x_y_z in radar.py)
theta_e = elevations * np.pi / 180.0 # elevation angle in radians.
theta_a = azimuths * np.pi / 180.0 # azimuth angle in radians.
R = 6371.0 * 1000.0 * 4.0 / 3.0 # effective radius of earth in meters.
r = ranges * 1000.0 # distances to gates in meters.
z = (r ** 2 + R ** 2 + 2.0 * r * R * np.sin(theta_e)) ** 0.5 - R
s = R * np.arcsin(r * np.cos(theta_e) / (R + z)) # arc length in m.
x = s * np.sin(theta_a)
y = s * np.cos(theta_a)
return x, y, z
Can you please tell me what's the difference here?