Ensuring Unit Correctness with Metpy.calc.divergence() #2350
-
Hello! I am using metpy.calc.divergence() using HFR vector fields of ocean currents for my thesis work of analyzing divergence trends. I am calculating divergence with u and v's with lat and lon coordinates. Upon calculating the divergence of the data array I arrive at data with units of 1/s. This seems well and dandy but my advisor is wondering how this package exactly converts dx and dy with degrees lat and lon to a discrete length scale distance which leads to the units of 1/s if my vectors are a speed in m/s My understanding is if I am plotting the data to a projection that already uses lat and lon coordinates (Mercator with transform=ccrs.PlateCarree on the plotting function) then it is not really a problem. But I could be wrong and I could be overlooking things. Is there anywhere that explicitly explains how metpy calculates the first_derivative dx on the longitude and dy on latitude to ensure the units are correct? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here's the documentation of And here's the actual source code that goes with it: Lines 952 to 1041 in df6f7c5 I think the key bit is here:
So as long as your DataArray object has coordinate and projection information attached, then it will be using that. Here's the actual reference for the mathematics used: I did not write this code nor claim to be an expert in mathematics, but wanted to provide this information in case it is useful! |
Beta Was this translation helpful? Give feedback.
Here's the documentation of
first_derivative()
:https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.first_derivative.html#metpy.calc.first_derivative
And here's the actual source code that goes with it:
MetPy/src/metpy/calc/tools.py
Lines 952 to 1041 in df6f7c5