{'fraction_non_alphanumeric': 0.027387521581637833, 'fraction_numerical': 0.014184637259216629, 'mean_word_length': 4.937688442211055, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Lebanon Solar Rooftop Potential Assessment using Buildings Segmentation from Aerial Images

Estimating solar rooftop potential at a national level is a fundamental building block for every country to utilize solar power efficiently. Solar rooftop potential assessment relies on several features such as building geometry, location, and surrounding facilities. Hence, national-level approximations that do not take these factors into deep consideration are often inaccurate. This paper introduces Lebanon's first comprehensive footprint and solar rooftop potential maps using deep learning-based instance segmentation to extract buildings' footprints from satellite images. A photovoltaic panels placement algorithm that considers the morphology of each roof is proposed. We show that the average rooftop's solar potential can fulfill the yearly electric needs of a single-family residence while using only 5% of the roof surface. The usage of 50% of a residential apartment rooftop area would achieve energy security for up to 8 households. We also compute the average and total solar rooftop potential per district to localize regions corresponding to the highest and lowest solar rooftop potential yield. Factors such as size, ground coverage ratio and PV_out are carefully investigated for each district. Baalbeck district yielded the highest total solar rooftop potential despite its low built-up area. While, Beirut capital city has the highest average solar rooftop potential due to its extremely populated urban nature. Reported results and analysis reveal solar rooftop potential urban patterns and provides policymakers and key stakeholders with tangible insights. Lebanon's total solar rooftop potential is about 28.1 TWh/year, two times larger than the national energy consumption in 2019.


Introduction
Building footprints extraction from aerial imagery is essential for many urban applications, including geographical databases, land use, and change analysis. Fully automated extraction and recognition of buildings' footprints geometries can help estimate the solar potential of every rooftop. Estimating rooftops' solar potential provides more insight into how a given country can efficiently utilize renewable resources for solar power generation. Solar power harvesting paves the way for ensuring a greener future and a better economic status. The first step to accomplish this task is acquiring rooftop geometries that we tackle via satellite imagery analysis and object segmentation.
Segmentation of urban aerial imagery is currently undergoing significant attention in the research community and notable development efforts in the industry. Remote sensing images are usually complex and characterized by significant intra-class variations, and often low inter-class variations [1].
Deep learning significantly reduces the time and cost required for aerial imagery segmentation due to its capabilities in automatically extracting features and patterns present in large scenes. This work uses deep convolutional neural networks to extract rooftop geometries and obtain Lebanon's first complete and comprehensive urban map.
We then use a solar panel placement algorithm that considers the area and morphology of every rooftop to estimate the number of panels that can fit on top. Automated solar rooftop potential estimation is made feasible given the corresponding photovoltaic (PV) power generated per unit of the installed panels.
The contribution of this paper is three-folds: (i) design the first complete Lebanese buildings' footprints map using instance segmentation from satellite images, (ii) present also the first Lebanese solar rooftop potential map by estimating the solar potential of every rooftop morphology, (iii) thorough analysis and insights of solar rooftop potential trends for each Lebanese district.
The rest of the paper is organized as follows: Section 2 shows the literature review related to the use of deep learning models for building footprints detection and solar estimation from aerial images. We present in Section 3 the TUM dataset created for the scope of segmenting Lebanese buildings. Buildings footprints map is discussed in Section 4. Solar rooftop potential assessment approach is presented in Section 5 and associated results are revealed in Section 6. Finally, Section 7 concludes the paper.

Buildings' Segmentation
Several techniques tackle the problem of buildings segmentation from aerial imagery. In [20], the authors use gated graph convolutional neural networks to output a Truncated Signed Distance Map (TSDM), which is then converted into a semantic segmentation mask of buildings. In [15], the authors propose two plug-and-play modules to generate spatial augmented, and channel augmented features for semantic segmentation from satellite images. In [14], the authors use augmentations like slicing, rescaling, and rotations, in addition to GIS data, to improve buildings' footprint extraction. However, a more direct approach is presented in [11] where the authors only use a semantic segmentation network with an additional output mask designating spacing between nearby buildings to separate building instances. Similar to [11] approach, we adopted in this work a multiclass semantic UNet-like architecture, followed by a watershed post-processing step to extract buildings' instances. However, in our proposed method, we introduced a third class which is buildings' borders to separate nearby instances. Indeed, employing an additional buildings' borders class improved F-score considerably with more than 10%. Specific details and discussions about this third class are beyond the scope of this paper.

Solar Rooftop Potential Estimation
Solar Rooftop Potential Estimation is currently drawing the attention of geospatial deep learning researchers due to its effectiveness in accurately predicting the potential usage of rooftops for solar power generation. Significant advances in this field have been made using statistical models, computer vision, numerical analysis, and geographic information systems. In [7], the authors use collected data about the solar radiation and the rooftop areas in Beirut city to estimate solar rooftop potential, without taking into consideration each rooftop morphology. A similar approach was conducted in [17] for a city in India, however the total building rooftop area in the city was estimated based on the building footprint extraction from satellite imagery using deep convolutional networks. In [8], authors use high precision photographic sensors mounted on a UAV to scan and create a digital surface model (DSM) for a single building. Further statistical analysis of the output DSM model, including shading analysis, solar irradiance estimation, and panel placement, was conducted to estimate a single roof's solar potential. In [5], the authors use satellite imagery to divide and segment building rooftops into sections using convolutional neural networks. They predict each section's pitch, azimuth, and shading mask and then use a greedy algorithm to place solar panels on rooftops to estimate their solar potential. A similar approach was adopted in [27] to estimate the solar potential at a city scale in China.
To the best of the authors' knowledge, there is no previous work to estimate the rooftop solar potential at a country scale for Lebanon. The presented work is thus the first attempt to produce Lebanese urban and solar rooftop potential maps. We used a deep learning model to segment rooftops from high-resolution satellite imagery (50cm/pixel).
Unlike the work in [7] [17] which only relies on buildings' footprint area for solar potential estimation, we devise a greedy algorithm to simulate photovoltaic (PV) panels' placement based on each rooftop morphology. Our proposed panels placement algorithm processes regularized buildings' footprints and thus return more accurate results compared to [5] [27].

Dataset Creation
We aim in this research to build an efficient and accurate building segmentation model from Lebanese satellite images. Since neural networks are not guaranteed to generalize well on Out-Of-Distribution (OOD) data, a training dataset covering Lebanese populated areas with accu-rate buildings ground truth labels is needed. Such a dataset does not exist to our knowledge, so we created our own for this project.
The training dataset should hold a representative distribution of building types from all over Lebanon. Thus, we chose the Tyre area since it includes urban, suburban, rural, and slum areas. Tyre city itself is a dense urban city that lies within the outer ring of residential suburbs. Moreover, the chosen area has a refugee camp and vast countryside areas. Hence, the annotated training dataset does well represent the various characteristics of Lebanese areas. A segmentation model trained using this dataset would generalize well to the majority of Lebanese scenes.
We first chose a 35372x28874 GeoTIFF image with RGB channels taken by the GeoEye-1 satellite sensor of 50 cm/pixel resolution covering the Tyre district in the Southern Lebanon. We cropped the chosen area of interest into 1024x1024 chips, resulting in 338 tiles for manual annotation using the VGG-Image-Annotator tool [6]. Finally, we further cropped each tile into non-overlapping 512x512 sized images while preserving each image's relative labeled polygons indices. We used non-overlapping tiles for the training dataset to avoid any redundant data which might cause model overfitting. The final training dataset includes 1,352 tiles of 512x512 dimensions with 10,000 buildings' objects. We refer to this dataset as Tyre Urban Map (TUM) dataset.
TUM has a balanced distribution of tiles with and without buildings (the ratio is roughly (9 : 10)). Figure 1 portrays the number of tiles present in the TUM dataset for each given range of buildings' count. The average count is 28 buildings per tile. Moreover, Figure 1 shows that the tiles are distributed over areas with varying building densities ranging from rural to suburban and urban regions. Thus, the created TUM dataset is expected to generalize well for the different aspects of building land cover distributions present in Lebanon.
As for the test set, we selected 30 areas of interest (AOI) from different Lebanese regions, including Beirut, Saida, Jounieh, Jbeil, and Tripoli. Selected AOI's encompass dense urban regions (Beirut), structured urban regions (Saida), and some rural areas. This diversity would help assess the generalizability of our model over the whole Lebanese territory. It is worthy to note that we addressed, at inference time, the issue of rooftops present at tiles' edges. Test images are cropped into 1024x1024 overlapping chips with a stride value of 512. Segmentation masks are averaged, resulting in smoothly merged buildings' footprints at the edges of the tiles.

Buildings' Footprints Map
This section describes our approach to extracting buildings' rooftop polygons from satellite imagery of Lebanon. We adopt a UNet-like architecture to output semantic segmentation masks of the rooftops. However, semantic segmentation of rooftops is not enough to separate very close buildings. Hence, we also predict semantic segmentation masks for the buildings' boundaries. The building and boundaries masks are post-processed using the watershed algorithm [18] to separate and tag each polygon with a unique identifier. Following this process, we obtain instance segmentation masks.

Model Architecture
UNet [19] is an end-to-end, fully convolutional neural network that serves the purpose of semantic segmentation of input images over multiple classes. It consists of a contracting path [Encoder] and an expansive path [Decoder] with skip connections between symmetrical blocks of identical size. The encoder part is comprised of repeated downsampling convolutional and pooling layers followed by an activation function at every stage (i.e. RELU) to output feature maps of higher semantics and lower resolution. In contrast, the decoder is made up of consecutive up-sampling blocks. Skip connections allow information to flow directly from the low level to high-level feature maps [11]. The overall architecture is a U -shaped encoder-decoder architecture as shown in Figure 2.
The Encoder part of the architecture can be chosen from powerful and deep convolutional neural networks like Residual Nets [10, 25], Inception Nets [22], dual-path nets [4], or the newly introduced Efficient-Nets [23]. In our experiments, Efficient-Net-B3 was found to perform better, in terms of accuracy and variance, than other members of the Efficient-Net family members and other encoders like ResNet34, ResNeXt50, InceptionV4, InceptionResNetV2 and DPN92 as shown in Table 1, where variance is defined as the Fscore difference between the training and validation datasets.The model trained with EfficientNetB3 encoder had the best performance (F score = 84.3%) and  As for the loss function, we chose a normalized weighted sum of losses across all output channels. Each single channel loss is a combination of Dice loss and Binary Cross-Entropy loss [12] in order to leverage the benefits of both. It is worthy to mention that we investigated a combination of Dice loss and Focal loss using EfficientNetB3 and Effi-cientNetB4 backbones. However, no improvement was noticed where EfficientNetB3 F-score was equal to 84.2% and EfficientNetB4 F-score equals 83.6%.

Training Pipeline
All models were trained for 100 epochs using Adam Optimizer [13] and the One-Cycle learning rate policy [21] starting with an initial learning rate = 0.0001 20 and increases for 40 epochs in a cosine annealing manner till it reaches a maximum of 0.0001 and then decreases for the rest 60 epoch in the same annealing fashion. For each experiment, we save weights' file of the best epoch with the highest Fscore on the validation set.
During training, we used mixed precision technique and applied random augmentations. We also used CutMix [26] data augmentation to further enhance our model robustness. We also used inference-time augmentations and employed post-processing to extract instance masks from semantic segmentation. The details of those different steps are beyond the scope of this manuscript. Figure 3 shows the buildings' footprints extraction model in practice applied to Jonieh City in Lebanon, with it's corresponding ground truth building mask (in red) and predicted building mask (in yellow). Finally, we polygonized and regularized the output instance masks to achieve eye-pleasing regular-shape polygons as shown in Figure 4.  . Solar panels fitting algorithm. The algorithm takes into consideration the morphology and the geometry of the roof. Solar panels are greedily placed along the longest axis of the building footprint to maximize the number of panels fitted inside the it's geometry. Panels extending outside the geometry are removed, and the remaining panels are taken into consideration for the solar potential calculation.

Solar Rooftop Potential Assessment
The first step in calculating the solar potential of rooftops is to find how many solar panels can fit on each roof. However, due to the lack of critical information such as rooftops' relative slope and azimuth angle, we assume that all roofs are flat and at an orthogonal angle with the satellite sensor. Other factors like shading are also not considered due to insufficient information on the heights of all buildings in the country. In this work, we assumed a standard commercial solar panel module of dimensions (1x1.98) meters and a nominal power P nominal = 0.4 KWp. To estimate the number of panels that can fit on each rooftop, researchers such as [7] simply normalize the rooftop surface by the panel's area. This approach would result in an over-estimation of the solar rooftop capacity since it does not take the roof's morphology into account.
For the scope of this work, we devise the PV panels fitting algorithm described in Algorithm 1 based on the work presented in [5]. The PV panels fitting algorithm is applied to the regularized buildings' footprints to avoid any segmentation irregularities present at the roof edges. Figure  5 shows a running example of the panels fitting algorithm for a rooftop with extremely irregular shape.
Finally, we use Equation 1 to calculate, SP r , the solar potential of every rooftop r as follows: where N r is the number of panels that fit on that roof, P nominal is the nominal power of the solar panel modules in (KW p), and P V out is the specific photovoltaic power output of the installation in (M W h/KW p). P V out is defined as the amount of power produced per unit of the installed solar panel. In our studies, we used P V out data obtained from the World Bank Global Solar Atlas 2.0 [9]. The acquired data comprise a mapping of yearly averaged P V out values for every 1Km 2 grid tile across the whole Lebanese territory. The P V out heatmap for Lebanon is shown in Figure 6. For every rooftop, we locate the corresponding tile within the P V out map and fetch its relative P V out value in (M W h/KW p). Thus, we base our calculation on a more accurate and precise P V out map than other studies that use fixed P V out values [7].

Results
In this section, we present analysis and results for the solar rooftop potentials on two levels: (i) rooftop level and (ii) district level. At the rooftop level, we reveal that the average roof's solar potential is sufficient enough to cover most of the energy needs of Lebanese households and achieve a sense of energy security. At the district level, we compute the total and average solar rooftop potentials per district and compare these values with the maximum hypothetical capacity of each district.

Household Energy Security
For every rooftop, we fetch its relative P V out value and fit the maximum number of panels. Since we use a greedy algorithm for the solar panels' placement, we then calculate the maximum theoretical solar rooftop potential capacity. Figure 7 shows the PV panels fitting algorithm and solar potential calculation scheme in action for a demo house where 45 panels were placed which corresponds to 30.4398 M W h/year.
In practical situations, fewer solar panels could be placed due to various parameters, including objects usually available on the roof (such as roof tanks and solar water heaters, among others), inclined roof slope, and the requirement of leaving sufficient room for service and emergency access. We multiply the number of fitted solar panels with a Utilization factor U to account for this effect. Although studies in the literature [3] [7] report results for only 50% and 75% utilization factors, for the scope of this work, we experimented with several utilization factors in the following results sub-sections, where U ∈ [0.1, 0.25, 0.5, 0.75, 1].  Figure 8 shows buildings' distribution across solar rooftop potential bins in M W h/year. Those results are computed assuming a 50% Utilization factor, U .

The histogram presented in
Rooftops' solar potential that falls in the range [ Figure 8.
where σ is the sample standard deviation and n is the number of samples.
A recent survey [2] shows that households in Lebanon consume on average 5.41 M W h/year. A low 10% Utilization factor can accommodate an average of 9.747 M W h/year which corresponds to 180% of the average household's electricity consumption per year. Using only around 5% of the roof surface, would allow single-family residences to significantly cut their electricity bills and meet near-net zero energy building (near-N ZEB) targets [24]. And also, sell surplus energy back to the grid and generate additional income, once corresponding energy regulations are updated to allow for net-metering.
Economic crisis and severe inflation witnessed since 2019, made energy security a real concern for Lebanese households. Energy security is defined as the uninterrupted availability of energy sources at an affordable price. In Lebanon, both conditions are not currently met, where most families suffer from long hours of electricity outage daily, while the average electricity bill largely exceeds the minimum wage rate. Assuming a 50% utilization factor scenario, the expected Average Solar rooftop Potential (ASP) of a building is 40.81 (M W h/year), which is equivalent to the average yearly consumption of 7.5 households. Hence, residential apartments can achieve a significant percentage of energy security by relying on rooftop solar energy production.

Urban Solar Potential Factors
Lebanese territory is divided into 26 districts, where each district exhibits its own urban and topographic characteristics. As shown in Figure 6, the specific photovoltaic power output of the installation, P V out values, are not uniformly distributed across districts. A wide P V out gap of more than 500 M W h/KW p is observed between locations receiving the lowest and highest amount of solar irradiation. Hence, rooftops, with the same panel capacity, in different districts, do not produce the same solar rooftop potential.
We calculate total solar rooftop potential in GW h/year for each district using a 50% Utilization factor. We also calculate the average solar rooftop potential in M W h/year using a sliding window of size (surface) 4Km 2 . We visualize those results in Figures 9a and 9b, respectively. Figure  10 is included as a reference figure to show the layout of the Lebanese districts. Figure 9a shows that Baalbeck (2,885 GW h/year), El-Metn (2,014 GW h/year) and Zahle (1,979 GW h/year) districts have the highest total solar rooftop potentials. On the other hand, in Figure 9b, we observe that Baalbeck district is almost uniformly blue, which indicates that it is not well populated. Baalbeck, the largest district with the highest P V out values, is indeed expected to provide the highest total solar rooftop potential. However, El-Metn district's total solar rooftop potential is only 871 GW h/year behind Baalbeck despite being 11 times smaller and witnessing lower P V out values. Baalbeck belongs to the most yellowish region in Figure 9a while being the most bluish one in Figure 9b.
To further analyse those results, we plot in Figure 11 a bubble chart that shows the Ground Coverage Ratio (GCR) [16] for each district. Ground Coverage Ratio, defined in Equation 3, is used to assess the percentage of built-up area in each district: Where A b is the built-up area or the total area of building footprints in a district, and A T is the domain area and for the context of this study, it is defined as the district area.
Baalbeck district has one of the lowest GCR values of 0.73%. EL Metn district on the other hand has 5.4% GCR value, which is 7x larger than Baalbek. This huge difference in built-up area justifies results observed in Figures 9a and  9b.
For the sake of clarity and to further expand this line of analysis, we define the maximum Hypothetical solar potential Capacity (HC i ) of each district i, as the maximum solar potential achievable at district i, if we lay solar panels across the district whole area. HC i is a hypothetical value, where we assume that the district topology is flat. HC i is used in the scope of this work as an indicator to assess the amount of solar potential that can be produced at each district level. HC i values are reported in Table 3.
Baalbeck, Lebanon's largest district, has a maximum hypothetical capacity of 845 T W h/year. However, due to the low built-up area in the region, solar potential cannot be efficiently exploited at the rooftop level. An alternative solution we suggest here is to install large solar farms in Baalabek district to avail solar potentials.

District-Level Analysis
Beirut solar map [7] reports 195 MWp as the nominal capacity of the city for a 50% Utilization factor and 295 MWp for a 75% Utilization Factor. Our findings shows that the nominal capacity of the city is 285 and 427 MWp for 50% and 75% Utilization factors, respectively. The difference is due to the following factors: The capital city (Beirut) and the economic capital (Tripoli) have fairly mid-range total rooftop solar potential with 907 and 516 GW h/year, respectively. These two districts have the most glowing spots on the heatmap shown in Figure 9b and exhibit the highest GCR percentages (27.7% and 13.9%, respectively) as shown in Figure 11.
Being extremely populated areas, Beirut and Tripoli districts have the highest average solar rooftop potential using a sliding window of surface 4Km 2 as shown in Figure 9b. However, if shadowing effects were considered, one would expect lower average solar rooftop potential in these two high-density districts.
Baabda ( Nabatiye (1,430 GW h/year) districts show a large distribution of pink spots in Figure 9b. These districts are midpopulated areas (GCR values between 4% and 6%) with high P V out values between 1,700 and 1,800 M W h/KW p. Using a 50% utilization factor, the total solar rooftop potential is fairly high in these districts and reach 3% to 4% of their maximum hypothetical capacity as shown in Table 3.
Finally, Hermel, Hasbaya, Jezzine, Rachaiya and Bcharre districts experience a blue tone in both Figures 9a and 9b. Average solar rooftop potential in those districts is poorly utilized, with less than 0.7% GCR value. Total solar rooftop potential does not exceed 1% of each district's maximum hypothetical capacity.
We also provide in Table 3 detailed average and total solar rooftop potential for every district while varying the utilization factor from 10% to 100%. Assuming a 50% utilization factor, the total solar rooftop potential for all dis- tricts sums up to 28.1 T W h/year. Whereas Lebanon total energy consumption for the year 2019 (including Electricity of Lebanon, EDL, and private generators) was estimated by our EDL expert contact to be around 12.5 T W h/year. In the last column, we report % T SP HC which constitutes the relative percentage of Total solar rooftop potential (at U = 100% ) with respect to the maximum hypothetical capacity for each district. It is worthy to note that % T SP HC is directly proportional to GCR.

Conclusion
We discussed in this manuscript buildings' footprints segmentation for Lebanon from satellite imagery. We also computed solar rooftop potential using a panel fitting algorithm to produce the first complete solar potential map of Lebanon. Furthermore, we conducted rooftop-and districtlevel analysis to deduce patterns and provide policymakers and key stakeholders with tangible insights to design tailored regulations and future directions. We showed that 5% of the roof surface would be enough to accommodate the yearly electric needs of a single-family residence. As for residential apartments, the average solar rooftop potential using a 50% utilization factor is sufficient to provide up to 8 households with energy security. Baalbek district holds the highest total solar rooftop potential, while Beirut reports the highest average solar rooftop potential. We found that Lebanon's total solar rooftop potential is 28.1 T W h/year assuming a 50% utilization factor, which is more than double the national energy consumption for 2019. Finally, we found that low-populated districts failed to deliver more than 1% of their maximum hypothetical capacity. Large solar farms are highly recommended solutions for Baalbek and Hermel districts to avail the high P V out potentials.
Although our work leverages more accurate estimates of the rooftop potential than previous works for Lebanon, certain improvements can be further conducted concerning the buildings footprint extraction, panel placement algorithm, assessment of the actual roof utilization factor and the P V out map. For instance, in addition to the segmentation masks we can estimate the building heights and the orientation of the points on the rooftops surface. This would eliminate the zero-shadowing and the orthogonal flat rooftop assumptions. Based on the heights, we can take shadowing effect between buildings into consideration. We can also reconstruct a 3D surface of the rooftops given the orientation parameter, which would yield in a better estimate of the total available area of the rooftop, it's morphology and the presence of any obstacles. The panel placement algorithm can be improved by aligning the panels along the direction that maximizes the energy production as done in practice instead of aligning them along the main axis of the rooftop. Rooftop obstacles, best PV panel installation angle, and the spacing between the panels can be also taken into consideration to find the best distribution of the panels for each rooftop. An assessment study to find the actual rooftop utilization factor in Lebanon is essential to report practical figures. Such assessment would require first to generate ground truth labels using either remote sensing or field visits. Finally, the extraction of a higher resolution P V out map is also key to attain more accurate results. Figure 11. Bubble Chart showing the Ground Coverage Ratio (GCR) [16] for each district. The x-and y-axes show each district surface and its corresponding rooftops area in Km 2 , respectively. The bubble size designates the GCR value for each district. Beirut district shows the highest GCR value of 27%, whereas the lowest GCR value corresponds to Rachaiya district with only 0.55%.
[6] Abhishek Dutta and Andrew Zisserman. The VIA annotation software for images, audio and video.