\section{VEIN model: methodology to estimate vehicular emissions}
\label{s2}

Temporal and spatial disaggregated emissions are estimated following a general approach of multiplication between activities and emission factors \citep{PullesHeslinga2010}, as shown in Eq. (\ref{eq:ena}).
\begin{equation}
    Emission_{pollutant} = \sum_{activity}\left( AR_{activity} \cdot EF_{pollutant, activity} \right)
    \label{eq:ena}
\end{equation}
where $Emission_{pollutant}$ for any type of pollutant depends on the activity rate $AR$ and the emission factors $EF$, which is the mass of pollutants generated according to the level of activity. 
In the context of vehicular emissions, $AR_{activity}$ represents the number of vehicles times the distance ($\mathrm{km}$) that they travel. $EF_{pollutant, activity}$ is the emission factor ($\mathrm{g \cdot km^{-1}}$) for pollutants of the vehicles.

For a bottom-up estimation of vehicular emissions,
a large number of parameters ashould be involved with the activity (traffic flow, vehicle composition, speed recording, length of road) and emission factors (speed or acceleration dependent) \citep{NtziachristosSamaras2016}. 
In this instance, the following sections provide the theory behind the VEIN model regarding traffic data arrangement, selection of emission factors, emissions estimation, spatial allocation and inputs for atmospheric models.

\subsection{Traffic data}

Traffic data required for the VEIN model must be represented as an hourly amount of vehicles per street.

This traffic data can be provided by traffic simulations, interpolations or by other sources.  
In the first step, VEIN reads spatial morning rush hour traffic data from each street of a desired area or city.  After reading it, VEIN arranges and organizes the data by vehicle composition, according to Eq. (\ref{eq:qvca}). 
\begin{equation}
    F^*_{i,j,k} = Q_{i} \cdot VC_{i,j} \cdot Age_{j,k}
    \label{eq:qvca}
\end{equation}
where $F^*_{i,j,k}$ is the vehicular flow at street link $i$ for vehicle type $j$ by age of use $k$. $j$ defines the vehicular composition according to their type of use, type of fuel, size of engine and gross weight, based on definitions of \cite{Corvalanetal2002}. $Q_i$ is the traffic flow at street link $i$. $VC_{i,j}$ is the fraction of vehicles varying according to the type of vehicles $j$ in the composition for street link $i$.  $Age_{j,k}$ is the age distribution by vehicular composition $j$ and age of use $k$. This Equation shows that $VC$ splits the total vehicular flow $Q$ to identify the vehicular fraction, which varies according to the type of fuel, size of motor and gross weight. For example, if $Q$ is light duty vehicles (LDV) and we know that 5\% of the $Q$ are passenger cars (PC), with engine lesser than 1400 cc, $VC$ is 0.05. This characterization of the fleet depends on the amount and quality of the available information. VEIN then multiplies the traffic with $Age$ to obtain the amount of each type of vehicle by age of use. 

Traffic data must be temporally extrapolated because it is usually available for morning rush hour. 
Traffic data can be estimated from short period traffic count datasets, then expanded to represent longer timespan, such as Annual Average Daily Traffic (AADT; \citealt{wang2009forecasting, lam2000estimation}). The next step is to extrapolate the vehicular flow at street link $i$, vehicle type $j$, and age of use $k$, to obtain the vehicular flow for hour of the week $l$ ($F_{i,j,k,l}$; see Eq. \ref{eq:F}).
\begin{equation}
    F_{i,j,k,l} = F^*_{i,j,k} \cdot TF_{j,l}
    \label{eq:F}
\end{equation}
\textcolor{red}{ (5) where $F_{i,j,k,l}$ is the traffic flow for each link $i$ and type of vehicle $j$ of the vehicular composition, with the age of use $k$ for the hour $l$.} $TF_{j,l}$ are the temporal factors varying according 
to each hour of $l$ and type of vehicle $j$. 
For instance, $TF$ is defined as a matrix with 24 lines and numbers of columns to each day considered, from Monday to Sunday. In order to expand traffic to other hours, $TF$ matrices must be normalized to the hour that represents the traffic data. It means that $TF$ values at morning peak hour must be 1 and the respective proportion must be assigned to the other hours. $TF$ values can be obtained from automatic traffic count stations \textcolor{red}{ or other hourly traffic data to obtain the temporal profile}. 
 

The average speed of traffic flow is very important and it must be determined for each link and hour. Once the vehicular flow is identified for each hour, the average speed is then identified for each hour. This was accomplished by employing curves from the Bureau of Public Roads (BPR; \citealt{bpr}), as shown in Eq. (\ref{eq:bpr}). The process involves calculating speed by dividing the length of road by the time. The time is calculated using the total traffic expanded to each street link $i$ and hour $l$. 
\begin{equation}
   T_{i,l} = To_i \cdot \left(1 +\alpha \cdot \left(\dfrac{Q_{i,l}}{C_i}\right)^\beta \right)
       \label{eq:bpr}
  \end{equation}
  
 In Eq. \ref{eq:bpr}, $T_i$ is the travel time per street link $i$ at each hour of the week $l$. $To_i$ is the travel time under free flow conditions where maximum speed was used. $Q_{i,l}$ is the traffic flow at peak hour for each street link $i$ and hour of the week $l$. $C_i$ is the capacity of vehicles on street link $i$. The parameters $\alpha$ and $\beta$ are adjustments with default values of 0.15 and 4, respectively \cite{bpr}. \textcolor{red}{ (6) Nevertheless, inside the VEIN model, the user can use other values. With this information it is possible to calculate the time to travel during the link $i$ at any hour $l$, and therefore, with the the length of the road, to obtain the speed.}
\textcolor{red}{ (6) However, the information of the capacity is not always available. When there is at least the information of the peak and free flow speeds, it is possible to apply a simple average between both speeds to obtain the average speeds and then distribute these speeds at different hours.}

\subsection{Selection of the emissions factors}
\label{ef}
The emissions factors describe the relationship intensity of activity and emissions for a given technology \citep{PullesHeslinga2010}. 
In the case of our model, an emission factor is the mass of pollutant emitted by the vehicular type, technology and years of use. VEIN counts with emission factors for hot and cold exhaust, evaporative, deterioration and wear emissions. VEIN allows three types of hot exhaust emission factors: 

\begin{itemize}
\item [1)] Speed functions from the Computer programme to calculate emissions from road transport (Copert; \citealt{NtziachristosSamaras2016}), which are stored internally in the model. This approach can be used if there is no local emission factors and if there is information about vehicular speed recordings, simulations, or knowledge of the representative speeds.

\item [2)] Emission factors from local sources. The values must be mass per km $g \cdot km^{-1}$ per specific type of vehicle, including fuel type, size and weight, by age of use.

\item [3)] Scaled local emission factors with Copert in order to incorporate speed variation for local factors, as shown in Eq. (\ref{eq:scale}). This produces a specific speed dependent on emission factor by age of use for the vehicle. 
   
\end{itemize}

\textcolor{red}{ (7) Copert emission factors are based on emissions measurement made in Europe. This means that there is an inherent fuel composition associated with these factors. When the user want to use these factors, they must be corrected with the local fuel properties as shown by \cite{NtziachristosSamaras2016}. However, if the user uses emission factors based on local measurements, this correction is not necessary. }

    \begin{equation}
    EF_{scaled}(V_{i,l})_{j,k,m} = EF(V_{i,l})_{j,k,m} \cdot \dfrac{EFlocal_{j,k,m}}{EF(Vdc_{i,l})_{j,k,m}}
        \label{eq:scale}
    \end{equation}  
where $EF_{scaled}(V_{i,l})_{j,k,m}$ is the scaled emission factor and $EF(V_{i,l})_{j,k,m}$ is the Copert emission factor for each street link $i$, vehicle from composition $k$, hour $l$ and pollutant $m$. $EFlocal_{j,k,m}$ represents the constant emission factor (not speed functions). $EF(Vdc_{i,l})_{j,k,m}$ are Copert emission factors with average speed value of the respective driving cycle for the vehicular category $j$. The São Paulo emission factors data includes recordings of Federal Test Procedure (FTP-75) driving cycle for LDV with an average speed of 34.12 $\mathrm{km \cdot h^{-1}}$, as shown in the report of driving cycles \citep{Barlowetal2009}.  
 
By default, VEIN includes deterioration factors from Copert \citep{NtziachristosSamaras2016}. However, it is possible to include other sources, such as from \cite{CorvalanVargas2003}. 
 

\subsection{Emissions estimation}
 
VEIN estimates type of emissions including hot exhaust (EH; Eq. \ref{eq:emi}), cold start exhaust (EC; Eq. \ref{eq:cold}), evaporative (EV; Eq. \ref{eq:ev1}), deterioration factors and speciation. The total vehicular emission is the sum of all types of emissions.

\begin{flushleft}
\textbf{Hot exhaust emission}
\end{flushleft}
     The VEIN process of emissions estimation is performed per street link, vehicle type, hour of week, and pollutant. Eq. (\ref{eq:emi}) shows the hot exhaust estimation:
 \begin{equation}
 EH_{i,j,k,l,m} =F_{i,j,k,l} \cdot L_i \cdot EF(V_{i,l})_{j,k,m} \cdot DF_{j,k}
        \label{eq:emi}
  \end{equation}
In Eq. (\ref{eq:emi}), $EH_{i,j,k,l,m}$ is the emissions for each street link $i$, vehicle category from composition $k$, hour $l$ and pollutant $m$, where $F_{i,j,k,l}$ is the vehicular flow calculated in Eq. 1. $L_i$ is the length of the street link $i$. $EF(V_{i,l})_{j,k,m}$ is the emission factor of each pollutant $m$. $DF_{j,k}$ is the deterioration factor for vehicle of type $j$ and age of use $k$. \textcolor{red}{ (4 and 8) Deterioration factors are emission degradation functions of gasoline vehicles using catalysts due to accumulated mileage based on European measurements \citep{NtziachristosSamaras2016}. Nevertheless, the user could use its own set of deterioration factors such as the proposed by \cite{Corvalanetal2002}}.\\

\begin{flushleft}
\textbf{Cold start emissions}
\end{flushleft}
      Cold start emissions are produced during engine startup, when the engine and/or catalytic converter system has not reached its normal operational temperature. \textcolor{red}{ (9) Consequently, these emissions occur when vehicle start the journey on parking locations or mostly in residential streets.} Several studies have shown the significant impact for these types of emissions \citep{chenetal2011} \citep{Weilenmannetaletal2009}. VEIN also considers cold start emissions - under this condition emissions will be higher, and if the atmospheric temperature decreases, cold start emissions will increase regardless of whether the catalyst has reached its optimum temperature for functioning \citep{cold}. For example, studies report that when ambient temperature is -7$^{\circ}$C, emissions are one order of magnitude higher than at 22$^{\circ}$C \citep{ludykaretal999}.

The VEIN model caters to these emissions by using the approach outlined in Copert \citep{NtziachristosSamaras2016}, as shown in Eq. (\ref{eq:cold}).
\begin{equation}
    EC_{i,j,k,l,m} =\beta_{j} \cdot F_{i,j,k,l} \cdot L_i \cdot EF(V_{i,l})_{j,k,m} \cdot DF_{j.k} \cdot \left(EF_{\mbox{cold}}(ta_n,V_{i,l})_{j,k,m}-1\right)
        \label{eq:cold}
\end{equation}
    
    This approach adds two terms to Eq. \ref{eq:emi}. The first term $EF_{cold}(ta_n,V_{i,l})_{j,k,m}-1$ is the emission factors for cold start conditions at each street link $i$, vehicle category from composition $k$, hour $l$ and pollutant $m$ and monthly average temperature $n$.  \cite{NtziachristosSamaras2016} suggest using monthly average temperature. \textcolor{red}{ (9) As the information about the parking location is limited or in the Eq. (\ref{eq:cold}) we are proposing the assignation of the emissions into the links.  In the case of better information available, these emissions should be assigned into parking locations. These are important aspect that will be reviewed in future versions of VEIN.}

    The second term $\beta_j$ is defined as the fraction of mileage driven with a cold engine/catalyst \citep{NtziachristosSamaras2016}. The VEIN model incorporates a dataset of cold starts recorded during the implementation of the International Vehicle Emissions (IVE) model \citep{Davisetal2005} in São Paulo \citep{ivesp}, which provides the hourly mileage driven with cold start conditions.
\begin{flushleft}
\textbf{Evaporative emissions}
\end{flushleft}
    Evaporative emissions are important sources of hydrocarbons and these emissions are produced by vaporization of fuel due to variations in ambient temperatures \citep{MelliosNtziachristos2016, Andradeetal2017}. There are mainly three types of evaporative emissions: diurnal emissions, due to increases in atmospheric temperature, which lead to thermal expansion of vapor fuel inside the tank; running losses, when the fuel evaporates inside the tank due to normal operation of the vehicle; and hot soak emissions, which occur when the hot engine is turned off. These methods implemented in VEIN were sourced from the evaporative emissions methods of Copert \citep{MelliosNtziachristos2016}. This approach is shown in Eqs. (\ref{eq:ev1}), (\ref{eq:ev2}) and (\ref{eq:ev3}).
\begin{equation}
    EV_{j,k} =\sum_{s}D_{s} \cdot \sum_{j}F_{j} \cdot (HS_{j,k}+de_{j,k}+RL_{j,k}) 
    \label{eq:ev1}
\end{equation}
where $EV_{j}$ are the volatile organic compounds (VOC) evaporative emissions due to each type of vehicle $j$. $D_s$ is the "seasonal days" or number of days when the mean monthly temperature is within a determined range: [-5$^{\circ}$,10$^{\circ}$C],  [0$^{\circ}$,  15$^{\circ}$C], [10$^{\circ}$, 25$^{\circ}$C] and [20$^{\circ}$, 35$^{\circ}$C]. 
$F_{j,k}$ is the number of vehicles according to the same type $j$ and age of use $k$. $HS_{j,k}$, $de_{j,k}$ and $RL_{j,k}$ are average hot/warm soak, diurnal and running losses evaporative emissions ($\mathrm{g \cdot day^{-1}}$), respectively, according to the vehicle type $j$ and age of use $k$. $HS_{j,k}$ and $RL_{j,k}$ are obtained using equations also sourced from :
\begin{equation}
%\centering
HS_{j,k} = x_{j,k} \cdot (c \cdot (p \cdot e_{shc}+(1-p) \cdot e_{swc})+(1-c) \cdot e_{shfi} )
        \label{eq:ev2}
\end{equation}
where $x$ are the number of trips per day for the vehicular type $j$ and age of use $k$. $c$ is the fraction of vehicles with fuel return systems. $p$ is the fraction of trips finished with hot engine, for example, an engine that has reached its normal operating temperature and the catalyst has reached its light-off temperature \citep{NtziachristosSamaras2016}. The light-off temperature is the temperature at the point when catalytic reactions occur inside a catalytic converter. $e_{shc}$ and $e_{swc}$ are average hot-soak and warm-soak emission factors for gasoline vehicles with carburettor or fuel return systems ($\mathrm{g \cdot parking^{-1}}$). $e_{shfi}$  is the average hot-soak emission factors for gasoline vehicles equipped with fuel injection and non-return fuel systems ($\mathrm{g \cdot parking^{-1}}$). 
\begin{equation}
RL_{j,k} = x_{j,k} \cdot (c \cdot (p \cdot e_{rhc}+(1-p) \cdot e_{rwc})+(1-c) \cdot e_{rhfi} )
        \label{eq:ev3}
\end{equation}
$x$ and $p$ have the same meanings of Eq. \ref{eq:ev2}. $e_{rhc}$ and  $e_{rwc}$ are average hot and warm running losses emission factors for gasoline vehicles with carburettor or fuel return systems ($\mathrm{g \cdot trip^{-1}}$) and $e_{rhfi}$  are average hot running losses emission factors for gasoline vehicles equipped with fuel injection and non-return fuel systems ($\mathrm{g \cdot trip^{-1}}$).
It is recommended to estimate the number of trips per day \citep{MelliosNtziachristos2016}, $x$, as the division between the mileage and 365 times the length of trip: $ x = \dfrac{mileage_j}{(365 \cdot ltrip)}$. However, the mileage of a vehicle is not constant throughout the years. Therefore, VEIN incorporates a dataset of equations to estimate mileage of different types of vehicles by age of use \citep{BruniBales2013}.
\textcolor{red}{ (10) and (11) The methods presented in this part corresponds to the Evaporative emission factors Tier 2 \cite{MelliosNtziachristos2016}. However, we expect to add Tier 3 methods in future versions of VEIN including hourly distribution parking patterns. Alternatively, the user could transform the units to produce emission factors in $g \cdot km$ for convenience. For instance, in Eq. (\ref{eq:ev2}) and (\ref{eq:ev3}) $x$ is the number of trips per day; knowing the mean distance per trip would allow to have $x$ as the distance traveled per day.}

\subsection{Speciation of emissions in chemical sub-components}

Particulate matter and hydrocarbons are a mixture of several chemical compounds that play an important role in atmospheric chemistry \citep{SeinfeldPandis2016}. VEIN includes speciation profiles for hydrocarbons and particulate matter from \cite{NtziachristosSamaras2016} and \cite{Rafee2015}. These profiles are percentages of the emissions by vehicle type, fuel, emission standard and other characteristics. Also included are speciations of particulate matter in black carbon and organic matter, particulate matter fractions for tire, brake and road wear, non-methanic hydrocarbons and nitrogen oxides.


\subsection{Spatial allocation and data-bases}

VEIN provides functions to generate grids and spatially allocate emissions into grids. This is helpful for visualization and generation of inputs for atmospheric models, and as a tool for urban planning. In addition, VEIN includes functions to produce a database of hourly emissions for vehicular composition by age of use. Section \ref{pe} provides details and examples about the emissions grids and databases.

\section{VEIN model design}

The VEIN model was constructed using the free open source R software \citep{R}.
R is a programming language and environment for statistical computing and graphics \citep{R}. %It is free open source software and the R language itself
It was developed primarily for analyzing data. 
However, since its capabilities have grown over time, R has become a flexible language with many different areas of application. It includes elements of programming language such as Lisp and syntax of S, as described by \cite{Leiner1997}. 

	
    
   The VEIN R package depends on the package \textbf{sp} \citep{Bivandetal2013}, as it uses several of its classes. VEIN imports some functions from the package \textbf{rgeos} \citep{BivandRundel2016}, which is an interface for the Geometry Open Source (GEOS) library (https://trac.osgeo.org/geos/). It also imports functions from \textbf{rgdal} \citep{Bivandetal2016}, which provides bindings to the Geospatial Data Abstraction Library (GDAL; http://www.gdal.org/). Therefore, these R packages must be installed prior to using the VEIN package. 

VEIN started between 2014 and 2016 as a collection of several R scripts, initially named R-EMIssions (REMI; \citealt{IbarraEspinosaYnoue2017_remitap}), which later evolved into an R package. It was developed in R due to the free open source advantages and because R allows easier reproducibility. VEIN is open to scrutiny from its community of users, thus allowing opportunities for user feedback and improvements. This facilitates widespread use of the model and identifying any software bugs/errors, with potential for adding new capabilities. VEIN has its own functions, but it also incorporates other data and functions such as emission factors and mileage.


VEIN can be installed from the Comprehensive R Archive Network (CRAN)  https://CRAN.R-project.org/package=vein or from the website Github https://github.com/ibarraespinosa/vein. In order to use the VEIN library and run the demo, it is necessary to run the following scripts in R:
    \begin{verbatim}
    install.packages("vein") #or
    library(devtools)
    install_github("ibarraespinosa/vein")
    
    library(vein)
    demo(VEIN)
    \end{verbatim}

The diagram process for estimating emissions is shown in Fig. \ref{fig:diagram}. The green circles in this Figure refer to the data and the blue boxes refer to the functions inside the model. The VEIN model diagram starts at the green circle traffic, which represents the morning rush hour traffic data for each street link. Then the \textit{age} functions (\textit{age\_ldv}, \textit{age\_hdv}, \textit{age\_ldv} or \textit{my\_ldv}) determine the vehicular composition by age of use as shown in Eq. (\ref{eq:qvca}). The data \textit{profile} allows to temporally extrapolate traffic data to the other hours and this allows to estimate the average vehicular speed to any hour and link using the function \textit{netspeed}. Emission factor selections start by adding the deterioration effect with the function \textit{emis\_det} into local, speed dependent emission factors from \cite{NtziachristosSamaras2016}, denoted as $speed\_ef$ or scaled emission factors denoted as $scaled\_ef$ in Fig. \ref{fig:diagram}. Besides including speed dependent emission factors from \cite{NtziachristosSamaras2016}, VEIN also includes local emission factors from \cite{CETESB2015}. Once the input data is ready, the function \textit{emis} estimates hourly emissions for each hour of the day, and day of the week. The function \textit{emis\_post} produces an emissions database by vehicle category or by street, denoted as df and street in Fig. \ref{fig:diagram} respectively. These emissions are then speciated with the function \textit{speciate}. At this time, the user can create a grid with the function \textit{make\_grid}, which creates a rectangular grid with format {\tt SpatialPolygonsDataFrame} or a {\tt SpatialGridDataFrame} used to allocate emissions spatially with the function \textit{emis\_grid}. The function \textit{emis\_wrf} reads the emissions grids and creates a data-frame ready to create an input for WRF-Chem model \citep{Grelletal2005}. This data-frame must be exported as a .txt file and could be used as an input into other atmospheric models such as BRAMS \citep{Freitasetal2005}.


\begin{figure}[h]
\centering
\includegraphics[width=17cm]{figures/diavein.png}
\caption{Representation of the VEIN model. Boxes and circles represent functions and data, respectively.}
\label{fig:diagram}
\end{figure} 



\subsection{Functions and classes}    


VEIN uses objects of class \textbf{Spatial} \citep{PebesmaBivand2005}, including {\tt SpatialLinesDataFrame}, to represent road segments. To read geospatial data, there are several packages,

such as \textbf{rgdal} \citep{Bivandetal2016} or \textbf{maptools} \citep{BivandLewinKoh2015}. 
The main requirement is that the network must be a {\tt SpatialLinesDataFrame}, class of \textbf{sp} \citep{PebesmaBivand2005}.

We included several functions to arrange traffic data, select or scale emission factors, as well as estimate and process emissions in VEIN, as shown in Table \ref{ta:functions}. These functions implement the equations shown in Section \ref{s2}.

VEIN incorporates 8 classes (see Table \ref{ta:functions}), which are objects with specific characteristics: methods and units. The methods are print, summary and plot. They are functions that return a specific result depending on each class.  
Another important characteristic of each class is that they include explicit units, in an effort to reduce human errors and improve the usability. For this task, VEIN imports some functions of the package \textbf{units} \citep{units},  which is an interface in the C library \textbf{udunits} from University Corporation for Atmospheric Research (UCAR). Therefore, this library must be installed on the system prior to using VEIN.  
Only the {\tt EmissionFactorsList} and {\tt EmissionsArray} do not show their units explicitly due to limitations with the units package. The classes outlined in Table \ref{ta:functions} are also constructor functions, which means that they can create VEIN classes and add the respective units. 
VEIN incorporate constructor functions to create classes such as  {\tt Vehicles} or  {\tt Emissions}. These functions are incorporated inside other VEIN functions in order that the output of VEIN has a class. When the constructor function are applied to a numeric element, the constructor simply adds the units and the resulting object has class \textbf{units}. For example, applying the function {\tt EmissionsArray} to a numeric vector will add the units $\mathrm{g \cdot h^{-1}}$ to the numeric vector.




\input{tables/tab_functions.tex}
