[Rnomads-user] Issue with using multiple Lat/Lon. Not sure what is causing it.

Ruben Kertesz rkertesz at emnet.net
Wed Mar 2 19:04:19 CET 2016


Thank you Danny,

I wanted to try and use some of the other functions in the rNOMADS package which require the use of ModelGrid so I thought I could define the map as Cartesian and define the projection using GEOmap.
The interesting thing I got from the grib file is this:

1:0:grid_template=30:winds(grid):
        Lambert Conformal: (8 x 10) input WE:SN output WE:SN res 8
        Lat1 36.887638 Lon1 237.104317 LoV 265.000000
        LatD 25.000000 Latin1 25.000000 Latin2 25.000000
        LatSP 0.000000 LonSP 0.000000
        North Pole (8 x 10) Dx 13545.000000 m Dy 13545.000000 m mode 8

* (lat1,lon1) = lat/lon of first grid point (deg)
 * lov = the orientation of the grid, i.e., the east longitude value of the   meridian which is parallel to the y-axis (or columns of the grid) along   which latitude increases as the y-coordinate increases. (Note: The   orientation longitude may, or may not, appear within a particular grid.)
* latin1 = The first latitude from the pole at which the secant cone cuts   the spherical earth. (deg)
* latin2 = The second latitude from the pole at which the secant cone cuts   the spherical earth. (deg)

I had trouble finding the center of the projection from this but lo and behold, I did get a 13 by 13 km resolution after projecting it using a default projection
proj = setPROJ(type = 2, LAT0 =23, LON0 = 35)
XY = GLOB.XY(grb.data$lat, grb.data$lon, proj)

Then I defined the following
cartnodes = list(x=XY$x, y=XY$y)

The problem that crept in is when I ran the following.
atmos <- ModelGrid(grb.data, resolution, grid.type, model.domain = domain, cartesian.nodes=cartnodes)

I think that the model domain should now be the extent of the result from GLOB.XY rather than the extents of the unprojected x/y values from the grib file.
Otherwise, what happens is that I use a 13 km resolution (see Dx and Dy in the grib file metadata at the top of this email) but the following code steps by the value 13 in a domain of span with value = 2 because there is a unit mismatch. Am I understanding correctly?

I know that you've not used this with projected models like this so I understand if you do not have time to provide any answers.

    grid <- list(x = seq(model.domain[1], model.domain[2], by = resolution[1]),
        y = seq(model.domain[4], model.domain[3], by = resolution[2]))
    fcst.grid <- list(z = array(rep(NA, length(grid$x) * length(grid$y) *
        length(variables) * length(levels)), dim = c(length(levels),
        length(variables), length(grid$x), length(grid$y))),
        x = grid$x, y = grid$y, variables = variables, levels = levels,
        model.run.date = model.run.date, fcst.date = fcst.date)



Ruben Kertesz, Ph.D.
Environmental Engineer
EmNet LLC
Office: 574.855.1012 x115

From: rnomads-user-bounces at lists.r-forge.r-project.org [mailto:rnomads-user-bounces at lists.r-forge.r-project.org] On Behalf Of Bowman, Daniel
Sent: Monday, February 29, 2016 7:49 PM
To: rnomads-user at lists.r-forge.r-project.org
Subject: Re: [Rnomads-user] Issue with using multiple Lat/Lon. Not sure what is causing it.


Hi Ruben,



The short answer is that the NARRE is not on a regular lat-lon grid, and my data processing codes are not optimized for such grids.



Long answer:

The data processing code in rNOMADS work best on regular lat lon grids, for the simple reason that I exclusively use the GFS in my own work.  I decided to put some of the more useful functions into the official package after considerable internal debate, mainly because I wanted to save users time.  At the same time, rNOMADS is intended to be a pipeline and not a "weather model processing package" so some of these functions are not very sophisticated.



Your best bet at this point is to download the grib file in the region of interest, read it in, examine the lat/lon values it returns, select the one closest to the region you want, and use that one.



I've written up a script that should do what you want:

http://pastebin.com/6gv6gkP6



Best,



Danny


Daniel C. Bowman
Doctoral Candidate in Geophysics
UNC Chapel Hill
phone: 575-418-8555
curriculum vitae:  http://www.unc.edu/~haksaeng/curriculum_vitae/bowman_cv.pdf
LinkedIn:  https://www.linkedin.com/in/dannycbowman
web:http://geosci.unc.edu/page/daniel-c-bowman
twitter: @dannycbowman

________________________________
From: rnomads-user-bounces at lists.r-forge.r-project.org<mailto:rnomads-user-bounces at lists.r-forge.r-project.org> <rnomads-user-bounces at lists.r-forge.r-project.org<mailto:rnomads-user-bounces at lists.r-forge.r-project.org>> on behalf of Ruben Kertesz <rkertesz at emnet.net<mailto:rkertesz at emnet.net>>
Sent: Monday, February 29, 2016 7:03 PM
To: rnomads-user at lists.r-forge.r-project.org<mailto:rnomads-user at lists.r-forge.r-project.org>
Subject: [Rnomads-user] Issue with using multiple Lat/Lon. Not sure what is causing it.


Good evening,



I have been using rNOMADS for some rainfall work and am happy to say that it is very powerful! Today I ran into an issue where I can't use multiple lat/lon values for the RTModelProfile function. Actually, I can if they are very close to (-79.052104, 35.907553 - lon/lat). I would like to ask if anyone has insight into why this is happening.



First of all, I put my code up to pastebin here: http://pastebin.com/WyVn84bp

The issue is showing up in BuildProfile. The code is reproduced here. I get valid values in layer.img when using the single x/y.



  if (spatial.average) {

        for (k in seq_len(length(gridded.data$levels))) {

            for (j in seq_len(length(gridded.data$variables))) {

                layer.img <- t(rbind(as.vector(cart.pts$x), as.vector(cart.pts$y[nrow(cart.pts$y):1,

                  ]), as.vector(t(gridded.data$z[k, j, , ]))))

                profile.data[k, j] <- MBA::mba.points(layer.img,

                  cbind(0, 0))[[1]][3]

            }



If I use this:

lon <- c(-79.052104)#, -78.010020)

lat <- c(35.907553)#, 36.000200)



Then I get this in layer.img:



            [,1]       [,2] [,3]

 [1,] -102.02596 -129.16620    0

 [2,] -102.68684  -73.50205    0

 [3,] -103.33989  -17.83809    0

 [4,] -103.98508   37.82569    0

 [5,] -104.62235   93.48929    0

 [6,]  -57.42160 -129.57281    0

 [7,]  -57.79351  -73.91126    0

 [8,]  -58.16101  -18.24976    0

 [9,]  -58.52409   37.41168    0

[10,]  -58.88271   93.07305    0

[11,]  -12.81848 -129.75192    0

[12,]  -12.90150  -74.09151    0

[13,]  -12.98354  -18.43110    0

[14,]  -13.06459   37.22931    0

[15,]  -13.14464   92.88971    0

[16,]   31.78435 -129.70356    0

[17,]   31.99021  -74.04284    0

[18,]   32.19362  -18.38214    0

[19,]   32.39459   37.27855    0

[20,]   32.59308   92.93921    0

[21,]   76.38788 -129.42772    0

[22,]   76.88265  -73.76524    0

[23,]   77.37156  -18.10286    0

[24,]   77.85458   37.55941    0

[25,]   78.33167   93.22158    0





BUT If I use this:

lon <- c(-79.052104, -78.010020)

lat <- c(35.907553, 36.000200)



Then I get this. The NA causes all sorts of problems. I ran out of steam to try and figure out why this is happening.



            [,1]       [,2] [,3]

 [1,] -101.50132 -141.10061   NA

 [2,] -102.16831  -85.43643    0

 [3,] -102.82751  -29.77243    0

 [4,] -103.47889   25.89139    0

 [5,] -104.12238   81.55503    0

 [6,] -104.75795  137.21848   NA

 [7,]  -57.12636 -141.50666    0

 [8,]  -57.50171  -85.84509    0

 [9,]  -57.87267  -30.18358    0

[10,]  -58.23923   25.47787    0

[11,]  -58.60135   81.13926    0

[12,]  -58.95901  136.80059    0

[13,]  -12.75258 -141.68551    0

[14,]  -12.83637  -86.02510    0

[15,]  -12.91917  -30.36469    0

[16,]  -13.00100   25.29572    0

[17,]  -13.08183   80.95612    0

[18,]  -13.16167  136.61652    0

[19,]   31.62094 -141.63722    0

[20,]   31.82869  -85.97649    0

[21,]   32.03402  -30.31579    0

[22,]   32.23692   25.34490    0

[23,]   32.43735   81.00557    0

[24,]   32.63532  136.66622    0

[25,]   75.99511 -141.36177    0

[26,]   76.49445  -85.69927    0

[27,]   76.98796  -30.03687    0

[28,]   77.47562   25.62543    0

[29,]   77.95737   81.28762    0

[30,]   78.43319  136.94971    0

[31,]  120.37085 -140.85909    0

[32,]  121.16188  -85.19335    0

[33,]  121.94369  -29.52787    0

[34,]  122.71621   26.13736    0

[35,]  123.47939   81.80233    0

[36,]  124.23317  137.46704    0

[37,]  164.74907 -140.12908    0

[38,]  165.83197  -84.45864    0

[39,]  166.90224  -28.78867    0

[40,]  167.95981   26.88082    0

[41,]  169.00459   82.54982    0

[42,]  170.03650  138.21833    0





Any help is greatly appreciated!



Ruben Kertesz, Ph.D.
Environmental Engineer
EmNet LLC
121 S. Niles Ave.
Suite #22
South Bend, IN 46617
Office: 574.855.1012 x115
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rnomads-user/attachments/20160302/121e044f/attachment-0001.html>


More information about the Rnomads-user mailing list