0

I am trying to load netcdf file into R:

f <- "A20020012002365.L3b_YR_CHL.nc"
u <- "https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/"
curl::curl_download(file.path(u, f), f)
r <- brick("A20020012002365.L3b_YR_CHL.nc")

Error message I get: Error in R_nc4_open: NetCDF: Unknown file format

Also tried:

tidync::tidync("A20020012002365.L3b_YR_CHL.nc")
nc <-  RNetCDF::open.nc("A20020012002365.L3b_YR_CHL.nc")
RNetCDF::print.nc(nc)
file <- RNetCDF::open.nc("A20020012002365.L3b_YR_CHL.nc")
ncdf4::nc_open("A20020012002365.L3b_YR_CHL.nc", verbose=TRUE, readunlim = FALSE, suppress_dimvals = TRUE)

none of those worked

yuliaUU
  • 1,581
  • 2
  • 12
  • 33
  • Upon closer inspection: if you run the commands above, the file that gets downloaded is an HTML page that requests your login / authentication (though presenting with a .nc file extension). At least for me. You'd best verify you have the correct file by downloading it manually through the NASA website. – Caspar V. May 03 '22 at 02:18
  • I have a .NC file downloaded with this code – yuliaUU May 03 '22 at 03:16
  • I am using R cause I do not have another program to check, I tried to run the following: file <- RNetCDF::open.nc("A20020012002365.L3b_YR_CHL.nc") RNetCDF::print.nc(file) class(file) gives me class NetCDF – yuliaUU May 03 '22 at 04:10
  • 1
    Alright, for me the command `file <- RNetCDF::open.nc("A20020012002365.L3b_YR_CHL.nc")` already gives an error: `NetCDF: Unknown file format`. So you have another problem. I don't have a login to access these files so can't help you further unfortunately. – Caspar V. May 03 '22 at 04:16
  • i asked a friend to check with matlab, and file opens perfectly – yuliaUU May 03 '22 at 16:01
  • These are not regular gridded data. You should be able to open the file with an hdf5 library if you know something about the underlying data structure. Otherwise, see discussion on the earthdata forum https://forum.earthdata.nasa.gov/viewtopic.php?f=7&t=1903 – Robert Davy May 04 '22 at 04:09
  • Related question: https://stackoverflow.com/questions/66296373/how-to-open-modis-netcdf-file-in-r – Robert Davy May 04 '22 at 05:29

0 Answers0