Hi Miluji, the R in general do not handle very well with netCDF. However I recommend you use the netcdf4 package before try others. This link is a good start: http://geog.uoregon.edu/bartlein/courses/geog490/week04-netCDF.html#get-coordinate-including-time-variables . The coordinates of this file is not in longitude and latitude, it use "number_of_lines" for X Axis and "number_of_pixels" for Y Axis. This way the difference between the cells is always one and raster package interprete the difference as one degree and return an warning about it. I open the file in the software Panoply (design to work with netCDF) and everything is OK apparently. Check bellow some exploration of the data in R.
library(raster) library(ncdf4) library(rgdal) # netcdf4 package netcdf_file <- "VNP02DNB_NRT.A2020069.1048.001.nc" nc <- nc_open(netcdf_file) print(nc) # check your variable is structured as: observation_data/DNB_observations[number_of_pixels,number_of_lines] # variables available names(nc[["var"]]) # properties from your variable ncatt_get(nc, "observation_data/DNB_observations") # get the variables values and check the structure obs_matrix <- ncvar_get(nc, "observation_data/DNB_observations") str(obs_matrix) # raster package nc_r <- brick(netcdf_file, lvar=0, values=TRUE, varname="observation_data/DNB_observations") # [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named number_of_pixels BUT this dimension HAS NO DIMVAR! Code will probably fail at this point" # [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named number_of_lines BUT this dimension HAS NO DIMVAR! Code will probably fail at this point" Best regards, Frederico Faleiro Postdoctoral Researcher in the INCT-EECBio (https://www.eecbio.ufg.br/) Federal University of Goiás | Brazil RG: https://www.researchgate.net/profile/Frederico_Faleiro On Tue, Mar 17, 2020 at 11:39 AM Miluji Sb <miluj...@gmail.com> wrote: > Dear all, > > Hope everyone is keeping safe. > > I am trying to extract/read VIIRS nighttime lights data but the output > seems rather strange. > > I have uploaded the file here > <https://drive.google.com/open?id=1zpqXJ8AlEcnk6ApRb75tfQc4-Y8AfK5h> so as > not exceed the size limit of the email. > > ## Code ## > library(ncdf4) > library(rgdal) > > netcdf_file <- c("VNP02DNB_NRT.A2020069.1048.001.nc") > nl <- brick(netcdf_file, lvar=0, values=TRUE, > varname="observation_data/DNB_observations") > > ## Detail ## > class : RasterLayer > dimensions : 3232, 4064, 13134848 (nrow, ncol, ncell) > resolution : 1, 1 (x, y) > extent : 0.5, 4064.5, 0.5, 3232.5 (xmin, xmax, ymin, ymax) > crs : NA > source : C:/Users/shour/Desktop/VNP02DNB_NRT.A2020069.1048.001.nc > names : DNB.observations.at.pixel.locations > zvar : observation_data/DNB_observations > > The spatial resolution is supposed to be 750m but this shows 1°. What am I > doing wrong? Any help will be greatly appreciated. Thank you. > > Sincerely, > > Millu > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo