NCEP.gather: Queries Weather Data

Description Usage Arguments Details Value Variable Naming Conventions Author(s) References Examples

View source: R/NCEP.gather.R

Description

This function queries weather data over the Internet from the NCEP/NCAR Reanalysis
or NCEP/DOE Reanalysis II datasets for the spatial and temporal extents specified in the function call and maintains the spatial and temporal structure of the data in a 3-D array.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
NCEP.gather(variable, level, months.minmax, years.minmax,
    lat.southnorth, lon.westeast, reanalysis2 = FALSE,
    return.units = TRUE, status.bar=TRUE)

## NCEP.gather is a wrapper function that calls one of the
## following functions based on the value of level.
## Users should avoid using these functions directly.
NCEP.gather.gaussian(variable, months.minmax, years.minmax,
    lat.minmax, lon.minmax, reanalysis2 = FALSE, 
    return.units = TRUE, increments=NULL, pb=NULL)
NCEP.gather.pressure(variable, months.minmax, years.minmax,
    lat.minmax, lon.minmax, pressure, reanalysis2 = FALSE, 
    return.units = TRUE, increments=NULL, pb=NULL)
NCEP.gather.surface(variable, months.minmax, years.minmax, 
    lat.minmax, lon.minmax, reanalysis2 = FALSE, 
    return.units = TRUE, increments=NULL, pb=NULL)

Arguments

variable

Character. The name of the weather variable to be obtained. See ‘Details’ for possible variable names.

level

A numeric pressure level or one of either ‘gaussian’ or ‘surface’. See ‘Details’.

months.minmax

Numeric. Specifies the range of months to be obtained from each year.

years.minmax

Numeric. Specifies the range of years to be obtained.

lat.southnorth

Numeric. Specifies the range of latitudes to be obtained in the order
c(southernmost, northernmost).

lat.minmax

Same as lat.southnorth.

lon.westeast

Numeric. Specifies the range of longitudes to be obtained in the order
c(westernmost, easternmost).

lon.minmax

Same as lat.westeast.

reanalysis2

Logical. Should the data be obtained from the Reanalysis I dataset (default) or from Reanalysis II?

return.units

Logical. Should the units of the variable being obtained be printed after the query finishes?

pressure

Numeric. A pressure level in millibars that is assigned automatically from the value of level when needed.

status.bar

Logical. Should a status bar be shown indicating the percentage of completion?

increments

Numeric. This value, which is assigned automatically when using NCEP.gather, indicates the number of queries necessary to retrieve all data.

pb

An object of class "tkProgressBar", which is assigned automatically when using NCEP.gather.

Details

NCEP.gather is a wrapper function that applies one of NCEP.gather.gaussian,
NCEP.gather.pressure, or NCEP.gather.surface depending on the value of level.

level must specify one of either ‘gaussian’ or ‘surface’ or give a numerical pressure level in millibars. Numeric pressure levels must be one of 1000, 925, 850, 700, 600, 500, 400, 300, 250, 200, 150, 100, 70, 50, 30, 20, 10 See ‘Variable Naming Conventions’ below to determine if your variable of interest is stored relative to the surface, a pressure level, or a T62 Gaussian grid. Note that variables on a T62 Gaussian grid are evenly spaced in longitude but unevenly spaced in latitude while variables from either the surface or a particular pressure level are evenly spaced in both latitude and longitude (2.5 deg. x 2.5 deg.)

Months and years in months.minmax and years.minmax must be numeric and given in the order c(minimum,maximum).

Latitude and longitude ranges should be given in decimal degrees. If the latitudes or longitudes given do not match a grid point in the NCEP dataset, the function moves to the next grid point such that the specified range is always included. Latitude should always be given in the order c(southernmost, northernmost) and longitude should always be given in the order c(westernmost, easternmost).

Latitudes below the equator are negative. Longitudes west of the Prime Meridian can be specified using either positive (i.e. 350) or negative (i.e. -10) notation.

Some variables are not in both the Reanalysis I and II datasets. If a variable is chosen that is not in the specified dataset, the other dataset will be used... with a warning.

Very large queries may cause errors due to memory limitations in R. See Memory-limits for more information or memory.limit to increase available memory. Alternatively, consider querying subsets of your total desired range. For instance, subset a very large spatial domain into several smaller regions, perform analyses on each geographical subset independently, and then combine the results. Functions in the raster-package may be useful for managing subsets in the temporal domain.

Note that the status bar may be hidden behind an active R window.

variable must be specified using one of the names found in the section ‘Variable Naming Conventions’ below...

Value

This function returns a three dimensional array of weather data. The three dimensions are latitude, longitude, and datetime reflected in the dimnames of the array. Datetimes are always expressed in UTC with the format "%Y_%m_%d_%H".

Optionally, the units of the variable being queried are printed upon completion.

Variable Naming Conventions

VARIABLES IN REFERENCE TO A PARTICULAR PRESSURE LEVEL

‘air’ Air Temperature deg K
‘hgt’ Geopotential Height m
‘rhum’ Relative Humidity %
‘shum’ Specific Humidity kg/kg
‘omega’ Omega [Vertical Velocity] Pascal/s
‘uwnd’ U-Wind Component [East/West] m/s
‘vwnd’ V-Wind Component [North/South] m/s

VARIABLES IN REFERENCE TO THE SURFACE

‘air.sig995’ Air Temperature (Near Surface) deg K
‘lftx.sfc’ Surface Lifted Index (At Surface) deg K
‘lftx4.sfc’ Best (4-layer) Lifted Index (At Surface) deg K
‘omega.sig995’ Omega [Vertical Velocity] (Near Surface) Pascal/s
‘pottmp.sig995’ Potential Temperature (Near Surface) deg K
‘pr_wtr.eatm’ Precipitable Water (Entire Atmosphere) kg/m^2
‘pres.sfc’ Pressure (At Surface) Pascals
‘rhum.sig995’ Relative Humidity (Near Surface) %
‘slp’ Sea Level Pressure (Sea Level) Pascals
‘mslp’ Mean Sea Level Pressure (Sea Level) Pascals
‘uwnd.sig995’ U-Wind Component [East/West] (Near Surface) m/s
‘vwnd.sig995’ V-Wind Component [North/South] (Near Surface) m/s

VARIABLES IN REFERENCE TO A T62 GAUSSIAN GRID

—– These variables are forecasts valid 6 hours after the reference time —–

‘air.2m’ Air Temperature (At 2 meters) deg K
‘icec.sfc’ Ice Concentration (At Surface) fraction
‘pevpr.sfc’ Potential Evaporation Rate (At Surface) W/m^2
‘pres.sfc’ Pressure (At Surface) Pascals
‘runof.sfc’ Water Runoff (At Surface) kg/m^2
‘sfcr.sfc’ Surface Roughness (At Surface) m
‘shum.2m’ Specific Humidity (At 2 meters) kg/kg
‘soilw.0-10cm’ Soil Moisture (From 0-10 cm) fraction
‘soilw.10-200cm’ Soil Moisture (From 10-200 cm) fraction
‘skt.sfc’ Skin Temperature (At Surface) deg K
‘tmp.0-10cm’ Temperature of 0-10 cm layer (From 0-10 cm) deg K
‘tmp.10-200cm’ Temperature of 10-200 cm layer (From 10-200 cm) deg K
‘tmp.300cm’ Temperature at 300 cm (From 300 cm) deg K
‘uwnd.10m’ U-wind (At 10 meters) m/s
‘vwnd.10m’ V-wind (At 10 meters) m/s
‘weasd.sfc’ Water equivalent of snow depth (At Surface) kg/m^2

—– These variables are 6 hour hindcasts from the reference time —–

‘tmax.2m’ Maximum temperature (At 2 meters) deg K
‘tmin.2m’ Minimum temperature (At 2 meters) deg K

—– These variables are 6 hour averages starting at the reference time —–

‘cfnlf.sfc’ Cloud forcing net longwave flux (At Surface) W/m^2
‘cfnsf.sfc’ Cloud forcing net solar flux (At Surface) W/m^2
‘cprat.sfc’ Convective precipitation rate (At Surface) Kg/m^2/s
‘csdlf.sfc’ Clear sky downward longwave flux (At Surface) W/m^2
‘csdsf.sfc’ Clear sky downward solar flux (At Surface) W/m^2
‘dlwrf.sfc’ Downward longwave radiation flux (At Surface) W/m^2
‘dswrf.sfc’ Downward solar radiation flux (At Surface) W/m^2
‘dswrf.ntat’ Downward solar radiation flux (Nominal Top of Atmosphere) W/m^2
‘gflux.sfc’ Ground heat flux (At Surface) W/m^2
‘lhtfl.sfc’ Latent heat net flux (At Surface) W/m^2
‘nbdsf.sfc’ Near IR beam downward solar flux (At Surface) W/m^2
‘nddsf.sfc’ Near IR diffuse downward solar flux (At Surface) W/m^2
‘nlwrs.sfc’ Net longwave radiation (At Surface) W/m^2
‘nswrs.sfc’ Net shortwave radiation (At Surface) W/m^2
‘prate.sfc’ Precipitation rate (At Surface) Kg/m^2/s
‘shtfl.sfc’ Sensible heat net flux (At Surface) W/m^2
‘uflx.sfc’ Momentum flux (zonal) (At Surface) N/m^2
‘ugwd.sfc’ Zonal gravity wave stress (At Surface) N/m^2
‘ulwrf.sfc’ Upward longwave radiation flux (At Surface) W/m^2
‘ulwrf.ntat’ Upward longwave radiation flux (Nominal Top of Atmosphere) W/m^2
‘uswrf.sfc’ Upward solar radiation flux (At Surface) W/m^2
‘uswrf.ntat’ Upward solar radiation flux (Nominal Top of Atmosphere) W/m^2
‘vbdsf.sfc’ Visable beam downward solar flux (At Surface) W/m^2
‘vddsf.sfc’ Visable diffuse downward solar flux (At Surface) W/m^2
‘vflx.sfc’ Momentum flux (meridional) (At Surface) N/m^2
‘vgwd.sfc’ Meridional gravity wave stress (At Surface) N/m^2

—– These variables are 6 hour averages starting at the reference time —–

‘csulf.ntat’ Clear Sky Upward Longwave Flux (Nominal Top of Atmosphere) W/m^2
‘csusf.ntat’ Clear Sky Upward Solar Flux (Nominal Top of Atmosphere) W/m^2
‘dswrf.ntat’ Downward Solar Radiation Flux (Nominal Top of Atmosphere) W/m^2
‘pres.hcb’ Pressure (High Cloud Bottom) Pascals
‘pres.hct’ Pressure (High Cloud Top) Pascals
‘pres.lcb’ Pressure (Low Cloud Bottom) Pascals
‘pres.lct’ Pressure (Low Cloud Top) Pascals
‘pres.mcb’ Pressure (Middle Cloud Bottom) Pascals
‘pres.mct’ Pressure (Middle Cloud Top) Pascals
‘tcdc.eatm’ Total Cloud Cover (Entire Atmosphere) %
‘ulwrf.ntat’ Upward Longwave Radiation Flux (Nominal Top of Atmosphere) W/m^2
‘uswrf.ntat’ Upward Solar Radiation Flux (Nominal Top of Atmosphere) W/m^2

Author(s)

Michael U. Kemp mukemp+RNCEP@gmail.com

References

To cite package 'RNCEP' in publications use:

Kemp, M.U., van Loon, E.E., Shamoun-Baranes, J.,and Bouten, W. (2011). RNCEP: global weather and climate data at your fingertips. Methods in Ecology and Evolution, DOI:10.1111/j.2041-210X.2011.00138.x.

To cite the NCEP/NCAR Reanalysis dataset use:

Kalnay et al. (1996), The NCEP/NCAR 40-year reanalysis project, Bull. Amer. Meteor. Soc., 77, 437-470

To cite the NCEP/DOE Reanalysis II dataset use:

Kanamitsu et al. (2002), NCEP-DOE AMIP-II Reanalysis (R-2). Bull. Amer. Meteor. Soc., 83, 1631-1643

Please acknowledge the use of NCEP data in any publications by including text such as, “NCEP Reanalysis data provided by the NOAA/OAR/ESRL PSD, Boulder, Colorado, USA, from their Web site at http://www.esrl.noaa.gov/psd/”. They would also appreciate a copy of any publications using NCEP data.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
## Not run: 
library(RNCEP)
## Query the temperature from a particular pressure level ##
wx.extent1 <- NCEP.gather(variable='air', level=850,
    months.minmax=c(9,10), years.minmax=c(1996,1997),
    lat.southnorth=c(50,55), lon.westeast=c(5,10),
    reanalysis2 = FALSE, return.units = TRUE)

## Query the temperature at 2 meters altitude with reference to
## the surface
wx.extent2 <- NCEP.gather(variable='air.sig995', level='surface',
    months.minmax=c(2,3), years.minmax=c(2000,2001),
    lat.southnorth=c(50,55), lon.westeast=c(0,5),
    reanalysis2 = FALSE, return.units = TRUE)

## Query the temperature at 2 meters altitude with reference to
## a T62 Gaussian grid
wx.extent3 <- NCEP.gather(variable='air.2m', level='gaussian',
    months.minmax=c(4,5), years.minmax=c(2006,2007),
    lat.southnorth=c(32,35), lon.westeast=c(-35,-32),
    reanalysis2 = FALSE, return.units = TRUE)

## Note that the dimnames of the data array indicate the 
## latitudes, longitudes, and datetimes	of the data. ##
dimnames(wx.extent1)
## Therefore, the latitudes, longitudes, and datetimes
## can be called. ##
dimnames(wx.extent1)[[1]] ## latitudes
dimnames(wx.extent1)[[2]] ## longitudes
dimnames(wx.extent1)[[3]] ## datetimes

#################################################################
#################################################################
#################################################################
## THERE ARE MANY OPTIONS FOR CREATING DIFFERENT R OBJECTS  
## AND/OR FOR EXPORTING THESE WEATHER DATA.
## HERE ARE A FEW EXAMPLES

#########################################################
#########################################################
## The data array may be saved directly as an R object ##
save(wx.extent, file='wx_extent.Rdata')
## And then later recalled ##
load(file='wx_extent.Rdata')


################################################################
################################################################
## Another option is to create a raster object from the array ##
## For more info, see package raster
library(raster)

## Using the data from a query above ##
## First create a stacked raster object using the first 
## layer (i.e. datetime) of the weather data array ##
## Notice the offset of 1.25 degrees (1/2 the spatial resolution)
## to describe the limits of the bounding box not the points
ras <- stack(raster(wx.extent1[,,1], crs="+proj=longlat +datum=WGS84", 
    xmn=min(as.numeric(dimnames(wx.extent1)[[2]])) - 1.25,
    xmx=max(as.numeric(dimnames(wx.extent1)[[2]])) + 1.25, 
    ymn=min(as.numeric(dimnames(wx.extent1)[[1]])) - 1.25,
    ymx=max(as.numeric(dimnames(wx.extent1)[[1]])) + 1.25))

## Then add each subsequent layer to the raster stack ##
for(i in 2:length(dimnames(wx.extent1)[[3]])){
    ras <- addLayer(ras, raster(wx.extent1[,,i], 
        crs="+proj=longlat +datum=WGS84", 
        xmn=min(as.numeric(dimnames(wx.extent1)[[2]])) - 1.25,
        xmx=max(as.numeric(dimnames(wx.extent1)[[2]])) + 1.25, 
        ymn=min(as.numeric(dimnames(wx.extent1)[[1]])) - 1.25,
        ymx=max(as.numeric(dimnames(wx.extent1)[[1]])) + 1.25))
    }

#######################################################
## Optionally, export a layer from the raster stack to 
## a format that can be imported by Esri's ArcGIS products ##

## First, select a layer from the raster stack ##
ras1 <- raster(ras, layer=1)

## Then write the data from that layer to a .bil file ##
writeRaster(ras, filename='ras_example.bil', format="EHdr")
## The file will be saved in your current working directory ##

## The resulting file can be imported into ArcGIS ##
## by using the "Raster to Other Format" tool in the 
## "To Raster" section of the ArcToolbox.

###########################################################
## NOTE: Weather data obtained from a Gaussian grid must 
## first be resampled onto a regular grid !!! ##
## Here we use the interp.loess() function
## from the tgp package

## Using data from a T62 Gaussian grid queried above 
## Interpolate the data from the first layer (i.e. datetime)
## onto a regular grid ##
library(tgp)
wx.reg <- interp.loess(x=rep(as.numeric(dimnames(wx.extent3)[[2]]), 
        each=length(dimnames(wx.extent3)[[1]])),
    y=rep(as.numeric(dimnames(wx.extent3)[[1]]), 
         length(dimnames(wx.extent3)[[2]])), 
    z=as.vector(wx.extent3[,,1]), span=0.6, 
    gridlen=c(length(dimnames(wx.extent3)[[2]]),
        length(dimnames(wx.extent3)[[1]])))

## Create a stacked raster object from the first layer 
## (i.e. datetime) after interpolation ##
## Again, notice the offset (1/2 the resolution) ##
## Also note that the matrix (i.e. wx.reg$z) must be flipped 
## along the y axis and transposed ##
## This is required b/c of the interpolation performed above ##
ras <- stack(raster(t(wx.reg$z[,length(wx.reg$y):1]), 
    crs="+proj=longlat +datum=WGS84", 
    xmn=min(as.numeric(wx.reg$x)) - abs(diff(wx.reg$x)[1]/2),
    xmx=max(as.numeric(wx.reg$x)) + abs(diff(wx.reg$x)[1]/2), 
    ymn=min(as.numeric(wx.reg$y)) - abs(diff(wx.reg$y)[1]/2),
    ymx=max(as.numeric(wx.reg$y)) + abs(diff(wx.reg$y)[1]/2)))
	
## Add each subsequent layer in the array to the raster stack ##
## after interpolating onto a regular grid ##

for(i in 2:length(dimnames(wx.extent3)[[3]])){

  ## Interpolate
  t.wx.reg <- interp.loess(x=rep(as.numeric(dimnames(wx.extent3)[[2]]), 
      each=length(dimnames(wx.extent3)[[1]])), 
      y=rep(as.numeric(dimnames(wx.extent3)[[1]]), 
      length(dimnames(wx.extent3)[[2]])), 
      z=as.vector(wx.extent3[,,i]), span=0.6, 
      gridlen=c(length(dimnames(wx.extent3)[[2]]),
      length(dimnames(wx.extent3)[[1]])))
  
  ## Note the offset ##
  ## Note flipping the matrix along the y axis and transposing ##
  ## Add layer to stack
  ras <- addLayer(ras, raster(t(t.wx.reg$z[,length(t.wx.reg$y):1]),
    crs="+proj=longlat +datum=WGS84",
    xmn=min(as.numeric(t.wx.reg$x)) - abs(diff(t.wx.reg$x)[1]/2),
    xmx=max(as.numeric(t.wx.reg$x)) + abs(diff(t.wx.reg$x)[1]/2), 
    ymn=min(as.numeric(t.wx.reg$y)) - abs(diff(t.wx.reg$y)[1]/2),
    ymx=max(as.numeric(t.wx.reg$y)) + abs(diff(t.wx.reg$y)[1]/2)))
  }

##################################################################
##################################################################
## Another option is to create a Spatial object
## using the sp package
## Again, data from a Gaussian grid may require special attention
## as the grid points are unevenly spaced
library(sp)

## Using the data from a query above
## Convert the array to a data.frame ##
wx.df <- NCEP.array2df(wx.extent2)

## Specify that the data.frame is a spatial object
library(sp)
coordinates(wx.df) <- ~longitude+latitude
gridded(wx.df) <- TRUE
proj4string(wx.df) <- CRS('+proj=longlat + datum=WGS84')

#########################################################
## A Spatial object of a single datetime (i.e. layer) can 
## be written to .asc, a format that may then be 
## imported into ArcGIS.

## First, convert the first layer of the array to a data.frame ##
wx.df <- NCEP.array2df(wx.extent2[,,1])

## Specify that the data.frame is a spatial object
library(sp)
coordinates(wx.df) <- ~longitude+latitude
gridded(wx.df) <- TRUE
proj4string(wx.df) <- CRS('+proj=longlat + datum=WGS84')

## Save the data in .asc format
write.asciigrid(wx.df, fname='wx.asc')
## Note: Data will be written to your working directory ##

## The resulting .asc file can be imported into ArcMap
## using ArcMap's "ASCII to Raster" tool in the "Conversion Tools"
## section of the ArcToolbox. ##

##################################################################
## There are still more options for writing these data to files ##
## See e.g. writeMat() in the R.matlab package for writing Matlab files
## Also see the RSAGA package for GIS functionality in R
## One could even write the data array back to NetCDF 
## (see packages RNetCDF and ncdf)

## End(Not run)

RNCEP documentation built on July 1, 2020, 7:10 p.m.