Subscribe to R-sig-geo feed
This is an archive for R-sig-geo, not a forum. It is not possible to post through Nabble - you may not start a new thread nor follow up an existing thread. If you wish to post, but are not subscribed to the list through the list homepage, subscribe first (through the list homepage, not via Nabble) and post from your subscribed email address. Until 2015-06-20, subscribers could post through Nabble, but policy has been changed as too many non-subscribers misunderstood the interface.
Updated: 1 min 45 sec ago

Introducing new local spatial statistic, ELSA, and Entrogram (a variogram-like graph)

Sat, 03/28/2020 - 23:07
Dear All,

Hope you are safe and well!

I am writing to inform you that the new R package, elsa, is released on
CRAN. This package is a framework that provides the methods for quantifying
the new local spatial statictic, named "entropy-based local indicator of
spatial association" (ELSA), that can be used for both continuous and
categorical data. In addition, global spatial structure can be measured
using a new variogram-like diagram, called entrogram.

The package vignette provides a quick demonstration of some main functions
in the package:

https://cran.r-project.org/web/packages/elsa/vignettes/elsa.html

The paper that introduces ELSA is published in the journal of spatial
statistics and is available here:

https://www.sciencedirect.com/science/article/abs/pii/S2211675318300228

The package, elsa, is also followed with functions to calculate other LISAs
and global statistics for different types of spatial datasets (i.e.,
Raster, SpatialPointsDataFrame, SpatialPolygonsDataFrame).

Best regards,

Babak Naimi






*University Researcher, Department of Geosciences and Geography,The
University of Helsinki,Gustaf Hällströmin Katu 2, 00014
HelsinkiFinlandHomepage I: http://r-gis.net <http://r-gis.net/>  Homepage
II: http://biogeoinformatics.org <http://biogeoinformatics.org/>  *

        [[alternative HTML version deleted]]

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

creating a data range for color coding and using it in color_manual_scale

Thu, 03/26/2020 - 08:52
 Dear All

I have been able to move one step forward but still haven't been able to
assign the correct color to the levels created

The r-code is as below with the output  in the url
I assigned Blue, green, yellow, orange and red to the different levels.
Unfortunately, the output is not as expected.

#create the five levels
Mrima_levels<-cut(Mrima_sf$dose,breaks=c(0,114,228,570,2293,5144))

#assign color code to the levels
palette=c(Mrima_levels, seecol(pal_signal,n=5))

#Use the five levels and palette created to create a discrete map
ggplot(Mrima, mapping=aes(x=lon,y=lat))+geom_sf(data=Mrima_sf, inherit.aes
= FALSE)+
  geom_point(aes(colour=Mrima_levels),alpha=0.6, size=1)+
  scale_color_manual(values=palette, aesthetics =c("colours", "fill") ,
breaks=waiver())+
ylab("Latitude")+xlab("Longitude")

https://rpubs.com/pkageliza/589877

Kindly assist
Thank you

--

The University of Nairobi is ISO 9001:2015 certified.
Website:
http://www.uonbi.ac.ke/ <http://www.uonbi.ac.ke/>
Facebook:
https://www.facebook.com/uonbi.ac.ke <https://www.facebook.com/uonbi.ac.ke>

Twitter: @uonbi  https://twitter.com/uonb <https://twitter.com/uonb>

        [[alternative HTML version deleted]]

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

Re: R spatial follows GDAL and PROJ development

Wed, 03/25/2020 - 02:15
Thanks to the CRAN team, sf 0.9-0 has been published. Windows and OSX
binaries should follow before long. Script authors and package
maintainers using sf should note the changes in this version, which may
require action - see the blog linked earlier in this thread. See also:

https://twitter.com/edzerpebesma/status/1242550145964806145
https://twitter.com/RogerBivand/status/1242551606505324544

Roger

On Wed, 18 Mar 2020, Ben Tupper wrote:

> This is very helpful - thank you!
>
> On Wed, Mar 18, 2020 at 9:12 AM Roger Bivand <[hidden email]> wrote:
>
>> A new blog: "R spatial follows GDAL and PROJ development" has been
>> published: https://www.r-spatial.org/r/2020/03/17/wkt.html.
>>
>> Those maintaining packages using sf or sp/rgdal, and authors of scripts
>> using them should read the blog and be prepared to take rapid action when
>> sf 0.9 is released and built using PROJ >= 6 and GDAL >= 3. An early
>> release of rgdal (>= 1.5, probably 1.6.0, is also to be expected).
>>
>> Roger
>>
>> --
>> Roger Bivand
>> Department of Economics, Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; e-mail: [hidden email]
>> https://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: Convert rectilinear to regular grid in R (stars and raster)

Tue, 03/24/2020 - 17:37
Hi Edzer,

thank you for your reply and modifications in the function.
Now the code is working fine, but the structure of the output was changed.
When I try extract the values converting to data.frame all values was
replaced by NA. However the plot is OK as you have tested.

1. How can I create a new grid with the new resolution in stars? Am I doing
it correctly (see bellow)?
2. How can I get the data.frame with the new values?
3. I have tried the function sf::st_interpolate_aw (see bellow), but there
is some warnings that I do not know the consequences for the calculation.

# update packages
library(devtools)
install_github("r-spatial/sf")
install_github("r-spatial/stars")

library(stars)

# read file
bc <- read_ncdf("pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc")
# create the new grid
grid_st <- st_as_stars(st_bbox(c(xmin=0,xmax=360,ymin=-90,ymax=90))) %>%
st_set_crs(4326)
# change resolution. Is it right?
attr(grid_st, "dimensions")[[1]]$delta <- 2.8125
attr(grid_st, "dimensions")[[2]]$delta <- - 2.8125

# change from rectilinear to regular grid with stars
bc_reg <- bc %>% st_warp(grid_st, method = "near")
# plot
plot(bc_reg[, , , 1:12])

# convert to data.frame
bc_reg_df <- as.data.frame(bc_reg_st)
# there is only NA in the variable
str(bc_reg_df)
range(bc_reg_df$pr)

# change from rectilinear to regular grid with sf
grid_sf <- st_as_sf(grid_st)
plot(grid_sf)
bc_sf <- st_as_sf(bc)
plot(bc_sf)
bc_sf_reg <- st_interpolate_aw(bc_sf, grid_sf, F)
#although coordinates are longitude/latitude, st_intersection assumes that
they are planar
#Warning message:
#In st_interpolate_aw.sf(bc_sf, grid_sf, F) :
#  st_interpolate_aw assumes attributes are constant over areas of x

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


Em ter., 24 de mar. de 2020 às 11:59, Edzer Pebesma <
[hidden email]> escreveu:

> The stars part of this question has also been sent as an issue on
> github, and that is where it has been answered (partially solved):
>
> https://github.com/r-spatial/stars/issues/264
>
> please feel free to send follow-up's here, or there.
>
> On 3/23/20 6:45 PM, Frederico Faleiro wrote:
> > Dear all,
> >
> > I am trying convert netCDF data from rectilinear to regular grid in R,
> but
> > I am not sure what is the best approach for it.
> > I would like to convert the grid modifying the original resolution only
> > when necessary. In some cases I must change resolution to keep regular
> cell
> > size and cover all the world extent.
> > I have tried without success st_warp from stars and I find a way with
> > rasterize from raster package (see script bellow).
> >
> > I have the following questions:
> > 1. What am I doing wrong in stars package (see script bellow)?
> > 2. Is there a way to rasterize points to raster using metrics that
> consider
> > distance (e.g. bilinear, nearest neighbor, etc)? Note that I need
> > use points in raster package because it do not handle with rectilinear
> grid.
> > 3. Do you recommend any other approach?
> >
> > The data are available in:
> > GDrive:
> >
> https://drive.google.com/file/d/1HKxFpAwvY9k_cFbasagKHAwi1luzLv90/view?usp=sharing
> > CMIP5 portal (you must make a login):
> >
> http://aims3.llnl.gov/thredds/fileServer/cmip5_css01_data/cmip5/output1/BCC/bcc-csm1-1/rcp45/mon/atmos/Amon/r1i1p1/v20120705/pr/pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc
> >
> > # script
> > library(stars)
> > library(raster)
> >
> > # prepare data
> > bc <- read_ncdf("pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc")
> > # get coordinates and data from the first time period
> > bc1 <- as.data.frame(bc[, , , 1])
> > # convert longitude to variate between -180 and 180
> > bc1$lon <- ifelse(bc1$lon > 180, bc1$lon - 360, bc1$lon)
> >
> > # original resolution
> > bc1$lon %>% diff %>% table
> > bc1$lat %>% diff %>% table
> > # new resolution
> > new_res <- c(2.8125, 2.8125)
> > # Is it multiple of 180 or 360?
> > 180 %% new_res
> >
> > # create a new standard grid
> > wgs84 <- "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
> > grid_r <- raster(res = new_res, crs = wgs84)
> > grid_st <- st_as_stars(grid_r)
> >
> > # change from rectilinear to regular grid
> > # stars package: use st_warp to change from rectilinear to regular raster
> > with different methods
> > bc_reg <- bc %>% st_warp(grid_st, method = "average")
> > bc_reg <- bc %>% st_warp(grid_st, method = "near")
> > bc_reg <- bc %>% st_warp(grid_st, method = "bilinear")
> > # In all cases I have this error: Error in 1:prod(dims[dxy]) : NA/NaN
> > argument
> >
> > # raster package: rasterize the points values to the new regular grid
> > bc1_sp <- bc1
> > coordinates(bc1_sp) <- ~ lon + lat
> > bc1_reg <- rasterize(bc1_sp, grid_r, field = "pr", fun = mean)
> >
> > # plot the first time period
> > dev.new(title = "rectilinear")
> > plot(bc[, , , 1])
> > dev.new(title = "regular with raster package")
> > plot(bc1_mn_reg)
> >
> > 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
> >
> >       [[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
>
        [[alternative HTML version deleted]]

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

Re: Convert rectilinear to regular grid in R (stars and raster)

Tue, 03/24/2020 - 08:58
The stars part of this question has also been sent as an issue on
github, and that is where it has been answered (partially solved):

https://github.com/r-spatial/stars/issues/264

please feel free to send follow-up's here, or there.

On 3/23/20 6:45 PM, Frederico Faleiro wrote:
> Dear all,
>
> I am trying convert netCDF data from rectilinear to regular grid in R, but
> I am not sure what is the best approach for it.
> I would like to convert the grid modifying the original resolution only
> when necessary. In some cases I must change resolution to keep regular cell
> size and cover all the world extent.
> I have tried without success st_warp from stars and I find a way with
> rasterize from raster package (see script bellow).
>
> I have the following questions:
> 1. What am I doing wrong in stars package (see script bellow)?
> 2. Is there a way to rasterize points to raster using metrics that consider
> distance (e.g. bilinear, nearest neighbor, etc)? Note that I need
> use points in raster package because it do not handle with rectilinear grid.
> 3. Do you recommend any other approach?
>
> The data are available in:
> GDrive:
> https://drive.google.com/file/d/1HKxFpAwvY9k_cFbasagKHAwi1luzLv90/view?usp=sharing
> CMIP5 portal (you must make a login):
> http://aims3.llnl.gov/thredds/fileServer/cmip5_css01_data/cmip5/output1/BCC/bcc-csm1-1/rcp45/mon/atmos/Amon/r1i1p1/v20120705/pr/pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc
>
> # script
> library(stars)
> library(raster)
>
> # prepare data
> bc <- read_ncdf("pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc")
> # get coordinates and data from the first time period
> bc1 <- as.data.frame(bc[, , , 1])
> # convert longitude to variate between -180 and 180
> bc1$lon <- ifelse(bc1$lon > 180, bc1$lon - 360, bc1$lon)
>
> # original resolution
> bc1$lon %>% diff %>% table
> bc1$lat %>% diff %>% table
> # new resolution
> new_res <- c(2.8125, 2.8125)
> # Is it multiple of 180 or 360?
> 180 %% new_res
>
> # create a new standard grid
> wgs84 <- "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
> grid_r <- raster(res = new_res, crs = wgs84)
> grid_st <- st_as_stars(grid_r)
>
> # change from rectilinear to regular grid
> # stars package: use st_warp to change from rectilinear to regular raster
> with different methods
> bc_reg <- bc %>% st_warp(grid_st, method = "average")
> bc_reg <- bc %>% st_warp(grid_st, method = "near")
> bc_reg <- bc %>% st_warp(grid_st, method = "bilinear")
> # In all cases I have this error: Error in 1:prod(dims[dxy]) : NA/NaN
> argument
>
> # raster package: rasterize the points values to the new regular grid
> bc1_sp <- bc1
> coordinates(bc1_sp) <- ~ lon + lat
> bc1_reg <- rasterize(bc1_sp, grid_r, field = "pr", fun = mean)
>
> # plot the first time period
> dev.new(title = "rectilinear")
> plot(bc[, , , 1])
> dev.new(title = "regular with raster package")
> plot(bc1_mn_reg)
>
> 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
>
> [[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

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Tue, 03/24/2020 - 03:42
I see at the end of the output obtained with running gdalinfo on the file:

Band 1 Block=1200x3 Type=UInt16, ColorInterp=Gray
  NoData Value=0
  Unit Type: K
  Offset: 0,   Scale:0.02
  Metadata:
    DESCRIPTION=8-day daytime 1km grid Land-surface Temperature

This means that Kelving values are obtained by computing

0 (offset) + 0.02 (scale) * pixel_value

packages stars and readGDAL do this transformation for you, so you get
actual Kelvin values, and represent them with doubles so there is no
rounding problem. Other, lower level tools may give you INT2 values
where you need to take care of the offset & scale yourself.

On 3/24/20 10:28 AM, Roger Bivand wrote:
> Opening in stars shows that the read data are interpreted as degrees
> Kelvin:
>
>> library(stars)
>> ss <- read_stars("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>> print(ss, n=1e8)
> stars object with 2 dimensions and 1 attribute
> attribute(s):
>  MOD11A2.A2000049.h17v05.006.2015058135048.tif [K]
>  Min.   :272.1
>  1st Qu.:293.3
>  Median :296.5
>  Mean   :296.1
>  3rd Qu.:298.8
>  Max.   :309.2
>  NA's   :926190
> dimension(s):
>   from   to   offset    delta  refsys point values
> x    1 1200 -1111951  926.625 unnamed FALSE   NULL [x]
> y    1 1200  4447802 -926.625 unnamed FALSE   NULL [y]
>
> The summary agrees with
>
>> library(rgdal)
>> o <- readGDAL("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>> summary(o)
> Object of class SpatialGridDataFrame
> Coordinates:
>        min     max
> x -1111951       0
> y  3335852 4447802
> Is projected: TRUE
> proj4string :
> [+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs]
> Grid attributes:
>   cellcentre.offset cellsize cells.dim
> x          -1111487 926.6254      1200
> y           3336315 926.6254      1200
> Data attributes:
>      band1
>  Min.   :272.1
>  1st Qu.:293.3
>  Median :296.5
>  Mean   :296.1
>  3rd Qu.:298.8
>  Max.   :309.2
>  NA's   :926190
>
> and
>
>> library(raster)
>> r <- raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>> summary(values(r))
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
>   272.1   293.3   296.5   296.1   298.8   309.2  926190
>
> So my feeling is that the representation is correct in degrees Kelvin.
>
> Others please join in, I'm not familiar with MODIS HDF data. I think
> something gives the metadata in the GeoTIFF the wrong data bounds - they
> do seem to be UInt16. The output of gdalinfo (command line) includes:
>
> ...
>   units=K
>   valid_range=7500, 65535
> ...
> Band 1 Block=1200x3 Type=UInt16, ColorInterp=Gray
>   NoData Value=0
>   Unit Type: K
> ...
>
> Roger
>
>
> On Tue, 24 Mar 2020, Victor F. Rodriguez Galiano wrote:
>
>> Hi Roger, the link to he image is given below. This image was generated
>> from a .hdf file using the function gdal_translate.
>>
>> gdal_translate(sds[1], dst_dataset=paste0(substr(filename, 1,
>> nchar(filename)-4) ,".tif", ))
>>
>> https://wetransfer.com/downloads/4569e9a85c02faad5016b83d0b50217820200324084015/f2eafdfafaae74de9ac8e25017fc5cc520200324084015/e46e80
>>
>>
>>
>> Thanks
>>
>> Victor
>>
>> El lun., 23 mar. 2020 a las 21:07, Roger Bivand (<[hidden email]>)
>> escribió:
>>
>>> Please make the file in question available for download (url), or the
>>> url
>>> you downloaded it from (no login), on this list. It looks as though the
>>> unsigned 16 bit integer is not right.
>>>
>>> Roger Bivand
>>> Norwegian School of Economics
>>> Bergen, Norway
>>>
>>> ------------------------------
>>> *Fra:* R-sig-Geo <[hidden email]> på vegne av Victor F.
>>> Rodriguez Galiano <[hidden email]>
>>> *Sendt:* mandag 23. mars 2020, 21.02
>>> *Til:* [hidden email]
>>> *Emne:* [R-sig-Geo] issue when opening raster image in R, the pixel
>>> values a rescaled somehow
>>>
>>> I opened a Geotiff image in R using the raster function. However, the
>>> image seems to be rescaled. The minimum and maximum values should be
>>> 13607
>>> and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is
>>> correct but not in R. This is my code: Script: library(raster)
>>> trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif",
>>> datatype =
>>> "INT2U") trial plot(trial) [[alternative HTML version deleted]]
>>> _______________________________________________ R-sig-Geo mailing list
>>> [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>
>
> _______________________________________________
> 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

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Tue, 03/24/2020 - 03:41
On Tue, 24 Mar 2020, Roger Bivand wrote:

> Opening in stars shows that the read data are interpreted as degrees Kelvin:
>
>>  library(stars)
>>  ss <- read_stars("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>>  print(ss, n=1e8)
> stars object with 2 dimensions and 1 attribute
> attribute(s):
>  MOD11A2.A2000049.h17v05.006.2015058135048.tif [K]
>  Min.   :272.1
>  1st Qu.:293.3
>  Median :296.5
>  Mean   :296.1
>  3rd Qu.:298.8
>  Max.   :309.2
>  NA's   :926190
> dimension(s):
>  from   to   offset    delta  refsys point values
> x    1 1200 -1111951  926.625 unnamed FALSE   NULL [x]
> y    1 1200  4447802 -926.625 unnamed FALSE   NULL [y]
>
> The summary agrees with
>
>>  library(rgdal)
>>  o <- readGDAL("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>>  summary(o)
> Object of class SpatialGridDataFrame
> Coordinates:
>       min     max
> x -1111951       0
> y  3335852 4447802
> Is projected: TRUE
> proj4string :
> [+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs]
> Grid attributes:
>  cellcentre.offset cellsize cells.dim
> x          -1111487 926.6254      1200
> y           3336315 926.6254      1200
> Data attributes:
>      band1
>  Min.   :272.1
>  1st Qu.:293.3
>  Median :296.5
>  Mean   :296.1
>  3rd Qu.:298.8
>  Max.   :309.2
>  NA's   :926190
>
> and
>
>>  library(raster)
>>  r <- raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
>>  summary(values(r))
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
>   272.1   293.3   296.5   296.1   298.8   309.2  926190
>
> So my feeling is that the representation is correct in degrees Kelvin.
>
> Others please join in, I'm not familiar with MODIS HDF data. I think
> something gives the metadata in the GeoTIFF the wrong data bounds - they do
> seem to be UInt16. The output of gdalinfo (command line) includes:
>
> ...
>   units=K
>   valid_range=7500, 65535
> ...
> Band 1 Block=1200x3 Type=UInt16, ColorInterp=Gray
>   NoData Value=0
>   Unit Type: K
> ... I missed the next line with the scale in it:

$gdalinfo -stats MOD11A2.A2000049.h17v05.006.2015058135048.tif
...
Band 1 Block=1200x3 Type=UInt16, ColorInterp=Gray
   Minimum=13607.000, Maximum=15461.000, Mean=14804.047, StdDev=191.673
   NoData Value=0
   Unit Type: K
   Offset: 0,   Scale:0.02
   Metadata:
     DESCRIPTION=8-day daytime 1km grid Land-surface Temperature
     STATISTICS_MAXIMUM=15461
     STATISTICS_MEAN=14804.046793562
     STATISTICS_MINIMUM=13607
     STATISTICS_STDDEV=191.67312038983
     STATISTICS_VALID_PERCENT=35.68

and 13607*0.02 = 272.14, 15461*0.02 = 309.22, so GDAL and the R interfaces
are using the scale factor to read the data as degrees Kelvin. Divide by
the scale factor if you need the input values.

Roger

>
> Roger
>
>
> On Tue, 24 Mar 2020, Victor F. Rodriguez Galiano wrote:
>
>>  Hi Roger, the link to he image is given below. This image was generated
>>  from a .hdf file using the function gdal_translate.
>>
>>  gdal_translate(sds[1], dst_dataset=paste0(substr(filename, 1,
>>  nchar(filename)-4) ,".tif", ))
>>
>>  https://wetransfer.com/downloads/4569e9a85c02faad5016b83d0b50217820200324084015/f2eafdfafaae74de9ac8e25017fc5cc520200324084015/e46e80
>>
>>
>>  Thanks
>>
>>  Victor
>>
>>  El lun., 23 mar. 2020 a las 21:07, Roger Bivand (<[hidden email]>)
>>  escribió:
>>
>>>  Please make the file in question available for download (url), or the
>>>  url
>>>  you downloaded it from (no login), on this list. It looks as though the
>>>  unsigned 16 bit integer is not right.
>>>
>>>  Roger Bivand
>>>  Norwegian School of Economics
>>>  Bergen, Norway
>>>
>>>  ------------------------------
>>>  *Fra:* R-sig-Geo <[hidden email]> på vegne av Victor F.
>>>  Rodriguez Galiano <[hidden email]>
>>>  *Sendt:* mandag 23. mars 2020, 21.02
>>>  *Til:* [hidden email]
>>>  *Emne:* [R-sig-Geo] issue when opening raster image in R, the pixel
>>>  values a rescaled somehow
>>>
>>>  I opened a Geotiff image in R using the raster function. However, the
>>>  image seems to be rescaled. The minimum and maximum values should be
>>>  13607
>>>  and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is
>>>  correct but not in R. This is my code: Script: library(raster)
>>>  trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif", datatype
>>>  =
>>>  "INT2U") trial plot(trial) [[alternative HTML version deleted]]
>>>  _______________________________________________ R-sig-Geo mailing list
>>>  [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Tue, 03/24/2020 - 03:28
Opening in stars shows that the read data are interpreted as degrees
Kelvin:

> library(stars)
> ss <- read_stars("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
> print(ss, n=1e8)
stars object with 2 dimensions and 1 attribute
attribute(s):
  MOD11A2.A2000049.h17v05.006.2015058135048.tif [K]
  Min.   :272.1
  1st Qu.:293.3
  Median :296.5
  Mean   :296.1
  3rd Qu.:298.8
  Max.   :309.2
  NA's   :926190
dimension(s):
   from   to   offset    delta  refsys point values
x    1 1200 -1111951  926.625 unnamed FALSE   NULL [x]
y    1 1200  4447802 -926.625 unnamed FALSE   NULL [y]

The summary agrees with

> library(rgdal)
> o <- readGDAL("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
> summary(o)
Object of class SpatialGridDataFrame
Coordinates:
        min     max
x -1111951       0
y  3335852 4447802
Is projected: TRUE
proj4string :
[+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs]
Grid attributes:
   cellcentre.offset cellsize cells.dim
x          -1111487 926.6254      1200
y           3336315 926.6254      1200
Data attributes:
      band1
  Min.   :272.1
  1st Qu.:293.3
  Median :296.5
  Mean   :296.1
  3rd Qu.:298.8
  Max.   :309.2
  NA's   :926190

and

> library(raster)
> r <- raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif")
> summary(values(r))
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
   272.1   293.3   296.5   296.1   298.8   309.2  926190

So my feeling is that the representation is correct in degrees Kelvin.

Others please join in, I'm not familiar with MODIS HDF data. I think
something gives the metadata in the GeoTIFF the wrong data bounds - they
do seem to be UInt16. The output of gdalinfo (command line) includes:

...
   units=K
   valid_range=7500, 65535
...
Band 1 Block=1200x3 Type=UInt16, ColorInterp=Gray
   NoData Value=0
   Unit Type: K
...

Roger


On Tue, 24 Mar 2020, Victor F. Rodriguez Galiano wrote:

> Hi Roger, the link to he image is given below. This image was generated
> from a .hdf file using the function gdal_translate.
>
> gdal_translate(sds[1], dst_dataset=paste0(substr(filename, 1,
> nchar(filename)-4) ,".tif", ))
>
> https://wetransfer.com/downloads/4569e9a85c02faad5016b83d0b50217820200324084015/f2eafdfafaae74de9ac8e25017fc5cc520200324084015/e46e80
>
>
> Thanks
>
> Victor
>
> El lun., 23 mar. 2020 a las 21:07, Roger Bivand (<[hidden email]>)
> escribió:
>
>> Please make the file in question available for download (url), or the url
>> you downloaded it from (no login), on this list. It looks as though the
>> unsigned 16 bit integer is not right.
>>
>> Roger Bivand
>> Norwegian School of Economics
>> Bergen, Norway
>>
>> ------------------------------
>> *Fra:* R-sig-Geo <[hidden email]> på vegne av Victor F.
>> Rodriguez Galiano <[hidden email]>
>> *Sendt:* mandag 23. mars 2020, 21.02
>> *Til:* [hidden email]
>> *Emne:* [R-sig-Geo] issue when opening raster image in R, the pixel
>> values a rescaled somehow
>>
>> I opened a Geotiff image in R using the raster function. However, the
>> image seems to be rescaled. The minimum and maximum values should be 13607
>> and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is
>> correct but not in R. This is my code: Script: library(raster)
>> trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif", datatype =
>> "INT2U") trial plot(trial) [[alternative HTML version deleted]]
>> _______________________________________________ R-sig-Geo mailing list
>> [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Tue, 03/24/2020 - 02:47
Please put the original file on the link too, so that we can track where
the misconfiguration occurs, and provide more of the workflow code. I
think we'll also need sessionInfo() output and GDAL version, both as seen
by gdalUtils, raster and rgdal.

Roger

On Tue, 24 Mar 2020, Victor F. Rodriguez Galiano wrote:

> Hi Roger, the link to he image is given below. This image was generated
> from a .hdf file using the function gdal_translate.
>
> gdal_translate(sds[1], dst_dataset=paste0(substr(filename, 1,
> nchar(filename)-4) ,".tif", ))
>
> https://wetransfer.com/downloads/4569e9a85c02faad5016b83d0b50217820200324084015/f2eafdfafaae74de9ac8e25017fc5cc520200324084015/e46e80
>
>
> Thanks
>
> Victor
>
> El lun., 23 mar. 2020 a las 21:07, Roger Bivand (<[hidden email]>)
> escribió:
>
>> Please make the file in question available for download (url), or the url
>> you downloaded it from (no login), on this list. It looks as though the
>> unsigned 16 bit integer is not right.
>>
>> Roger Bivand
>> Norwegian School of Economics
>> Bergen, Norway
>>
>> ------------------------------
>> *Fra:* R-sig-Geo <[hidden email]> på vegne av Victor F.
>> Rodriguez Galiano <[hidden email]>
>> *Sendt:* mandag 23. mars 2020, 21.02
>> *Til:* [hidden email]
>> *Emne:* [R-sig-Geo] issue when opening raster image in R, the pixel
>> values a rescaled somehow
>>
>> I opened a Geotiff image in R using the raster function. However, the
>> image seems to be rescaled. The minimum and maximum values should be 13607
>> and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is
>> correct but not in R. This is my code: Script: library(raster)
>> trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif", datatype =
>> "INT2U") trial plot(trial) [[alternative HTML version deleted]]
>> _______________________________________________ R-sig-Geo mailing list
>> [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Tue, 03/24/2020 - 02:43
Hi Roger, the link to he image is given below. This image was generated
from a .hdf file using the function gdal_translate.

gdal_translate(sds[1], dst_dataset=paste0(substr(filename, 1,
nchar(filename)-4) ,".tif", ))

https://wetransfer.com/downloads/4569e9a85c02faad5016b83d0b50217820200324084015/f2eafdfafaae74de9ac8e25017fc5cc520200324084015/e46e80


Thanks

Victor

El lun., 23 mar. 2020 a las 21:07, Roger Bivand (<[hidden email]>)
escribió:

> Please make the file in question available for download (url), or the url
> you downloaded it from (no login), on this list. It looks as though the
> unsigned 16 bit integer is not right.
>
> Roger Bivand
> Norwegian School of Economics
> Bergen, Norway
>
> ------------------------------
> *Fra:* R-sig-Geo <[hidden email]> på vegne av Victor F.
> Rodriguez Galiano <[hidden email]>
> *Sendt:* mandag 23. mars 2020, 21.02
> *Til:* [hidden email]
> *Emne:* [R-sig-Geo] issue when opening raster image in R, the pixel
> values a rescaled somehow
>
> I opened a Geotiff image in R using the raster function. However, the
> image seems to be rescaled. The minimum and maximum values should be 13607
> and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is
> correct but not in R. This is my code: Script: library(raster)
> trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif", datatype =
> "INT2U") trial plot(trial) [[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

Re: Request for help about running a loop and reading .NC files

Mon, 03/23/2020 - 18:30
Hi Ben, Rolf,

Thanks for your help.

Ben : the code works perfectly.

thanks once again,

bhaskar

On Mon, Mar 23, 2020 at 4:17 PM Ben Tupper <[hidden email]> wrote:

> Hi,
>
> Rolf is correct that you might consider enclosing your nc_open(...) with
> try(nc_open(...)), and then testing if the value returned by try() inherits
> from the "try-error" class. If there is no problem opening the NCDF file,
> then it will return an "ncdf4" class object.
>
> Also, you might isolate the file extraction stuff into a function to make
> your life easier. Something like this (obviously not tested)...
>
>
> ### START
> # extract data from a NCDF file
> # @param filename the path and name of the file
> # @return either NULL (for an exception) or a data.frame
> extract_from_nc <- function(filename){
>
>   nc <- try(nc_open(filename))
>   if (inherits(nc, "try-error")){
>     # if it isn't a healthy NCDF file you will be here
>     x <- NULL
>   } else {
>     # otherwise you will be here and you can run your extraction
>     mean1 <- ...
>      ...
>     x <- as.data.frame(mean_chl_df)
>     write.csv(x, ... other stuff here ...)
>     nc_close(nc)
>   }
>   return(x)
> }
>
> flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$",
> full.names = TRUE)
>
> xx <- lapply(flist, extract_from_nc)
> ix <- sapply(xx, is.null)                    # find the NULLS
> xx <- xx[!ix]                                # remove them (if any)
> if (length(xx) > 0) x <- do.call(rbind, xx)  # row bind what remains into
> one data frame (in case that is helpful)
> ### END
>
> I hope that helps.
>
> Cheers,
> Ben
>
>
>
>
>
> On Mon, Mar 23, 2020 at 5:53 PM Bhaskar Mitra <[hidden email]>
> wrote:
>
>> Hello Everyone,
>>
>> I have written a loop which reads hundreds of .nc files
>> and extract information from each .nc file and
>> exports that corresponding information as a csv file.
>>
>> The loop works fine until it encounters a .nc file which it cannot read
>> and the loop stops. I would appreciate if anyone can suggest how can I
>> modify
>> the loop, whereby the loop will continue to run by bypassing those
>> particular
>> files which it cannot read.
>>
>> In the end I was also hoping to modify the loop such that it
>> will generate a report which will inform me which
>> files were not read by the loop.  The codes are given below
>>
>> Thanks,
>> Bhaskar Mitra
>> NAU
>>
>> #_------------------------------------------------------------------
>>
>>
>> library(ncdf4)
>> library(reshape2)
>> library(dplyr)
>> library(stringr)
>>
>>
>> setwd("directory path")
>>
>> Output <- "directory path"
>>
>> flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$")
>>
>> for (i in 1: length(flist))
>> {
>>
>>   nc <- nc_open(paste0("NCFiles/",flist[i]))
>>   mean1 <- ncvar_get(nc,attributes(nc$dim)$names[3])
>>   nc_close(nc)
>>
>>   mean_chl_df <- melt(mean1)
>>   trial.table.df <-as.data.frame(mean_chl_df)
>>
>>
>> write.csv(trial.table.df,paste0(Output,"/",tools::file_path_sans_ext(flist[i]),".csv"))
>>
>> }
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
> --
> Ben Tupper
> Bigelow Laboratory for Ocean Science
> East Boothbay, Maine
> http://www.bigelow.org/
> https://eco.bigelow.org
>
>
        [[alternative HTML version deleted]]

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

Re: Request for help about running a loop and reading .NC files

Mon, 03/23/2020 - 17:17
Hi,

Rolf is correct that you might consider enclosing your nc_open(...) with
try(nc_open(...)), and then testing if the value returned by try() inherits
from the "try-error" class. If there is no problem opening the NCDF file,
then it will return an "ncdf4" class object.

Also, you might isolate the file extraction stuff into a function to make
your life easier. Something like this (obviously not tested)...


### START
# extract data from a NCDF file
# @param filename the path and name of the file
# @return either NULL (for an exception) or a data.frame
extract_from_nc <- function(filename){

  nc <- try(nc_open(filename))
  if (inherits(nc, "try-error")){
    # if it isn't a healthy NCDF file you will be here
    x <- NULL
  } else {
    # otherwise you will be here and you can run your extraction
    mean1 <- ...
     ...
    x <- as.data.frame(mean_chl_df)
    write.csv(x, ... other stuff here ...)
    nc_close(nc)
  }
  return(x)
}

flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$",
full.names = TRUE)

xx <- lapply(flist, extract_from_nc)
ix <- sapply(xx, is.null)                    # find the NULLS
xx <- xx[!ix]                                # remove them (if any)
if (length(xx) > 0) x <- do.call(rbind, xx)  # row bind what remains into
one data frame (in case that is helpful)
### END

I hope that helps.

Cheers,
Ben





On Mon, Mar 23, 2020 at 5:53 PM Bhaskar Mitra <[hidden email]>
wrote:

> Hello Everyone,
>
> I have written a loop which reads hundreds of .nc files
> and extract information from each .nc file and
> exports that corresponding information as a csv file.
>
> The loop works fine until it encounters a .nc file which it cannot read
> and the loop stops. I would appreciate if anyone can suggest how can I
> modify
> the loop, whereby the loop will continue to run by bypassing those
> particular
> files which it cannot read.
>
> In the end I was also hoping to modify the loop such that it
> will generate a report which will inform me which
> files were not read by the loop.  The codes are given below
>
> Thanks,
> Bhaskar Mitra
> NAU
>
> #_------------------------------------------------------------------
>
>
> library(ncdf4)
> library(reshape2)
> library(dplyr)
> library(stringr)
>
>
> setwd("directory path")
>
> Output <- "directory path"
>
> flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$")
>
> for (i in 1: length(flist))
> {
>
>   nc <- nc_open(paste0("NCFiles/",flist[i]))
>   mean1 <- ncvar_get(nc,attributes(nc$dim)$names[3])
>   nc_close(nc)
>
>   mean_chl_df <- melt(mean1)
>   trial.table.df <-as.data.frame(mean_chl_df)
>
>
> write.csv(trial.table.df,paste0(Output,"/",tools::file_path_sans_ext(flist[i]),".csv"))
>
> }
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Ben Tupper
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

        [[alternative HTML version deleted]]

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

Re: [FORGED] Request for help about running a loop and reading .NC files

Mon, 03/23/2020 - 16:36

On 24/03/20 10:52 am, Bhaskar Mitra wrote:

> Hello Everyone,
>
> I have written a loop which reads hundreds of .nc files
> and extract information from each .nc file and
> exports that corresponding information as a csv file.
>
> The loop works fine until it encounters a .nc file which it cannot read
> and the loop stops. I would appreciate if anyone can suggest how can I
> modify
> the loop, whereby the loop will continue to run by bypassing those
> particular
> files which it cannot read.
>
> In the end I was also hoping to modify the loop such that it
> will generate a report which will inform me which
> files were not read by the loop.  The codes are given below
Perhaps use try()???

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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

Request for help about running a loop and reading .NC files

Mon, 03/23/2020 - 15:52
Hello Everyone,

I have written a loop which reads hundreds of .nc files
and extract information from each .nc file and
exports that corresponding information as a csv file.

The loop works fine until it encounters a .nc file which it cannot read
and the loop stops. I would appreciate if anyone can suggest how can I
modify
the loop, whereby the loop will continue to run by bypassing those
particular
files which it cannot read.

In the end I was also hoping to modify the loop such that it
will generate a report which will inform me which
files were not read by the loop.  The codes are given below

Thanks,
Bhaskar Mitra
NAU

#_------------------------------------------------------------------


library(ncdf4)
library(reshape2)
library(dplyr)
library(stringr)


setwd("directory path")

Output <- "directory path"

flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$")

for (i in 1: length(flist))
{

  nc <- nc_open(paste0("NCFiles/",flist[i]))
  mean1 <- ncvar_get(nc,attributes(nc$dim)$names[3])
  nc_close(nc)

  mean_chl_df <- melt(mean1)
  trial.table.df <-as.data.frame(mean_chl_df)

write.csv(trial.table.df,paste0(Output,"/",tools::file_path_sans_ext(flist[i]),".csv"))

}

        [[alternative HTML version deleted]]

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

Re: issue when opening raster image in R, the pixel values a rescaled somehow

Mon, 03/23/2020 - 14:06
Please make the file in question available for download (url), or the url you downloaded it from (no login), on this list. It looks as though the unsigned 16 bit integer is not right.

Roger Bivand
Norwegian School of Economics
Bergen, Norway

________________________________
Fra: R-sig-Geo <[hidden email]> p� vegne av Victor F. Rodriguez Galiano <[hidden email]>
Sendt: mandag 23. mars 2020, 21.02
Til: [hidden email]
Emne: [R-sig-Geo] issue when opening raster image in R, the pixel values a rescaled somehow

I opened a Geotiff image in R using the raster function. However, the image seems to be rescaled. The minimum and maximum values should be 13607 and 15461 but are 275 and 305. The Geotiff image when opened in a GIS is correct but not in R. This is my code: Script: library(raster) trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif", datatype = "INT2U") trial plot(trial) [[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
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

issue when opening raster image in R, the pixel values a rescaled somehow

Mon, 03/23/2020 - 14:01
I opened a Geotiff image in R using the raster function. However, the image
seems to be rescaled. The minimum and maximum values should be 13607 and
15461 but are 275 and 305. The Geotiff image when opened in a GIS is
correct but not in R.

This is my code:

Script:

library(raster)

trial<-raster("MOD11A2.A2000049.h17v05.006.2015058135048.tif",
datatype = "INT2U")

trial

plot(trial)

        [[alternative HTML version deleted]]

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

Re: Modifications of the methods in resample() function using raster package

Mon, 03/23/2020 - 13:26
Thanks Frederico,

But at this moment, I'll try to reduce steps (extract() - focal() -
resample()) and using only resample() function to change the number of
nearest cells, if is possible.

First, in "bilinear" method, I'll like to change the function for work
with the different number of nearest cells and second I'll expected to
create a mean method to calculate the arithmetic average of the n
nearest cells too.

For example, in the first case for 25 nearest cells, I'll like to do
something like resample (myraster, myresolution, window=matrix
(nrow=5,nol=5), method="bilinear") and in the second case resample
(myraster, myresolution, window=matrix (nrow=5,nol=5), fun=mean). But,
obviously this commands doesn't work but expressed my general goal.

Best wishes,

Alexandre

--
Alexandre dos Santos
Geotechnologies and Spatial Statistics applied to Forest Entomology
Instituto Federal de Mato Grosso (IFMT) - Campus Caceres
Caixa Postal 244 (PO Box)
Avenida dos Ramires, s/n - Vila Real
Caceres - MT - CEP 78201-380 (ZIP code)
Phone: (+55) 65 99686-6970 / (+55) 65 3221-2674
Lattes CV: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722
ResearchGate: www.researchgate.net/profile/Alexandre_Santos10
Publons: https://publons.com/researcher/3085587/alexandre-dos-santos/
--

Em 23/03/2020 14:23, Frederico Faleiro escreveu:
> Hi Alexandre,
>
> you can use extract from raster (check the examples in the help page).
> Depending of your data you can create a spatial polygon that cover the
> number of cells you want and define the summary function or use the
> buffer argument.
>
> 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
>
>
> Em seg., 23 de mar. de 2020 às 10:41, ASANTOS via R-sig-Geo
> <[hidden email] <mailto:[hidden email]>> escreveu:
>
>     Dear r-sig-geo members,
>
>      ??? I?ve like to know the possibility of make some modifications in
>     resample() function in raster package. First, in "bilinear" method by
>     default is assigns a weighted average of the four nearest cells, and
>     I?ll like to change for five and six nearest cells, too, is possible?
>     Second, is it possible too to create the mean method to calculate the
>     arithmetic average of the four, five, and six nearest cells?
>
>     Thanks in advanced,
>     Alexandre
>
>     --
>     Alexandre dos Santos
>     Geotechnologies and Spatial Statistics applied to Forest Entomology
>     Instituto Federal de Mato Grosso (IFMT) - Campus Caceres
>     Caixa Postal 244 (PO Box)
>     Avenida dos Ramires, s/n - Vila Real
>     Caceres - MT - CEP 78201-380 (ZIP code)
>     Phone: (+55) 65 99686-6970 / (+55) 65 3221-2674
>     Lattes CV: http://lattes.cnpq.br/1360403201088680
>     OrcID: orcid.org/0000-0001-8232-6722
>     <http://orcid.org/0000-0001-8232-6722>
>     ResearchGate: www.researchgate.net/profile/Alexandre_Santos10
>     <http://www.researchgate.net/profile/Alexandre_Santos10>
>     Publons: https://publons.com/researcher/3085587/alexandre-dos-santos/
>     --
>
>     _______________________________________________
>     R-sig-Geo mailing list
>     [hidden email] <mailto:[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

Re: ENFA specialization values

Mon, 03/23/2020 - 12:37

Hi Ruth,

 

I had some experience with ENFA 5 years ago. Based on what I wrote back then, I didn’t interpret the specialization values as is, but instead they were aggregated into the overall (global) specialization index and then converted into the tolerance value by simply inverted it (x becomes 1/x). However, the absolute values are the ones that matter in interpreting the specialization coefficient of each EGV: “the higher the absolute value, the more restricted is the range of the focal species on the corresponding variable” Hirzel’s original paper (2002) page 2031 right below the equation (10).

 

Hope this helps a bit.

 

Adrian

 

From: [hidden email]
Sent: Monday, March 23, 2020 8:36 AM
To: [hidden email]
Subject: [R-sig-Geo] ENFA specialization values

 

Hello,

 

I am running an ENFA analysis and am having trouble interpreting the specialization values. Do the specialization values correspond to each ecogeographical variable? If so they don't make sense in terms of what I am seeing for the marginality values, i.e. marginality value for water is high and displays a long arrow on the biplot. Therefore, I would think that the specialization value for water would be high, but if the vector of specialization values corresponds to each ecogeographical variable then this is not the case. Am I missing a line of code? An explanation of how to interpret the specialization values from the code and output below would be much appreciated.

 

 

slot(maps,"data")[,1:9] <- sqrt(slot(maps,"data")[,1:9])

hist(maps, type = "l")

 

## Prepare the data for the ENFA

tab <- slot(maps, "data")

pr <- slot(count.points(pipl, maps), "data")[,1]

 

 

## Perform the PCA before the ENFA

pc <- dudi.pca(tab, scannf = FALSE)

pc

 

(enfa1 <- enfa(pc, pr,scannf = FALSE))

 

enfa1$s #gives specialization values

enfa1$mar#gives marginality values

 

##OUTPUT##

 

> (enfa1 <- enfa(pc, pr,scannf = FALSE))

ENFA

$call: enfa(dudi = pc, pr = pr, scannf = FALSE)

 

marginality: 1.731

eigen values of specialization: 6.61 2.583 1.924 1.49 1.153 ...

$nf: 1 axis of specialization saved

 

  vector length mode    content

1 $pr    385923 numeric vector of presence

2 $lw    385923 numeric row weights

3 $cw    10     numeric column weights

4 $mar   10     numeric coordinates of the marginality vector

5 $s     9      numeric eigen values of specialization

 

  data.frame nrow   ncol content

1 $tab       385923 10   modified array

2 $li        385923 2    row coordinates

3 $co        10     2    column coordinates

 

> enfa1$s  #gives specialization values

[1] 6.6101077 2.5830759 1.9242150 1.4895781 1.1533000 1.0651184 0.8456433 0.7114272 0.4710257

 

> enfa1$mar #gives marginality values

           Annual         Perennial         Grassland         Deciduous        Coniferous

       0.38442513        0.33468805        0.62931566       -0.31320996       -0.55314134

            Mixed             Water           Wetland             Shrub Distance_to_Roads

      -0.53532160        0.55172030       -0.25751795        0.02533396       -0.11602451

 

Thank you

~Ruth

 

 

 

 

 

 

 

 

                [[alternative HTML version deleted]]

 

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

 


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

Re: Modifications of the methods in resample() function using raster package

Mon, 03/23/2020 - 12:23
Hi Alexandre,

you can use extract from raster (check the examples in the help page).
Depending of your data you can create a spatial polygon that cover the
number of cells you want and define the summary function or use the buffer
argument.

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



Em seg., 23 de mar. de 2020 às 10:41, ASANTOS via R-sig-Geo <
[hidden email]> escreveu:

> Dear r-sig-geo members,
>
>  ??? I?ve like to know the possibility of make some modifications in
> resample() function in raster package. First, in "bilinear" method by
> default is assigns a weighted average of the four nearest cells, and
> I?ll like to change for five and six nearest cells, too, is possible?
> Second, is it possible too to create the mean method to calculate the
> arithmetic average of the four, five, and six nearest cells?
>
> Thanks in advanced,
> Alexandre
>
> --
> Alexandre dos Santos
> Geotechnologies and Spatial Statistics applied to Forest Entomology
> Instituto Federal de Mato Grosso (IFMT) - Campus Caceres
> Caixa Postal 244 (PO Box)
> Avenida dos Ramires, s/n - Vila Real
> Caceres - MT - CEP 78201-380 (ZIP code)
> Phone: (+55) 65 99686-6970 / (+55) 65 3221-2674
> Lattes CV: http://lattes.cnpq.br/1360403201088680
> OrcID: orcid.org/0000-0001-8232-6722
> ResearchGate: www.researchgate.net/profile/Alexandre_Santos10
> Publons: https://publons.com/researcher/3085587/alexandre-dos-santos/
> --
>
> _______________________________________________
> 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

Convert rectilinear to regular grid in R (stars and raster)

Mon, 03/23/2020 - 11:45
Dear all,

I am trying convert netCDF data from rectilinear to regular grid in R, but
I am not sure what is the best approach for it.
I would like to convert the grid modifying the original resolution only
when necessary. In some cases I must change resolution to keep regular cell
size and cover all the world extent.
I have tried without success st_warp from stars and I find a way with
rasterize from raster package (see script bellow).

I have the following questions:
1. What am I doing wrong in stars package (see script bellow)?
2. Is there a way to rasterize points to raster using metrics that consider
distance (e.g. bilinear, nearest neighbor, etc)? Note that I need
use points in raster package because it do not handle with rectilinear grid.
3. Do you recommend any other approach?

The data are available in:
GDrive:
https://drive.google.com/file/d/1HKxFpAwvY9k_cFbasagKHAwi1luzLv90/view?usp=sharing
CMIP5 portal (you must make a login):
http://aims3.llnl.gov/thredds/fileServer/cmip5_css01_data/cmip5/output1/BCC/bcc-csm1-1/rcp45/mon/atmos/Amon/r1i1p1/v20120705/pr/pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc

# script
library(stars)
library(raster)

# prepare data
bc <- read_ncdf("pr_Amon_bcc-csm1-1_rcp45_r1i1p1_200601-209912.nc")
# get coordinates and data from the first time period
bc1 <- as.data.frame(bc[, , , 1])
# convert longitude to variate between -180 and 180
bc1$lon <- ifelse(bc1$lon > 180, bc1$lon - 360, bc1$lon)

# original resolution
bc1$lon %>% diff %>% table
bc1$lat %>% diff %>% table
# new resolution
new_res <- c(2.8125, 2.8125)
# Is it multiple of 180 or 360?
180 %% new_res

# create a new standard grid
wgs84 <- "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
grid_r <- raster(res = new_res, crs = wgs84)
grid_st <- st_as_stars(grid_r)

# change from rectilinear to regular grid
# stars package: use st_warp to change from rectilinear to regular raster
with different methods
bc_reg <- bc %>% st_warp(grid_st, method = "average")
bc_reg <- bc %>% st_warp(grid_st, method = "near")
bc_reg <- bc %>% st_warp(grid_st, method = "bilinear")
# In all cases I have this error: Error in 1:prod(dims[dxy]) : NA/NaN
argument

# raster package: rasterize the points values to the new regular grid
bc1_sp <- bc1
coordinates(bc1_sp) <- ~ lon + lat
bc1_reg <- rasterize(bc1_sp, grid_r, field = "pr", fun = mean)

# plot the first time period
dev.new(title = "rectilinear")
plot(bc[, , , 1])
dev.new(title = "regular with raster package")
plot(bc1_mn_reg)

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

        [[alternative HTML version deleted]]

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

Pages