The potential of agroforestry to buffer climate change impacts on suitability of coffee and banana in Uganda

Coffee, an important global commodity, is threatened by climate change. Agroforestry has been considered as one option to maintain or enhance coffee production. In this study, we use a machine learning ensemble consisting of MaxEnt, Random Forest and Boosted Regression Trees to assess climate change impacts on the suitability to grow Arabica coffee, Robusta coffee and bananas in Uganda by 2050. Based on this, the buffering potential of Cordia africana and Ficus natalensis, the two commonly used shading trees in agroforestry systems is assessed. Our robust models (AUC of 0.7–0.9) indicate temperature-related variables as relevant for Arabica coffee suitability, while precipitation-related variables determine Robusta coffee and banana suitability. Under current climatic conditions, only a quarter of the total land area is suitable for growing Ara-bica coffee, while over three-quarters are suitable for Robusta coffee and bananas. Our results suggest that climate change will reduce the area suitable to grow Arabica coffee, Robusta coffee and bananas by 20%, 9% and 3.5%, respectively, under SSP3-RCP7.0 by 2050. A shift in areas suitable for Arabica coffee to highlands might occur, leading to potential encroachment on protected areas. In our model, implementing agroforestry with up to 50% shading could partially offset suitable area losses for Robusta coffee—but not for Arabica coffee. The potential to produce valuable Arabica coffee thus decreases under climate change and cannot be averted by agroforestry. We conclude that the implementation and design of agroforestry must be based on species, elevation, and regional climate projections to avoid maladaptation.


Introduction
Coffee is an important cash crop grown by over 25 million smallholder farmers globally in over 70 countries across the tropics (FAO 2015).There are 124 known coffee species (Davis et al. 2019).However, just two (Coffea Arabica L and Coffea canephora Pierre ex A.Froehner), known as Arabica and Robusta, are mostly commercially produced and traded on a global market (Jayakumar et al. 2017).Arabica that originates from the southwestern Ethiopian highlands (Anthony et al. 2002;Steiger et al. 2002), accounts for a relatively higher share (70%) of world production and is used to make fine and highquality coffee blends (FAO 2015).Despite the superior quality, flavour profiles, and aromatic nuances, the production costs for Arabica coffee are relatively higher due to the unique soil and climatic conditions, primary production and crop management, including numerous pests such as coffee leaf rust and berry diseases (Van der Vossen et al. 2015).It is mainly grown on higher altitudes above 600 m and is well suited in temperatures ranging between 18-21 °C.Temperatures above 23 °C after fruiting often lead to early fruit ripening, compromising the bean quality (Camargo 2010).On the other hand, Robusta is native to the tropical understory forests of Africa, where it still exists in the wild (Davis et al. 2006).The species is grown at lower altitudes and is more resistant to harsh weather, pests and diseases.Robusta coffee can survive in higher temperatures of up to 30 °C, but its optimal range is between 22 and 28 °C, above which the bean quality and yield deteriorate (Kath et al. 2021).However, this species is also affected by intra-seasonal temperature variability, especially during critical phenological stages such as flowering (Kath et al. 2023).
Coffee is particularly susceptible to climate change impacts such as extreme temperatures (DaMatta and Ramalho 2006).Though climate change impacts on coffee primarily affect the production stage, production shocks will propagate through the whole value chain (Laderach et al. 2010).At the production stage, studies have shown a possible reduction in the area suitable for coffee growing on a global scale (Bunn et al. 2015;Gruter et al. 2022;Läderach et al. 2016;Magrach and Ghazoul 2015;Ovalle-Rivera et al. 2015).Coffee yield will also be highly affected as fluctuations in temperature and precipitation, especially during the growing, blossom and backing stages affect flower bud development (Jayakumar et al. 2017;Kath et al. 2020Kath et al. , 2023)).In addition, rising temperatures accelerate ripening before proper maturation, affecting the beans' size, and quality (Ahmed and Stepp 2016;dos Santos et al. 2015).The change in precipitation patterns and global mean temperature also exposes coffee to increased pest and disease incidence (Ziska et al. 2018).Such climate-related risks pose a significant concern for the future supply of coffee, given the ever-increasing demand partly driven by a rising population and higher incomes (Torga and Spers 2020).The CO 2 enrichment in the atmosphere might initially enhance coffee production and increase yields (DaMatta et al. 2019).However, whether this effect will offset the negative effects associated with climate change or affect bean quality remains elusive.
Banana (Musa sp) is an important food crop for many tropical countries and the East African great lakes region in particular (Heslop-Harrison and Schwarzacher 2007).In Uganda, it is consumed by over 7 million people and contributes substantially to food and nutritional security (Nyombi 2013).The flowering and fruiting patterns are synchronous, thus allowing farmers to harvest throughout the year.For coffee-based systems, intercropping bananas with coffee has proved to increase farmers' incomes by up to 50% compared to coffee mono-cropping systems (van Asten et al. 2011).However, the banana plant is susceptible to drought (Nansamba et al. 2020).Studies have shown a potential 50% reduction in yield in major banana-producing regions by 2050 due to climate change (Varma and Bebber 2019).This has strong food and nutritional security implications and crop diversification potential for coffee-banana-based systems.To meet the increasing coffee demand and maintain banana for food security amidst the vagaries of future climate, farmers must adapt accordingly.
The extent of adaptation depends on the projected severity of climate impacts (Bunn et al. 2019;Rickards and Howden 2012), and different adaptation mechanisms have far-reaching effects and limitations.For example, land availability limits shifting to new areas and might create conflicts with alternative land users (Magrach and Ghazoul 2015).The complex land tenure systems also limit the level and type of adaptation strategies adopted by farmers (Murken and Gornott 2022).Opening new agricultural fields poses a risk of encroachment on protected areas and fragile ecosystems (Ahmed et al. 2021;Magrach and Ghazoul 2015).An adaptation measure frequently recommended is changing to varieties that are more resistant to climate extremes and the associated consequences, such as increased pests and disease prevalence (Pham et al. 2019).However, this is limited by cultural and economic constraints towards new varieties, given that coffee is a long-term crop and, therefore long-term investment.The diverse projected impacts of climate change on coffee systems call for a multipurpose ecologically diverse adaptation measure.Agroforestry could be such an option, having been identified as a low-cost measure with a wide range of applicability and functions (FAO 2007).
Agroforestry refers to a land use system involving perennial woody species, crops, and animals on the same land (FAO 2007;Nair 1993).In coffee systems, agroforestry can play a vital role by the modification of microclimate (Merle et al. 2022;Sarmiento-Soler et al. 2019), increasing soil moisture (Brenda 2010), soil nutrient cycling (Barrios et al. 2012), and enhancing biodiversity including pollinators (De Beenhouwer et al. 2013;Jha and Vandermeer 2010).For farmers, agroforestry systems can provide additional income and enhance food availability and diversity by harvesting fruits and vegetative parts of different tree species (Rice 2011).
In the face of climate change, agroforestry's microclimate regulating function may become vital.Shading by agroforestry trees reduces the amount of incoming radiation, buffering crops from extreme weather and reducing soil evaporation, thereby sustaining soil water availability for longer (Kanzler et al. 2019;Stigter 2015).In addition, agroforestry systems' microclimate regulation enhances soil macrofauna and soil fertility (Martius et al. 2004).However, extreme temperature associated with prolonged droughts limits agroforestry functionality and could foster soil water competition that is detrimental to crops compared to full sun systems (Abdulai et al. 2018).The microclimate regulation effect in coffee systems can potentially buffer coffee suitable area losses (Gomes et al. 2020) and increase coffee yield and quality (Somporn et al. 2012).In addition, shading stabilizes production between the years by reducing the biennial yield patterns (DaMatta 2004).Sensory attributes such as fragrance, acidity, and sweetness are also affected by shading, though the effect differs across altitudes (Bosselmann et al. 2009;Muschler 2001).Despite the numerous positive effects, negative impacts might also occur and have been reported mainly due to over-shading (Piato et al. 2020), which might additionally foster the spread of pests and diseases (Avelino et al. 2020).Shading slightly increases night temperatures, leading to heat conservation, which is detrimental especially to Arabica coffee (Craparo et al. 2015).The high night temperatures deactivate the phytochromes turning into thermoreceptors hence restricting coffee plant growth (Craparo et al. 2021).Coffee shading systems vary across regions and sites, with dense systems exceeding 50% (DaMatta 2004;Koutouleas et al. 2022;Piato et al. 2020).To optimize production, a shading not exceeding 50% is recommended, as more would cause yield and quality penalties (Bosselmann et al. 2009;Charbonnier et al. 2017;Durand-Bessart et al. 2020;Soto-Pinto et al. 2000).However, climate change makes it unclear whether this threshold still applies.The decline in yields due to over-shading is attributed to several factors, including high vegetative growth stimulation rather than flower buds, fewer nodes and flower buds formed per branch and lower carbon assimilation (DaMatta 2004).Agroforestry systems should therefore be properly designed to increase the adaptation potential and avoid maladaptation.
In Uganda, the 8th global leading coffee producer and second largest coffee exporter in Africa, studies have projected adverse effects of climate change on coffee production.For example, a study by Mulinde et al. (2022) projects a decrease of 64% in marginal areas for coffee and banana areas by 2050, while Wichern et al. (2019) projected a shift in the area suitable to grow coffee to highlands above 1000 masl.Similarly, regional studies project a decrease in area suitable for growing coffee across Uganda, e.g.(Jaramillo et al. 2011;Jassogne et al. 2013).Bunn et al. (2019) argues that to sustain coffee production in Uganda, 60% of the areas will require complete system redesigning (e.g.introducing varieties from other regions), while 30% will require systemic change (e.g.switching from Arabica to Robusta coffee).All the above studies acknowledge agroforestry as a possible adaptation strategy.However, the extent to which agroforestry can buffer climate change effects on coffee remains uncertain.The shading effect is determined by the agroforestry tree species, age, crown cover, field design, and planting density.The ability of agroforestry species to buffer crops against climate change effects also depends on tree resilience extreme weather conditions (de Sousa et al. 2019;Ranjitkar et al. 2016a) hence the need to assess the area suitability of individual agroforestry trees as a first step to making good choices regarding species-site.Therefore, in this study, we assess agroforestry's potential to buffer coffee systems against climate change effects.The study starts by exploring the suitability to grow coffee and bananas in Uganda and how this will change by 2050 under two emissions scenarios.Secondly, the suitability of two widely used agroforestry tree species (Ficus natalensis and Cordia africana) across Uganda is assessed, along with its changes by midcentury under the same emission scenarios.Thirdly, the buffering potential of the agroforestry species is evaluated in two ways: (1) by the potential shift in climate envelopes of agroforestry species relative to climate-affected coffee areas and (2) by the micro-climate regulation function of agroforestry systems.To give an insight into food and income diversification potential within coffee-growing regions, the effect of climate change on the areas suitable for the coffee-banana intercropping system is also assessed separately.

Study area
Uganda is an East African landlocked country located between 4° North to 1° South and 29.5°West to 35.5° East.The elevation is mostly plateau (average 1000 m a.s.l), with the lowest point at 500 m a.s.l and the highest point at 5110 m a.s.l (Fig. 1).The annual precipitation ranges between 500 and 2800 mm, with an average of 1600 mm.The rainfall regimes are differentiated by region where northern part of the country receives a unimodal rainfall cycle, with the rainfall season between March and May while the southern, western, central and eastern parts of the country receive a bimodal rainfall cycle characterised by two seasons (March-May, and September-October).Between the two rainy seasons is a dry season in which little or no precipitation is received and temperatures peak.(Majaliwa et al. 2015).Agriculture occupies 75% of the total land area.This percentage has stabilized in 2010 after strong expansion between 1965 and 2009.On the contrary, forestry areas have declined sharply from 18% in 1990 to 11% in 2020 (WorldBank 2020), pointing to a potential encroachment on natural forests to increase agricultural land.

Coffee production areas
Crop presence points for the years 2005-2020 were obtained from the Global Biodiversity Facility (GBIF) (www.gbif.org) and literature.The points were validated by spatially comparing them against yield datasets from the Uganda Bureau of Statistics database.The datasets were merged and cleaned (see supplementary material).The spatial distribution of coffee presence points is shown in Fig. 1.

Climate and environmental data
The study used climatic, soil pH and topographic variables (Table 1).The climatic and elevation variables were obtained from the WorldClim database (Hijmans et al. 2005) at a 2.5 arcminute spatial resolution.The climate dataset is already bias-adjusted using the delta method, employing a baseline derived from historical WorldClim datasets constructed using observational weather data from over 47,000 global weather stations from 1950 to 2000 (Bunn et al. 2015;Chemura et al. 2021;Ovalle-Rivera et al. 2015).This database contains 19 bioclimatic variables representing the annual and interseason variation in temperature and precipitation that are agronomically relevant for crop production.The data set is preferred due to its fine resolution, which makes it best for suitability modelling for small areas such as Uganda.The soil pH data was obtained from ISRIC database (Hengl et al. 2015)  Vol:.( 1234567890) CNRM-CM6-1).Since climate models differ in their seasonal and inter-annual prediction of precipitation in East Africa (Otieno and Anyah 2013), the GCMs have been chosen based on recommendations by Ayugi et al. (2021), Ngoma et al. (2021) and Ongoma et al. (2018a) as the best-performing models for projecting precipitation and temperature over Uganda.Two climate scenarios, SSP2-RCP4.5-representingthe medium emissions scenario and SSP3-RCP7.0representingthe high emissions scenario, were used.

Suitability model set-up and evaluation
Crop suitability refers the level of appropriateness of a given area to support the production cycle of a specific crop and meet the target output given the climatic and biophysical characteristics (Chemura et al. 2020;Møller et al. 2021).It is a concept widely used to understand the effect of climate change on agriculture and has been used as a contribution to the recent IPCC 6th assessment report (IPCC 2022).It has been applied for Robusta and Arabica coffee (Pham et al. 2019), bananas (Ochola et al. 2022;Ranjitkar et al. 2016b;Sabiiti et al. 2018) and agroforestry trees (de Sousa et al. 2019;Lima et al. 2022;Ranjitkar et al. 2016a).In this study, we used an ensemble of three machine learning algorithms, including maximum entropy (MaxEnt), random forest (RF), and boosted regression trees (BRT), to model the suitability of each crop.The use of single models sometimes gives divergent results in terms of climate envelopes of species; confer e.g.(Pearson et al. 2006;Thuiller et al. 2004).Ensemble models offer better predictions by combining numerous algorithms, boosting the model performance and reducing erroneous predictions (Breiner et al. 2015;Hao et al. 2020).A species distribution model was set up in the R environment (R Studio Team 2020).A correlation analysis was performed between the 21 variables aggregated over each grid cell to eliminate collinear variables before running any of the three suitability models.Variable elimination was done using the variable inflation function (VIF), and for highly correlated variables (r > 0.9), only one variable was included (see supplementary material).The presence points dataset for each crop was systematically partitioned, where 70% of the data were randomly allocated for model training, while the remaining 30% were reserved for model evaluation.This partitioning process was executed iteratively across multiple runs, reflecting a deliberate and repetitive subsampling approach.Pseudo-absence (background points without crops) were randomly selected at a ratio of three times the number of presence points for each crop (Phillips et al. 2009) using the subsampling method, ensuring that no actual presence points were taken as absence points.These points are required for model construction, representing those areas where the species are assumed absent and therefore capture the background and environmental data (Liu et al. 2011).An ensemble model combining the three algorithms was used to derive the suitability index using the weighted averaging method and the AUC as the evaluation statistic (Eq.1).Notably, the contribution of each individual model to the ensemble was determined based on its respective AUC score, reflecting the discriminatory power of each algorithm in the final model.A confusion matrix (Visa et al. 2011) was used to show model accuracy and performance using the spatial production allocation model (SPAM) yield data sets as a reference (International Food Policy Research Institute 2019).We calculated the relative variable importance of different variables towards model building (see supplementary material, Fig. SI3).
The model produced suitability maps with index ranges of 0-1, which were classified into two formats.First, we binned the suitability values into four categories by applying quartile splits (< 0.25, 0.25-0.5,0.5-0.75,> 0.75 for unsuitable, marginal, suitable and highly suitable, respectively) (Fig. 3) as in (Chemura et al. 2020).This was done to show the spatial ranges of appropriateness of producing each crop.Secondly, we classified the maps into suitable and unsuitable areas (supplementary material, Fig. SI7).We used the threshold at which the model maximizes the sum of specificity and sensitivity (Chemura et al. 2021;Liu et al. 2011) there by maximizing the ability of the model to predict the actual positives and negatives.This classification is vital for precisely calculating changes in areas suitable for each crop due to climate change.
Equation 1: Formular for deriving the ensemble suitability model by the combination of Maxent, Random forest and Boosted regression trees, where E is the ensemble model and M is the individual model.

Assessment of climate change impact on coffee and bananas
By replacing the current climate with the projected climate in a model, we calculate the effect of climate change on an ecosystem assuming soil conditions and management practices remain constant (Chapman et al. 2020).Therefore, the bioclimatic variables used were replaced with the projected future climate data in 2050, represented by five GCMs and the two emissions scenarios (see "Climate and environmental data" above) (Fig. 2).

Coffee-Banana intercropping
The area suitable for coffee-banana intercropping was derived by overlaying the suitability maps of the two individual crops using a method described by Chemura et al. (2020).The intersection of the different layers was used to distinguish pixels where the area is suitable for a combination of coffee and bananas.This was repeated for future climate scenarios to show possible impacts of climate change on the suitable area.The physiological interactions between coffee and bananas were not considered since there were not enough data available for model input.However, this interaction is vital and could give a clear picture of the potential of this intercropping system.The consideration of limited shading imparted by banana plants to juvenile coffee plants was omitted in this analysis, owing to the heightened susceptibility of banana crops to temperature extremes, which might nullify the shading effect of bananas in exactly those times when it would be most useful for coffee plants.

Potential of agroforestry to buffer climate change effects
To model the buffering potential of agroforestry on the suitability to grow coffee, the representative trees suitability was modelled first to show their most suitable climate envelopes.Two agroforestry tree species were selected: Cordia african and Ficus natalensis.The agroforestry tree species occurrence points were obtained from literature (Gram et al. 2017;Gwali et al. 2015;Masters 2021;Nampanzira et al. 2015;Ojelel et al. 2015;Sebuliba et al. 2021), the World Agroforestry database (https:// world agrof orest ry.org/ tree-knowl edge/ type-of-resou rce/ tree-datab ases) and the GBIF.The data from literature were geo-referenced using Google Earth Pro to get the actual presence of the respective tree species, by creating points to mark the center of the reported district or subcounty.To assess the buffering potential of the two species against climate change effects on coffee, two frameworks were used (Fig. 2).
Framework 1 considers the potential effect of climate change on the suitability of individual agroforestry trees (de Sousa et al. 2019;Lima et al. 2022;Ranjitkar et al. 2016a).The climate envelopes for these agroforestry species are compared with the areas where a potential loss in the suitability to grow coffee has been projected to identify whether the agroforestry tree species are potential agroforestry candidates.This is done by overlaying the suitability maps of individual agroforestry species with those of projected changes in the suitability to grow coffee to identify the overlaps (Chemura et al. 2020), assuming a buffering potential of agroforestry has been documented in the literature (see above).Framework 2 involves exploring the microclimate effect of agroforestry on coffee systems and how this can buffer area loss due to climate change.Shading in agroforestry can reduce the average maximum temperature by up to 4 °C compared to open sun systems (Charbonnier et al. 2017;Merle et al. 2022;Moreira et al. 2018;Muschler 2001;Soto-Pinto et al. 2000).In our study, we represent the diverse shading by using two contrasting shading levels.To mimic a 25% and 50% shading effect, the monthly maximum temperature files were adjusted by subtracting 2 °C and 4 °C while adding 0.5 °C and 1 °C on the minimum temperature files, respectively as extrapolated from experimental microclimate regulation results for Cordia africana in Uganda (Sarmiento-Soler et al. 2019).The adjustment was made for the historical weather files and the projected climate for the five GCMs and two climate scenarios.The adjusted files were used to re-calculate the 19 bio-climatic variables using the "biovars" R library under the "dismo" package (Hijmans et al. 2022).The recalculated variables were then used to re-run the model to derive the current suitability of growing the two coffee species under agroforestry systems and the projected changes in suitability due to climate change.The buffering potential is therefore calculated as the difference between the coffee suitability with and without agroforestry (for current and future climate separately).The modelling framework does not consider the physiological coffee-tree interactions such as water competition and soil fertility enhancement that might be vital in coffee production systems.

Model calibration and evaluation
We attained robust models for the three crops evidenced by high out-of-sample AUC values of 0.90, 0.77, and 0.78 for Arabica coffee, Robusta coffee and Banana, respectively (Fig. SI1).In addition, model validation using a confusion matrix against the SPAM yield data, which were not used for calibration, produced high accuracy levels of 0.74, 0.72 and 0.64 for the three crops (Fig. SI2).The models also captured at least 95% of all the points for the currently known areas where the crops are grown (Fig. SI7), providing Vol.: (0123456789) further basis for confidence in the ensemble suitability model.

Projected climate changes
On average, all five GCMs show a projected increase in precipitation and temperatures across the country under both emission scenarios by 2050 (2041-2060) compared to the baseline  averages.An average increase of up to 140 mm and 174 mm in the annual precipitation is expected under SSP2-RCP4.5 and SSP3-RCP7.0,respectively.More precipitation is expected in northern and eastern areas.The region in the Northeast is expected to remain drier, with an annual rainfall increase below 50 mm under both emission scenarios.The individual models do not fully agree on the general trend in change in precipitation across the country, especially in the northern region.Whereas CanESM5 and UKESM1-0-LL predict very high increases in rainfall across the country, the other three models (CNRM-CM6-1, MIROC6 and MRI-ESM2-0) project increases but also possible decreases in other parts of the country.An average temperature increase of 1.9 °C and 2.1 °C under SSP2-RCP4.5 and SSP3-RCP7.0 is projected.All the GCMs agree on the warming trends across the country though MRI-ESM2-0 and UKESM1-0-LL models project higher average temperature increases (2.7 °C and 2.91 °C).

Major factors affecting crop distribution
We calculated the relative contribution of each variable to model building for each crop.The determinants of Arabica coffee suitability predominantly hinge on temperature-related variables (Table 1).Temperature seasonality contributes significantly, with a weight of 60% to the overall suitability model.However, for Robusta coffee, both precipitation and temperature-related variables are essential for its suitability.Precipitation-related variables contribute more (42%) than temperature-related variables (30%).The temperature mean diurnal range and precipitation of the coldest month have the highest influence (20% and 16%).Soil pH is equally vital in the suitability of Robusta coffee, contributing 15% to the overall suitability model.Though precipitation variables contribute most (approximately 45%) to the suitability of banana, the individual contribution of soil pH and elevation is also high (24 and 13%), respectively (Fig. SI3).

Current suitability of coffee and bananas
Under current climatic conditions, the two coffee species are suitable in two distinct areas with few overlaps in the country's northern and south western parts (Fig. 3).Unlike Arabica coffee, whose suitability is high only in limited areas particularly the eastern and south western highlands, the suitability of Robusta coffee and bananas is spread throughout the country (Figs.3a, 4b).The area suitable for Arabica coffee is approximately 13% of the total land area.This species is highly suitable in highland areas (Fig. 4c), specifically the south west, east around Elgon mountain and west Nile.Robusta coffee is suitable in a relatively larger area representing 70% of the total land area.The species is highly suitable in lowlands below 1500masl (Fig. 4c), mostly the country's central and northwestern parts.Bananas are suitable in the largest area covering over two-thirds of the country's land (Fig. 3).The crop is highly suitable in the country's central, western and south western parts.

Change in areas suitable for coffee and bananas by 2050
The effects of climate change on coffee and banana across Uganda will be crop and region-specific (Figs. 3, 4a).Climate change effects on both crops will be more severe in SSP3-RCP7.0than SSP2-RCP4.5scenarios.Arabica coffee will beaffected most with a decrease of 18% and 22% of the current suitable area under SSP2-RCP4.5 and SSP3-RCP7.0,respectively, notably in the lowland areas of western Nile and southwestern Uganda (Fig. 3).Despite the slight suitability gains for Arabica coffee in the southwestern region, the overall loss will overshadow the increase leading to a net negative change under both emission scenarios (Fig. 4a).The suitability to grow Robusta coffee will also reduce by 2050 with the highest reduction (9%) in SSP3-RCP7.0compared to (5%) under SSP2-RCP4.5.A minimal increase in suitability is expected in the southwestern parts of the country, though this will be shrouded by suitability losses elsewhere.Like Robusta coffee, the suitability to grow bananas is expected to decrease in the northern regions with a reduction of up to 4% of the currently suitable area under SSP3-RCP7.0.However, net change under SSP2-RCP4.5 is projected to be positive, indicating possible suitability gains will surpass the suitability loses.For all crops, CanESM5 and MRI-ESM2-0 show the highest percentage reduction in the area suitable under both emission scenarios compared to the rest of the GCMs (Fig. 4a).
The suitability to grow both coffee species is expected to slightly increase at higher elevations, possibly leading to a potential shift of coffee growing to highlands.A more pronounced shift is expected for Arabica coffee, especially under the high emission scenario where the crop will become more suitable at elevations above 1500 m. (Fig. 4c).Both species are currently less grown at elevations around 1000 m, possibly due to high settlements and competition with other landuse activities and not necessarily restricted by bio-climatic constraints.Addditionally, some suitability gains are projected in wildlife and forest reserves (Fig. SI4).

Coffee-Banana intercropping
Currently, 63% of the land area in Uganda is suitable for Robusta-banana intercropping, while 11% is suitable for Arabica-banana intercropping.Banana-Robusta intercropping is best combined in central, southwestern, western, and northern Uganda.The area suitable for Robusta-banana intercropping will reduce by 1% and 4% under the high and medium emissions scenarios by 2050.Arabica-banana intercropping system will remain relatively stable with marginal decreases of up to 0.5% under SSP3-RCP7.0by 2050.Arabica-banana intercropping will remain viable in the southwestern and northwestern parts of the country (Fig. 5).

Current and future ecological envelopes of agroforestry tree species
The two-agroforestry tree species (Ficus natalensis and Cordia africana) are suitable in distinct areas but intersect in the northern parts.Ficus natalensis has a larger climate envelope stretching from the southern regions through the central, western and eastern,  covering approximately three-quarters of the total land area.Cordia africana, meanwhile, is suitable in the country's northern parts, covering approximately a quarter of the land area (Fig. 6).Climate change will slightly positively affect the suitability of both Ficus natalensis and Cordia africana under both emission scenarios, expanding their geographic envelope (Fig. SI5).

Agroforestry buffering potential by climate envelopes (framework 1)
The wide climate envelope of Ficus natalensis provides a potential for buffering the projected decline in the suitability to grow coffee.Following the suitability overlay (framework 1, see methods), up to 90% of the projected areas with reduced coffee suitability can potentially be buffered by Ficus natalensis.Additionally, Ficus natalensis encompasses almost all the areas where Arabica coffee is projected to become unsuitable.In contrast, the buffering potential of Cordia africana is geographically limited within Uganda.However, this agroforestry species can buffer larger areas of Robusta than Arabica, since the projected decline in suitability to grow Robusta is in the northern parts of the country where Cordia africana is suitable, covering approximately 84% of the projected decline of Robusta.Contrarily, Cordia africana has a lower potential to buffer Arabica coffee, because up to 81% of the projected reductions in the suitable area fall outside its climate envelope, particularly under SSP2-RCP4.5 (Fig. SI6).

Agroforestry buffering potential through micro-climate regulation (framework 2)
Model results show that agroforestry, by regulating the coffee microclimate (framework 2, see methods), has the potential to partially mitigate climate change effects on suitability to grow Robusta in Uganda under both emission scenarios; a higher buffering potential is attested for SSP2-RCP4.5 (Fig. 7).Using 25% and 50% shading under SSP2-RCP4.5,agroforestry can buffer 6% and 17% of the area projected to become unsuitable for Robusta coffee by 2050.The same shading percentages can buffer 4% and 10% of the projected suitable area loss under the SSP3-RCP7.0.In addition, agroforestry is projected to expand the area further, which is suitable for Robusta coffee, especially within the country's southern parts.By expanding the climate envelope and partly buffering area losses, implementing agroforestry can minimize the net reduction in the area suitable for Robusta coffee by up to 86% and 38% under SSP2-RCP4.5 and SSP3-RCP7.0,respectively, compared to the unshaded systems.On the other hand, implementing agroforestry cannot buffer Arabica coffee against the effects of climate change by 2050 under both emission scenarios.
However, implementing agroforestry lowers coffee suitability in some regions, for example, the west Nile and southwestern parts for Arabica coffee and the northern-central parts for Robusta coffee.Therefore, agroforestry design and recommendation should consider several factors, including altitude, regional climate, and water availability.Based on our model results and literature, we have developed  Y a,r Buffer against extreme events, stabilizing production Fig. 8 Visualisation for the multicriteria for recommending agroforestry as a climate change adaptation for two coffee species across Uganda by 2050 as shown in Table 2.The colour key shows recommendation in the order of elevation, precipitation, temperature and water balance (proxy for water availability).The more Y = Yes there are at a given location, the more coffee could profit from shading by agroforestry (green shades).If the N = No's are overweighing, agroforestry is not recommended (red/brown shades).Not all 16 possible combinations occur in Uganda and recommendations have to tailored to each site under consideration a multicriteria system for choosing where to implement agroforestry depending on the relative impact on coffee systems (Table 2, Fig. 8).For each grid cell, the four factors elevation, temperature, precipitation and water balance were determined and led to a fourdimensional decision aid-the more "Yes" there are in one site, the more likely agroforestry has a buffering potential, and vice versa.

Discussion
Changes in weather patterns across Uganda The mean model for the 5 GCMs shows a general trend of increasing temperature and precipitation across the country compared to the 1970-2000 averages.The projected increase in precipitation contrasts the observed past (1980s-2010) decline across East Africa and has resulted in the "East African climate paradox".The trend in reduced precipitation has continued, and the region has recently been hit by severe droughts leading to the death of animals and the destruction of crops (Haile et al. 2019).This paradox can be explained by various factors, including local geographic factors, remote forcing like the Indian Ocean Dipole, costal influences, uneven representation of aerosols, and regional circulations such as the moisture transport and the tropical Easterly Jet (Nicholson 2017).Within our study, we assume future precipitation projections from our set of chosen GCMs as reasonable, given their acceptable agreement with past precipitation trends (Ngoma et al. 2021;Ongoma et al. 2018a, b).
Climate change effects on coffee and banana suitability by mid-century Similar to Davis et al. (2012), Mulinde et al. (2022) and Wichern et al. ( 2019), we project substantial reductions in areas suitable for Arabica coffee specifically in the lowlands.All GCMs agree that the marginally suitable areas in the West Nile region will become unsuitable under the high-emissions scenario by 2050.Robusta coffee farming could replace the heat-stressed Arabica coffee in this region since the species is more heat tolerant.This has a significant implication on the livelihoods of Arabica coffee farmers and the country's revenue from coffee export since Arabica is more valuable and fetches a higher price (UCDA 2019a).Given the limited environmental envelope for Arabica coffee in Uganda, possible climate adaptation measures should be implemented to buffer this crop against the projected adverse effects of climate change.
The Robusta coffee suitability loss in the northwestern region can be attributed to the subsequent rise in the minimum temperature growing months which is detrimental to young coffee plants, since the shallow roots cannot access water from deeper layers (DaMatta and Ramalho 2006;León-Rojas et al. 2023).The increase in temperature at such vegetative and reproductive stages is associated with bud failure and flower drop, which might affect the crop's final yield (DaMatta and Ramalho 2006).A projected upward altitudinal shift of coffee species, threatens fragile ecosystems (see supplementary material, Fig. SI4) and could create human-wildlife conflicts and increase environmental degradation in the form of deforestation.Though the higher elevations could support coffee growing, it could be limited by temperature fluctuations in addition to environmental challenges such as erosion and landslides.The rising coffee demand and climate change push should not compromise the existing nature-protected areas and fragile ecosystems, as this will affect livelihoods, well-being and biodiversity.The likely extent of future encroachment could not be assessed as no updated data about protected areas was available.However, as shown in the supplementary material, we give a picture of the likely pressure of the two-coffee species due to climate change.Currently, varieties being used by coffee farmers are not fully maximized in terms of breeding for drought resistance, implying there is room for improvement.For example, clonal output from an Arabica shoot stock and Robusta rootstock has shown better resistance to harsh temperatures (Van der Vossen et al. 2015), providing evidence for possible better varieties.Other coffee species such as Liberica have also not been thoroughly researched and considered for breeding for resistance and yet could offer possibilities.
Similar to Sabiiti et al. (2018), our model results show a possible mean increase in the area suitable for banana growing under less warming but a reduction under the high emissions scenario.The reduction in areas suitable for bananas is attributed to high moisture deficits from increased temperatures (Sabiiti et al. 2018).The projected decline in areas suitable for coffee and bananas will reduce the possibility of banana-coffee intercropping across the country.This has a strong implication for the country's food security since bananas are one of the major permanent food crops in the country (UBOS 2022) and farmers' incomes (van Asten et al. 2011).Therefore, adaptation measures tailored to maintaining moisture and water available to coffee and bananas such as irrigation are necessary to avert the projected decline and safeguard livelihoods.The reduction in the suitability of bananas within coffee growing areas also indicates the inability of bananas to shade young coffee plants, necessitating the need for other shading/ adaptation mechanisms such as using tree-based shading systems.

Buffering potential of agroforestry
Being a generalist with both strangling, epiphytic and phenotypic plasticity characteristics (Schmidt and Tracey 2006) that help survive in broad ecological environments, Ficus natalensis will not be affected by climate change.Cordia africana on the other hand, can buffer area losses in the northern and eastern parts of the country.Therefore, a combined agroforestry system of the two species is recommended in the north while Ficus natalensis is recommended for the country's central, western and southern parts.The two-tree species are ever-green in nature hence they can provide shading throughout the year (Nigussie et al. 2021;Yadessa et al. 2001).Since agroforestry systems with diverse tree species provide more ecological and environmental functions (Torrez et al. 2023), an additional assessment should be made on the possibility of other local shading species for each region.However, the mere presence of climate envelopes of the respective trees does not provide conclusive buffering evidence for coffee plants.The true effectiveness of agroforestry services in buffering the impact of climate change can only be assessed through evaluating their actual benefits to the crops.This is why, in this study, we additionally researched the microclimate regulation function towards coffee productivity.
Our model results show that microclimate regulation by agroforestry can allay a significant projected net loss in areas suitable to grow Robusta coffee partly by expanding its climate envelopes and minimizing the projected reductions in suitability under open systems, especially under the low emissions scenario.Since precipitation-related variables influence Robusta coffee (Bunn et al. 2015), reducing maximum temperatures through shading ensures continuous soil moisture (Lin 2010).Against expectation, model results show that implementing agroforestry will not buffer suitability loss for Arabica coffee.This is partly explained by the fact that shading by agroforestry trees increases the minimum temperature during the night, which is detrimental to Arabica coffee (Craparo et al. 2015).The conservation of nocturnal heat hinders a sufficient decrease in mean temperature, which is imperative for facilitating the reproductive growth processes in most crops (Hatfield et al. 2011;Nagarajan et al. 2010).Moreover, a reduction in the suitability of Arabica coffee is projected in low-land areas of northern Uganda, whose minimum temperatures are predicted to exceed the optimal thresholds for Arabica coffee production.We limit our analysis to 50% shading since extra shading has been found to reduce yield and quality directly through light and nutrient competition or indirectly through increased pest and disease incidence (Bosselmann et al. 2009;Charbonnier et al. 2017;Durand-Bessart et al. 2020;Soto-Pinto et al. 2000).
The design and implementation of agroforestry should be carefully done to minimize potential maladaptation.Agroforestry implementation should follow a well-structured criterion catalogue that considers temperature ranges, precipitation, elevation, and water availability to maximise its functionality.To avoid economic losses, optimizing shade should be done through management practices such as pruning and thinning (UCDA 2019b) rather than planting more shade trees to maintain coffee plant stocking, thereby minimizing yield losses.The two methodologies used to assess the potential of agroforestry in this study are complementary as the first one shows the proper species site matching, which is an essential first step in choosing the right agroforestry system.The binary overlay of the different factors is relevant to identifying whether the selected species would not be limiting to coffee production.Most studies have often considered individual factors such as cost-effectiveness, land tenure, biophysical characteristics, social acceptability, and species site matchings (Müller and Scherr 1990).Our study is the first to give an insight into using climate projections and crop-specific information to design resilient agroforestry systems.

Model and data uncertainty
Like all models, the modelling approach here has some uncertainty; therefore, all results are projections, not predictions.Suitability models assume total equilibrium between the species and the environmental variables in which they occur, which might not be true for newly introduced species such as coffee plants that are continuously planted in new agricultural areas.In addition, the modelling approach used here used only presence data, which limits the ability to precisely and accurately capture environmental specifications for the absent records (Barry and Elith 2006).Moreover, not all coffee farms are captured in this study since complete survey data were not readily available, leading to possible sampling bias.The model was also run on an assumption of constant soil pH up to midcentury, but this will most likely change in the face of climate change as soils will become more acidic due to leaching and other soil water exchange mechanisms (Rengel 2011) and could as well be affected by implementing agroforestry (Muchane et al. 2020).The intercropping potential of bananas and coffee did not consider physiological interactions such as nutrient sharing, light competition, as well as shading of coffee by banana plants (Tehulie and Nigatie 2023;van Asten et al. 2011), yet such interactions affect the success of the banana-coffee intercropping systems and should form the basis for further research.
Despite the projected declines in coffee-suitable areas, studies have shown a possible positive effect of elevated CO 2 on coffee productivity in the face of climate change through stimulation of photosynthesis, a higher water use efficiency, better growth, crop yield and reduction of leaf miners hence possibly mitigating the negative impacts (DaMatta et al. 2019;Ghini et al. 2015;Ramalho et al. 2018).The accumulation of biomass could, however lead to increased water demand as in most crops (Bodner et al. 2015) making the coffee plant vulnerable during severe droughts (Vega et al. 2020), hence the need for management practices such as shading and irrigation (Marçal et al. 2021).Elevated CO 2 affects the final coffee quality as higher growth rates lead to mineral dilution and poor cup quality (Martins et al. 2014;Vega et al. 2020).These effects have not been represented in this study and could result in minimal area loss or potential suitability gain.Despite the reported positive effects of elevated CO 2 , the projected variable rainfall patterns and severe temperatures due to climate change cause uncertainty about the coffee productivity potential (DaMatta et al. 2018).
There is also potential mismatch between the baseline historical datasets from Worldclim with the coffee presence points records.However, as a permanent crop, coffee is highly affected by previous historical climate, making the mismatch less relevant.In addition, most coffee suitability studies employ the same baseline climate data, making them comparable to our study (Bunn et al. 2015;Chemura et al. 2021;Ovalle-Rivera et al. 2015).Though the GCMS used in this study were carefully selected as described above, they still vary in the spatial projection of precipitation across the country leading to possible bias.Climate models incorporate different dynamics related to atmospheric circulation, ocean effects, or feedback between the land surface and the atmosphere hence diverging results.The climate projection bias can affect model outputs and lead to an underestimation of the climate change impacts on coffee suitability.However, we try to overcome this limitation by assembling them individual GCM suitability results by means there by reducing the bias.
The assessment of agroforestry buffering potential is solely based on suitability and microclimate regulation, one of the various functions of this system.The modelling framework used here assumes that the microclimate regulation of agroforestry in terms of radiation interception is the major function for buffering climate change effects on coffee systems.However, tree crop interactions are complex, involving numerous functions, including interception, hydrological cycle modification, light intensity modification, biomass provision, and pollinator effect (Jacobs et al. 2022), all of which vital in ensuring resilient systems.In dry conditions, for example, agroforestry trees could play a vital role in hydraulic lift (Lin 2010), providing water to coffee plants in the upper layers, thereby reducing water stress.The shading function is also differentiated by region, cloud cover and all of which determine the effect on the understory crops (Aalto et al. 2022;Muñoz-Villers et al. 2020).However, such physiological interactions between coffee plants and agroforestry trees can only Vol:.( 1234567890) be captured by processed-based models, hence a draw back to our study.Integrating such complex interactions would give a better understanding of the actual system balance and buffering potential under climate change and should form a basis for further studies.Therefore, our study's results might have underestimated the relative potential of agroforestry in buffering climate impacts on coffee systems, but provides an initial modelling basis especially for spatially planning these systems.

Conclusion
This study assessed the suitability to grow coffee (Arabica and Robusta) as well as the possibility of coffee-banana intercropping across Uganda and how this will be affected by climate change.The extent to which agroforestry can buffer coffee fields against the impact of climate change through microclimate regulation by 2050 was also assessed.The implementation of suitability models enabled us to identify where agroforestry is a proffered adaptation strategy against climate change effects.The two-coffee species are currently suitable in distinct areas of the country.Climate change will negatively affect both coffee and bananas, but the effects will be region and crop-specific.Still, Arabica coffee will be affected most due to its limiting environmental and climatic requirements.The suitability of bananas will also be affected across the country, modifying the coffee-banana intercropping system.Microclimate regulation by agroforestry will positively affect Robusta coffee's suitability, but not Arabica coffee.The highest shading buffering potential will be under SSP2-RCP4.5compared to SSP3-RCP7.0.Proper site-species matching is vital for agroforestry tree species to maximize the agroforestry potential.Additional and the combination of adaptation measures, such as irrigation and breeding resistant varieties, will be required to keep coffee, particular Arabica, viable in these regions.Further research endeavors should focus on agroforestry tree interactions, including water use, the effect on coffee pests and other benefits to crops such as biomass provision and soil health enhancement.

Fig. 1
Fig. 1 Map of Uganda showing administrative divisions, elevation and reported coffee growing regions . Historical climate data represents averages of 1970-2000 while the projections of midcentury represent averages of 2041-2060 simulated by five GCMs (Canadian Earth System Model (CanESM5), Meteorological Research Institute Earth System Model (MRI-ESM2-0), Model for Interdisciplinary Research on Climate (MIROC6), UK Earth System Modelling project (UKESM1-0-LL), and

Fig. 2
Fig. 2 Methodological flowchart showing the modelling framework for the current suitability, climate change effect and the potential of agroforestry.Abbreviations: RF, Random Forest, BRT, Boosted Regression Trees

Fig. 3
Fig. 3 Modelled current suitability of Arabica coffee, Robusta coffee and bananas in Uganda and the changes by 2050 under the two emission scenarios.The changes are differences between the future and current suitability of respective crops

Fig. 5
Fig. 5 Modelled current spatial distribution of the areas suitable for coffeebanana intercropping and the projected changes by 2050 due to climate change

Fig. 7
Fig. 7 Effect of implementing agroforestry with different shading intensities on the area suitable for coffee growing in Uganda by 2050

Table 1
Current values for the predictor variables and changes by 2050 (2041-2060 averages) under the two emissions scenarios used in the modelling of coffee and bananasThe changes represent the mean changes for the five GCMs

Table 2
Mulicriteria for decision on shading based on environmental and climatic factors by 2050 For letter keys, Y = recommended, N = not recommended, a = Arabica, r = Robusta r Competition for light, reduced yields, increased pest and disease incidence ≤ 50%