geospatialrasterrasterizingsatellite

Why won't my raster image display with levelplot?


I am attempting to overlay a netcdf4 raster containing Aerosol Height data over Hawaii specifically. A sample file is available here. My variables of interest are latitude, longitude, time and aerosol height. Here is some reproducible data.

s1 <- data.frame(as.vector(lon), as.vector(lat), as.vector(ah))
s1
#    as.vector.lon. as.vector.lat. as.vector.ah.
#1       -127.45199      -79.15431            NA
#2       -126.99632      -79.16919            NA
#3       -126.54577      -79.18321            NA
#4       -126.10027      -79.19641            NA
#5       -125.65974      -79.20880            NA
#6       -125.22412      -79.22042            NA
#7       -124.79333      -79.23129            NA

crsLatLon <- "+proj=longlat +datum=WGS84"
ex <- extent(c(-180,180,-90,90))

#empty raster with 0.1 degree resolution
pmraster <- raster(ncol=360*10, nrow=180*10, crs=crsLatLon,ext=ex)

#fills the empty raster with values from dataframe, s1
pmraster <- rasterize(s1[,1:2], pmraster, s1[,3], fun=mean, na.rm=T)

show(pmraster)
#class      : RasterLayer 
#dimensions : 1800, 3600, 6480000  (nrow, ncol, ncell)
#resolution : 0.1, 0.1  (x, y)
#extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
#source     : r_tmp_2020-06-26_114048_16840_75885.grd 
#names      : layer 
#values     : 0.1314196, 9424.118  (min, max)

#specifies region over Hawaii
exHI <- extent(c(-180,-140,10,30))

levelplot(crop(pmraster,exHI))

#Error: $ operator is invalid for atomic vectors
#In addition: Warning messages:
#1: In min(x) : no non-missing arguments to min; returning Inf
#2: In max(x) : no non-missing arguments to max; returning -Inf
#3: In min(x) : no non-missing arguments to min; returning Inf
#4: In max(x) : no non-missing arguments to max; returning -Inf

Can anyone help explain why I am getting this error message and how I may proceed to produce the desired raster image? Thank you in advance!


Solution

  • After trying this on different files, it became clear to me that there was no data available over the specific region I was isolating, resulting in my confusion.