Thank you Dennis,<br>I will try to use that, or maybe I will find an other quicker solution.<br><br>Giorgio<br>
<br>
----Messaggio originale----<br>Da: shea@ucar.edu<br>Data: 30-set-2015 17.52<br>A: "Giorgio Graffino"<giorgio.graffino@alice.it><br>Ogg: Re: [ncl-talk] R: NCL uv2vr_cfd function on Python<br><br>Attached..<br><br>Not sure why you want to do python. Mimicking the NCL function could<br>be cumbersome.<br>Also, 'for/do' loops in any interpreted language can be slow.<br><br>Good Luck<br><br>On Wed, Sep 30, 2015 at 9:49 AM, Dennis Shea <shea@ucar.edu> wrote:<br>> The underlying code used by NCL is a f77 subroutine that handles the<br>> boundaries (half widths). Also, it allows both the lat and lon arrays<br>> to be unequally spaced. ie<br>><br>> dlat_a = lat(2)-lat(0) , dlat_b = lat(10)-lat(8)<br>><br>> dlat_a does not need to be the same as dlat_b<br>><br>> Allowing the above, makes the code a bit more involved than your simple script.<br>><br>> The f77 code will be set to you<br>><br>><br>><br>><br>><br>><br>><br>> On Tue, Sep 29, 2015 at 8:29 AM, Giorgio Graffino<br>> <giorgio.graffino@alice.it> wrote:<br>>> Ok, I think I've found the problem: dx2 and dy2 are distance in meters, not<br>>> degrees.<br>>> Since u and v are given in latitude/longitude, there must be an implicit<br>>> conversion inside the uv2vr_cfd function.<br>>><br>>> Anyone knows how this conversion is performed?<br>>><br>>> Giorgio<br>>><br>>><br>>> ----Messaggio originale----<br>>> Da: giorgio.graffino@alice.it<br>>> Data: 29-set-2015 11.31<br>>> A: <ncl-talk@ucar.edu><br>>> Ogg: [ncl-talk] NCL uv2vr_cfd function on Python<br>>><br>>><br>>> Dear NCL Users,<br>>> I'm trying to adapt an NCL script I wrote to compute water vertical speed on<br>>> Python.<br>>><br>>> In particular, I'm finding some difficulties on "translating" the NCL<br>>> built-in function uv2vr_cfd into Python; I used that function to compute the<br>>> vertical component of wind stress. On the web page<br>>> (https://www.ncl.ucar.edu/Document/Functions/Built-in/uv2vr_cfd.shtml) it's<br>>> stated that<br>>><br>>> According to H.B. Bluestein [Synoptic-Dynamic Meteorology in Midlatitudes,<br>>> 1992, Oxford Univ. Press p113-114], let D represent the partial derivative,<br>>> a the radius of the earth, phi the latitude and dx2/dy2 the appropriate<br>>> longitudinal and latitudinal spacing, respectively. Then, letting j be the<br>>> latitude y-subscript, and i be the longitude x-subscript:<br>>><br>>> rv = Dv/Dx - Du/Dy + (u/a)*tan(phi)<br>>><br>>> rv(j,i) = (v(j,i+1)-v(j,i-1))/dx2(j)<br>>> - (u(j+1,i)-u(j-1,i))/dy2(j)<br>>> + (u(j,i)/a)*tan(phi(j))<br>>><br>>> Now, I tried to write that function on Python in this way<br>>><br>>> def Curl(u,v,nlat,nlon):<br>>><br>>> rv = np.empty(shape=(nlat,nlon))<br>>><br>>> rv.fill(np.nan)<br>>><br>>> M0 = np.arange(1,nlat-1) # M0 = [1,...,nlat-1]<br>>><br>>> N0 = np.arange(1,nlon-1) # N0 = [1,...,nlon-1]<br>>><br>>> for m in M0:<br>>><br>>> for n in N0:<br>>><br>>> rv[m,n] = (v[m,n+1]-v[m,n-1])/(lons[n+1]-lons[n-1]) - \<br>>><br>>> (u[m+1,n]-u[m-1,n])/(lats[m+1]-lats[m-1]) + \<br>>><br>>> (u[m,n]/radius)*tans[m]<br>>><br>>> return rv<br>>><br>>><br>>> but, even if the pattern is similar, there are four orders of magnitude<br>>> between the values. I attach results using NCL (MedDailyINDEX.png file) and<br>>> Python (WindStressCurl.png) for the same day.<br>>><br>>> Could it be possible to know how exactly rv is computed inside uv2vr_cfd<br>>> function? Because I think there is something missing in my implementation...<br>>><br>>> Thanks for your attention.<br>>><br>>> Regards,<br>>> Giorgio<br>>><br>>><br>>><br>>><br>>><br>>> _______________________________________________<br>>> ncl-talk mailing list<br>>> ncl-talk@ucar.edu<br>>> List instructions, subscriber options, unsubscribe:<br>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br>>><br><br><br>