A handy function to create a simple anemometer plot for anywhere in the world in R.
- Install
ansiweather
in the command line (Terminal) via any one of following: OpenBSD, NetBSD, FreeBSD, Debian, Ubuntu, or Homebrew. I use Homebrew on my Mac via: $brew install ansiweather
ansiweather
fetches weather data from OpenWeatherMap's free API
Access ansiweather
's manual for more information
- Install the following libraries in R:
You can do this easily with the following command:
install.packages(c("jsonlite", "processx", "lutz", "lubridate", "caroline", "rlang", "rgbif"))
- Pre-load the city file, which is the location JSON (Javascript Object Notation) database
ansiweather
uses to identify place names. You could add this to the function itself, but it slows processing down considerably, so it's best to load before running the function.
cityfile <- jsonlite::fromJSON(gzcon(url("https://bulk.openweathermap.org/sample/city.list.json.gz")))
The 2-digit ISO country code can be found here, and you can access various versions and scales of the source JSON database here.
-
Should you wish the elevation (metres above sea level; 'm asl') of the location to be displayed on the plot, you will need to register for a free user name on the GeoNames geographical database. Once you approve your account, ensure that you enable free webservices on your 'manage account' page.
-
Run both the functions
plotCompass
andAnemometerFunction
in R (the former is invoked by the latter; both scripts are included together inAnemometerFunction.R
), then you're ready to plot a real-time anemometer (including windspeed, wind direction temperature, humidity, air pressure, latitude, longitude, date, time, and elevation (optional) as in the example plot above).
Note: if you registered at GeoNames, you need to include your user name using the option GEONAMES_USERNAME="my_user_name"
; if you do not provide a user name, the elevation will return 'no elev data' in the plot.
Some examples:
AnemometerFunc(Place="Adelaide,AU", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Darlington,AU", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Hobart,AU", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Perth,AU", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Port Moresby,PG", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Dunedin,NZ", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Wellington,NZ", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Sapporo,JP", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Helsinki,FI", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Paris,FR", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Kyiv,UA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Reykjavik,IS", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Vancouver,CA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Whitehorse,CA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Sachs Harbour,CA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Rimouski,CA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Ushuaia,AR", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Punta Arenas,CL", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Agadez,NE", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Dar es Salaam,TZ", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Phalaborwa,ZA", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Kolkata,IN", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
AnemometerFunc(Place="Bengaluru,IN", PlaceFile=cityfile, GEONAMES_USERNAME="my_user_name")
Note that the arrow's line width varies as a function of windspeed (thicker with higher speeds), that the colour of the temperature text (T) on the plot varies from blue to red (cold to hot), that the humidity (H) display varies from yellow to dark blue (dry to wet), and that the pressure (P) ranges from dark red, red, pink, to orange (very low, low, moderate, high).
Prof Corey J. A. Bradshaw
Global Ecology, Flinders University, Adelaide, Australia
March 2022