Skip to content

Commit

Permalink
- removed remain dependencies of sp package
Browse files Browse the repository at this point in the history
- removed suggest packages: osmar,RCurl,rgdal
  • Loading branch information
schuch666 committed Mar 24, 2023
1 parent eeaf14a commit 5730129
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 68 deletions.
11 changes: 4 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: EmissV
Title: Tools for Create Emissions for Air Quality Models
Date: 2022-05-31
Version: 0.665.6.3
Date: 2023-03-24
Version: 0.665.6.6
Authors@R: c(
person(given = "Daniel",
family = "Schuch",
Expand All @@ -25,14 +25,11 @@ Description: Processing tools to create emissions for use in numerical air
such as satellite images (Martins et al, 2012) <doi:10.3389/fenvs.2015.00009>
or openstreetmap data (Andrade et al, 2015) <doi:10.3389/fenvs.2015.00009>.
Depends: R (>= 3.4)
Imports: ncdf4, units(>= 0.5-1), raster, sp, sf, methods, data.table
Imports: ncdf4, units(>= 0.5-1), raster, sf, methods, data.table
Suggests:
testthat (>= 2.1.0),
covr,
osmar,
RCurl,
lwgeom,
rgdal
lwgeom
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export(vehicles)
import(ncdf4)
import(raster)
import(sf)
import(sp)
import(units)
importFrom(data.table,.SD)
importFrom(data.table,data.table)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version: 0.665.6.6 (2023-03-24)
- removed remain dependencies of sp package
- removed suggest packages: osmar,RCurl,rgdal
- updated on examples, documentation and site

## Version: 0.665.6.2 (2022-02-19)
- update in gridInfo cen_lon

Expand Down
13 changes: 5 additions & 8 deletions R/areaSouce.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @export
#'
#' @import raster sp sf
#' @import raster sf
#'
#' @examples
#' shape <- raster::shapefile(paste(system.file("extdata", package = "EmissV"),
Expand All @@ -24,12 +24,8 @@
#' grid <- gridInfo(paste(system.file("extdata", package = "EmissV"),"/wrfinput_d02",sep=""))
#' SP <- areaSource(shape,raster,grid,name = "SPMA")
#' \donttest{
#' sp::spplot(SP,scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
#' main=list(label="Spatial Distribution by Lights for Sao Paulo - Brazil"),
#' col.regions = c("#031638","#001E48","#002756","#003062",
#' "#003A6E","#004579","#005084","#005C8E",
#' "#006897","#0074A1","#0081AA","#008FB3",
#' "#009EBD","#00AFC8","#00C2D6","#00E3F0"))
#' raster::plot(SP,ylab="Lat",xlab="Lon",
#' main ="Spatial Distribution by Lights for Sao Paulo - Brazil")
#'}
#'
#'@source Data avaliable \url{https://www.ospo.noaa.gov/Operations/DMSP/index.html}
Expand All @@ -41,7 +37,8 @@ areaSource <- function(s,r,grid = NA,name = "",as_frac=FALSE,verbose = TRUE){
cat(paste("processing ",name,"area ... \n",sep = ""))
}

sp <- suppressWarnings( raster::mask(r,sp::spTransform(s,sp::CRS(sp::proj4string(r)))) )
# sp <- suppressWarnings( raster::mask(r,sp::spTransform(s,sp::CRS(sp::proj4string(r)))) )
sp <- suppressWarnings( raster::mask(r,sf::st_transform(sf::st_as_sf(s),crs = raster::crs(r,asText=TRUE))))

if(!is.na(grid[1])){
if(grid$map_proj == 1){
Expand Down
45 changes: 29 additions & 16 deletions R/emission.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#'
#' @export
#'
#' @import units raster sp
#' @import units raster
#'
#' @examples
#' fleet <- vehicles(example = TRUE)
Expand Down Expand Up @@ -107,14 +107,20 @@ emission <- function(inventory = NULL,grid,mm = 1, aerosol = FALSE,check = TRUE,
legenda <- paste("Emissions of", pol ,"[",units::deparse_unit(VAR_e),"]")
}

a <- sp::spplot(r,scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
main=list(label=legenda),
col.regions = c("#031638","#001E48","#002756","#003062",
"#003A6E","#004579","#005084","#005C8E",
"#006897","#0074A1","#0081AA","#008FB3",
"#009EBD","#00AFC8","#00C2D6","#00E3F0"))
# a <- sp::spplot(r,scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
# main=list(label=legenda),
# col.regions = c("#031638","#001E48","#002756","#003062",
# "#003A6E","#004579","#005084","#005C8E",
# "#006897","#0074A1","#0081AA","#008FB3",
# "#009EBD","#00AFC8","#00C2D6","#00E3F0"))
#
# print(a)

print(a)
plot(r,main = legenda,
col = c("#031638","#001E48","#002756","#003062",
"#003A6E","#004579","#005084","#005C8E",
"#006897","#0074A1","#0081AA","#008FB3",
"#009EBD","#00AFC8","#00C2D6","#00E3F0"))
}
if(check){
VAR_e <- check_positive(VAR_e,pol)
Expand Down Expand Up @@ -153,7 +159,8 @@ emission <- function(inventory = NULL,grid,mm = 1, aerosol = FALSE,check = TRUE,
area <- unname(area)

if(length(area) > 1){
VAR_e <- do.call(sp::merge,area)
# VAR_e <- do.call(sp::merge,area)
VAR_e <- Reduce(raster::merge, area)
}else{
VAR_e <- area[[1]]
}
Expand Down Expand Up @@ -204,14 +211,20 @@ emission <- function(inventory = NULL,grid,mm = 1, aerosol = FALSE,check = TRUE,
raster::values(r) <- as.matrix(as.numeric(VAR_e),ncol = col,nrow = row,byrow = TRUE)
r <- raster::flip(r,2)

a <- sp::spplot(r,scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
main=list(label=paste("Emisions of", pol ,"[",deparse_unit(VAR_e),"]")),
col.regions = c("#031638","#001E48","#002756","#003062",
"#003A6E","#004579","#005084","#005C8E",
"#006897","#0074A1","#0081AA","#008FB3",
"#009EBD","#00AFC8","#00C2D6","#00E3F0"))
# a <- sp::spplot(r,scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
# main=list(label=paste("Emisions of", pol ,"[",deparse_unit(VAR_e),"]")),
# col.regions = c("#031638","#001E48","#002756","#003062",
# "#003A6E","#004579","#005084","#005C8E",
# "#006897","#0074A1","#0081AA","#008FB3",
# "#009EBD","#00AFC8","#00C2D6","#00E3F0"))
# print(a)

plot(r,#main = legenda,
col = c("#031638","#001E48","#002756","#003062",
"#003A6E","#004579","#005084","#005C8E",
"#006897","#0074A1","#0081AA","#008FB3",
"#009EBD","#00AFC8","#00C2D6","#00E3F0"))

print(a)
}
if(check){
VAR_e <- check_positive(VAR_e,pol)
Expand Down
20 changes: 11 additions & 9 deletions R/gridinfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @note just WRF-Chem is suported by now
#'
#' @import ncdf4 sp
#' @import ncdf4
#'
#' @export
#'
Expand All @@ -23,16 +23,15 @@
#' "/wrfinput_d03",sep=""))
#' names(grid_d1)
#' # for plot the shapes
#' library(sp)
#' shape <- raster::shapefile(paste0(system.file("extdata", package = "EmissV"),
#' "/BR.shp"))
#' plot(shape,xlim = c(-55,-40),ylim = c(-30,-15), main="3 nested domains")
#' raster::plot(shape,xlim = c(-55,-40),ylim = c(-30,-15), main="3 nested domains")
#' axis(1); axis(2); box(); grid()
#' lines(grid_d1$Box, col = "red")
#' lines(grid_d1$boundary, col = "red")
#' text(grid_d1$xlim[2],grid_d1$Ylim[1],"d1",pos=4, offset = 0.5)
#' lines(grid_d2$Box, col = "red")
#' lines(grid_d2$boundary, col = "red")
#' text(grid_d2$xlim[2],grid_d2$Ylim[1],"d2",pos=4, offset = 0.5)
#' lines(grid_d3$Box, col = "red")
#' lines(grid_d3$boundary, col = "red")
#' text(grid_d3$xlim[1],grid_d3$Ylim[2],"d3",pos=2, offset = 0.0)
#'}

Expand Down Expand Up @@ -155,9 +154,12 @@ gridInfo <- function(file = file.choose(),z = FALSE,verbose = TRUE){
y = c(ly[2],ly[2],ly[1],ly[1],ly[2])),
boundary = list(x = c(lon[1,],lon[,nxj],rev(lon[nxi,]),rev(lon[,1])),
y = c(lat[1,],lat[,nxj],rev(lat[nxi,]),rev(lat[,1]))),
poligon = sp::Polygon(matrix(c( c(lon[1,],lon[,nxj],rev(lon[nxi,]),rev(lon[,1])),
c(lat[1,],lat[,nxj],rev(lat[nxi,]),rev(lat[,1]))),
ncol = 2)),
# polygon = sp::Polygon(matrix(c( c(lon[1,],lon[,nxj],rev(lon[nxi,]),rev(lon[,1])),
# c(lat[1,],lat[,nxj],rev(lat[nxi,]),rev(lat[,1]))),
# ncol = 2)),
polygon = sf::st_polygon(x = list(matrix(c( c(lon[1,],lon[,nxj],rev(lon[nxi,]),rev(lon[,1])),
c(lat[1,],lat[,nxj],rev(lat[nxi,]),rev(lat[,1]))),
ncol = 2))),
map_proj = map_proj,
coords = coords,
geogrd.proj = geogrd.proj)
Expand Down
24 changes: 8 additions & 16 deletions R/lineSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,17 @@
#'
#' @seealso \code{\link{gridInfo}} and \code{\link{rasterSource}}
#'
#'
#' @examples \donttest{
#' roads <- osmar::get_osm(osmar::complete_file(),
#' source = osmar::osmsource_file(paste(system.file("extdata",
#' package="EmissV"),"/streets.osm.xz",sep="")))
#' road_lines <- osmar::as_sp(roads,what = "lines")
#'
#' # selecting only 2 roads
#' road_lines <- road_lines[1:2,]
#'
#' roads <- sf::st_as_sf(road_lines)
#'
#' # loading a shapefile with osm data for sao paulo metropolitan area
#' roads <- sf::st_read(paste0(system.file("extdata",package="EmissV"),"/streets.shp"))
#' d3 <- gridInfo(paste0(system.file("extdata", package = "EmissV"),"/wrfinput_d03"))
#'
#' roadLength <- lineSource(roads,d3,as_raster=TRUE)
#' sp::spplot(roadLength,
#' scales = list(draw=TRUE),
#' ylab="Lat", xlab="Lon",main="Length of roads",
#' sp.layout=list("sp.lines", road_lines))
#' # calculating only for 2 streets
#' roadLength <- lineSource(roads[1:2,],d3,as_raster=TRUE)
#'
#' # to generate a quick plot
#' raster::plot(roadLength,ylab="Lat", xlab="Lon",main="Length of roads")
#' # lines(road_lines)
#' }
#'
#'
Expand Down
14 changes: 8 additions & 6 deletions R/pointSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @return a raster
#'
#' @import sp raster
#' @import raster
#'
#' @export
#'
Expand All @@ -22,8 +22,8 @@
#'
#' p_emissions <- pointSource(emissions = p, grid = d1)
#' \donttest{
#' sp::spplot(p_emissions,scales = list(draw=TRUE), ylab="Lat", xlab="Lon",
#' main = "3 point sources for domain d1")
#' raster::plot(p_emissions,ylab="Lat", xlab="Lon",
#' main = "3 point sources for domain d1")
#'}
#'
#' @seealso \code{\link{gridInfo}} and \code{\link{rasterSource}}
Expand All @@ -40,8 +40,9 @@ pointSource <- function(emissions, grid, verbose = TRUE){
values(emis) <- rep(0,ncell(emis))

for(i in 1:length(emissions[[1]])){
id.cell <- extract(emis,SpatialPoints(cbind(emissions$lon[i],emissions$lat[i])),
cellnumbers=TRUE)[1]
id.cell <- raster::extract(emis,
cbind(emissions$lon[i],emissions$lat[i]),
cellnumbers=TRUE)[1]
if(verbose){
xy <- xyFromCell(emis,id.cell)
lon <- xy[1]
Expand All @@ -66,7 +67,8 @@ pointSource <- function(emissions, grid, verbose = TRUE){
values(emis) <- rep(0,ncell(emis))

for(i in 1:length(emissions[[1]])){
id.cell <- extract(emis,SpatialPoints(cbind(emissions$lon[i],emissions$lat[i])),
id.cell <- extract(emis,
cbind(emissions$lon[i],emissions$lat[i]),
cellnumbers=TRUE)[1]
altura <- z[rowFromCell(emis, id.cell),rowFromCell(emis, id.cell),]
if(verbose){
Expand Down
2 changes: 1 addition & 1 deletion R/rasterSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'
#' @export
#'
#' @import raster sp sf
#' @import raster sf
#'
#' @examples
#' grid <- gridInfo(paste(system.file("extdata", package = "EmissV"),"/wrfinput_d01",sep=""))
Expand Down
11 changes: 7 additions & 4 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@
#' spec = c(E_NO = 0.9 , # 90% of NOx is NO
#' E_NO2 = 0.1 )) # 10% of NOx is NO2
#' setwd(folder)
#'
#' sp::spplot(nox$E_NO, scales = list(draw=TRUE),
#' xlab="Lat", ylab="Lon",
#' main="NO emissions from EDGAR (in g / m2 s)")
#' # creating a color scale
#' cor <- colorRampPalette(colors = c(c("#031057", "#0522FC",
#' "#7E0AFA", "#EF0AFF",
#' "#FFA530", "#FFF957")))
#' raster::plot(nox$E_NO,xlab="Lat", ylab="Lon",
#' col = cor(12),zlim = c(-6.5e-7,1.4e-5),
#' main="NO emissions from EDGAR (in g / m2 s)")
#'
#' d1 <- gridInfo(paste(system.file("extdata", package = "EmissV"),"/wrfinput_d01",sep=""))
#' NO <- emission(grid = d1, inventory = nox$E_NO, pol = "NO", mm = 30.01, plot = TRUE)
Expand Down

0 comments on commit 5730129

Please sign in to comment.