Dear Milu,
It is more practical for yourself and more helpful for others when you
reply to the list. I now Cc: the list, but that is not how it is
supposed to work. Also, please use text mails, not html with inline
links. Finally, your links point to things you downloaded and
reuploaded, not to the place where you got the dataset from - for future
users having the same problem and consulting mailing list archives this
is also not really helpful.
I tried this:
# maybe: remotes::install_github("r-spatial/stars")
library(stars)
r = read_stars("VNP02DNB_NRT.A2020069.1048.001.nc")
latlon = read_stars(
c('NETCDF:"VNP03DNB.A2020015.0236.001.2020044182419.nc
":/geolocation_data/latitude',
'NETCDF:"VNP03DNB.A2020015.0236.001.2020044182419.nc
":/geolocation_data/longitude'))
r_ll = st_as_stars(r,
curvilinear = list(x = latlon[[2]], y = latlon[[1]]))
plot(r_ll, reset = FALSE, axes = TRUE)
maps::map('world', add = TRUE, col = 'red')
Although I don't really know what the data is about, the plot generated
(attached) to me seems to indicate that you are trying to glue the wrong
latitudes and longitudes to your measurements.
On 3/19/20 11:29 PM, Miluji Sb wrote:
Thanks again and stay safe.
Best,
Milu
On Wed, Mar 18, 2020 at 5:25 PM Edzer Pebesma
<edzer.pebesma at uni-muenster.de <mailto:edzer.pebesma at uni-muenster.de>>
wrote:
If the product info is in this document:
then it sounds like these data are distributed as curvilinear grids,
meaning that there are two additional raster with for each pixel the
longitude and the latitude. The file you pointed to does not contain
these two grids, but you should be able to get them at the place
you got the data. With that, you can use package stars to load them,
e.g. resample to some (more) regular grid.
See e.g.
On 3/18/20 3:29 PM, Michael Sumner wrote:
> You won't find much on this kind of file in the R community, this
> relatively new NetCDF-4 with "groups", and contains a satellite
> a kind of pre-mapping raw data array with only technical
> where the scanning occurred.
>
> In short, raster and stars package (and RNetCDF and ncdf4) will
> data from this file, but give very little or no help for how to
> like a map. The spatial resolution and extent are purely nominal
> by raster, a spacing of 1 in two dimensions and extending from 0
> 0 to ncols (with a half cell shift). There aren't any coordinate
> the file, or any simple way to transform from this matrix-space to
> geography as far as I know. (Would love to be corrected on how to
> that).
>
> You'd need to pursue domain-specific expertise to discover the
> this, unless some kind soul turns up to help here. I expect you'll
> find a product that has been converted into simpler form for these
>
> Cheers, Mike.
>
>
> On Wed, Mar 18, 2020 at 1:39 AM Miluji Sb <milujisb at gmail.com
<mailto:milujisb at gmail.com>> wrote:
>> Dear all,
>>
>> Hope everyone is keeping safe.
>>
>> I am trying to extract/read VIIRS nighttime lights data but the
>> seems rather strange.
>>
>> I have uploaded the file here
>>
>> 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 :
>> names : DNB.observations.at.pixel.locations
>> zvar : observation_data/DNB_observations
>>
>> The spatial resolution is supposed to be 750m but this shows 1?.
>> doing wrong? Any help will be greatly appreciated. Thank you.
>>
>> Sincerely,
>>
>> Millu
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org <mailto:R-sig-Geo at r-project.org>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48149 Muenster, Germany
Phone: +49 251 8333081