Extract VIIRS data in R

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract VIIRS data in R

Miluji Sb
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
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Frederico Faleiro
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 <[hidden email]> 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
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Washington Correia Filho
In reply to this post by Miluji Sb
Dear Millu,

The data they use is not with the CRS set, so the displayed result is showing the grid points (extent: 0.5, 4064.5, 0.5, 3232.5). Then you should consult the VIIRS data guide so that you can organize your data, to which you need to know the start data for both latitude and longitude, as well as the multiplication factor and so you will have your data readjusted. I also have a similar problem to solve, if I can, I can contact you and give you the data and the scheme I used. See you soon.

Sincerely,
Washington L.F. Correia Filho
Postdoctoral Research Fellowship in Meteorology, UFAL, Brazil
Dr. in Climate Sciences, UFRN, Brazil
http://lattes.cnpq.br/7596712599262929
ORCID: https://orcid.org/0000-0002-4029-4491/

________________________________
De: R-sig-Geo <[hidden email]> em nome de Miluji Sb <[hidden email]>
Enviado: ter�a-feira, 17 de mar�o de 2020 11:29
Para: R-sig-geo mailing list <[hidden email]>
Assunto: [R-sig-Geo] Extract VIIRS data in R

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
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>  Livre de v�rus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>.

        [[alternative HTML version deleted]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Michael Sumner-2
In reply to this post by Miluji Sb
You won't find much on this kind of file in the R community, this is
relatively new NetCDF-4 with "groups", and contains a satellite "granule" -
a kind of pre-mapping raw data array with only technical information about
where the scanning occurred.

In short, raster and stars package (and RNetCDF and ncdf4) will read the
data from this file, but give very little or no help for how to treat it
like a map. The spatial resolution and extent are purely nominal as shown
by raster, a spacing of 1 in two dimensions and extending from 0 to nrows,
0 to ncols (with a  half cell shift). There aren't any coordinate arrays in
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 do
that).

You'd need to pursue domain-specific expertise to discover the mapping of
this, unless some kind soul turns up to help here. I expect you'll want to
find a product that has been converted into simpler form for these data.

Cheers, Mike.


On Wed, Mar 18, 2020 at 1:39 AM Miluji Sb <[hidden email]> 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
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


--
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: [hidden email]

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Zia Ahmed
In reply to this post by Frederico Faleiro
This is might help you:

https://zia207.github.io/geospatial-r-github.io/netCDF-data-processing.html

Zia

On Wed, Mar 18, 2020, 9:34 AM Frederico Faleiro <[hidden email]> wrote:

> 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 <[hidden email]> 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
> > [hidden email]
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Miluji Sb
Dear all,

Thank you everyone. The issue (as pointed out) is the following;

# [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"

I have contacted the VIIRS people and will keep you posted here. Thank you
again!

Best,

Milu

On Wed, Mar 18, 2020 at 3:34 PM Zia Ahmed <[hidden email]> wrote:

> This is might help you:
>
> https://zia207.github.io/geospatial-r-github.io/netCDF-data-processing.html
>
>
> Zia
>
> On Wed, Mar 18, 2020, 9:34 AM Frederico Faleiro <[hidden email]>
> wrote:
>
>> 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 <[hidden email]> 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
>> > [hidden email]
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

edzer
In reply to this post by Michael Sumner-2
If the product info is in this document:
https://ladsweb.modaps.eosdis.nasa.gov/missions-and-measurements/viirs/NASAVIIRSL1BUGAug2019.pdf

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 where
you got the data. With that, you can use package stars to load them, and
e.g. resample to some (more) regular grid.

See e.g.
https://r-spatial.github.io/stars/articles/stars4.html#curvilinear-grids

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 is
> relatively new NetCDF-4 with "groups", and contains a satellite "granule" -
> a kind of pre-mapping raw data array with only technical information about
> where the scanning occurred.
>
> In short, raster and stars package (and RNetCDF and ncdf4) will read the
> data from this file, but give very little or no help for how to treat it
> like a map. The spatial resolution and extent are purely nominal as shown
> by raster, a spacing of 1 in two dimensions and extending from 0 to nrows,
> 0 to ncols (with a  half cell shift). There aren't any coordinate arrays in
> 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 do
> that).
>
> You'd need to pursue domain-specific expertise to discover the mapping of
> this, unless some kind soul turns up to help here. I expect you'll want to
> find a product that has been converted into simpler form for these data.
>
> Cheers, Mike.
>
>
> On Wed, Mar 18, 2020 at 1:39 AM Miluji Sb <[hidden email]> 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
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48149 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pEpkey.asc (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Extract VIIRS data in R

Miluji Sb
Dear Edzer,

Thank you for your reply and the suggestions. Apologies for not copying the
list, I forgot to hit 'reply all'.

The data is Nighttime lights from Black Marble.

Source of the geo-location data (VNP03DNB):
https://ladsweb.modaps.eosdis.nasa.gov/missions-and-measurements/products/VNP03DNB/
Observation data (VNP02DNB):
https://ladsweb.modaps.eosdis.nasa.gov/missions-and-measurements/products/VNP02DNB/


Thank you for the code, I only changed the path but I am getting the
following error when I run the following part;

latlon = read_stars(
c('NETCDF:"VNP03DNB.A2020015.0236.001.2020044182419.nc
":/geolocation_data/latitude',
'NETCDF:"VNP03DNB.A2020015.0236.001.2020044182419.nc
":/geolocation_data/longitude'))

"Error in CPL_read_gdal(as.character(x), as.character(options),
as.character(driver),  :  file not found"

I checked the path. Thank you again.

Best,

Milu

On Fri, Mar 20, 2020 at 9:27 AM Edzer Pebesma <[hidden email]>
wrote:

> 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:
> > Thank you for your reply and the information.
> >
> > This file
> > <https://drive.google.com/open?id=1zpqXJ8AlEcnk6ApRb75tfQc4-Y8AfK5h
> > needs
> > to be combined with the geo-location data in this file
> > <https://drive.google.com/open?id=1jLmXLjG0WGgdH3g4pGJNz0ZOqXOfKpcW>. I
> > will try out the stars package, any suggestions will be highly
> appreciated.
> >
> > Thanks again and stay safe.
> >
> > Best,
> >
> > Milu
> >
> > On Wed, Mar 18, 2020 at 5:25 PM Edzer Pebesma
> > <[hidden email] <mailto:[hidden email]>>
> > wrote:
> >
> >     If the product info is in this document:
> >
> https://ladsweb.modaps.eosdis.nasa.gov/missions-and-measurements/viirs/NASAVIIRSL1BUGAug2019.pdf
> >
> >     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
> where
> >     you got the data. With that, you can use package stars to load them,
> and
> >     e.g. resample to some (more) regular grid.
> >
> >     See e.g.
> >
> https://r-spatial.github.io/stars/articles/stars4.html#curvilinear-grids
> >
> >     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
> is
> >     > relatively new NetCDF-4 with "groups", and contains a satellite
> >     "granule" -
> >     > a kind of pre-mapping raw data array with only technical
> >     information about
> >     > where the scanning occurred.
> >     >
> >     > In short, raster and stars package (and RNetCDF and ncdf4) will
> >     read the
> >     > data from this file, but give very little or no help for how to
> >     treat it
> >     > like a map. The spatial resolution and extent are purely nominal
> >     as shown
> >     > by raster, a spacing of 1 in two dimensions and extending from 0
> >     to nrows,
> >     > 0 to ncols (with a  half cell shift). There aren't any coordinate
> >     arrays in
> >     > 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
> do
> >     > that).
> >     >
> >     > You'd need to pursue domain-specific expertise to discover the
> >     mapping of
> >     > this, unless some kind soul turns up to help here. I expect you'll
> >     want to
> >     > find a product that has been converted into simpler form for these
> >     data.
> >     >
> >     > Cheers, Mike.
> >     >
> >     >
> >     > On Wed, Mar 18, 2020 at 1:39 AM Miluji Sb <[hidden email]
> >     <mailto:[hidden email]>> 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
> >     <http://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
> >     <http://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
> >     >> [hidden email] <mailto:[hidden email]>
> >     >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >     >>
> >     >
> >     >
> >
> >     --
> >     Edzer Pebesma
> >     Institute for Geoinformatics
> >     Heisenbergstrasse 2, 48149 Muenster, Germany
> >     Phone: +49 251 8333081
> >     _______________________________________________
> >     R-sig-Geo mailing list
> >     [hidden email] <mailto:[hidden email]>
> >     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> --
> Edzer Pebesma
> Institute for Geoinformatics
> Heisenbergstrasse 2, 48149 Muenster, Germany
> Phone: +49 251 8333081
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo