0

I am new here and am just beginning with R Studio. I have downloaded .nc data files from ST5 Satellite from the Copernicus hub and am attempting to make a plot with the variables - latitude, longitude, time and aerosol height. I have tried to use other examples to resolve but to no avail. Here is as far as I have gotten.

library(ncdf4)

library(raster)
ncpath <- ("~/Desktop/Summer 2020/Tropomi/Aerosol Height")
ncname <- "S5P_RPRO_L2__AER_LH_20180722T230340_20180723T004708_04009_01_010301_20190531T123254.nc"
nc <- nc_open(ncname)
lat <- ncvar_get(nc, varid = "PRODUCT/latitude")
lon <- ncvar_get(nc, varid = "PRODUCT/longitude")
time <- ncvar_get(nc, varid = "PRODUCT/time_utc")
so2 <- ncvar_get(nc, varid = "PRODUCT/aerosol_mid_height")
r <-brick(nc)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘brick’ for signature ‘"ncdf4"’

Why am I getting this error message? Does anyone have any suggestions for what to try next? Thank you for reading.

Matt
  • 15
  • 5

1 Answers1

1

With most ncdf files, it is much simpler, and you can do

library(raster)
ncname <- "S5P_RPRO_L2__AER_LH_20180722T230340_20180723T004708_04009_01_010301_20190531T123254.nc"
r <-brick(ncname)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Thank you for your input, Robert but surprisingly, this does not work either. I get the following error message even after installing the correct pathway: Error in R_nc4_open: No such file or directory Error in ncdf4::nc_open(filename, suppress_dimvals = TRUE) : Error in nc_open trying to open file S5P_RPRO_L2__AER_LH_20180722T230340_20180723T004708_04009_01_010301_20190531T123254.nc – Matt Jun 13 '20 at 19:39
  • Have you checked that? Try `file.exists(ncname)`. You need to either provide the full filname as in `d:/path/to/file/filename.nc` or for set the working directory to where the file is as in `setwd("d:/path/to/file/")` – Robert Hijmans Jun 13 '20 at 20:03
  • Thank you, Robert. I identified an error in my file path! – Matt Jun 23 '20 at 21:47