Introduction

Food security is a critical sustainable development goal1. However, the resource and environmental costs associated with food production have become prohibitively high in recent decades2. Excessive nitrogen and phosphorus inputs to more than half of the world’s crops3, coupled with a generally low fertilizer use efficiency4, have resulted in farmland greenhouse gas emissions5, surface water pollution6, and biodiversity loss7 that exceed the planet’s environmental boundaries8. It is estimated that in global food systems, the nitrogen and phosphorus use efficiency must be doubled to meet both food security and ecological safety goals9,10. How to feed the projected9 billion people in the future while avoiding ecosystem collapse has become a major challenge for ensuring global sustainability11,12. Optimizing the cropland layout13,14 and transforming crop allocation15,16 can mitigate the negative environmental impacts of food production, but socioeconomic and cultural barriers still hinder the implementation of these strategies17. Therefore, the precise allocation and regulation of farmland nutrient resources are particularly important for achieving the goal of zero hunger under planetary boundary constraints18,19,20.

The precise management of farmland nutrients has remained a challenge for digital agriculture because of the complex relationships among crops, soils, fertilizers and other environmental factors21. Three key issues must be addressed: the first issue is accurate crop yield prediction, which is a prerequisite for nutrient demand assessment. Over the years, meteorological models22, remote sensing models23 and crop growth models24 have been widely employed for crop yield prediction. Meteorological models are mainly used to assess the impact of climate change on the crop yield because of the single predictor variable adopted25,26. Remote sensing models can be used to quickly and accurately predict crop yields at large scales by modeling the relationships between multispectral data (Thematic Mapper (TM), Moderate Resolution Imaging Spectroradiometer (MODIS), and photosynthetically active radiation (FPAR) data) or agronomic parameters (normalized difference vegetation index (NDVI), enhanced vegetation index (EVI), leaf area index (LAI), and net primary production (NPP)) and observed yields27,28, but they can hardly explain yield changes23. Crop growth models, such as the decision support system for agrotechnology transfer (DSSAT)29, WOrld FOod STudies (WOFOST) model30, CropGrow31, and Agricultural Production Systems Simulator (APSIM)32, aim to simulate the crop growth process and provide accurate yield predictions (the prediction errors are generally smaller than 10%). However, owing to the complexity and heterogeneity in ecosystems, it is difficult to obtain many parameters for crop growth models24. Currently, new models that combine multisource environmental data (meteorological, soil, topographic, crop and management, and other data)33,34,35,36 with machine learning algorithms (artificial neural network (ANN), random forest (RF), support vector machine (SVM), long short-term memory (LSTM), etc.)37,38,39,40,41 have become the frontier and hotspot of crop yield prediction42. In particular, the RF algorithm, which not only accurately captures the complex nonlinear relationship between the crop yield and environmental factors but also provides the importance of predictor variables, has broad application prospects in crop yield prediction43,44.

The second issue is the accurate assessment of nutrient balances, which is key to identifying the location and degree of crop nutrient deficiencies or excesses45. Scholars have assessed global46,47, national48,49,50,51, and regional52,53,54 nutrient balances by comparing nutrient inputs and outputs of agroecosystems55,56 or soil systems57,58. However, as crop yields and nutrient inputs have mostly been derived from statistical panel data, many studies can reflect only the overall nutrient balances within administrative districts or ecological zones, but it is difficult to achieve spatially accurate assessment and mapping of nutrient balances for different crops at different scales59,60. In recent years, field-localized experiments and observations have provided the basis for accurate calculations of crop nutrient balances. Unfortunately, owing to the high geographical variation in crop nutrient balances, reliable methods for upscaling fertilizer field experiment data at the macroscopic scale remain lacking61,62. Therefore, the accurate calculation and mapping of crop nutrient balances, driven by large amounts of data on soils, fertilizers, crops and other environmental factors, has become an important trend in sustainable nutrient management in farmland63,64.

The third issue is the precise regulation of farmland nutrients. Soil management zoning has long been an important approach for achieving precision fertilization65. Scholars have selected soil, meteorological, topographic and other indicators for comprehensive evaluation to delineate fertilizer management units with relatively consistent natural conditions to achieve spatially precise quantification of fertilizer inputs under specific target yields66,67,68,69,70. In recent years, quantitative research on the fertilizer reduction potential has become a hotspot for nutrient regulation. Most previous studies were based on soil monitoring and fertilizer field experiments, thereby comparing the recommended fertilizer rates with the actual fertilizer rates employed by farmers71,72 or comparing the soil nutrient content with environmental thresholds73,74 to estimate nutrient excess or deficiency areas. Unfortunately, these studies are highly compartmentalized. On the one hand, precision fertilization and fertilizer reduction are considered two separate topics, and the spatial redistribution and balancing of farmland nutrients have not been systematically addressed. On the other hand, food security and ecological security objectives have been addressed separately, thereby neglecting their consistency. Farmland nutrient regulation entails a multiobjective optimization problem, and the trade-offs and coordination between food production and environmental pressures must be considered75,76. The nondominated sorting genetic algorithm (NSGA) is currently one of the most representative multiobjective optimization algorithms77 and has been widely applied in land use optimization78, crop structure adjustment79 and ecological protection planning80, which has provided new opportunities for multiobjective farmland nutrient optimization management.

Over the next 30 years, China’s food production not only faces the risk of yield stagnation in one-third of the region81 but also exhibits the need to reduce phosphorus and nitrogen losses, greenhouse gas emissions, and blue water depletion by more than half to meet the national environmental security boundary82. In particular, major grain-producing regions have become the center of agricultural nonpoint source pollution in China, and there is an urgent need to improve the sustainable management of farmland nutrients83,84. For this reason, many soil monitoring85, fertilization surveys86,87 and fertilizer experiments88,89 have been conducted in China over the past 20 years, which has significantly contributed to soil nutrient assessment and fertilizer formulation development90. However, relevant studies and applications are isolated and fragmented91 and generally lack effective methods for spatially mining and modeling big data on soil nutrients, fertilizer inputs and crop yields, making it difficult to meet the systematic and precise requirements for future nutrient management decisions21,92. Therefore, adopting a major grain-producing region in Southwest China as an example, a multiobjective farmland nutrient optimization method was proposed that integrates multisource big data and intelligent optimization algorithms to achieve (1) accurate prediction of crop yield distributions under different nutrient conditions; (2) accurate assessment of the crop nutrient balance; and (3) spatial optimization of crop fertilizer rates under the dual objectives of ensuring food security and ecological security.

Results

Spatial heterogeneity in the contribution of fertilizer application to the crop yield

Six RF-based yield prediction models were established in ArcGIS for the three crops considered (Tables 1, 2 and Supplementary Fig. 1), which were generally well fitted and reliable, with R2 values above 0.89, mean absolute error (MAE) values between 0.56 and 0.9 t ha−1, root mean square error (RMSE) values ranging from 0.8 to 1.21 t ha−1, and symmetric mean absolute percentage error (SMAPE) values between 10.02 and 24.46%. Moreover, the prediction accuracy of the rice RF model was greater than that of the maize and wheat RF models, which may be related to the larger number of training samples for the rice model. In particular, the prediction accuracy for the fertilized yield (YF) was significantly greater than that for the soil-based yield (YS), with the SMAPE of the YF prediction model ranging from 10.02 to 15.24%, whereas that of the YS prediction model ranged from 14.52 to 24.46%. This phenomenon reflects, on the one hand, that the YS exhibits greater uncertainty and is determined by more complex influencing factors and, on the other hand, that fertilization increases the predictability for the crop yield.

Table 1 Evaluation indices for the prediction accuracy of the RF models
Table 2 RF model prediction results for the crop yield from 2009 to 2019 in Southwest (SW) China

From 2009 to 2019, crop yields in the study area showed an increasing trend (Figs. 1 and 2). The soil-based yield (YS) is the crop yield in the current year without fertilization, reflecting the inherent soil productivity of farmland93. The fertilized yield (YF) is the crop yield under fertilization conditions. The average YS of rice increased from 5.76 t ha−1 in 2009 to 5.82 t ha−1 in 2019, and the average YF of rice increased from 8.33 t ha−1 in 2009 to 8.35 t ha−1 in 2019; the average YS of maize increased from 4.07 t ha−1 in 2009 to 4.36 t ha−1 in 2019, and the average YF of maize increased from 7.04 t ha−1 in 2009 to 7.17 t ha−1 in 2019; the average YS of wheat increased from 2.83 t ha−1 in 2009 to 2.90 t ha−1 in 2019, and the average YF of wheat increased from 5.20 t ha−1 in 2009 to 5.34 t ha−1 in 2019. As fertilizer rates decreased over the 10-year period, the improvement in soil nutrients in farmland was probably the main reason for the increase in the crop yield, indicating that China’s policies on farmland protection and systematic fertilization were effective. Compared with YS, fertilization significantly increased the crop yield, increasing the YF of rice increasing by 43.6–44.7%, the YF of maize increasing by 64.7–73.0% and the YF of wheat increasing by 83.9–84.4%. More importantly, fertilization effectively increased the stability of the crop yield94; notably, the coefficient of variation (CV) of the rice YS ranged from 8.2 to 10.0%, and that of the rice YF was reduced to 4.0–4.5%; the CV of the maize YS ranged from 8.9 to 12.0%, and that of the maize YF was reduced to 6.6–6.8%; and the CV of the wheat YS ranged from 18.0 to 18.8%, while that of the what YF was reduced to 10.5–11.3%. The spatial distributions of the yields of these three crops in 2009 and 2019 were similar. The crop yields were highest in the western plains due to the flat topography and fertile soils; the crop yields were slightly lower in the southern part of the Yangtze River coast and eastern parallel valleys than in the plains due to the low elevation and favorable light and heat conditions; the crop yields were relatively low in the central hilly areas due to soil nutrient and rainfall limitations; and the mountainous areas around the basin exhibited the lowest crop yields due to their high elevation and complex terrain. In addition, the relatively high fertilizer rates for maize cultivation in East China and North China resulted in relatively high maize YF values in these regions.

Fig. 1: Spatial distributions of the crop soil-based yield (YS) in SW China from 2009 to 2019.
Fig. 1: Spatial distributions of the crop soil-based yield (YS) in SW China from 2009 to 2019.
Full size image

The maps show the spatial distributions of the YS of rice in 2009 (a) and 2019 (b), the spatial distributions of the YS of maize in 2009 (c) and 2019 (d), and the spatial distributions of the YS of wheat in 2009 (e) and 2019 (f). The color bands denote various yield classes (t ha−1). The box of the violin plot indicates the interquartile range with the median value shown as a bold line, the whiskers of the violin plot denote the 1.5 interquartile range, and the outer border of the violin plot denotes the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Fig. 2: Spatial distributions of the crop fertilized yield (YF) from 2009 to 2019 in SW China.
Fig. 2: Spatial distributions of the crop fertilized yield (YF) from 2009 to 2019 in SW China.
Full size image

The maps show the spatial distributions of the YF of rice in 2009 (a) and 2019 (b), the spatial distributions of the YF of maize in 2009 (c) and 2019 (d), and the spatial distributions of the YF of wheat in 2009 (e) and 2019 (f). The color bands denote different yield classes (t ha−1). The box of the violin plot denotes the interquartile range with the median value shown as a bold line, the whiskers of the violin plot denote the 1.5 interquartile range, and the outer border of the violin plot indicates the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Although fertilization is a key factor in increasing crop yields, we observed spatial heterogeneity and a decreasing trend in the contribution of fertilization to crop yields in the study area (Fig. 3). The fertilizer increased yield (FIY) was used to express the increase in the crop yield due to fertilizer application by subtracting the YS from the YF, and the fertilizer contribution ratio (FCR) was used to measure the contribution of fertilizer to crop yield. For rice, the average FIY value decreased from 2.57 t ha−1 in 2009 to 2.47 t ha−1 in 2019, and the average FCR decreased from 30.9% in 2009 to 29.8% in 2019; for maize, the average FIY decreased from 2.97 t ha−1 in 2009 to 2.79 t ha−1 in 2019, and the average FCR decreased from 42.1 to 38.9% in 2019; for wheat, the average FIY and FCR essentially remained unchanged. The FIY and FCR of rice and maize generally exhibited the opposite trend to the spatial distribution of crop yields, with the highest values occurring in the central and northern hills and the lowest values occurring in the western plains and along the Minjiang and Yangtze rivers. In contrast, the FIY and FCR of wheat typically followed the crop yield distribution, with higher values in the northern hills and western plains than in the central hills. Therefore, it is necessary to optimize the quantity and distribution of fertilizer inputs to increase nutrient sustainability in Southwest China.

Fig. 3: Spatial distributions of the crop fertilizer increased yield (FIY) from 2009 to 2019 in SW China.
Fig. 3: Spatial distributions of the crop fertilizer increased yield (FIY) from 2009 to 2019 in SW China.
Full size image

The maps show the spatial distributions of the FIY of rice in 2009 (a) and 2019 (b), the spatial distributions of the FIY of maize in 2009 (c) and 2019 (d), and the spatial distributions of the FIY of wheat in 2009 (e) and 2019 (f). The color bands denote various yield classes (t ha−1). The box of the violin plot denotes the interquartile range with the median value shown as a bold line, the whiskers of the violin plot indicate the 1.5 interquartile range, and the outer border of the violin plot denotes the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Widespread crop nutrient imbalances

The nutrient balance assessment results (Figs. 46, Table 3 and Supplementary Figs. 24) revealed that nutrient imbalance occurred widespread among the three crops in the study area, with an overall excess of nitrogen and deficiencies in phosphorus and potassium. Rice exhibited an excess of nitrogen in most regions, with an average nutrient balance ratio of nitrogen (NBRN) higher than 0.6. The degree of excess nitrogen was higher in the western plains and along the Minjiang and Yangtze rivers, with the actual fertilizer rate in some regions even reaching approximately 10 times the theoretical fertilizer rate. The rice nutrient balance ratio of phosphorus (NBRP) and the nutrient balance ratio of potassium (NBRK) ranged from −0.1 to −0.2, but there was a polarization trend in the spatial distribution. Notably, rice phosphorus and potassium excess areas were distributed in the western plains and along the Minjiang and Yangtze rivers, but there were large phosphorus and potassium deficiency areas in the northeastern and central parts of China. Moreover, the polarization trend in the rice phosphorus and potassium balance increased from 2009 to 2019. For maize, there was a slight excess of nitrogen, with NBRN values ranging from 0.13 to 0.18. Moreover, there was a greater risk of nitrogen excess due to higher nitrogen fertilizer rates for maize in the eastern–central hills and western mountains. The maize NBRP and NBRK values ranged from −0.38 to −0.48, with significant deficiencies in phosphorus and potassium nutrient inputs, except for a few areas in the west and south. For wheat, nitrogen was generally balanced, with an NBRN value of approximately −0.1, but there was a risk of increasing nitrogen deficiencies in the northeastern region. Phosphorus and potassium deficiencies were most severe for wheat, with NBRP and NBRK values ranging from −0.44 to −0.62, and nutrient deficiencies were generally greater in the northern regions.

Fig. 4: Spatial distributions of the rice nutrient balance ratio from 2009 to 2019 in SW China.
Fig. 4: Spatial distributions of the rice nutrient balance ratio from 2009 to 2019 in SW China.
Full size image

The maps show the spatial distributions of the rice nitrogen nutrient balance ratio (NBRN) in 2009 (a) and 2019 (b), the spatial distributions of the rice phosphorus nutrient balance ratio (NBRP) in 2009 (c) and 2019 (d), and the spatial distributions of the rice potassium nutrient balance ratio (NBRK) in 2009 (e) and 2019 (f). Nutrient balance ratios greater than zero represent excessive fertilizer inputs, ratios equal to zero represent balanced fertilizer inputs, and ratios less than zero represent insufficient fertilizer inputs. The color bands denote various nutrient balance ratio classes. The box of the violin plot denotes the interquartile range with the median value shown as a bold line, the whiskers of the violin plot indicate the 1.5 interquartile range, and the outer border of the violin plot denotes the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Fig. 5: Spatial distributions of the maize nutrient balance ratio from 2009 to 2019 in SW China.
Fig. 5: Spatial distributions of the maize nutrient balance ratio from 2009 to 2019 in SW China.
Full size image

The maps show the spatial distributions of the maize nitrogen nutrient balance ratio (NBRN) in 2009 (a) and 2019 (b), the spatial distributions of the maize phosphorus nutrient balance ratio (NBRP) in 2009 (c) and 2019 (d), and the spatial distributions of the maize potassium nutrient balance ratio (NBRK) in 2009 (e) and 2019 (f). Nutrient balance ratios greater than zero represent excessive fertilizer inputs, ratios equal to zero represent balanced fertilizer inputs, and ratios less than zero represent insufficient fertilizer inputs. The color bands represent various nutrient balance ratio classes. The box of the violin plot indicates the interquartile range with the median value shown as a bold line, the whiskers of the violin plot denote the 1.5 interquartile range, and the outer border of the violin plot indicates the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Fig. 6: Spatial distributions of the wheat nutrient balance ratio from 2009 to 2019 in SW China.
Fig. 6: Spatial distributions of the wheat nutrient balance ratio from 2009 to 2019 in SW China.
Full size image

The maps show the spatial distributions of the wheat nitrogen nutrient balance ratio (NBRN) in 2009 (a) and 2019 (b), the spatial distributions of the wheat phosphorus nutrient balance ratio (NBRP) in 2009 (c) and 2019 (d), and the spatial distributions of the wheat potassium nutrient balance ratio (NBRK) in 2009 (e) and 2019 (f). Nutrient balance ratios greater than zero represent excessive fertilizer inputs, ratios equal to zero represent balanced fertilizer inputs, and ratios less than zero represent insufficient fertilizer inputs. The color bands represent different nutrient balance ratio classes. The box of the violin plot indicates the interquartile range with the median value as the bold line, the whiskers of the violin plot denote the 1.5 interquartile range, and the outer border of the violin plot indicates the data distribution. The symbol t denotes the value obtained from the t-test, with the asterisk (*) indicating that the mean difference between 2009 and 2019 is statistically significant at the 0.05 confidence level.

Table 3 Nutrient balance statistics for the crop yield from 2009 to 2019 in SW China

Reducing nitrogen fertilizer rates and optimizing nutrient structures can enhance agricultural sustainability

Due to significant spatial variability in crop nutrient balance ratio (NBR), fertilizer rates should be reduced in areas where NBR > 0 and increased in areas where NBR < 0. Therefore, for computational convenience and expression, we adopted the adjustment gradient (%) of fertilizer rates as the optimization variable. The optimal adjustment gradients for nitrogen, phosphorus, and potassium fertilizer for different crops were determined through multiobjective optimization. Taking the optimization of nitrogen fertilizer rates as an example, the greater the adjustment gradient, the closer the fertilizer rate approaches the theoretical fertilizer rate (100% adjustment gradient corresponds to TFRN). Conversely, the smaller the adjustment gradient, the closer the fertilizer rate approaches the fertilizer rate by the farmer’s survey (0% adjustment gradient corresponds to FRN).On the basis of the crop fertilizer rate in 2019 and the theoretical fertilizer rate, regression models of the adjustment gradients of nitrogen fertilizer rates (x1), phosphorus fertilizer rates (x2), and potassium fertilizer rates (x3) with the corresponding total crop yield (OYN, OYP, and OYK) and total fertilizer rate (OFRN, OFRP, and OFRK) were developed (Supplementary Tables 19 and Supplementary Figs. 522). Table 4 and Fig. 7 show that the regression results for the total nitrogen response yield (OYN), the total phosphorus response yield (OYP), and the total potassium response yield (OYK) could be captured by cubic polynomial regression models with R2 values ranging from 0.78 to 0.99, whereas those for the total nitrogen fertilizer rate (OFRN), the total phosphorus fertilizer rate (OFRP), and the total potassium fertilizer rate (OFRK) could be represented by primary linear models with R2 values of 1.00. The above regression models were used as the objective function of the NSGA-II to calculate Pareto solution sets for the fertilizer rate adjustment gradients of rice, maize, and wheat in MATLAB software. These Pareto solution sets contain several preferable solutions (Supplementary Tables 1012), requiring further identification of the optimal solution with the lowest fertilizer rate and relatively high crop yield. Given the widespread nitrogen excess in the study area, we initially selected 5–6 solutions with the lowest total nitrogen fertilizer rate (OFRN). We then screened these further to identify 2–3 solutions with the lowest total phosphorus (OFRP) or potassium (OFRK) fertilizer rates. The optimal solution was finally identified as the one with the highest overall crop response yield (OYN, OYP, and OYK) among these 2–3 solutions. Figure 7 shows the optimal adjustment gradients for rice nitrogen, phosphorus, and potassium fertilizer rates at 93%, 24%, and 9%, respectively; for maize nitrogen, phosphorus, and potassium fertilizer rates at 83%, 22%, and 9%, respectively; and for wheat nitrogen, phosphorus, and potassium fertilizer rates at 1%, 1%, and 8%, respectively.

Fig. 7: Multiobjective NSGA optimization of the crop fertilizer rate in SW China.
Fig. 7: Multiobjective NSGA optimization of the crop fertilizer rate in SW China.
Full size image

Regression models of the fertilizer rate adjustment gradient with the total nitrogen response yield (OYN), total phosphorus response yield (OYP) and total potassium response yield (OYK): Rice (a), maize (c), and wheat (e). Regression models of the fertilizer rate adjustment gradient with the total nitrogen fertilizer rates (OFRN), total phosphorus fertilizer rates (OFRP), and total potassium fertilizer rates (OFRK): Rice (b), maize (d), and wheat (f). The ring charts in the middle show the optimal adjustment gradients (%) of the nitrogen, phosphorus and potassium fertilizer rates calculated by the NSGA for the 3 crops. The maps on the right show the yields (t ha−1) of rice (g), maize (h), and wheat (i) after fertilizer rate optimization. The ring charts in the map show the total crop yield (106 t), with the green color denoting the total YF in 2019 and the orange color denoting the total YF after fertilizer rate optimization.

Table 4 Regression model for crop fertilizer rate optimization

According to the optimal adjustment gradient, grid data of the optimal fertilizer rates for the three crops were generated in ArcGIS, and the established RF model was subsequently employed to predict crop yields. Table 5 and Fig. 7 show that the total crop yield in the study area increased by 13.4 × 104 t after fertilizer rate optimization compared with that in 2019, of which the total rice yield increased by 8.6 × 104 t, the total maize yield increased by 4.8 × 104 t, and the wheat yield remained constant. Moreover, the total fertilizer rate in the study area decreased by 7.9 × 104 t (7.2%) compared with that in 2019, of which the nitrogen fertilizer rate decreased by 11.3 × 104 t (17.8%), the phosphorus fertilizer rate increased by 2.4 × 104 t (9.9% increase), and the potassium fertilizer rate increased by 1.0 × 104 t (5.0%). Among the crops, the fertilizer rates decreased by 6.8 × 104 t for rice, by 1.3 × 104 t for maize, and increased slightly (0.3 × 104 t) for wheat. In general, the nitrogen fertilizer rate significantly decreased in the study area, while the nutrient structure was optimized, and the ratio of nitrogen, phosphorus, and potassium fertilizer rates was optimized from 1:0.38:0.33 in 2019 to 1:0.51:0.42, which reached the appropriate nutrient input level for Chinese farmland95,96. Optimization mapping of farmland nutrients can accurately reveal the magnitude and distribution of fertilizer rate adjustments (Fig. 8) via the analysis of the spatial changes in crop fertilizer rates before and after optimization. Obviously, there was spatial heterogeneity in the optimization of fertilizer rates for the three crops. For rice, the nitrogen fertilizer rate must be reduced in most areas, especially in the western plains, along the Minjiang and Fujiang Rivers, and in the lower reaches of the Tuojiang River; the phosphorus and potassium fertilizer rates must be reduced in the western plains and along the Minjiang River but must be increased in the central and northern hills. For maize, the nitrogen fertilizer rate must be reduced in hilly areas on both sides of the Fujiang and Jialingjiang Rivers, but must be moderately increased in the western plains and southern hills; the phosphorus and potassium fertilizer rates must be increased in most areas except along the Minjiang River and in southern mountainous areas. For wheat, the fertilizer rates must be moderately reduced in the central hills and moderately increased in the northern hills and mountains.

Fig. 8: Spatial optimization of farmland nutrients in SW China.
Fig. 8: Spatial optimization of farmland nutrients in SW China.
Full size image

The maps show the spatial distributions of the optimized adjustments of the rice, maize and wheat fertilizer rates (a positive value indicates an increase in the fertilizer rate, whereas a negative value indicates a decrease in the fertilizer rate): ac Changes in the rice nitrogen, phosphorus and potassium fertilizer rates (kg ha−1); df changes in the maize nitrogen, phosphorus and potassium fertilizer rates (kg ha−1); gi changes in the wheat nitrogen, phosphorus and potassium and potassium fertilizer rates (kg ha−1). The ring charts show the total fertilizer rate (104 t), with the green color indicating the total fertilizer rate in 2019 and the orange color representing the total fertilizer rate after optimization.

Table 5 Comparison of the crop fertilizer rates and yields before and after optimization in SW China

Discussion

The precision management of nutrient resources at the national and regional scales is a key issue for ensuring sustainable agriculture21. Over the years, fertilizer field experiments have revealed the quantitative relationship between farmland nutrients and crop yields at the microscale, but due to the lack of methods for spatially associating and scaling up field experimental data, there is uncertainty in the spatially optimal allocation and management of farmland nutrient resources91. On the basis of the widely employed 3414 fertilizer field experimental method in China, an RF prediction model for the crop yield was established under different nutrient conditions, which bridges the gaps in macroscale application of single-point fertilizer field experiments. In an empirical study in Southwest China, we reported that the contribution of fertilizer application to the crop yield decreases with increasing basal soil fertility, whereas the FCR varies across regions (plains<hills<mountains) and crops (rice<maize<wheat), which is consistent with the findings of relevant studies97,98,99. Importantly, our research approach is more advantageous for spatially simulating crop yield responses to nutrient regulation. The general variable importance trend of the RF model was as follows: location factors > meteorological factors > nutrient factors > topographic factors (Supplementary Tables 1318). Latitude and longitude exhibited the greatest importance, indicating a significant spatial correlation in the crop yield, which further supports the need for spatial optimization of nutrient resources. On one hand, the study area is situated in the transitional zone between the Qinghai–Tibet Plateau and the middle–lower Yangtze River Plain, where location factors significantly influence the distribution of light and heat resources, thereby affecting crop yield potential100,101. On the other hand, relevant studies indicate that crop yield prediction exhibits scale dependency24. Variables such as longitude and latitude may be more suitable for large-scale and mesoscale yield prediction models, while such variables may not be necessary in small-scale regions with low spatial autocorrelation. Precipitation and temperature are also important for the crop yield; in particular, precipitation is the most important factor for wheat, but the effect of temperature is significantly lower for maize than for the other crops, which may be due to the more favorable environmental adaptability of maize102. The importance of nutrient factors exhibited the order of phosphorus>nitrogen>potassium, and all three crops demonstrated phosphorus sensitivity103, indicating that maintaining a phosphorus balance is important for maintaining crop yield stability in the study area. The importance of the vegetation index was moderate for all the RF models, indicating that vegetation information can effectively reflect crop growth trends. Owing to the overall low altitude of the study area, the effect of altitude on the crop yield was limited, while the slope and pH were the least important factors. In addition, there was no significant difference in the absolute errors of the YS and YF predictions, indicating that the prediction errors may be caused by uncertain factors of crop growth, such as crop varieties, extreme weather, and pests104,105,106. Therefore, yield prediction models should further integrate crop characteristics and adverse environmental factors to increase their accuracy.

In previous macroscale farmland nutrient balance studies, the apparent balance method has been applied, which can hardly reveal the nutrient balance of different crops54,107. Moreover, microscale crop nutrient balance assessments are limited to a few field experimental sites61, which neglects the spatial application of experimental data. To bridge this research gap, a nutrient balance assessment framework was proposed on the basis of the crop fertilization response. On the one hand, YS and YF values have been obtained under the same environmental conditions in fertilizer field experiments. Thus, the FIY excludes the complex effects of environmental factors other than fertilization, such as nutrients contained in the soil, derived from the atmosphere, and brought in by water, which increases the accuracy and reliability of nutrient demand measurements. On the other hand, this approach facilitates spatial identification and accurate mapping of the crop nutrient balance, which provides a basis for the next step of optimal regulation of fertilizer inputs. Empirical studies have shown regional and crop differences in nutrient balances in the study area, highlighting the importance of different nutrient management strategies. First, it was confirmed that nitrogen reduction management strategies are particularly important for Southwest China, and the keys to nitrogen regulation are rice and maize in the western plains and along major rivers54,108,109. Second, there was widespread phosphorus deficiency in the central and northeastern parts of the study area, especially for maize and wheat, with NBRP values ranging from −0.4 to −0.5, which differs from previous findings of phosphorus excess in Chinese farmlands110. On the one hand, the phosphorus fertilizer rate for cash crops is much higher than that for grain crops55, so the apparent balance method can reflect only the general trend in farmland phosphorus excess; on the other hand, although the soil phosphorus content increased slightly in the study area, it remained low (soil available phosphorus < 15 mg/kg) in most areas111. This phenomenon, coupled with a significant decrease in the phosphorus fertilizer rate per unit area (18 and 13%) for rice and wheat since 2009, has resulted in an increased risk of phosphorus deficiency for half of the crops. Third, the results of this study confirm the consensus that potassium is widely deficient in Chinese farmlands112,113. Although the soil available potassium content has increased in Southwest China over the past decade, the potassium fertilizer rates per unit area for rice and maize have decreased (24% and 7%, respectively), resulting in insufficient potassium inputs109. Unexpectedly, the potassium balance of rice showed a polarized trend, which may be related to the fact that farmers in the economically developed regions of the plains and Minjiang River more closely accounted for potassium fertilizer inputs114. In addition, owing to the limited number of fertilizer utilization efficiency field experiments, the accuracy of spatial variation simulations for fertilizer utilization efficiency is insufficient. Therefore, the average fertilizer utilization efficiency of Sichuan Basin was used in this study, but the fertilizer utilization efficiency varies by 1–2% across different regions (plains<hills<mountains)108, which may cause the theoretical fertilizer rate for crops to be slightly lower than the actual requirements in the plains and slightly higher in the mountains. Therefore, it is necessary to increase the accuracy of determining the fertilizer utilization efficiency in further studies.

Finding the optimal balance between food security and ecological security is a relevant and difficult issue in the sustainable management of farmland nutrients75. In this study, we adopted a multiobjective NSGA optimization method, which not only aims to provide the optimal solution of fertilizer adjustment but also aims to facilitate the spatial mapping of the optimal solution. The optimization results revealed that the nitrogen fertilizer reduction potential in Southwest China was 17.8%, which is consistent with the range of values of 10–20% estimated in related studies115,116. The nitrogen fertilizer reduction potential of rice reached 32.5%, and the average fertilizer rate can be reduced from 136 kg ha−1 in 2019 to 92 kg ha−1, which is higher than the estimates obtained in related studies117. The main reason may be that the organic matter and total nitrogen contents in paddy soils (with averages of 26.7 g kg−1 and 1.47 g kg−1, respectively) in the study area are significantly greater than those in dryland soils (with averages of 19.4 g kg−1 and 1.14 g kg−1, respectively), which results in a lower contribution of fertilizer application to the rice yield than that to the yields of the other crops. The highest nitrogen reduction potential of rice was observed in the western plains, where the average soil organic matter and total nitrogen contents are greater than 30 and 1.7 g kg−1, respectively118, while the fertilization rate is greater than 150 kg ha−1. The maize nitrogen fertilization rate can be reduced by 11.4%, from 206 kg ha−1 in 2019 to 183 kg ha−1, which conforms with related studies119. Although there was an increase in the optimized phosphorus and potassium fertilization rates for the three crops, the fertilization rates are still lower than the recommendations of related studies119,120,121, indicating that the fertilization structure in the study area has been optimized to ensure the stability of crop yields.

The ‘field experiment modeling-crop yield prediction-nutrient balance optimization’ methodological framework established in this study has achieved satisfactory results in optimizing fertilizer rates in southwestern China. However, the application of these findings remains limited. Firstly, crop yield prediction variables require regional adjustments; for example, factors such as soil moisture and drought frequency may need to be considered in the arid regions of northern China122. Secondly, this approach may not be suitable for high-input intensive systems where nutrient dynamics differ substantially. Greenhouse cultivation systems, for example, suffer from serious nutrient accumulation and continuous cropping issues, resulting in distinct crop nutrient demand patterns compared to field crops. This makes it difficult to establish models such as fertilizer effect functions and nutrient balance123. Thirdly, constrained by computational efficiency, the computational complexity was reduced by fitting a linear model of the gradient adjustment and yield and fertilizer rates without implementing grid-by-grid iterative NSGA optimization, which will be further explored and addressed in our future research. Notably, since 2020, the Chinese government has launched a new round of fertilizer reduction initiatives124, mandating further decreases in fertilizer rates and implementing quota management for nitrogen fertilizers in crops, thereby providing extensive application scenarios for the methodological framework developed in this study. Next, we will utilize the latest soil and field experiment data to conduct research, aiming to provide decision-making references for the precise management of farmland nutrient resources in China.

Methods

Study area

The Sichuan Basin, one of China’s four major basins, is located in the southern–central part of the Asian continent (28°–32°N, 102°–108°E) and is surrounded by the Tibetan Plateau, Yunnan-Guizhou Plateau, Wushan Mountains, and Daba Mountains. The total size of the study area is approximately 18 × 104 km2 (Fig. 9), with plains and hills in the central part (250–750 m altitude) surrounded by mountains (1000–3000 m altitude). The surface of the basin is covered by Mesozoic purple–red sandstone and mudstone, forming the largest purple soil distribution area in China. The climate is warm and humid, and the area belongs to the mid-subtropical humid climate zone, with an average annual temperature of 16–18 °C, an annual precipitation of 1000–1200 mm, an annual accumulated temperature of 4000–6000 °C, and an annual sunshine duration of only 1000–1400 h; hence, the area receives the least sunshine in China125. The number of rivers in the basin exceeds one thousand, with runoff exceeding 250 billion m3, and the famous Yangtze River originates in the southern part of the basin. The Chengdu‒Chongqing urban agglomeration in the Sichuan Basin is one of the most economically developed regions in China, with a population of more than 75 million people, a gross domestic product (GDP) of more than 5 trillion CNY, and an urbanization rate of 60%. Moreover, grain has been cultivated in the region for more than 3000 years, and the current annual grain yield is above 28 million tons, making it the most important grain-producing area in Southwest China. However, due to long-term irrational fertilization, the consumption of chemical fertilizers in the region exceeds 300 kg ha−1 (that of N exceeds 140 kg ha−1)126, leading to serious problems such as greenhouse gas emissions and water pollution by nitrogen and phosphorus83,84. The fertilizer inputs in the Sichuan Basin are much higher than the international average95, with agricultural nonpoint source pollution already at the moderate risk level127. The optimal regulation of nutrient resources in farmlands in the Sichuan Basin is therefore important for ensuring environmental protection and food security in the upper reaches of the Yangtze River in China.

Fig. 9: Map of the location, landforms and crop distribution in SW China.
Fig. 9: Map of the location, landforms and crop distribution in SW China.
Full size image

a Location and landforms of the study area. The colors denote the altitude (m) of the study area. The blue lines denote the major rivers. b Distribution of rice, maize, and wheat planting areas and patterns. c Statistical chart of rice, maize, and wheat planting areas (103 ha).

Data sources and processing

Spatial distribution data (30 × 30 m) of rice, maize, and wheat for the study area were obtained from the National Ecosystem Science Data Center128,129,130. Soil and fertilizer rate data were collected from the Soil Testing and Formulated Fertilization Project (STFF) and the Cultivated Land Quality Monitoring Project (CLQM) of Sichuan Province. A total of 20,798 and 17,737 surface soil samples (0–20 cm) from cropland were collected in the study area in 2009 and 2019 (Fig. 10), respectively, and the soil property indicators included organic matter (OM), pH, available phosphorus (AP), and available potassium (AK) (Supplementary Table 19). The nitrogen fertilizer rate (FRN), phosphorus fertilizer rate (FRP), and potassium fertilizer rate (FRK) for rice, maize, and wheat were obtained from a farmer’s fertilization survey, which included 3918 and 3344 samples for rice, 4212 and 3592 samples for maize, and 1591 and 957 samples for wheat in 2009 and 2019, respectively (Table 6 and Supplementary Table 20). The method of fertilization survey refers to the Technical Code for Cultivated Land Quality Monitoring (NY/T 1119). FRN, FRP, and FRK were calculated for each crop cultivation survey site based on the nutrient content, dosage, and frequency of fertilizers. The formula can be expressed as

$${FRN}=\mathop{\sum }\limits_{i=1}^{n}\left({{NCN}}_{i}\times {Q}_{i}\right)$$
(1)
$${FRP}=\mathop{\sum }\limits_{i=1}^{n}\left({{NCP}}_{i}\times {Q}_{i}\right)$$
(2)
$${FRK}=\mathop{\sum }\limits_{i=1}^{n}\left({{NCK}}_{i}\times {Q}_{i}\right)$$
(3)

where FRN, FRP, and FRK refers to the nitrogen fertilizer rate (N), phosphorus fertilizer rate (P2O5), potassium fertilizer rate (K2O) during the growth period of rice (kg ha−1); n refers to the frequency of fertilization during the growth period of rice; \({{NCN}}_{i}\), \({{NCP}}_{i}\), and \({{NCK}}_{i}\) refers to the N, P2O5, and K2O contents of the i times of fertilization (%), respectively; \({Q}_{i}\) refers to the actual rate of the i times fertilizer (kg ha−1).

Fig. 10: Distribution of fertilizer field experiments, soil samples and fertilization survey samples in SW China.
Fig. 10: Distribution of fertilizer field experiments, soil samples and fertilization survey samples in SW China.
Full size image

The gray fills in the map indicate the planting areas of rice, maize, or wheat. The ring chart shows the number of fertilizer field experiments (green denotes the number of training samples, and orange denotes the number of validation samples). a Rice fertilizer field experiments. b Maize fertilizer field experiments. c Wheat fertilizer field experiments. d Soil sample sites in 2009. e Soil sample sites in 2019. f Rice fertilization survey sites in 2009. g Rice fertilization survey sites in 2019. h Maize fertilization survey sites in 2009. i Maize fertilization survey sites in 2019. j Wheat fertilization survey sites in 2009. k Wheat fertilization survey sites in 2019.

Table 6 Statistics of crop field experiments, soil and fertilizer survey samples in SW China

Geostatistical methods were used to predict the spatial distributions of soil properties and fertilizer rates131,132. The Kolmogorov-Smirnov (K-S) method was used in SPSS 24 software for testing the normal distribution of the original data. Finally, we used a logarithmic transformation to make pH, AP, AK, FRN, FRP, and FRK conform to normal distributions to meet the requirements of geostatistical analysis. Geostatistics is based on the theory of regionalized variables and uses semi-variance functions as the main tool to reveal the spatial distribution, variation, and related characteristics of attribute variables. Geostatistical analysis has been widely applied in the study of the spatial distribution of soil and fertilizers. The semi-variance function is the key to geostatistical analysis, reflecting the degree of the spatial autocorrelation of observations at different distances. The model can be expressed as

$$\gamma \left(h\right)=\frac{1}{2N\left(h\right)}\mathop{\sum }\limits_{i=1}^{N\left(h\right)}{\left[Z\left({x}_{i}\right)-Z\left({x}_{i}+h\right)\right]}^{2}$$
(4)

where \(\gamma \left(h\right)\) refers to the semi-variance function; h refers to the step size; N(h) refers to the logarithm of the observed sample points, and \(Z\left({x}_{i}\right)\) and \(Z\left({x}_{i}+h\right)\) refer to the measured values of the variable Z(x) at the spatial positions \({x}_{i}\) and \({x}_{i}+h\), respectively.

The ratio of Nugget to Sill C0/(C0 + C) can indicate the degree of spatial heterogeneity caused by random factors, which is often used as a classification basis for spatial correlation of variables. C0/(C0 + C) less than 25% indicates strong spatial correlation; C0/(C0 + C) is a moderate spatial correlation between 25 and 75%; C0/(C0 + C) greater than 75% indicates weak spatial correlation. We used GS+ software to fit the semi-variance function model of each indicator, and after repeated simulations, we ultimately selected the optimal fitting function to obtain the semi-variance function graph (Supplementary Fig. 23 and Supplementary Fig. 24) and structural parameters (Supplementary Tables 21 and 22). The results showed that each soil and fertilizer index had a good semi-variance structure and spatial correlation. Error analysis revealed that the geostatistical spatial distribution predictions were reliable. ArcGIS was used to map the spatial distribution of each factor (Supplementary Fig. 2529).

Fertilizer field experimental data were collected from the STFF of the Sichuan Basin, including 2327 experiments (rice: 1182; maize: 512; wheat: 633) from 2009 to 2019 (Fig. 10). These experiments relied on the “3414” design scheme, which was proposed by the Chinese Ministry of Agriculture. The “3414” field experiment is not a long-term experiment and is usually conducted for one or several years at each site. All fertilizer field experiments were conducted by technicians from county agricultural government departments to ensure the reliability of the test results. The “3414” field experiment refers to 3 factors (nitrogen, phosphorus, and potassium), 4 fertilization levels (0, 1, 2, and 3), and 14 treatments93. Four fertilization levels were employed: level 0 refers to no fertilization; level 2 refers to the representative fertilization rate of the experimental area (N, P2O5, and K2O); level 1 = level 2 × 0.5 (this level represents insufficient fertilization); and level 3 = level 2 × 1.5 (this level represents excessive fertilization). The 14 experimental treatments were (1) N0P0K0, (2) N0P2K2, (3) N1P2K2, (4) N2P0K2, (5) N2P1K2, (6) N2P2K2, (7) N2P3K2, (8) N2P2K0, (9) N2P2K1, (10) N2P2K3, (11) N3P2K2, (12) N1P1K2, (13) N1P2K1, and (14) N2P1K1 (Supplementary Table 23). The ‘3414’ field experiment is described in Supplementary Note 1.

The Resource and Environmental Science Data Platform provides spatial datasets of digital elevation models (DEMs), annual mean precipitation (PRE), annual mean temperature (TEM), NDVI values at the crop maturity stage, roads, rivers, and administrative districts133,134,135,136. These grid data were converted to a uniform spatial resolution (30 × 30 m) via ArcGIS 10.8 (Supplementary Table 25 and Supplementary Figs. 28 and 29). Socioeconomic data were collected from the Statistical Yearbook of Sichuan Province126,137.

Crop yield prediction under different nutrient conditions

The RF algorithm is a machine learning algorithm that integrates many classification and regression trees (CARTs) and involves the use of a double random sampling method to avoid overfitting43. RF regression analysis first involves constructing n regression trees by randomly selecting a subset of n samples from the original sample using the bootstrap method. The remaining samples constitute out-of-bag (OOB) data each time for error estimation and variable importance evaluation. Second, while each tree is generated, m variables (m < M) are randomly selected from the set of M explanatory variables, and the optimal branches are recursively selected via the mean square deviation as a node splitting criterion. Finally, the average of all the decision tree predictions is adopted as the final result138. In this work, RF yield prediction models for rice, maize and wheat were established in ArcGIS software using 2327 fertilizer field experiments (approximately 90% of the data were randomly selected as training samples, and approximately 10% of the data were used as validation samples) (Fig. 10). After several fitting comparison steps, the RF model parameters were set as follows: the number of decision trees is 1000, the minimum leaf size is 5, the number of randomly sampled variables is the square root of the total number of explanatory variables, and the remaining parameters were set to software default values.

Our previous study revealed that the crop nutrient balance can be effectively evaluated by predicting crop yields under different nutrient conditions (nonfertilization and fertilization)118. Therefore, we established RF prediction models for the soil-based yield (YS) and fertilized yield (YF) of the three crops. The YS refers to the crop yield in the current year without fertilization, reflecting the inherent soil productivity of farmland, and it can be expressed as the yield of treatment 1 (N0P0K0) under the 3414 experimental scheme. The YS prediction model included 11 explanatory variables: longitude (X1), latitude (X2), altitude (X3), slope (X4), soil OM (X5), soil pH (X6), soil AP (X7), soil AK (X8), PRE (X9), TEM (X10), and the NDVI at the crop maturity stage (X11). The YF denotes the crop yield under fertilization conditions, which can be expressed as the yield of treatment 6 (N2P2K2) under the 3414 experimental scheme. The number of explanatory variables of the YF model was 14, with the addition of three fertilization rate variables: FRN (X12), FRP (X13), and FRK (X14). Supplementary Table 24 shows the statistics of rice YS (treatment 1), YF (treatment 6), and fertilizer rate (level 2) for all “3414” field experimental points in this study. The fertilizer increased yield (FIY) was used to express the increase in the crop yield due to fertilizer application by subtracting the YS from the YF. Since the YS and YF were obtained under the same natural and farm management conditions in the field experiments, the FIY can reliably reveal the independent effect of fertilization on the crop yield by excluding soil nutrient differences139. The fertilizer contribution ratio (FCR) was used to measure the contribution of fertilizer to crop yield140. The calculation is as follows:

$${YS}=G\left({X}_{k}\right),\,{X}_{k}={X}_{1},\,{X}_{2},\,\cdots ,\,{X}_{11}$$
(5)
$${YF}=H\left({X}_{k}\right),\,{X}_{k}={X}_{1},\,{X}_{2},\,\cdots ,\,{X}_{14}$$
(6)
$${FIY}={YF}-{YS}$$
(7)
$${FCR}=\left({YF}-{YS}\right)/{YF}\times 100 \%$$
(8)

where \({YS}\), \({YF}\), \({FIY}\) and \({FCR}\) denote the soil-based yield (kg ha−1), the fertilized yield (kg ha−1), the fertilizer increased yield (kg ha−1) and the fertilizer contribution ratio (%), respectively, in each crop planting grid (30 × 30 m); \(G\left({X}_{k}\right)\) and \(H\left({X}_{k}\right)\) denote the \({YS}\) and \({YF}\) RF prediction models, respectively, established in the field experiments; and \({X}_{k}\) is the value of the explanatory variable k in each crop planting grid.

To evaluate the simulation accuracy of the RF model, we randomly selected 225 field experiments (rice: 110; maize: 52; wheat: 63) as validation samples to calculate the error between the actual and predicted yields (Fig. 10). The evaluation metrics can be calculated as follows:

$${ME}=1/n\mathop{\sum }\limits_{i=1}^{n}\left\{z\left({x}_{i}\right)-{z}^{{\prime} }({x}_{i})\right\}$$
(9)
$${MAE}=1/n\mathop{\sum }\limits_{i=1}^{n}\left\{\left|z\left({x}_{i}\right)-{z}^{{\prime} }({x}_{i})\right|\right\}$$
(10)
$${RMSE}=\sqrt{1/n\mathop{\sum }\limits_{i=1}^{n}{\left\{z\left({x}_{i}\right)-{z}^{{\prime} }({x}_{i})\right\}}^{2}}$$
(11)
$${SMAPE}=1/n\mathop{\sum }\limits_{i=1}^{n}\left\{\left(2\times \left|z\left({x}_{i}\right)-{z}^{{\prime} }({x}_{i})\right|\right)/\left(\left|z\left({x}_{i}\right)\right|+\left|{z}^{{\prime} }({x}_{i})\right|\right)\right\}\times 100 \%$$
(12)

where ME, MAE, RMSE, and SMAPE are the mean error, the mean absolute error, the root mean square error, the mean relative error, and the symmetric mean absolute percentage error, respectively; \({z}^{{\prime} }({x}_{i})\) is the predicted value of sample i; \(z\left({x}_{i}\right)\) is the actual observed value of sample i; and n is the number of samples. The smaller the MAE, RMSE, and SMAPE values are, the smaller the error and the higher the simulation accuracy.

Crop nutrient balance assessment

The spatial distributions of the nutrient balances for the three crops were evaluated according to our previous research methodology118. First, the average nutrient uptake per 100 kg of the crop yield141 and the fertilizer utilization efficiency142,143 were calculated for the three crops using 214 fertilizer utilization efficiency field experiments in the Sichuan Basin (Table 7 and Supplementary Fig. 30). Second, on the basis of the nutrient balance method144, the theoretical fertilizer rates for the three crops were calculated using the FIY prediction results. Finally, the theoretical fertilizer rate was compared with the actual fertilizer rate to calculate the nutrient balance ratios of nitrogen, phosphorus, and potassium for the three crops61. The calculation is as follows:

$${NUTN}=\left[{Y}_{{SE}}\times {{NCN}}_{{SE}}+{Y}_{{SL}}\times {{NCN}}_{{SL}}\times \left(1-{SR}\right)\right]/{Y}_{{SE}}\times 100$$
(13)
$${NUTP}=\left[{Y}_{{SE}}\times {{NCP}}_{{SE}}+{Y}_{{SL}}\times {{NCP}}_{{SL}}\times \left(1-{SR}\right)\right]/{Y}_{{SE}}\times 100$$
(14)
$${NUTK}=\left[{Y}_{{SE}}\times {{NCK}}_{{SE}}+{Y}_{{SL}}\times {{NCK}}_{{SL}}\times \left(1-{SR}\right)\right]/{Y}_{{SE}}\times 100$$
(15)
$${REN}={NUTN}\times \left({Y}_{{NPK}}-{Y}_{{PK}}\right)/{FerN}\times 100$$
(16)
$${REP}={NUTP}\times \left({Y}_{{NPK}}-{Y}_{{NK}}\right)/{FerP}\times 100$$
(17)
$${REK}={NUTK}\times \left({Y}_{{NPK}}-{Y}_{{NP}}\right)/{FerK}\times 100$$
(18)

where \({NUTN}\), \({NUTP}\) and \({NUTK}\) denote nitrogen, phosphorus and potassium nutrient uptake values (kg) per 100 kg of the crop yield, respectively; \({Y}_{{SE}}\) and \({Y}_{{SL}}\) are the crop seed yield and stem-leaf yield (kg ha−1), respectively; \({{NCN}}_{{SE}}\) and \({{NCN}}_{{SL}}\) denote the total nitrogen contents (g kg−1) in crop seeds and stems–leaves, respectively; \({{NCP}}_{{SE}}\) and \({{NCP}}_{{SL}}\) denote the total phosphorus contents (g kg−1) in crop seeds and stems–leaves, respectively; and \({{NCK}}_{{SE}}\) and \({{NCK}}_{{SL}}\) denote the total potassium contents (g kg−1) in crop seeds and stems–leaves, respectively; and \({SR}\) is the rice straw return rate. According to relevant research145, the straw return rates for rice, maize, and wheat in the Sichuan Basin are 63.64%, 42.36% and 40.55%, respectively. Moreover, \({REN}\), \({REP}\) and \({REK}\) denote the crop nitrogen, phosphorus and potassium fertilizer utilization efficiency values (%), respectively; \({Y}_{{NPK}}\) denotes the crop yield under the field experiment treatment using nitrogen, phosphorus and potassium fertilizers; \({Y}_{{PK}}\) is the crop yield under the field experiment treatment using phosphorus and potassium fertilizers; \({Y}_{{NK}}\) denotes the crop yield under the field experiment treatment using nitrogen and potassium fertilizers; \({Y}_{{NP}}\) denotes the crop yield under the field experiment treatment using nitrogen and phosphorus fertilizers; and \({FerN}\), \({FerP}\) and \({FerK}\) are the nitrogen, phosphorus and potassium fertilizer rates (kg ha−1), respectively, in the fertilizer utilization efficiency field experiment.

$${TFRN}=\left[{FIY}\times {NUTN}\right]/\left({REN}\times 100\right)$$
(19)
$${TFRP}=\left[{FIY}\times {NUTP}\right]/\left({REP}\times 100\right)$$
(20)
$${TFRK}=\left[{FIY}\times {NUTK}\right]/\left({REK}\times 100\right)$$
(21)
$${NBRN}=\left({FRN}-{TFRN}\right)/{TFRN}$$
(22)
$${NBRP}=\left({FRP}-{TFRP}\right)/{TFRP}$$
(23)
$${NBRK}=\left({FRK}-{TFRK}\right)/{TFRK}$$
(24)

where \({TFRN}\), \({TFRP}\) and \({TFRK}\) denote the theoretical nitrogen fertilizer rate (kg ha−1), the theoretical phosphorus fertilizer rate (kg ha−1), and the theoretical potassium fertilizer rate (kg ha−1) for the crop, respectively; \({FRN}\), \({FRP}\) and \({FRK}\) denote the actual nitrogen, phosphorus and potassium fertilizer rates (kg ha−1) for the crop, respectively; and \({NBRN}\), \({NBRP}\) and \({NBRK}\) denote the crop nutrient balance ratios (\({NBR}\)) of nitrogen, phosphorus and potassium, respectively (\({NBR} > 0\) indicates excessive fertilizer inputs; \({NBR}=0\) indicates balanced fertilizer inputs; and \({NBR} < 0\) indicates insufficient fertilizer inputs).

Table 7 The average nutrient uptake per 100 kg of the crop yield and the fertilizer utilization efficiency in the Sichuan Basin, SW China

Multiobjective spatial optimization of crop fertilizer rates

In this study, the NSGA-II was used to optimize crop fertilizer application rates. Step 1: Considering the spatial variability in the crop nutrient balance, the actual fertilizer rate in each grid cell was gradually adjusted to the theoretical fertilizer rate with a gradient of 10% (i.e., the 0% gradient yields the actual fertilizer rate, and the 100% gradient yields the theoretical fertilizer rate), and grid data of nitrogen, phosphorus and potassium fertilizer rates under different adjustment gradients were generated. Step 2: The grid data of all nitrogen fertilizer rate gradients from step 1 were sequentially input into the established RF yield prediction model (with the other model parameters remaining constant) to generate crop nitrogen response yield grid data under different adjustment gradients; the same method was applied to generate crop yield grid data under the predicted phosphorus and potassium fertilizer rate gradients. In step 3, the total nitrogen fertilizer rate (OFRN), total phosphorus fertilizer rate (OFRP), and total potassium fertilizer rate (OFRK) were calculated for the 3 crops under each adjustment gradient in the study area using the fertilizer rate grid data from step 2. The total nitrogen response yield (OYN), total phosphorus response yield (OYP), and total potassium response yield (OYK) were calculated for the 3 crops under each adjustment gradient in the study area using the crop yield grid data from step 2. A linear regression model was fitted with the total crop yield or the total fertilizer rate as the dependent variable and the corresponding adjustment gradient as the independent variable. Step 4: A Pareto solution set was computed via the NSGA module of MATLAB software using the above linear regression model as the objective function. This Pareto solution set contains several preferable solutions, and finally, the combination yielding a stable crop yield (increased or unchanged total yield) and the minimum fertilizer rate (especially nitrogen fertilizer) was selected as the nutrient optimization solution. The objective function can be expressed as:

$${{FRN}}^{{{\prime} }}={TFRN}\times \left[1+\left(1-{x}_{1}\right)\times {NBRN}\right]$$
(25)
$${{FRP}}^{{{\prime} }}={TFRP}\times \left[1+\left(1-{x}_{2}\right)\times {NBRP}\right]$$
(26)
$${{FRK}}^{{{\prime} }}={TFRK}\times \left[1+\left(1-{x}_{3}\right)\times {NBRK}\right]$$
(27)
$${OFRN}=\mathop{\sum }\limits_{i=1}^{n}{{FRN}}^{{{\prime} }}$$
(28)
$${OFRP}=\mathop{\sum }\limits_{i=1}^{n}{{FRP}}^{{{\prime} }}$$
(29)
$${OFRK}=\mathop{\sum }\limits_{i=1}^{n}{{FRK}}^{{{\prime} }}$$
(30)
$${OYN}=\mathop{\sum }\limits_{i=1}^{n}H({{FRN}}^{{{\prime} }})$$
(31)
$${OYP}=\mathop{\sum }\limits_{i=1}^{n}H({{FRP}}^{{{\prime} }})$$
(32)
$${OYK}=\mathop{\sum }\limits_{i=1}^{n}H({{FRK}}^{{{\prime} }})$$
(33)
$${MIN}\left({OFRN}\right)=u\left({x}_{1}\right)$$
(34)
$${MIN}\left({OFRP}\right)=u\left({x}_{2}\right)$$
(35)
$${MIN}\left({OFRK}\right)=u\left({x}_{3}\right)$$
(36)
$${MAX}\left({OYN}\right)=v\left({x}_{1}\right)$$
(37)
$${MAX}\left({OYP}\right)=v\left({x}_{2}\right)$$
(38)
$${MAX}\left({OYK}\right)=v\left({x}_{3}\right)$$
(39)

where \({x}_{1}\), \({x}_{2}\) and \({x}_{3}\) denote the adjustment gradients (%) of the nitrogen, phosphorus and potassium fertilizer rates, respectively; n denotes the total number of grid units for the crop planting map of the study area; \({{FRN}}^{{{\prime} }}\), \({{FRP}}^{{{\prime} }}\) and \({{FRK}}^{{{\prime} }}\) denote the nitrogen, phosphorus and potassium fertilizer rates (kg ha−1), respectively, for a given crop in each grid under a certain fertilizer rate adjustment gradient; \({OFRN}\), \({OFRP}\) and \({OFRK}\) are the total nitrogen fertilizer rate, total phosphorus fertilizer rate and total potassium fertilizer rate, respectively, for the crop under the fertilizer rate adjustment gradient; \({OYN}\), \({OYP}\) and \({OYK}\) denote the total nitrogen response yield, total phosphorus response yield and total potassium response yield, respectively, of the crop under the fertilizer rate adjustment gradient; H(x) denotes the established RF prediction model for the crop YF; \(u\left({x}_{1}\right)\), \(u\left({x}_{2}\right)\) and \(u\left({x}_{3}\right)\) denote the regression models of the adjustment gradients (%) of the nitrogen, phosphorus and potassium fertilizer rates with \({OFRN}\), \({OFRP}\) and \({OFRK}\), respectively; and \(v\left({x}_{1}\right)\), \(v\left({x}_{2}\right)\) and \(v\left({x}_{3}\right)\) denote the regression models of the adjustment gradients (%) of the nitrogen, phosphorus and potassium fertilizer rates with \({OYN}\), \({OYP}\) and \({OYK}\), respectively.

In addition, the upper and lower boundary constraints (0–1) were set in MATLAB for parameters \({x}_{1}\), \({x}_{2}\), and \({x}_{3}\); the population size was 100; and the number of generations, crossover probability, and mutation probability were set to system default values.