[ncl-talk] R: NCL uv2vr_cfd function on Python

Dennis Shea shea at ucar.edu
Wed Sep 30 09:49:58 MDT 2015


The underlying code used by NCL is a f77 subroutine that handles the
boundaries (half widths). Also, it allows both the lat and lon arrays
to be unequally spaced. ie

    dlat_a = lat(2)-lat(0)   , dlat_b = lat(10)-lat(8)

    dlat_a does not need to be the same as dlat_b

Allowing the above, makes the code a bit more involved than your simple script.

The f77 code will be set to you







On Tue, Sep 29, 2015 at 8:29 AM, Giorgio Graffino
<giorgio.graffino at alice.it> wrote:
> Ok, I think I've found the problem: dx2 and dy2 are distance in meters, not
> degrees.
> Since u and v are given in latitude/longitude, there must be an implicit
> conversion inside the uv2vr_cfd function.
>
> Anyone knows how this conversion is performed?
>
> Giorgio
>
>
> ----Messaggio originale----
> Da: giorgio.graffino at alice.it
> Data: 29-set-2015 11.31
> A: <ncl-talk at ucar.edu>
> Ogg: [ncl-talk] NCL uv2vr_cfd function on Python
>
>
> Dear NCL Users,
> I'm trying to adapt an NCL script I wrote to compute water vertical speed on
> Python.
>
> In particular, I'm finding some difficulties on "translating" the NCL
> built-in function uv2vr_cfd into Python; I used that function to compute the
> vertical component of wind stress. On the web page
> (https://www.ncl.ucar.edu/Document/Functions/Built-in/uv2vr_cfd.shtml) it's
> stated that
>
> According to H.B. Bluestein [Synoptic-Dynamic Meteorology in Midlatitudes,
> 1992, Oxford Univ. Press p113-114], let D represent the partial derivative,
> a the radius of the earth, phi the latitude and dx2/dy2 the appropriate
> longitudinal and latitudinal spacing, respectively. Then, letting j be the
> latitude y-subscript, and i be the longitude x-subscript:
>
>     rv = Dv/Dx - Du/Dy + (u/a)*tan(phi)
>
>     rv(j,i) = (v(j,i+1)-v(j,i-1))/dx2(j)
>               - (u(j+1,i)-u(j-1,i))/dy2(j)
>               + (u(j,i)/a)*tan(phi(j))
>
> Now, I tried to write that function on Python in this way
>
> def Curl(u,v,nlat,nlon):
>
> rv = np.empty(shape=(nlat,nlon))
>
> rv.fill(np.nan)
>
> M0 = np.arange(1,nlat-1) # M0 = [1,...,nlat-1]
>
> N0 = np.arange(1,nlon-1) # N0 = [1,...,nlon-1]
>
> for m in M0:
>
> for n in N0:
>
> rv[m,n] = (v[m,n+1]-v[m,n-1])/(lons[n+1]-lons[n-1]) - \
>
> (u[m+1,n]-u[m-1,n])/(lats[m+1]-lats[m-1]) + \
>
> (u[m,n]/radius)*tans[m]
>
> return rv
>
>
> but, even if the pattern is similar, there are four orders of magnitude
> between the values. I attach results using NCL (MedDailyINDEX.png file) and
> Python (WindStressCurl.png) for the same day.
>
> Could it be possible to know how exactly rv is computed inside uv2vr_cfd
> function? Because I think there is something missing in my implementation...
>
> Thanks for your attention.
>
> Regards,
> Giorgio
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


More information about the ncl-talk mailing list