Git Product home page Git Product logo

emissv's Introduction

EmissV

windown Build Coverage Status R build status Licence:MIT CRAN_Status_Badge cran checks metacran downloads metacran downloads DOI status

hex_logo

This package provides tools to create emissions (with a focus on vehicular emissions) for use in numeric air quality models such as WRF-Chem.

Installation

System dependencies

EmissV import functions from ncdf4 for reading model information, raster and sf to process grinded/geographic information and units. These packages need some aditional libraries:

To Ubuntu

The following steps are required for installation on Ubuntu:

  sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes
  sudo apt-get --yes --force-yes update -qq
  # netcdf dependencies:
  sudo apt-get install --yes libnetcdf-dev netcdf-bin
  # units/udunits2 dependency:
  sudo apt-get install --yes libudunits2-dev
  # sf dependencies (without libudunits2-dev):
  sudo apt-get install --yes libgdal-dev libgeos-dev libproj-dev

To Fedora

The following steps are required for installation on Fedora:

  sudo dnf update
  # netcdf dependencies:
  sudo yum install netcdf-devel
  # units/udunits2 dependency:
  sudo yum install udunits2-devel
  # sf dependencies (without libudunits2-dev):
  sudo yum install gdal-devel proj-devel proj-epsg proj-nad geos-devel

To Windows

No additional steps for windows installation.

Detailed instructions can be found at netcdf, libudunits2-dev and sf developers page.

To conda (miniconda / anaconda)

First create a new environment called rspatial (or a better name):

  conda create -n rspatial -y
  conda activate rspatial

and to install some requisites:

  conda install -c conda-forge r-sf -y
  conda install -c conda-forge r-rgdal -y
  conda install -c conda-forge r-lwgeom -y
  conda install -c conda-forge r-raster -y

Package installation

To install the CRAN version (0.665.5.2):

install.packages("EmissV")

To install the development version (0.665.5.3) using remotes:

require("remotes")
remotes::install_github("atmoschem/EmissV")

or to install the development version (0.665.5.3) using devtools:

require("devtools")
devtools::install_github("atmoschem/EmissV")

Using EmissV with EDGAR 5.0 emissions

EmissV can be used to process emissions of atmospheric pollutants and green house gases from inventories such as EDGAR, RCP, GAINS and other datasets in NetCDF format, the GEIA-ACCENT and ECCAD emission data portal makes available some of these inventories. You can verify the supported format with:

EmissV::read()

To generate a simple emission it's a straightforward process in 4 steps:

library(EmissV)
### 1. download the EDGAR Netcdf using the function get_edgar from the eixport R-package 
### or from the http://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/EDGAR/datasets/v50_AP/ 
### EDGAR 5.0 website and unzip inside a temporary directory
# create the temporary directory to download the data
dir.create(file.path(tempdir(), "EDGAR"))
# download the total emissions of NOx from EDGAR v50_AP for 2015
eixport::get_edgar(dataset = "v50_AP",
                   pol     = 'NOx',
                   sector  = "TOTALS",
                   year    = 2015,
                   type    = 'nc', ask = FALSE, copyright = FALSE,
                   destpath = file.path(tempdir(), "EDGAR"))
# unzip the file
unzip(zipfile = paste0(file.path(tempdir(), "EDGAR"),'/v50_NOx_2015.0.1x0.1.zip'),
      exdir   = paste0(file.path(tempdir(), "EDGAR")))

### 2. read the emissions (using the spec argument to split NOx into NO and NO2)
NOx <- read(paste0(file.path(tempdir(), "EDGAR"),'/v50_NOx_2015.0.1x0.1.nc'),
            version = 'EDGAR',
            spec    = c(E_NO  = 0.9 ,   # optional, 90% of NOx used to NO
                        E_NO2 = 0.1 ))  # optional, 10% of NOx uset to NO2

### 3. get the information from a WRF grid from a initial conditions file (wrfinput)
g   <- gridInfo(paste(system.file("extdata", package = "EmissV"),"/wrfinput_d01",sep=""))

### 4. calculate the emissions for grid g
NO  <- emission(grid = g, inventory = NOx$E_NO, pol = "NO", mm = 30.01,   plot = T)
NO2 <- emission(grid = g, inventory = NOx$E_NO2,pol = "NO2",mm = 46.0055, plot = T)

The next step is to save the emission in a emission file, the next example show how to save emissions using the eixport R-package:

library(eixport)
### create a temporary folder for emissions
dir.create(file.path(tempdir(), "EMISSION"))

### create the emision file
wrf_create(wrfinput_dir = system.file("extdata", package = "EmissV"),
           wrfchemi_dir = file.path(tempdir(), "EMISSION"),
           domains      = 1)
           
### get the file path of the emission file
emis_file <- list.files(path = file.path(tempdir(), "EMISSION"),
                        pattern = "wrfchemi_d01",
                        full.names = TRUE)

### save the emission
wrf_put(NO,  file = emis_file, name = "E_NO",  verbose = TRUE)
wrf_put(NO2, file = emis_file, name = "E_NO2", verbose = TRUE)

Check the wrf_create, wrf_put and to_wrf to more information and customize for your application.

NOTE: The emission file must be compatible with the WRF-Chem options (many arguments are the same as the namelist.input from WRF) check the eixport R-Package documentation and the WRF-Chem manual for more information.

Other R-packages are available to write netcdf such as ncdf4, RNetCDF, tidync are available on CRAN. Other languages such as NCL leanguage and the Python package wrf-python, and preprocessor anthro_emiss are aternative to write NetCDF files.

Using EmissV to estimate vehicular emissions

In EmissV the vehicular emissions are estimated by a top-down approach, i.e. the emissions are calculated using the statistical description of the fleet at avaliable level (National, Estadual, City, etc).The following steps show an example workflow for calculating vehicular emissions, these emissions are initially temporally and spatially disaggregated, and then distributed spatially and temporally.

I. Total: emission of pollutants is estimated from the fleet, use and emission factors and for the interest area (cities, states, countries, etc).

library(EmissV)

fleet <- vehicles(example = T)
# using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
#                              Category   Type Fuel      Use       SP ...
# Light Duty Vehicles Gasohol   LDV_E25    LDV  E25  41 km/d 11624342 ...
# Light Duty Vehicles Ethanol  LDV_E100    LDV E100  41 km/d   874627 ...
# Light Duty Vehicles Flex        LDV_F    LDV FLEX  41 km/d  9845022 ...
# Diesel Trucks               TRUCKS_B5 TRUCKS   B5 110 km/d   710634 ...
# Diesel Urban Busses           CBUS_B5    BUS   B5 165 km/d   792630 ...
# Diesel Intercity Busses       MBUS_B5    BUS   B5 165 km/d    21865 ...
# Gasohol Motorcycles          MOTO_E25   MOTO  E25 140 km/d  3227921 ...
# Flex Motorcycles               MOTO_F   MOTO FLEX 140 km/d   235056 ...

fleet <- fleet[,c(-6,-8,-9)] # dropping RJ, PR and SC

EF     <- emissionFactor(example = T)
# using a example emission factor (values calculated from CETESB 2015):
#                                     CO          PM
# Light duty Vehicles Gasohol  1.75 g/km 0.0013 g/km
# Light Duty Vehicles Ethanol 10.04 g/km 0.0000 g/km
# Light Duty Vehicles Flex     0.39 g/km 0.0010 g/km
# Diesel trucks                0.45 g/km 0.0612 g/km
# Diesel urban busses          0.77 g/km 0.1052 g/km
# Diesel intercity busses      1.48 g/km 0.1693 g/km
# Gasohol motorcycles          1.61 g/km 0.0000 g/km
# Flex motorcycles             0.75 g/km 0.0000 g/km

TOTAL  <- totalEmission(fleet,EF,pol = c("CO"),verbose = T)
# Total of CO : 1128297.0993334 t year-1

II. Spatial distribution: The package has functions to read information from tables, georeferenced images (tiff), shapefiles (sh), OpenStreet maps (osm), global inventories in NetCDF format (nc) to calculate point, line and area sources.

raster <- raster::raster(paste(system.file("extdata", package = "EmissV"),
                         "/dmsp.tiff",sep=""))

grid   <- gridInfo(paste(system.file("extdata", package = "EmissV"),
                   "/wrfinput_d02",sep=""))
# Grid information from: .../EmissV/extdata/wrfinput_d02

shape  <- raster::shapefile(paste(system.file("extdata", package = "EmissV"),
                            "/BR.shp",sep=""),verbose = F)[12,1]
Minas_Gerais <- areaSource(shape,raster,grid,name = "Minas Gerais")
# processing Minas Gerais area ...
# fraction of Minas Gerais area inside the domain = 0.0145921494236101

shape  <- raster::shapefile(paste(system.file("extdata", package = "EmissV"),
                            "/BR.shp",sep=""),verbose = F)[22,1]
Sao_Paulo <- areaSource(shape,raster,grid,name = "Sao Paulo")
# processing Sao Paulo area ...
# fraction of Sao Paulo area inside the domain = 0.474658563750987

sp::spplot(raster::merge(drop_units(TOTAL$CO[[1]]) * Sao_Paulo, 
                         drop_units(TOTAL$CO[[2]]) * Minas_Gerais),
           scales = list(draw=TRUE),ylab="Lat",xlab="Lon",
           main=list(label="Emissions of CO [g/d]"),
           col.regions = c("#031638","#001E48","#002756","#003062",
                           "#003A6E","#004579","#005084","#005C8E",
                           "#006897","#0074A1","#0081AA","#008FB3",
                           "#009EBD","#00AFC8","#00C2D6","#00E3F0"))

Figure 1 - Emissions of CO using nocturnal lights.

III. Emission calculation: calculate the final emission from all different sources and converts to model units and resolution.

CO_emissions <- emission(total = TOTAL,
                         pol   = "CO",
                         area  = list(SP = Sao_Paulo, MG = Minas_Gerais),
                         grid  = grid,
                         mm    = 28, 
                         plot  = T)
# calculating emissions for CO using molar mass = 28 ...

Figure 2 - CO emissions ready for use in air quality model.

IV. Temporal distribution: the package has a set of hourly profiles that represent the mean activity for each day of the week calculated from traffic counts of toll stations located in São Paulo city.

data(perfil)
names(perfil)

The package has additional functions for read netcdf data, create line and point sources (with plume rise) and to estimate the total emissions of of volatile organic compounds from exhaust (through the exhaust pipe), liquid (carter and evaporative) and vapor (fuel transfer operations).

Functions:

Sample datasets:

  • Species: species mapping tables
  • Perfil: vehicle counting profile for vehicular activity
  • Sample of an image of persistent lights of the Defense Meteorological Satellite Program (DMSP)
  • CETESB 2015 emission factors as emissionFactor(example=T)
  • DETRAN 2016 data and SP vahicle distribution as vehicles(example=T)
  • Shapefiles for Brazil states

Contributing

Bug reports, suggestions, and code contributions are all welcome. Please see CONTRIBUTING.md for details. Note that this project adopt the Contributor Code of Conduct and by participating in this project you agree to abide by its terms.

License

EmissV is published under the terms of the MIT License. Copyright (c) 2018 Daniel Schuch.

emissv's People

Contributors

edzer avatar ibarraespinosa avatar schuch666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

emissv's Issues

Add profiles

Topdown emissions needs temporal profiles for distributing the emissions. They must be based on traffic, emissions and experiments. This profiles could be stored in a list.

e.g.:
data(profiles)

Issues with the upcoming release of units 0.8-0

Dear maintainer,

We are preparing units 0.8-0 for release in approximately a month. I'm writing to you because our revdep checks report new issues in your package with this new version (you can check them here).

These issues seem to be caused by references to the old interface to install units (this or this, deprecated since 0.7-0 in favor of the new and more intuitive interface), which may cause a mere WARNING if CRAN checks find a reference to a non-exported object, or an ERROR if some part of the package or the tests use them.

To address this, if you wish to maintain compatibility with units < 0.7-0, I suggest the approach taken in the constants package, as you can see here, to avoid direct references to non-exported objects. Otherwise, you can just substitute the old interface with the new interface and depend on units >= 0.7-0.

EmissV vulnerable to forthcoming changes in sp and rgdal

Running revdep checks for current rgdal on R-Forge - see:

https://stat.ethz.ch/pipermail/r-sig-geo/2019-November/027801.html

shows the errors in the test failures below, related to use of PROJ&/GDAL3
and required changes to sp and rgdal. If useful find a regerence to a docker
image in this thread:

r-spatial/discuss#28

Changes will occur quite fast, and packages need to be prepared.


R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(testthat)
> library(EmissV)
> 
> test_check("EmissV")
using a example emission factor (values calculated from CETESB 2015):
                                      CO            PM
Light Duty Vehicles Gasohol  1.75 [g/km] 0.0013 [g/km]
Light Duty Vehicles Ethanol 10.04 [g/km] 0.0000 [g/km]
Light Duty Vehicles Flex     0.39 [g/km] 0.0010 [g/km]
Diesel Trucks                0.45 [g/km] 0.0612 [g/km]
Diesel Urban Busses          0.77 [g/km] 0.1052 [g/km]
Diesel Intercity Busses      1.48 [g/km] 0.1693 [g/km]
Gasohol Motorcycles          1.61 [g/km] 0.0000 [g/km]
Flex Motorcycles             0.75 [g/km] 0.0000 [g/km]
Emission factors:
                                      CO            PM
Light Duty Vehicles Gasohol  1.75 [g/km] 0.0013 [g/km]
Light Duty Vehicles Ethanol 10.04 [g/km] 0.0000 [g/km]
Light Duty Vehicles Flex     0.39 [g/km] 0.0010 [g/km]
Diesel Trucks                0.45 [g/km] 0.0612 [g/km]
Diesel Urban Busses          0.77 [g/km] 0.1052 [g/km]
Diesel Intercity Busses      1.48 [g/km] 0.1693 [g/km]
Gasohol Motorcycles          1.61 [g/km] 0.0000 [g/km]
Flex Motorcycles             0.75 [g/km] 0.0000 [g/km]
processing area ... 
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
fraction of area inside the domain = 0.955761973247402
── 1. Failure: emissions with source by area (@test-areaSource.R#4)  ───────────
areaSource(...) not equal to readRDS("data01.Rds").
Attributes: < Component "crs": Attributes: < Names: 1 string mismatch > >
Attributes: < Component "crs": Attributes: < Length mismatch: comparison on first 2 components > >
Attributes: < Component "crs": Attributes: < Component 2: 1 string mismatch > >

processing Chururuba area ... 
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
fraction of Chururuba area inside the domain = 0.955761973247402
processing Juruzinha area ... 
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example emission factor (values calculated from CETESB 2015):
Total of CO : 1676996.43578795 t year-1 
FISH not found in total !
FISH not found in total !
calculating emissions for CO as aerosol ...
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example emission factor (values calculated from CETESB 2015):
Total of CO : 1676996.43578795 t year-1 
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
calculating emissions for CO using molar mass = 28 ...
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example emission factor (values calculated from CETESB 2015):
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
reading emi_co (EDGAR) output unit is g m-2 s-1 ...
from edgar_co_test.nc x 1.00 
Using raster from inventory ...
Grid output: 99 columns 93 rows
reading emi_co (EDGAR) output unit is g m-2 s-1 ...
from edgar_co_test.nc x 1.00 
Using raster from inventory ...
Grid output: 99 columns 93 rows
Grid information from: vertical.nc 
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d03 
using length as emission variable
Number of lat points 51
Number of lon points 51
using length as emission variable
Number of lat points 51
Number of lon points 51
convective, h/L = -5.7372346528973 
using weil max= 31 
convective, h/L = -8.61326442721792 
strong convective, h/L = -16.3733115022513 
using weil max= 155 
strong convective, h/L = -33.003300330033 
using weil max= 217 
strong convective, h/L = -67.7966101694915 
strong convective, h/L = -79.3650793650794 
strong convective, h/L = -110.650069156293 
strong convective, h/L = -32.0056899004267 
stable, h/L = 200 - calm, U= 0.11 m/s 
stable, h/L = 200 - windy, U= 3.11 m/s 
neutral, h/L = 0.956937799043062 
* max iterations reached! 
Grid information from: vertical.nc 
Layer limits for grid position lat= -23.5803346633911 lon= -44.9668502807617 
  height= 0.00 m k= 1 
  height= 59.74 m k= 2 
  height= 145.50 m k= 3 
  height= 257.90 m k= 4 
  height= 397.87 m k= 5 
  height= 575.59 m k= 6 
  height= 802.06 m k= 7 
  height= 1070.66 m k= 8 
  height= 1532.39 m k= 9 
  height= 2014.39 m k= 10 
  height= 2519.01 m k= 11 
  height= 3049.04 m k= 12 
  height= 4035.38 m k= 13 
  height= 5020.68 m k= 14 
  height= 6005.89 m k= 15 
  height= 6992.68 m k= 16 
  height= 7982.44 m k= 17 
  height= 8976.27 m k= 18 
  height= 9968.42 m k= 19 
  height= 10957.52 m k= 20 
  height= 11941.38 m k= 21 
  height= 12920.99 m k= 22 
  height= 13908.15 m k= 23 
  height= 14879.66 m k= 24 
  height= 15842.59 m k= 25 
  height= 16803.16 m k= 26 
  height= 17760.40 m k= 27 
  height= 18715.93 m k= 28 
  height= 19676.74 m k= 29 
  height= 20649.44 m k= 30 
Emission heigh between 59.74 m and 145.50 m at k= 2 for z= 100
Layer limits for grid position lat= -23.5803346633911 lon= -44.9668502807617 
  height= 0.00 m k= 1 
  height= 59.74 m k= 2 
  height= 145.50 m k= 3 
  height= 257.90 m k= 4 
  height= 397.87 m k= 5 
  height= 575.59 m k= 6 
  height= 802.06 m k= 7 
  height= 1070.66 m k= 8 
  height= 1532.39 m k= 9 
  height= 2014.39 m k= 10 
  height= 2519.01 m k= 11 
  height= 3049.04 m k= 12 
  height= 4035.38 m k= 13 
  height= 5020.68 m k= 14 
  height= 6005.89 m k= 15 
  height= 6992.68 m k= 16 
  height= 7982.44 m k= 17 
  height= 8976.27 m k= 18 
  height= 9968.42 m k= 19 
  height= 10957.52 m k= 20 
  height= 11941.38 m k= 21 
  height= 12920.99 m k= 22 
  height= 13908.15 m k= 23 
  height= 14879.66 m k= 24 
  height= 15842.59 m k= 25 
  height= 16803.16 m k= 26 
  height= 17760.40 m k= 27 
  height= 18715.93 m k= 28 
  height= 19676.74 m k= 29 
  height= 20649.44 m k= 30 
Emission heigh between 802.06 m and 1070.66 m at k= 7 for z= 1000
Layer limits for grid position lat= -23.5196027755737 lon= -44.9668502807617 
  height= 0.00 m k= 1 
  height= 59.81 m k= 2 
  height= 145.61 m k= 3 
  height= 257.97 m k= 4 
  height= 397.90 m k= 5 
  height= 575.53 m k= 6 
  height= 801.97 m k= 7 
  height= 1070.70 m k= 8 
  height= 1532.64 m k= 9 
  height= 2014.67 m k= 10 
  height= 2519.25 m k= 11 
  height= 3049.28 m k= 12 
  height= 4035.69 m k= 13 
  height= 5020.84 m k= 14 
  height= 6005.95 m k= 15 
  height= 6993.00 m k= 16 
  height= 7982.73 m k= 17 
  height= 8976.44 m k= 18 
  height= 9968.59 m k= 19 
  height= 10957.95 m k= 20 
  height= 11942.11 m k= 21 
  height= 12921.73 m k= 22 
  height= 13908.66 m k= 23 
  height= 14880.00 m k= 24 
  height= 15842.81 m k= 25 
  height= 16803.23 m k= 26 
  height= 17760.21 m k= 27 
  height= 18715.41 m k= 28 
  height= 19675.99 m k= 29 
  height= 20648.63 m k= 30 
Emission heigh between 575.53 m and 801.97 m at k= 6 for z= 666
Grid information from: /home/rsb/topics/packages/rgdal/deps_ng/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
grid position lat= -22.010806627171 lon= -46.0152584808041 
grid position lat= -22.010806627171 lon= -47.9944115841027 
grid position lat= -23.4723500487625 lon= -47.0048350324534 
Grid information from: vertical.nc 
Grid output: 4 columns 4 rows 30 levels
Grid information from: vertical.nc 
Grid output: 4 columns 4 rows 30 levels
reading emi_co (EDGAR) output unit is g m-2 s-1 ...
from edgar_co_test.nc x 1.00 
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
                             Category   Type Fuel        Use       SP      RJ
Light Duty Vehicles Gasohol   LDV_E25    LDV  E25  41 [km/d] 11624342 2712343
Light Duty Vehicles Ethanol  LDV_E100    LDV E100  41 [km/d]   874627  204079
Light Duty Vehicles Flex        LDV_F    LDV FLEX  41 [km/d]  9845022 2297169
Diesel Trucks               TRUCKS_B5 TRUCKS   B5 110 [km/d]   710634  165814
Diesel Urban Busses           CBUS_B5    BUS   B5 165 [km/d]   792630  184947
Diesel Intercity Busses       MBUS_B5    BUS   B5 165 [km/d]    21865    5101
Gasohol Motorcycles          MOTO_E25   MOTO  E25 140 [km/d]  3227921  753180
Flex Motorcycles               MOTO_F   MOTO FLEX 140 [km/d]   235056   54846
                                 MG      PR      SC
Light Duty Vehicles Gasohol 4371228 3036828 2029599
Light Duty Vehicles Ethanol  328895  228494  152709
Light Duty Vehicles Flex    3702131 2571986 1718932
Diesel Trucks                267227  185651  124076
Diesel Urban Busses          298061  207072  138392
Diesel Intercity Busses        8222    5712    3817
Gasohol Motorcycles         1213830  843285  563592
Flex Motorcycles              88390   61407   41040
using a example emission factor (values calculated from CETESB 2015):
                                      CO            PM
Light Duty Vehicles Gasohol  1.75 [g/km] 0.0013 [g/km]
Light Duty Vehicles Ethanol 10.04 [g/km] 0.0000 [g/km]
Light Duty Vehicles Flex     0.39 [g/km] 0.0010 [g/km]
Diesel Trucks                0.45 [g/km] 0.0612 [g/km]
Diesel Urban Busses          0.77 [g/km] 0.1052 [g/km]
Diesel Intercity Busses      1.48 [g/km] 0.1693 [g/km]
Gasohol Motorcycles          1.61 [g/km] 0.0000 [g/km]
Flex Motorcycles             0.75 [g/km] 0.0000 [g/km]
Total of PM : 15071.8124616163 t year-1 
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example emission factor (values calculated from CETESB 2015):
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example emission factor (values calculated from CETESB 2015):
FISH not found in emission factor!
The emissions factors contains:
CO
 PM
function totalVOC will be discontinued in the next versions
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
Total COV: 2703251.58732021 t year-1 
xyl 262330984930.355 MOL year-1 
function totalVOC will be discontinued in the next versions
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
a is not in suported COV speciation
The specie list contains:
eth hc3 hc5 hc8 ol2 olt oli iso tol xyl ket ch3oh ald 
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
                             Category   Type Fuel        Use       SP      RJ
Light Duty Vehicles Gasohol   LDV_E25    LDV  E25  41 [km/d] 11624342 2712343
Light Duty Vehicles Ethanol  LDV_E100    LDV E100  41 [km/d]   874627  204079
Light Duty Vehicles Flex        LDV_F    LDV FLEX  41 [km/d]  9845022 2297169
Diesel Trucks               TRUCKS_B5 TRUCKS   B5 110 [km/d]   710634  165814
Diesel Urban Busses           CBUS_B5    BUS   B5 165 [km/d]   792630  184947
Diesel Intercity Busses       MBUS_B5    BUS   B5 165 [km/d]    21865    5101
Gasohol Motorcycles          MOTO_E25   MOTO  E25 140 [km/d]  3227921  753180
Flex Motorcycles               MOTO_F   MOTO FLEX 140 [km/d]   235056   54846
                                 MG      PR      SC
Light Duty Vehicles Gasohol 4371228 3036828 2029599
Light Duty Vehicles Ethanol  328895  228494  152709
Light Duty Vehicles Flex    3702131 2571986 1718932
Diesel Trucks                267227  185651  124076
Diesel Urban Busses          298061  207072  138392
Diesel Intercity Busses        8222    5712    3817
Gasohol Motorcycles         1213830  843285  563592
Flex Motorcycles              88390   61407   41040
vehicles:
  Category Type Fuel       Use       SP
1       B5  LDV   NA 41 [km/d] 27332097
══ testthat results  ═══════════════════════════════════════════════════════════
[ OK: 21 | SKIPPED: 0 | WARNINGS: 72 | FAILED: 1 ]
1. Failure: emissions with source by area (@test-areaSource.R#4) 

Error: testthat unit tests failed
Execution halted

read EVERYTHING

Vamos fazer que EmissV leia TODOS os inventarios disponiveis.
Eu vou adicionar uma função para baixar os dados tambem.

sample.tiff missing

I get an error with this line, and can't see this file in https://github.com/atmoschem/EmissV/tree/master/inst/extdata

raster <- raster::raster(paste(system.file("extdata", package = "EmissV"),
                                "/sample.tiff",sep=""))
Error in .local(.Object, ...) : 

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file. (file does not exist)
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] EmissV_0.664.5

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17         compiler_3.5.0       git2r_0.21.0         class_7.3-14        
 [5] tools_3.5.0          ncdf4_1.16           rpart_4.1-13         digest_0.6.15       
 [9] goftest_1.1-1        memoise_1.1.0        nlme_3.1-137         lattice_0.20-35     
[13] mgcv_1.8-23          Matrix_1.2-14        DBI_1.0.0            rgdal_1.2-20        
[17] curl_3.2             spData_0.2.8.3       e1071_1.6-8          spatstat.data_1.2-0 
[21] withr_2.1.2          httr_1.3.1           raster_2.6-7         knitr_1.20          
[25] devtools_1.13.5      spatstat.utils_1.8-0 classInt_0.2-3       grid_3.5.0          
[29] data.table_1.11.2    sf_0.6-4             R6_2.2.2             foreign_0.8-70      
[33] sp_1.2-7             polyclip_1.8-7       tensor_1.5           deldir_0.1-15       
[37] udunits2_0.13        magrittr_1.5         units_0.5-1          maptools_0.9-2      
[41] abind_1.4-5          spatstat_1.55-1 

Add importsFrom in streetDist function

EmissV::streetDist should include importFrom in roxygen2 and include sf field in DESCRIPTION in imports. It is better than depending on so many packages.

read()

this function can work wonderfully? need testing

Units

use the package 'units' for all variables

chemical border conditions

Oi @Schuch666

Que tu acha de adicionar aqui, ou no eixport, colocar condições de borde com quimica no wrf_bdy?
A ideia sera ler os dados de um modelo global e mapear os poluentes para o mecanismo quimico, e adicioanr esta informação no netcdf de wrf_bdy. Abs

Newer version for lineSource

There is a need of a newer version of lineSource to achieve 2 objectives:

  • Faster and simple: A new version of the code simpler and comprehensive using sf or another faster package, the current version take too long especially to implement tests;
  • To consider a wrf grid using the grid output from EmissV::gridInfo().

Clarify documentation

(part of openjournals/joss-reviews#662)

  • ?vehicles
    • tells me it returns "data frame with lines by vehicle category and columns for category, type, Fuel, use and a additional column for each area." - What does the value in the column for each area mean?
    • "diary use" - do you mean "average daily kilometres driven by the vehicle type" ? Recommend to be a bit more verbose here.

Re-check language of examples and comments

(part of openjournals/joss-reviews#662)

It's fun to learn some Portuguese and always refreshing to interact with different languages and cultures. However, for the code examples, I suggest to stick to English terms for clarity.

Translating some source code comments might be more welcoming to non-Portuguese contributors, e.g. https://github.com/atmoschem/EmissV/blob/master/R/plumerise.R

streetDist problems

This is a brilliant package that we would like to incorporate within our analyses. To do that, we would like to use the streetDist function which does not appear to work in current form. Reproducible code follows:

library (EmissV)
library (osmdata)
library (sf)
city <- "accra"
bb <- getbb (city)
dat <- opq (bbox = city) %>%
    add_osm_feature (key = "highway") %>%
    osmdata_sf (quiet = FALSE) %>%
    osmdata::osm_poly2line () %>%
    magrittr::extract2 ("osm_lines")
#saveRDS (dat, file = "accra-hw.Rds")
utm <- 32630 # for Accra

# Get a raster grid of population density to use for the emission distribution:
url <- paste0 ("https://github.com/ATFutures/who-data/releases/download/",
               "v0.0.2-worldpop-tif-gha-npl/accra.2fpopdens.2fGHA15adj_040213.tif")
download.file (url, "accra-pop.tif", mode = "wb")
ras <- raster::raster ("accra-pop.tif") %>%
    raster::crop (raster::extent (bb)) %>%
    as ("SpatialPolygons") %>%
    st_as_sf ()

#dat <- readRDS (file = "accra-hw.Rds")
dat <- dat [dat$highway %in% c ("motorway", "trunk", "primary",
                                "secondary", "teritary"), ]

s <- streetDist (emission = 1, dist = c (1, 0, 0, 0, 0), grid = ras,
                 osm = dat, epsg = utm)
# Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column
# In addition: Warning message:
# attribute variables are assumed to be spatially constant throughout all geometries

Any help appreciated!


Note also the use of the osmdata package which might be of general use within this package to very easily obtain OSM street networks.

upcoming package units causes errors in EmissV

I'm planning a new units submission to CRAN in about a week; it will break EmissV as of now.

Could you please look into this:

edzer@gin-edzer:/tmp/rdeps$ cat rdepends_EmissV.Rcheck/00check.log 
* using log directory/tmp/rdeps/EmissV.Rcheck* using R version 3.5.1 (2018-07-02)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using option--no-vignettes* checking for fileEmissV/DESCRIPTION... OK
* this is packageEmissVversion0.664.7* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether packageEmissVcan be installed ... OK
* checking installed package size ... OK
* checking package directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking contents ofdatadirectory ... OK
* checking data for non-ASCII characters ... OK
* checking data for ASCII and uncompressed saves ... OK
* checking examples ... ERROR
Running examples inEmissV-Ex.Rfailed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: emission
> ### Title: Emissions in the format for atmospheric models
> ### Aliases: emission
> 
> ### ** Examples
> 
> veiculos <- vehicles(example = TRUE)
using a example of vehicles (DETRAN 2016 data and SP vahicle distribution):
                             Category   Type Fuel        Use       SP      RJ
Light Duty Vehicles Gasohol   LDV_E25    LDV  E25  41 [km/d] 11624342 2712343
Light Duty Vehicles Ethanol  LDV_E100    LDV E100  41 [km/d]   874627  204079
Light Duty Vehicles Flex        LDV_F    LDV FLEX  41 [km/d]  9845022 2297169
Diesel Trucks               TRUCKS_B5 TRUCKS   B5 110 [km/d]   710634  165814
Diesel Urban Busses           CBUS_B5    BUS   B5 165 [km/d]   792630  184947
Diesel Intercity Busses       MBUS_B5    BUS   B5 165 [km/d]    21865    5101
Gasohol Motorcycles          MOTO_E25   MOTO  E25 140 [km/d]  3227921  753180
Flex Motorcycles               MOTO_F   MOTO FLEX 140 [km/d]   235056   54846
                                 MG      PR      SC
Light Duty Vehicles Gasohol 4371228 3036828 2029599
Light Duty Vehicles Ethanol  328895  228494  152709
Light Duty Vehicles Flex    3702131 2571986 1718932
Diesel Trucks                267227  185651  124076
Diesel Urban Busses          298061  207072  138392
Diesel Intercity Busses        8222    5712    3817
Gasohol Motorcycles         1213830  843285  563592
Flex Motorcycles              88390   61407   41040
> 
> EmissionFactors <- emissionFactor(example = TRUE)
using a example emission factor (values calculated from CETESB 2015):
                                      CO            PM
Light Duty Vehicles Gasohol  1.75 [g/km] 0.0013 [g/km]
Light Duty Vehicles Ethanol 10.04 [g/km] 0.0000 [g/km]
Light Duty Vehicles Flex     0.39 [g/km] 0.0010 [g/km]
Diesel Trucks                0.45 [g/km] 0.0612 [g/km]
Diesel Urban Busses          0.77 [g/km] 0.1052 [g/km]
Diesel Intercity Busses      1.48 [g/km] 0.1693 [g/km]
Gasohol Motorcycles          1.61 [g/km] 0.0000 [g/km]
Flex Motorcycles             0.75 [g/km] 0.0000 [g/km]
> 
> TOTAL  <- totalEmission(veiculos,EmissionFactors,pol = c("CO"),verbose = TRUE)
Total of CO : 1676996.43578795 t year-1 
> 
> grid   <- gridInfo(paste0(system.file("extdata", package = "EmissV"),"/wrfinput_d01"))
Grid information from: /tmp/rdeps/EmissV.Rcheck/EmissV/extdata/wrfinput_d01 
> shape  <- raster::shapefile(paste0(system.file("extdata", package = "EmissV"),"/BR.shp"))
> raster <- raster::raster(paste0(system.file("extdata", package = "EmissV"),"/dmsp.tiff"))
> 
> SP     <- areaSource(shape[22,1],raster,grid,name = "SP")
processing SP area ... fraction of SP area inside the domain = 0.955761973247402> RJ     <- areaSource(shape[17,1],raster,grid,name = "RJ")
processing RJ area ... fraction of RJ area inside the domain = 0.748007015306122> 
> e_CO   <- emission(TOTAL,"CO",list(SP = SP, RJ = RJ),grid,mm=28)
calculating emissions for CO using molar mass = 28 ...
Error in R_ut_remove_unit(name) : unknown unit name or symbol
Calls: emission -> remove_symbolic_unit -> R_ut_remove_unit
Execution halted
* checking for unstated dependencies intests... OK
* checking tests ... ERROR
  Runningtestthat.RRunning the tests intests/testthat.Rfailed.
Last 13 lines of output:
  Light Duty Vehicles Flex    3702131 2571986 1718932
  Diesel Trucks                267227  185651  124076
  Diesel Urban Busses          298061  207072  138392
  Diesel Intercity Busses        8222    5712    3817
  Gasohol Motorcycles         1213830  843285  563592
  Flex Motorcycles              88390   61407   41040
  vehicles:
    Category Type Fuel       Use       SP
  1       B5  LDV   NA 41 [km/d] 27332097
  ══ testthat results  ═══════════════════════════════════════════════════════════
  OK: 18 SKIPPED: 0 FAILED: 1
  1. Error: final emission works (@test-emission.R#21) 
  
  Error: testthat unit tests failed
  Execution halted
* checking PDF version of manual ... OK
* DONE
Status: 2 ERRORs

totalvocs

Simplify the input EF and the calculations

change the name and add better verbose (better info to user)

Restructure and extend README

(part of openjournals/joss-reviews#662)

I suggest to restructure the README file to better align with the required sections:

# EmissV

statement of need, in plain language

## Installation

### System dependencies

Ubuntu, Fedora, ...

### Package installation

devtools::...

## Using `EmissV`

[R code chunk]

## ...

[add info about contribution, code of conduct, reporting bugs, seeking support, ...]

## License

...

  • Can you provide installation instructions for Windows? The Appveyor build works, so I assume a Windows installation is possible. Possibly just mention that no specific steps are needed.
  • Regarding the "needed packages"
    • This list will at some point be out of sync with your DESCRIPTION file, which is "Good" according to the reviewer guidelines already. I suggest to only list packages here that you actually provide information about, like how/why you import them, what they are needed for - and only if it is not obvious (like sp and raster for geospatial data)
    • "The dependency of the packages spatsts, maptools and sp will be removed son." This is potentially confusing if you do not provide motivation. I suggest to remove this from README and instead create an issue stating that these packages should be removed any why.
  • For the Example, I suggest you switch to using a README.Rmd file to generate the README.md with a R code based example, see http://usethis.r-lib.org/reference/use_readme_rmd.html
  • Meta-Information related to Community guidelines are missing, check the ROpenSci GitHub org for examples (such as https://github.com/ropensci/nomisr#meta)

rgdal is retiring soon

Please protect your package from the forthcoming retirement of rgdal: https://r-spatial.org/r/2022/04/12/evolution.html

CMD check on a platform without retiring packages and with _SP_EVOLUTION_STATUS=2 has this log:
00check.log

Condition use of raster on the the availability of rgdal (raster::projectRaster fails if rgdal is not present), or preferably transition from raster to terra at your earliest convenience. terra is a re-implementation of raster but accesses GDAL directly.

We need a substitute of anthro_emiss

I believe we need a substitute of anthro_emiss in EmissV. This tool would allow us to merge/speciate EDGAR and other emissions scenarios/data and use eixport::wrf_create to create wrfcheminputs

Error with totalEmission()

I was working through paper.md until I got to totalEmission:

TOTAL  <- totalEmission(veiculos,EF,pol = c("CO"),verbose = T)
Error: $ operator is invalid for atomic vectors 
5.
as.character.units(structure(1127549.32468524, units = structure(list(
    numerator = "t", denominator = "year"), .Names = c("numerator", 
"denominator"), class = "symbolic_units"), class = "units")) 
4.
as.character(structure(1127549.32468524, units = structure(list(
    numerator = "t", denominator = "year"), .Names = c("numerator", 
"denominator"), class = "symbolic_units"), class = "units")) 
3.
paste("Total of", pol[i], ":", sum(total_t_y), units::deparse_unit(total_t_y)) 
2.
print(paste("Total of", pol[i], ":", sum(total_t_y), units::deparse_unit(total_t_y))) at totalEmission.R#62
1.
totalEmission(veiculos, EF, pol = c("CO"), verbose = T)
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] EmissV_0.664.5

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17         raster_2.5-8         tensor_1.5           magrittr_1.5        
 [5] maptools_0.9-2       spatstat.utils_1.7-0 units_0.5-1          spatstat_1.52-1     
 [9] lattice_0.20-35      udunits2_0.13        tools_3.4.1          grid_3.4.1          
[13] data.table_1.10.4    nlme_3.1-131         mgcv_1.8-19          DBI_0.7             
[17] deldir_0.1-14        abind_1.4-5          goftest_1.1-1        sf_0.5-4            
[21] Matrix_1.2-11        rpart_4.1-11         ncdf4_1.16           polyclip_1.6-1      
[25] sp_1.2-5             compiler_3.4.1       foreign_0.8-69      

Add automated tests

(part of openjournals/joss-reviews#662)

Strongly recommend to use testthat to add tests for the package functionality.
AFAICS the Travis and Appveyor tests only run an installation of the package, but no unit or integration tests. Pointers welcome if I'm wrong!

It is also worth having examples in the docs that actually run (I saw mostly "dontrun" code blocks).

color palette of EmissV?

por exemplo, EmissV.colors, or algo assim, e que vai criar a tua paleta de cores....

Me envia o RGB

dependencies of lineSource function

This function cause dependencies of 2 r-packages: spatsts, maptools and uses sp

The package sf can be used to speed-up this function and make the package less dependent

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.