<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/"></div></div><div><a data-url="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/" data-counturl="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/" data-count="horizontal" data-text="Accessing ensemble weather models with rNOMADS" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://bovineaerospace.wordpress.com/2016/11/24/accessing-ensemble-weather-models-with-rnomads/"> R – Bovine Aerospace</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Downloading a weather model and using it to predict stuff is all well and good – but what are the sources of error?  Specifically, how accurate is the atmospheric parametrization?   Luckily, NOMADS provides sets of models with slightly different initialization values.  The result is a set of realizations that captures the variability of the model product.  Here’s how to get that product, and examples of what you can do with it.</p>
<pre>

library(rNOMADS)

#Get the latest ensemble model run
model.urls &amp;amp;lt;- GetDODSDates(&quot;gens&quot;)
latest.model &amp;amp;lt;- tail(model.urls$url, 1)
model.runs &amp;amp;lt;- GetDODSModelRuns(latest.model)
model.run &amp;amp;lt;- tail(model.runs$model.run[grepl(&quot;all&quot;,
    model.runs$model.run)], 1)

#Define region of interest: Chapel Hill, NC
lon &amp;amp;lt;- -79.052104
lat &amp;amp;lt;- 35.907553

#Set up DODS model grid indices
#Use GetDODSModelRunInfo() to figure out how to do this for other products
lons &amp;amp;lt;- seq(0, 359, by = 1)
lats &amp;amp;lt;- seq(-90, 90, by = 1)

lon.diff &amp;amp;lt;- abs(lon + 360 - lons)
lat.diff &amp;amp;lt;- abs(lat - lats)

model.lon.ind &amp;amp;lt;- which(lon.diff == min(lon.diff)) - 1
model.lat.ind &amp;amp;lt;- which(lat.diff == min(lat.diff)) - 1

#Set up call to NOMADS GrADS-DODS server
#Analysis(?) model only
time &amp;amp;lt;- c(0, 0)
#Longitude grid
node.lon  &amp;amp;lt;- c(model.lon.ind - 2, model.lon.ind + 2)
#Latitude grid
node.lat  &amp;amp;lt;- c(model.lat.ind - 2, model.lat.ind + 2)
#Temperature, wind speeds, and geopotential height
variables &amp;amp;lt;- c(&quot;tmpprs&quot;, &quot;ugrdprs&quot;, &quot;vgrdprs&quot;, &quot;hgtprs&quot;)
levels    &amp;amp;lt;- c(0, 25) #All available levels
ensemble &amp;amp;lt;- c(0, 20)  #All available ensembles

model.data &amp;amp;lt;- DODSGrab(latest.model, model.run, variables,
    time, node.lon, node.lat, levels = levels, ensemble = ensemble)

#Plot temperature variability
plot(c(-65, 25), c(0, 35), xlab = &quot;Temperature (C)&quot;,
    ylab = &quot;Geopotential Height (km)&quot;, type = 'n')

for(k in ((ensemble[1]:ensemble[2] + 1))) {
    model.data.sub &amp;amp;lt;- SubsetNOMADS(model.data, ensemble = c(k),
        variables = c(&quot;hgtprs&quot;, &quot;tmpprs&quot;))
    profile &amp;amp;lt;- BuildProfile(model.data.sub, lon, lat)
    points(profile[[1]]$profile.data[,
        which(profile[[1]]$variables == &quot;tmpprs&quot;), 1] - 272.15,
        profile[[1]]$profile.data[,
        which(profile[[1]]$variables == &quot;hgtprs&quot;), 1] / 1000)
}

#Plot winds
zonal.wind &amp;amp;lt;- NULL
merid.wind &amp;amp;lt;- NULL
height     &amp;amp;lt;- NULL

for(k in ((ensemble[1]:ensemble[2] + 1))) {
    model.data.sub &amp;amp;lt;- SubsetNOMADS(model.data,
        ensemble = c(k), variables = c(&quot;hgtprs&quot;,
        &quot;ugrdprs&quot;, &quot;vgrdprs&quot;))
    profile &amp;amp;lt;- BuildProfile(model.data.sub, lon, lat)
    hgt     &amp;amp;lt;- profile[[1]]$profile.data[,
        which(profile[[1]]$variables == &quot;hgtprs&quot;),]
    ugrd    &amp;amp;lt;- profile[[1]]$profile.data[,
        which(profile[[1]]$variables == &quot;ugrdprs&quot;),]
    vgrd    &amp;amp;lt;- profile[[1]]$profile.data[,
        which(profile[[1]]$variables == &quot;vgrdprs&quot;),]

   synth.hgt &amp;amp;lt;- seq(min(hgt),
       max(hgt), length.out = 1000)
   ugrd.spline &amp;amp;lt;- splinefun(hgt, ugrd, method = &quot;natural&quot;)
   vgrd.spline &amp;amp;lt;- splinefun(hgt, vgrd, method = &quot;natural&quot;)
   zonal.wind[[k]] &amp;amp;lt;- ugrd.spline(synth.hgt)
   merid.wind[[k]] &amp;amp;lt;- vgrd.spline(synth.hgt)
   height[[k]] &amp;amp;lt;- synth.hgt
}

dev.new()
PlotWindProfile(zonal.wind, merid.wind, height, lines = TRUE,
    points = FALSE, elev.circles = c(0, 15000, 30000),
    elev.labels = c(0, 15, 30), radial.lines = seq(45, 360, by = 45),
    colorbar = TRUE, invert = FALSE,
    point.cex = 2, pch = 19, lty = 1, lwd = 1,
    height.range = c(0, 30000), colorbar.label = &quot;Wind Speed (m/s)&quot;)

</pre>
<p>Here’s atmospheric profiles from GFS ensemble runs on November 24, 2016 for Chapel Hill, NC. Temperature is quite variable at low altitudes (several degrees Celsius) and at 5 km above sea level (a couple degrees). Ensemble runs are more consistent for the rest of the atmosphere.</p>
<div data-shortcode="caption" class="wp-caption"><img sizes="(max-width: 620px) 100vw, 620px" alt="chapel_hill_temperature" class="wp-image-44518" src="https://i1.wp.com/bovineaerospace.files.wordpress.com/2016/11/chapel_hill_temperature.png?w=456&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">Temperature profile above the Geology Department at UNC Chapel Hill for November 24, 2016 at 18:00 UTC.</p>
</div>
<p>Wind speeds are pretty consistent, at least at the resolution of the color scale I’m using.  Wind direction varies by a few degrees below 15 km, but becomes quite a bit less reliable between 15 and 30 km altitude.  This is one reason that our solar balloon trajectories are so hard to predict.  The other reason is because we still don’t really understand the physics of solar balloon flight, but that’s a subject for another post.</p>
<p><img sizes="(max-width: 620px) 100vw, 620px" alt="chapel_hill_wind_profile" class="wp-image-44519" src="https://i2.wp.com/bovineaerospace.files.wordpress.com/2016/11/chapel_hill_wind_profile.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bovineaerospace.wordpress.com/44480/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/bovineaerospace.wordpress.com/44480/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/"></div></div><div><a data-url="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/" data-counturl="https://www.r-bloggers.com/accessing-ensemble-weather-models-with-rnomads/" data-count="vertical" data-text="Accessing ensemble weather models with rNOMADS" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://bovineaerospace.wordpress.com/2016/11/24/accessing-ensemble-weather-models-with-rnomads/"> R – Bovine Aerospace</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/vyq2Y1oLxEY"></a></div>