%% \section{%% Copernicus Publications Manuscript Preparation Template for LaTeX Submissions}
%% ---------------------------------
%% This template should be used for copernicus.cls
%% The class file and some style files are bundled in the Copernicus Latex Package, which can be downloaded from the different journal webpages.
%% For further assistance please contact Copernicus Publications at: production@copernicus.org
%% http://publications.copernicus.org/for_authors/manuscript_preparation.html


%% Please use the following documentclass and journal abbreviations for discussion papers and final revised papers.


%% 2-column papers and discussion papers
\documentclass[gmd, manuscript,twocolumns]{copernicus}



%% Journal abbreviations (please use the same for discussion papers and final revised papers)

% Archives Animal Breeding (aab)
% Atmospheric Chemistry and Physics (acp)
% Advances in Geosciences (adgeo)
% Advances in Statistical Climatology, Meteorology and Oceanography (ascmo)
% Annales Geophysicae (angeo)
% ASTRA Proceedings (ap)
% Atmospheric Measurement Techniques (amt)
% Advances in Radio Science (ars)
% Advances in Science and Research (asr)
% Biogeosciences (bg)
% Climate of the Past (cp)
% Drinking Water Engineering and Science (dwes)
% Earth System Dynamics (esd)
% Earth Surface Dynamics (esurf)
% Earth System Science Data (essd)
% Fossil Record (fr)
% Geographica Helvetica (gh)
% Geoscientific Instrumentation, Methods and Data Systems (gi)
% Geoscientific Model Development (gmd)
% Geothermal Energy Science (gtes)
% Hydrology and Earth System Sciences (hess)
% History of Geo- and Space Sciences (hgss)
% Journal of Sensors and Sensor Systems (jsss)
% Mechanical Sciences (ms)
% Natural Hazards and Earth System Sciences (nhess)
% Nonlinear Processes in Geophysics (npg)
% Ocean Science (os)
% Proceedings of the International Association of Hydrological Sciences (piahs)
% Primate Biology (pb)
% Scientific Drilling (sd)
% SOIL (soil)
% Solid Earth (se)
% The Cryosphere (tc)
% Web Ecology (we)
% Wind Energy Science (wes)
  

%% \usepackage commands included in the copernicus.cls:
%\usepackage[german, english]{babel}
%\usepackage{tabularx}
%\usepackage{cancel}
%\usepackage{multirow}
%\usepackage{supertabular}
%\usepackage{algorithmic}
%\usepackage{algorithm}
%\usepackage{amsthm}
%\usepackage{float}
%\usepackage{subfig}
%\usepackage{rotating}
% Os pacotes abaixo foram adicionados por Sergio. Comentei eles em 24/06/17: AR
%\usepackage{url} 
%\usepackage{breakurl}
%\usepackage{multirow}
%\usepackage{float}
%\usepackage{graphicx}
%\graphicspath{{./figures/}}
%\usepackage{caption}
%\usepackage{subcaption}
%\usepackage{booktabs,array,dcolumn}
%\usepackage{tabularx,ragged2e,booktabs,caption}
%\usepackage[flushleft]{threeparttable}
%\usepackage{lscape}
%\usepackage{siunitx}
%\usepackage{rotating}
%\usepackage{babel,blindtext}
\usepackage{longtable}

\begin{document}

\title{VEIN v0.2.2: an R package for bottom-up Vehicular Emissions Inventories}


% \Author[affil]{given_name}{surname}

\Author[1]{Sergio}{Ibarra-Espinosa}
\Author[1]{Rita}{Ynoue}
\Author[2]{Shane}{O'Sullivan}
\Author[3]{Edzer}{Pebesma}
\Author[1]{Maria de Fátima}{Andrade}
\Author[4]{Mauricio}{Osses}

\affil[1]{Department of Atmospheric Sciences, Universidade de São Paulo, Rua do Matão 1226, São Paulo, SP, Brazil}
\affil[2]{Department of Pathology, Faculdade de Medicina, Universidade de São Paulo, Av. Dr. Arnaldo 455, São Paulo, SP, Brazil}
\affil[3]{Institute for Geoinformatics, Westfälische Wilhelms-Universität Münster, Heisenbergstraße 2, 48149 Münster, Germany}
\affil[4]{Department of Mechanical Engineering, Universidad Técnica Federico Santa María, Vicuña Mackenna 3939, Santiago, Chile}


%% The [] brackets identify the author with the corresponding affiliation. 1, 2, 3, etc. should be inserted.



\runningtitle{VEIN v0.2.2: an R package for bottom-up vehicular emissions inventories}

\runningauthor{S. Ibarra-Espinosa}

\correspondence{Sergio Ibarra-Espinosa (zergioibarra@gmail.com)}


\received{}
\pubdiscuss{} %% only important for two-stage journals
\revised{}
\accepted{}
\published{}

%% These dates will be inserted by Copernicus Publications during the typesetting process.


\firstpage{1}

\maketitle

\input{texts/abstract.tex}

%\copyrightstatement{TEXT????????????}

\input{texts/intro.tex}
%Metodo:
\input{texts/development.tex}
\input{texts/application_example.tex}
%Aplicacao:
\input{texts/results.tex}
\input{texts/conclusions.tex}

%% The following commands are for the statements about the availability of data sets and/or software code corresponding to the manuscript.
%% It is strongly recommended to make use of these sections in case data sets and/or software code have been part of your research the article is based on.

%\codeavailability{} %% use this section when having only software code available


%\dataavailability{%} %% use this section when having only data sets available



\codedataavailability{VEIN is available at the Comprehensive R Archive Network (CRAN)  https://CRAN.R-project.org/package=vein and github https://github.com/ibarraespinosa/vein/releases DOI:10.5281/zenodo.1039236, updates available at https://github.com/ibarraespinosa/vein/. The software version "Vehicular Emissions INventories (VEIN) v0.2.2" was developed using the R programming language v3.4.1. For further information about the VEIN package, contact developer Sergio Ibarra Espinosa at sergio.ibarra@usp.br.
Datasets included: Emission factors \textit{fe2015} and mileage functions \textit{fkm} from the Environmental Agency of São Paulo (CETESB). 
In addition, emission and deterioration factors are provided in the form of look-up tables from Copert \citep{NtziachristosSamaras2016}. These include hot emissions factors for light duty vehicles (LDV), heavy duty vehicles (HDV), cold start, evaporative factors, cold starts, resuspension and performs speciations. 
Emission factor functions are included for USEPA/AP42 \citep{epa2002comprehensive} estimations with default parameters. There are also two datasets to perform the example functions, a data-frame to extrapolate morning peak hour vehicle traffic data to each hour of the week  \textit{pc\_profile}, and a vehicle start pattern \textit{pc\_cold} to be used for cold start estimation. Moreover, VEIN includes a traffic simulation for the western region of São Paulo City named, \textit{net}. Software required: VEIN depends on the package "sp" and uses some functions from "rgeos", "rgdal", "raster" and "units" packages. The user must install libraries \textbf{geos, v3.5.1}, \textbf{gdal, v2.1.2} and \textbf{udunits, v2.2.20}.} 


\appendix
\section{Intercept grid and street emissions}    %% Appendix A
\begin{verbatim}
library(vein)
library(sf)
# Converting objects into "sf" and projecting to UTM zone 23S - EPSG:31983
g_sf <- st_as_sf(spTransform(g, CRSobj = "+init=epsg:31983"))
net_sf <- st_as_sf(spTransform(net, CRSobj = "+init=epsg:31983"))
# Calculating initial length of net_sf
net_sf$LKM <- st_length(st_cast(net_sf[st_dimension(net_sf) == 1,]))
# Intersecting net and grid
net_sf_g <- st_intersection(net_sf, g_sf)
# Calculating new length of net_sf
net_sf_g$LKM2 <- st_length(st_cast(net_sf_g[st_dimension(net_sf_g) ==1,]))
# Checking dimensions
dim(net_sf_g)
# Converting from sf to data.frame
net_sf_gg <- as.data.frame(net_sf_g)
# Eliminating column 'geometry'
net_sf_gg <- net_sf_gg[,-171]
# Obtaining proportional emissions of 168 hours of the week
net_sf_gg[,1:168] <- net_sf_gg[,1:168] *
					as.numeric(net_sf_gg$LKM2/net_sf_gg$LKM)
# Agregating emissions by id of grid
dfm <- aggregate(cbind(net_sf_gg[, 1:168]), 
                 by = list(net_sf_gg$id), sum, na.rm = TRUE)
# naming columns of data-frame dfm
names(dfm) <- c("id", paste0("h", 1:168))
# Creating data-frame for id of grid
gx <- data.frame(id = g$id)
# merging data-frames
gx <- merge(gx, dfm, by="id", all.x = T)
# Generating spatial grid and converting to "Spatial"
E_CO_g <- as(st_sf(gx, geometry = g_sf$geometry), "Spatial")
# Converting to WGS84 lat lon
E_CO_g <- spTransform(E_CO_g, "+init=epsg:4326")

\end{verbatim}

\noappendix       %% use this to mark the end of the appendix section

%% Regarding figures and tables in appendices, the following two options are possible depending on your general handling of figures and tables in the manuscript environment:

%% Option 1: If you sorted all figures and tables into the sections of the text, please also sort the appendix figures and appendix tables into the respective appendix sections.
%% They will be correctly named automatically.

%% Option 2: If you put all figures after the reference list, please insert appendix tables and figures after the normal tables and figures.
%% To rename them correctly to A1, A2, etc., please add the following commands in front of them:

\appendixfigures  %% needs to be added in front of appendix figures

\appendixtables   %% needs to be added in front of appendix tables

%% Please add \clearpage between each table and/or figure. Further guidelines on figures and tables can be found below.

\authorcontribution{SIE designed and implemented the entire model. All authors contributed to the final manuscript.} 
%\authorcontribution{SIE designed and implemented the entire model. SIE also wrote
%the manuscript. SO contributed with the English revision and edition. EP suggested create classes S3, revised and edited the manuscript and made some contributions to the code. MO gave suggestions about methods regarding vehicular emissions and edited the manuscript. MFA revised and edited the manuscript. RY revised and edited the manuscript. All authors contributed to the final manuscript.} 

\competinginterests{The authors declare they have no actual or potential competing interest.} %% this section is mandatory even if you declare that no competing interests are present

%\disclaimer{TEXT} %% optional section

\begin{acknowledgements}
We thank the Environmental Agency of São Paulo State (CETESB), the programs CAPES and CNPQ (Ministry of Education, Brazil) and CONICYT (Ministry of Education, Chile). Also, this work was partially supported by the FONDAP/ CONICYT 15110009 project. These entities provided data and support that was invaluable to this study. We also thank Angel Vara-Vela from Department of Atmospheric Sciences at University of São Paulo, for discussions and tests relating to the integration between AAS4WRF and VEIN.
\end{acknowledgements}




%% REFERENCES

%% The reference list is compiled as follows:

%\begin{thebibliography}{}

%\bibitem[AUTHOR(YEAR)]{LABEL}
%REFERENCE 1

%\bibitem[AUTHOR(YEAR)]{LABEL}
%REFERENCE 2

%\end{thebibliography}

%% Since the Copernicus LaTeX package includes the BibTeX style file copernicus.bst,
%% authors experienced with BibTeX only have to include the following two lines:
%%
\bibliographystyle{GMD_template/copernicus}
\bibliography{texts/ref.bib}
%%
%% URLs and DOIs can be entered in your BibTeX file as:
%%
%% URL = {http://www.xyz.org/~jones/idx_g.htm}
%% DOI = {10.5194/xyz}


%% LITERATURE CITATIONS
%%
%% command                        & example result
%% \citet{jones90}|               & Jones et al. (1990)
%% \citep{jones90}|               & (Jones et al., 1990)
%% \citep{jones90,jones93}|       & (Jones et al., 1990, 1993)
%% \citep[p.~32]{jones90}|        & (Jones et al., 1990, p.~32)
%% \citep[e.g.,][]{jones90}|      & (e.g., Jones et al., 1990)
%% \citep[e.g.,][p.~32]{jones90}| & (e.g., Jones et al., 1990, p.~32)
%% \citeauthor{jones90}|          & Jones et al.
%% \citeyear{jones90}|            & 1990



%% FIGURES

%% When figures and tables are placed at the end of the MS (article in one-column style), please add \clearpage
%% between bibliography and first table and/or figure as well as between each table and/or figure.


%% ONE-COLUMN FIGURES

%%f
%\begin{figure}[t]
%\includegraphics[width=8.3cm]{FILE NAME}
%\caption{TEXT}
%\end{figure}
%
%%% TWO-COLUMN FIGURES
%
%%f
%\begin{figure*}[t]
%\includegraphics[width=12cm]{FILE NAME}
%\caption{TEXT}
%\end{figure*}
%
%
%%% TABLES
%%%
%%% The different columns must be seperated with a & command and should
%%% end with \\ to identify the column brake.
%
%%% ONE-COLUMN TABLE
%
%%t
%\begin{table}[t]
%\caption{TEXT}
%\begin{tabular}{column = lcr}
%\tophline
%
%\middlehline
%
%\bottomhline
%\end{tabular}
%\belowtable{} % Table Footnotes
%\end{table}
%
%%% TWO-COLUMN TABLE
%
%%t
%\begin{table*}[t]
%\caption{TEXT}
%\begin{tabular}{column = lcr}
%\tophline
%
%\middlehline
%
%\bottomhline
%\end{tabular}
%\belowtable{} % Table Footnotes
%\end{table*}
%
%
%%% MATHEMATICAL EXPRESSIONS
%
%%% All papers typeset by Copernicus Publications follow the math typesetting regulations
%%% given by the IUPAC Green Book (IUPAC: Quantities, Units and Symbols in Physical Chemistry,
%%% 2nd Edn., Blackwell Science, available at: http://old.iupac.org/publications/books/gbook/green_book_2ed.pdf, 1993).
%%%
%%% Physical quantities/variables are typeset in italic font (t for time, T for Temperature)
%%% Indices which are not defined are typeset in italic font (x, y, z, a, b, c)
%%% Items/objects which are defined are typeset in roman font (Car A, Car B)
%%% Descriptions/specifications which are defined by itself are typeset in roman font (abs, rel, ref, tot, net, ice)
%%% Abbreviations from 2 letters are typeset in roman font (RH, LAI)
%%% Vectors are identified in bold italic font using \vec{x}
%%% Matrices are identified in bold roman font
%%% Multiplication signs are typeset using the LaTeX commands \times (for vector products, grids, and exponential notations) or \cdot
%%% The character * should not be applied as mutliplication sign
%
%
%%% EQUATIONS
%
%%% Single-row equation
%
%\begin{equation}
%
%\end{equation}
%
%%% Multiline equation
%
%\begin{align}
%& 3 + 5 = 8\\
%& 3 + 5 = 8\\
%& 3 + 5 = 8
%\end{align}
%
%
%%% MATRICES
%
%\begin{matrix}
%x & y & z\\
%x & y & z\\
%x & y & z\\
%\end{matrix}
%
%
%%% ALGORITHM
%
%\begin{algorithm}
%\caption{?}
%\label{a1}
%\begin{algorithmic}
%?
%\end{algorithmic}
%\end{algorithm}
%
%
%%% CHEMICAL FORMULAS AND REACTIONS
%
%%% For formulas embedded in the text, please use \chem{}
%
%%% The reaction environment creates labels including the letter R, i.e. (R1), (R2), etc.
%
%\begin{reaction}
%%% \rightarrow should be used for normal (one-way) chemical reactions
%%% \rightleftharpoons should be used for equilibria
%%% \leftrightarrow should be used for resonance structures
%\end{reaction}
%
%
%%% PHYSICAL UNITS
%%%
%%% Please use \unit{} and apply the exponential notation


\end{document}
