The use of deep recurrent neural networks to predict performance of photovoltaic system for charging electric vehicles

: Electric vehicles are fully ecological means of transport only when the electricity required to charge them comes from Renewable Energy Sources (RES). When building a photovoltaic carport, the complex of its functions must consider the power consumption necessary to charge an electric vehicle. The performance of the photovoltaic system depends on the season and on the intensity of the sunlight, which in turn depends on the geographical conditions and the current weather. This means that even a large photovoltaic system is not always able to generate the amount of energy required to charge an electric vehicle. The problem discussed in the article is maximization of the share of renewable energy in the process of charging of electric vehicle batteries. Deep recurrent neural networks (RNN) trained on the past data collected by performance monitoring system can be applied to predict the future performance of the photovoltaic system. The accuracy of the presented forecast is sufficient to manage the process of the distribution of energy produced from renewable energy sources. The purpose of the numerical calculations is to maximize the use of the energy produced by the photovoltaic system for charging electric cars.


Introduction
Currently, two global trends may be observed and they are also becoming increasingly visible in Poland. The first of *Corresponding Author: Arkadiusz Małek: University of Economics and Innovation in Lublin; Email: arkadiusz.malek@wsei.lublin.pl Andrzej Marciniak: University of Economics and Innovation in Lublin; Email: andrzej.marciniak@wsei.lublin.pl these is the production of energy from renewable energy sources, especially photovoltaic cells. The second trend is electromobility, which is the tendency to drive different types of vehicles with electric motors for the transport of people and goods [1].
Electric means of transport began to appear on the streets at the beginning of the second decade of the 21st century. They have many advantages over their predecessors powered by internal combustion engines. They are quiet because they do not have a noisy internal combustion engine [2]. They are also characterized by a very good driving performance in the form of rapid acceleration which is a result of the torque characteristics of electric motors. Driving electric vehicles is also very straightforward because it does not require the use of a gearbox. In addition, electric vehicles are ecological as they do not emit exhaust gases or other substances into the atmosphere [3]. In the first few years of their presence on the market, electric vehicles were only dedicated to urban driving due to their short range on one battery charge [4]. However, after several years of the development of traction battery systems, they are now able to accumulate enough energy to travel 400 km or more on a single charge. This means that electric vehicles can be used not only for urban driving over short distances but also for traveling between cities and even for longer international journeys.
In order to achieve the free movement of an electric vehicle on short and long routes, in addition to capacious traction batteries, sufficient infrastructure to charge them is required [5]. The most common solution for charging vehicle traction batteries is the use of a low-power on-board single-phase AC charger with a voltage of 230 V. Such chargers have a power of 2 to 7 kW. They most often use Schuko electrical plugs, which are the most common standard in Europe and in many countries across the globe. This is the slowest way to charge a vehicle's battery, but it is the most accessible method for the home, garage or garden of the user. This method is usually used to slowly charge the battery at home during the night or at work during the day. Charging posts with a power output of up to 22 kW are usu-ally used to charge vehicle traction batteries in public areas, they provide a three-phase alternating current to the onboard chargers fitted in the vehicle. These access points to the power grid usually use Type 2 charging terminals that are equipped with charging posts for the vehicles. Fast DC chargers are used for the rapid charging of electric vehicle batteries [6]. This term refers to large stationary chargers, which are converters of alternating current from the power grid into the direct current required to charge the vehicle's traction batteries. With this solution, the vehicle does not need to be equipped with an on-board charger. Fast DC chargers usually have capacities ranging from 40 kW to as high as 150 kW. Fast chargers usually use two charging standards, CCS and Chademo, which correspond to plugs which have a specific shape and current parameters.
Once the appropriate vehicle has been selected, along with the corresponding charging method, the user only needs to provide the electricity required to charge the vehicle. This aspect of vehicle use provides the most evidence of how ecological electric vehicles really are. Electric vehicles are not fully ecological if the electric current required to charge them comes from fossil sources such as coal or natural gas [7]. In this case, the greenhouse gas emissions produced in the process of providing electricity for the electric vehicle will effectively be shifted from its place of use to the place of electricity productioni.e. the power plant. This has one obvious advantage in that the electric vehicle does not emit any harmful substances in the centres of crowded cities. However, for an electric vehicle to be considered fully ecological, the electric current required to charge it should come from Renewable Energy Sources. In recent times, solar power and wind energy have become the most popular RES in the world. In order to generate electricity from the wind, expensive and large-scale infrastructure in the form of windmills is required. Photovoltaic panels are used to produce energy from the sun, they can be mounted on the roofs of buildings, on the ground and even on the roofs of vehicles. Of course, the amount of energy produced will depend on the number of photovoltaic panels installed [8]. Photovoltaic systems are the basis for distributed electricity generation in many European and other countries worldwide. The photovoltaic system is designed to meet the needs of individual farms, buildings or companies. The size of the photovoltaic system depends on the number of electricity consumers at a given location, their peak power requirements and the overall energy demand. An electric vehicle can be than regarded as an electricity consumer and storage location of such an energy generating system.
At present, most photovoltaic systems are built and connected to the existing power grid (on-grid connection). This means that the excess electricity produced by the photovoltaic system can be fed into the power grid. A building powered by such a system also has the ability to draw electricity from the power grid when the photovoltaic system is unable to provide adequate power or when it is not operating, for example, at night. The more expensive solution is an off-grid connection. It does not require the presence of a power grid at all, but it needs expensive stationary batteries capable of accumulating large amounts of electricity. Currently, the batteries used for mobile and stationary applications are very expensive [9]. For example, their cost is about half the cost of the electric vehicle that they power. That is why most photovoltaic systems are currently operating in on-grid mode. The creation and application of effective diagnostic algorithms for monitoring inefficiencies in the operation of the system [10,11] is a big challenge for scientists and engineers involved in the development of photovoltaic systems.
In the second and third decades of the 21st century, both electric vehicles, chargers and photovoltaic systems have become devices in the Internet of Things and Industry 4.0 [12]. They are able to acquire measurement data and use them for performance monitoring and self-diagnosis. They are also able to transfer measurement data to a data cloud for displaying reports and for more advanced on-line and off-line diagnostics. On-line diagnostics are possible because the data can be read in real time. Off-line analysis is also possible due to the collection of large volumes of data in the cloud. Both on-line and off-line data analysis uses advanced algorithms to detect anomalies and optimize the operation of the entire system. As an example, measurement data from photovoltaic systems for the basis the energy management in the bulildings thay supply. In such systems the energy consumers and the chargers must communicate with each other and notify the user of certain decisions. For example, in the area of charging vehicles from Renewable Energy Sources, the user can easily obtain a lot of data that may be used in an advanced way to enhance the the operation of the system, e.g. data concerning the state of charge of electric batteries may be used to predict the range of the electric vehicle before it requires subsequent charging.
As mentioned, electric vehicles may be considered fully ecological when the electricity required to charge them comes from renewable energy sources. If a photovoltaic system exists in on-grid mode, the multiplicity of its functions must take into account the power consumption necessary to charge the electric vehicle. We must also be aware that the performance of the photovoltaic system depends on the season of the year and the intensity of sunlight, which in turn depends on the geographical conditions and cur-rent weather. This means that even a large photovoltaic system is not always able to generate adequate power and the amount of energy required to charge an electric vehicle [13]. The problem discussed in the article concerns the maximization of the share of renewable energy used in the charging process of electric vehicle batteries.
In order to model and predict the performance of a photovoltaic system, it is necessary to thoroughly understand the nature and structure of these processes. Therefore, at the beginning, it is worth making the characteristics of monitoring systems in photovoltaic farms, as was done in the article [14]. So far, many different types of neural networks have been used, employing many different algorithms to predict the power produced by photovoltaic systems. The most important of them include: • gated recurrent unit (GRU) algorithm [14], neural network [29].
In some articles, the prediction of the performance of a photovoltaic system is made indirectly. For example, the article [33] presents an ultra-short-term prediction model for photovoltaic power generation based on dynamic characteristics of the cloud that is sheltering the sun. The comparative analysis of the state-of-the-art techniques for solar power generation I presented in [34]. Recently, many machine learning techniques have been successfully employed in photovoltaic (PV) power output prediction because of their strong non-linear regression capacities. Only some articles show the practical application of prediction methods in practice. In paper [32] was characterized the effect of PV power prediction errors on energy storage system (ESS)-based PV power trading in energy markets.

Research objects
There are two research objects in the article. The first is a photovoltaic carport, whose main function is to generate electricity from photovoltaic panels placed on its roof. The second function is to generate shade for the vehicles parked underneath it. Generating shade is very useful on hot summer days, when the interiors of our vehicles may heat up to very high temperatures. That is why photovoltaic carports often consisting of several hundred or even several thousand photovoltaic panels can be found in warm Mediterranean countries such as Italy. They are usually built in parking lots next to large shopping centres, and provide electricity to nearby buildings as well as shade and electricity for the parked electric vehicles. The second research object is a Renault Twizy electric vehicle, which is charged with electricity from the photovoltaic carport, as shown in Figure 1.

Photovoltaic carport
The photovoltaic carport with a peak power of 3 kWp was constructed in 2016 beside a building in the Lublin Science and Technology Park and to date it has generated over 11 MWh of electricity. The carport consists of 12 monocrystalline photovoltaic panels made with glass-glass technology. Electricity production in individual months and years is shown in Figure 2. In addition to the innovative design of the panels themselves, a noteworthy feature is the energy management system which includes individual energy optimizers mounted on each of the photovoltaic panels. The electricity produced by the carport is managed by an inverter. The inverter used is an Internet of Things device capable of transmitting data to the network. Then, using a dedicated internet platform, the user may visualize and analyze the collected data. Data analysis is possible on-line due to the extensive visualization functions that allow the user to compare the current performance of each panel in the system. This feature is  Figure 3. O ine analysis is also possible due to the function of exporting archived data in a csv format.

Electric vehicle
The other research object is a Renault Twizy, which is the smallest electric vehicle produced by the Renault automotive group. It is a two-seater, four-wheeled car capable of developing a maximum speed of 85 km/h. The vehicle was launched in 2012 and is very popular, especially in Mediterranean countries. The photovoltaic carport was constructed for the purpose of charging the Renault Twizy. The actual power generated by the carport was matched to the power requirements of the vehicle's on-board charger. The data presented in Figure 4 shows that on a sunny day in summer, the vehicle can be charged from the carport even in off-grid mode. The data presented in Figure 4 shows that it is possible to fully charge two Renault Twizy vehicle batteries in one day. The vehicle is equipped with lithium-ion batteries with an energy capacity of 6.1 kWh and on this day (09/06/2019) the carport produced over 22 kWh of electricity. The example shows that the presented instantaneous power of the photovoltaic system is able to cover the power demand for almost two complete battery charging processes of the Renault Twizy electric vehicle. The daily amount of energy produced by the photovoltaic system also exceeds the need to charge the traction batteries twice from 0 to 100% state of charge of the battery (SoC). The research presented in the article is a case study of a photovoltaic system and an electric vehicle. Based on this case study, the authors intend to develop a system for managing the charging of an electric vehicle fleet with energy from a photovoltaic system. The system can then be universal for photovoltaic systems with different peak powers and electric vehicles with different battery capacities and different charging powers.

Plan of the experiment
The aim of the research activity concerns utilization of data stream generated by monitoring system of the photovoltaic plant. The data flow diagram is shown in Figure 5. Data stream contains time stamped instant power generation and produced energy as consequence. The well-known method (RNN LSTM) and algorithms of deep neural network predictor was used. Predictions of energy production are needed for Energy Management Systems. 24 hours forecast and requirements of the energy amount for charging of electric vehicle will be used for maximization energy utilization form Renewable Energy Resources. Design of Energy Management Module will be the aim of our next paper.
The aim of the article is to forecast the performance of a photovoltaic system in order to optimize the process of charging electric vehicle batteries with electricity from this system. The main purpose of the control is to maximize the use of energy from the photovoltaic system and thus to min-imize the energy drawn from the power grid. Energy from a photovoltaic system is clean energy, while energy from the grid usually in Poland comes from coal. Another benefit of charging electric vehicles with energy from RES is its price. After a 5-10 years payback period for the construction of a photovoltaic plant, the user practically gets energy for free.

Predictive modeling
In the rest of this article we present application of deep recurrent neural networks for modeling future energy production from the solar power plant introduced in the previous sections. We start with a description of the data and the modeling methodology. Next, we provide a summary of the conducted experiments and give the evaluation results.
In the final section we present the conclusions and outline further research and experiments.

Data Analysis
For constructing and evaluating the predictive models we used solar power output data collected from the power   As the first preprocessing step we compress the data by averaging the power output values recorded in a single hour which yields the total of 30,655 aggregated data points.
From the distribution plot of the raw data in Figure 6, we can see that it is stationary (also confirmed with Dickey-Fuller Test at p=0). The statistical properties of the data (or the process which generates it) do not change over time as the rolling mean (computed with the 24 hour window) and standard deviation remain stable year by year.
Another characteristic of the data which we can observe from the box plots in Figure 6, which present monthly and hourly fluctuations, is that it exhibits mild seasonality. The generated power output is lowest in the winter months and at night and higher in the summer months and during the day.

Modeling Methodology
Building a predictive model for time series data can be framed as a supervised Machine Learning (ML) problem, where the model is first trained on the known historical data and then applied to predict the future data. To construct training instances we can take an arbitrarily long sequence of past observations as the input variables X and select a future time step as the target variable y. A machine learning algorithm will then learn the mapping function from the input to the output: y = f (X). The specific task of predicting the energy production can be further formulated as a regression problem since the target variable y is a real number.
Recurrent Neural Networks (RNNs) with memory cells have been demonstrated to be especially suited for such formulated prediction problems [36][37][38] due to their ability to handle temporal dependencies between data. Traditional RNN architectures [39] suffer however, from the vanishing and exploding gradient problems when applied to very long sequences [40,41].
The Long Short-Term Memory (LSTM) cell was proposed by Hochreiter and Schmidhuber [42] as a solution to this vanishing and exploding gradient issues through the introduction of two separate states: the hidden state corresponding to the short-term memory component and the cell state corresponds to the long-term memory. It also adds a gating mechanism comprising of the input, forget and the output gates so that during training the network can choose which input observations should be preserved and which can be dropped.
RNNs with LSTM units have become a de facto standard neural network architecture for modeling different types of time series problems, such as forecasting stock prices [43,44], water quality prediction [45,46] or traffic speed prediction [47]. Similar RNN-LSTM architectures have also been used for the related task of anomaly detection where any deviation from the normal behavior of the time series, as predicted by the model, is considered an anomaly [48,49].
In the remaining sections we present the experiments building and evaluating the predictive model for solar energy production using Long Short Term Memory RNNs.

Train-Test Split
To follow the standard machine learning methodology, we split the available data into two sets, taking the measurements from years 2016 -2018 for model training and using the data from 2019 for testing. Hence, we simulate the future application where the available historical data will be used to construct the model which we will be then run on the new unseen data generated in the future. This should guarantee that any changes in the data distribution which have occurred most recently will be reflected in the evaluation.

Feature Extraction
We further preprocessed the raw data points to generate the actual targets which the model should learn to predict and the features to be used for training. As discussed, the raw measurements obtained from the power plant represent power output of the solar plant in watts (W) and arguably they do not constitute useful targets for prediction. Instead we used the power measurements to calculate the energy production in kilowatt hours (kWh) in 6-, 12-and 24-hour time windows. Using those as targets, the model would learn to predict how much total energy will be produced in the future which is more important from the practical standpoint as the operators of the power plant would be able to better plan its allocation to different applications.
In addition to the produced energy features we extracted temporal features such as quarter, month and hour from the actual dates of the measurements. The role of these features was to identify those characteristics of the measurements which impact the data seasonality.
A snapshot of the data with all the extracted features from a single day (6am-6pm) is presented in Figure 8. We can see that as the values for the hourly power output (power_1h_w) and the produced energy in the 6 and 12 hour windows (energy_6h_kwh, energy_12_kwh) fluctuate, the total 24 hour energy production (energy_24h_kwh) stays fairly stable as it is not affected by the time of the day.
On the other hand, if we compare the distribution the 24 hour energy production for different quarters of the year (cf. e.g. 1st and 2nd quarter of 2017 in Figure 9) we can see strong seasonal fluctuations with relatively stable periods spanning several days in a row.

Instance Generation with Rolling Time Windows
To train and test the ML models we extracted instances from the respective train and test sets using the rolling window approach (Figure 10). For each time step t i , we defined a look-behind window of t i−48 past observations and lookahead windows of t i+6 , t i+12 , t i+24 future observations. The specific length of 48 hours was selected empirically; extending it even further back brought no extra gain at the cost introducing more parameters to be trained and increasing the model training time. Hence, we would use the observations from the past 48 hours to predict targets for the different scenarios corresponding to the future 6-, 12-and 24-hour energy production.

Experiments
For each of the three prediction scenarios with targets corresponding to the energy production in the 6-, 12-and 24-hour time windows we conducted a series of 3 experiments using different sets of features for the past observations. The goal was to find out how the availability of different information affects the quality of the predictions.

Feature Variant 1
In this baseline experiment we trained the model with only one feature corresponding to the target used for the particular scenario. E.g., for predicting the 6-hour target, we would only use the information about previous 6-hour energy production for each of the past 48 steps used as the model input.
Feature Variant 2 Energy production in larger time windows is not sensitive to most recent weather changes which may impact future energy production. Hence we extended Feature Variant 1 to include the hourly power output as an extra feature indicating the most recent fluctuations in the generated power. The hourly power output can be regarded as a proxy for the weather features which we do not use in the experiments described here.

Feature Variant 3
In this experiment we used the features from Feature Variant 2 together with the temporal features indicating quarter of the year, month and hour, which account for the seasonal and daily variations in the energy productions.
To make the numerical features and the target values better suited for neural network training we further rescaled them using min-max normalization method. We also encoded the temporal features as one-hot vectors [50]. For evaluation all the predicted results were unscaled.
We also experimented with different lengths of the lookbehind windows, starting with 24-hour windows and extending them to 48, 72 and 96. We found that no gains resulted from using more than 48 past observations as the input to the training process and settled the length of the For each scenario and feature variant we trained and evaluated multiple RNN-LSTM topologies with different numbers of LSTM layers and units, using Rectified Linear activation functions (ReLU). Training was done with Adam optimization algorithm [51]. We found that for variant 1 (single feature for each past observation) and variant 2 (2 features for each past observation) a single hidden layer with 32 LSTM units yielded best results and for variant 3 (with multiple temporal features added for each past observation) best results were obtained using 2 LSTM layers with 64 units each. These findings were consistent for all prediction scenarios. To avoid overfitting, we also added dropout (0.2) after each LSTM layer.

Results
To evaluate the performance of different models we used two metrics commonly applied to measuring real-valued predictions, Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE): Both MAE and RMSE preserve the units of the expected outcomes. MAE is robust to outliers and can be interpreted as the model bias. RMSE on the other hand takes the square of the errors and puts a heavy penalty on outliers. Table 1 summarizes results of the best models for different scenarios and feature variants, reporting the MAE and RMSE metrics and the model topology.
We can see that the variant 3 with temporal features outperforms variants 1 and 2 but the biggest drop in the error metrics (MAE and RMSE) occurs between variants 1 and 2, after adding the hourly power output as a feature. We can think of this feature as providing the local context reflecting the recent changes in the produced energy, due to e.g. differing weather conditions. The temporal features on the other hand which account for the further error drop between variants 2 and 3 provides both local daily context (hour) and annual context (month and quarter). We can also see that the reported root mean squared error is consistently higher than the mean absolute error, which indicates that the models make big errors for a smaller number of cases which can be seen as outliers. Both RMSE and MAE are of comparable magnitudes but RMSE penalizes larger errors more heavily.
We can indeed observe this in Figures 11, 12 and 13 which present prediction snapshots for 6-, 12-and 24-hour time windows for a single month of July, 2019. We can see that the 6-hour predictions ( Figure 6) look fairly accurate except for two time windows, on June 1 and between June 10 and June 12, where the actual recorded energy production values are unusually low and the predicted values are much higher resulting in large prediction errors. Cases where the actual values are low can be regarded anomalies and we can see that the same predictive model could also be used for the task of anomaly detection. We can presume that the drop in the actual energy production for those time windows was due to the unfavorable weather conditions. It is still interesting to observe that even though the model failed to predict that the energy output would drop so low, it still managed to forecast that some lowering would occur -the predicted values for those days are lower than before and afterwards. Since we did not use the explicit weather features for training the models we can conclude that the hourly power output which we assumed would  work as a weak proxy for the weather features did partially work. Similar patterns can be observed for 12-hour (Figure 12) and 24-hour predictions ( Figure 13). We see drops in the actual energy production for the same days as with 6-hour windows which the models cannot predict. We also see smaller but consistent errors for other days, where the models either overestimate or underestimate the future energy output and this is especially evident for the 24-hour predictions. We can conclude that longer term prediction is evidently more difficult. It also seems that the information about the recent hourly power output helps the model for shorter term predictions (in our case for 6-hour windows) but would fail for longer forecasting. To be able to predict that the energy production will drop in times windows as long as 12 or 24 hour we would need true weather features for the look-behind observations and weather forecasts for the look-ahead periods.

Discussion
The presented experiments and the results show that modern predicting techniques for time series data, based on deep neural nets, can be applied to the problem of predicting future solar energy production. For those modeling techniques to find practical applications they would have to be closely integrated with the monitoring infrastructure of the solar panel plants so that the predictive models could be continuously trained on any new available data and then evaluated in real time. Also, as indicated in the previous section, the system would largely benefit from access to the historical weather information as well as the future forecasts which could be used as features for model training and execution [51].
The key problem that we notice is the randomness of the process introduced by the external weather factor which cannot be easily handled by improving the actual modeling techniques or the amount of the training data. This is not a problem which can be handled by a more complex DNN architecture, e.g. combining CNNs with LSTMs which benefits text processing/analysis tasks is in our view unlikely to improve the prediction for the current task.
In the paper we discuss this problem and propose the use of contextual features indirectly indicating the seasonal and local weather fluctuations esp. the recent drops in the hourly power output. We show that introduction of such features combined with the increased depth of the RNN does improve performance for time periods with imperfect weather conditions. In future publications we will compare the efficacy of these proxy weather features with the actual weather features coming from the weather forecasts and historical weather details.
We also intend to run more experiments with combining models for different time windows, so that models for making longer term predictions, e.g. 24 hours could utilize the outputs from shorter term predictions, e.g. for 6 and 12 hours. For the current paper, the selected look-ahead windows which specify the prediction horizons only serve as an illustration. In practice, they should be determined by the requirements of the PV management system. As for the lengths of the look-behind windows, it definitely makes sense to closely couple the lengths of look-behind and lookahead windows. To predict the immediate future (e.g. for the next 6 hours) the very recent context with higher granularity (i.e. the last few hours or even minutes if available) seems more important than the longer term history. On the other hand, for future predictions spanning multiple days, any fluctuations occurring in the last few hours probably carry relatively low importance. Also, even if the number of look-behind time-steps does not affect the size of the models (i.e. the number of parameters to be trained stays the same) it definitely impacts the training and execution times and lowering it for short-term prediction models would be definitely beneficial. A simple approach would be to equate the size of both windows but more experiments are needed for that.

Conclusions
Electric vehicles began to appear on the streets at the beginning of the second decade of the 21st century. They have many advantages over their predecessors powered by internal combustion engines. Electric vehicles are fully ecological means of transport only when the electricity required to charge them comes from Renewable Energy Sources.
The aim of the article was to forecast the performance of a photovoltaic system in order to optimize the process of charging electric vehicle batteries with electricity from this system. The main purpose of the control is to maximize the use of energy from the photovoltaic system and thus to minimize the energy drawn from the power grid. Energy from a photovoltaic system is clean energy, while energy from the grid usually in Poland comes from coal. Another benefit of charging electric vehicles with energy from RES is its price.
After a 5-10 years payback period for the construction of a photovoltaic plant, the user practically gets energy for free.
Based on data stream from the photovoltaic performance monitoring system, it is possible to predict the system performance one day and even one week in advance. This way, the user of an electric vehicle can find out how much of the energy needed to charge the vehicle's battery comes from the photovoltaic system. The accuracy of the forecast can be sufficient to manage the process of the distribution of the energy produced from Renewable Energy Sources. The purpose of the prediction is to maximize the use of the energy produced by the photovoltaic system for charging electric cars.
The authors intend to continue the ongoing research. We believe that more research is needed on training predictive models for not just one but multiple solar panel plants having different peak power and located in different geographical locations with differing weather conditions. Such a system could be trained to predict the total energy production of all plants in different time windows so that it would be robust to local weather fluctuations or operation failures in individual locations.