Farmland heavy metal accumulation prediction method based on material flow

Through a material flow-based farmland heavy metal accumulation prediction method, using machine learning models and material flow analysis, the problem of soil and crop heavy metal accumulation risk prediction deviating from reality due to long-term fertilization was solved, and high-precision multi-cycle accumulation effect simulation and risk zone zoning adjustment were achieved, ensuring the safety of the farmland system.

CN120656580APending Publication Date: 2025-09-16CHINA AGRI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510673430.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-23
Publication Date
2025-09-16

Smart Images

  • Figure CN120656580A_ABST
    Figure CN120656580A_ABST
Patent Text Reader

Abstract

The invention provides a material flow-based farmland heavy metal accumulation prediction method. The method comprises the following steps of S1, collecting historical soil data, crop data and fertilizer data; s2, constructing a machine learning model based on a material flow analysis strategy, and training the machine learning model by using the data obtained in S1 to obtain a prediction model; s3, inputting soil data, planned fertilizer data and planned crop data into the prediction model, and performing iterative operation by the prediction model according to the planting period to obtain soil heavy metal content and crop heavy metal content of a specified number of planting periods; and S4, judging whether to adjust the planned fertilizer and the planned crops according to a comparison result. The method has the advantages that the multi-cycle cumulative effect can be simulated according to the planting cycle iteration input, meanwhile, the historical soil physical and chemical indexes are utilized, the material conservation formula serves as a framework based on the organic combination of the material flow principle and machine learning, and the accuracy and practicability of the prediction result are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of farmland heavy metal accumulation prediction, and in particular relates to a farmland heavy metal accumulation prediction method based on material flow. Background Art

[0002] Fertilization is an essential agronomic measure in agricultural production. Harmful heavy metal elements in fertilizers accumulate in farmland soil after long-term fertilization, posing a potential pollution risk to agricultural product safety. Accurately predicting the risk of heavy metal pollution in soil and crops caused by long-term fertilization is an important means to ensure food production safety and reduce the risk of human heavy metal exposure.

[0003] Mineral phosphate fertilizers and organic fertilizers often contain different levels of harmful heavy metal elements, among which cadmium is the primary inorganic pollutant. Long-term agricultural production activities with fertilization will lead to the accumulation of heavy metals in the soil and there is a risk of migration from the soil to crops. Compared with point source pollution, the accumulation of heavy metals in the soil and crops caused by fertilization is hidden, and usually requires decades of continuous monitoring. Long-term positioning tests have a long cycle and high cost, and it is difficult to use it as an effective means to monitor the risk of heavy metal pollution in farmland systems caused by long-term fertilization.

[0004] The traditional method for predicting the risk of heavy metal accumulation in farmland systems caused by long-term fertilization is to establish the relationship between heavy metal content in crops and soil properties through the Freundlich model, and calculate the system's heavy metal output flux; combined with the heavy metal flux introduced into the system by fertilization measures, the accumulation characteristics of heavy metals in the soil are calculated through the material flow model. However, in long-term fertilized soils, the heavy metal content in crops usually shows a nonlinear relationship with soil properties. Therefore, it is necessary to find a prediction method that is superior to the traditional Freundlich model. In addition, there are differences in heavy metal input due to different fertilizer sources; changes in soil properties with increasing fertilization years will also affect the characteristics of crop heavy metal enrichment. The currently widely used static model does not take into account the annual changes in system heavy metal input and output. As the prediction time step increases, the prediction results gradually deviate from the actual situation. Summary of the Invention

[0005] In view of this, the present invention aims to propose a method for predicting heavy metal accumulation in farmland based on material flow, in order to solve at least one of the above-mentioned technical problems.

[0006] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0007] A first aspect of the present invention provides a method for predicting heavy metal accumulation in farmland based on material flow, comprising the following steps:

[0008] S1. Collect historical soil data, crop data, and fertilizer data;

[0009] S2, build a machine learning model based on the material flow analysis strategy, use the data obtained in S1 to train the machine learning model, and obtain a prediction model;

[0010] S3. Collect soil data, input soil data, planned fertilizer data, and planned crop data into the prediction model. The prediction model performs iterative calculations based on the planting cycle to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles.

[0011] S4. Compare the soil heavy metal content obtained in S3 with the crop heavy metal content and the threshold value, and determine whether to adjust the planned fertilizer and planned crops based on the comparison results.

[0012] Furthermore, the historical soil data includes: historical soil pH value data, historical soil heavy metal content data, historical soil cation exchange capacity data, and historical soil organic matter content data;

[0013] Historical crop data include: historical crop heavy metal content, variety and yield data;

[0014] Historical fertilizer data include: historical fertilizer heavy metal content and weight data;

[0015] The data of soil heavy metal exceeding the standard is removed from the historical soil data in S1, and the data of crop heavy metal exceeding the standard is removed from the crop data.

[0016] Furthermore, step S4 includes the following steps:

[0017] S41. Set the soil heavy metal content threshold and the crop heavy metal content threshold.

[0018] S42. If the soil heavy metal content in a specified planting period exceeds the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, the area is determined to be a high-risk area;

[0019] If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, it will be determined as a specific risk area;

[0020] If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, it is determined to be a safe planting area;

[0021] If the soil heavy metal content in a specified planting cycle exceeds the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, the area is determined to be a medium-risk area;

[0022] S43. For high-risk areas, plant low-cadmium-accumulating crops or select crops with larger biomass to replace the original crop planting plan to form new planned crop data;

[0023] For medium-risk areas, shorten the designated number of planting cycles in step S3 to conduct continuous monitoring and plant crops as planned;

[0024] For specific risk areas, fertilizers with lower heavy metal content are selected to replace the original fertilization plan to form new planned fertilizer data;

[0025] Plant crops according to plan in safe planting areas;

[0026] S44. Return the new planned crop data and the new planned fertilizer data obtained in S43 to step S3 to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles, and repeat steps S41-S43.

[0027] Furthermore, the process of collecting soil data in step S3 is as follows:

[0028] S31. Collect multiple soil samples within a preset range at the selected point, and calculate the coefficient of variation of soil pH value data, soil heavy metal content data, soil cation exchange capacity data, and soil organic matter content data;

[0029] S32. If the coefficient of variation of three or four data points is less than 5%, the area is determined to be homogeneous, and the specified range is expanded based on the preset range until the coefficient of variation of at least two data points within the final range is not less than 5%. The mean of the last sampling is taken as the model input value;

[0030] Otherwise, the specified range is narrowed based on the preset range until the coefficient of variation of three or four data within the final range is less than 5%, and the mean is taken as the model input value.

[0031] Furthermore, the step S3 further includes the following steps:

[0032] S33, using all soil sample data within the final range in S32 to input into the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles, and calculating the probability of heavy metal exceeding the standard for the crops based on the heavy metal content of multiple crops;

[0033] S34. If the probability of excessive heavy metals in crops exceeds the probability threshold, the final range is narrowed, and step S33 is repeated until the probability of no excessive heavy metals in crops exceeds the probability threshold;

[0034] Otherwise, proceed to step S35;

[0035] S35, using the model input value obtained in S32 to input the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles;

[0036] The calculation formula for the heavy metal content of crops in S42 is as follows:

[0037] Cd1=Cd2×(1+p);

[0038] Among them, Cd1 is the heavy metal content of crops in S42, Cd2 is the heavy metal content of crops obtained in S35, and p is the probability threshold in S34.

[0039] Furthermore, in step S2, a machine learning model is constructed based on the material flow analysis strategy, and the material flow formula is:

[0040] Cd re =Cd bac +Cd fer -Cd grain -Cd straw -Cd water ;

[0041] Among them, Cd re The content of heavy metals in soil after planting and harvesting, Cd bac is the content of heavy metals in soil before planting, Cd fer The amount of heavy metals input for fertilization, Cd grain is the amount of crop grain removed, Cd straw is the amount of crop straw removed, Cd water Includes surface runoff and leaching losses, calculated using leaching and runoff coefficients based on local rainfall;

[0042] The amount of heavy metals input by fertilization is:

[0043] Cd fer =X×C Cdf ;

[0044] Where C Cdf is the heavy metal content in the fertilizer (mg / kg), and X is the amount of fertilizer applied (kg).

[0045] The amount removed from crop seeds is:

[0046] Cd grain =A×ML[C cdg ];

[0047] Where A is the crop yield (kg), C cdg is the cadmium content in crops (mg / kg), and ML is the optimal machine learning model selected after training.

[0048] Removed from crop residues:

[0049] Cd straw =r×ML[C cdg ]×d;

[0050] Where r is the crop straw-to-grain ratio, and d is the heavy metal content in crop straw and the coefficient of heavy metal content in crops.

[0051] Furthermore, in S2, the historical data is divided into K pre-training sets and 1 validation set;

[0052] The internal parameter range of the machine learning model is set through grid search, and K+1-fold cross-validation is performed. The validation results are used for parameter optimization and model evaluation.

[0053] The coefficient of determination R is used for model evaluation 2 The two loss functions RMSE and MAE are used as evaluation indicators, and the training set, prediction set and K+1 fold cross-validation results are comprehensively judged to screen out the optimal model.

[0054] A second aspect of the present invention provides an electronic device, comprising a processor and a memory communicatively connected to the processor and configured to store instructions executable by the processor, wherein the processor is configured to execute the method described in the first aspect.

[0055] The third aspect of the present invention provides a server, comprising at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to enable the at least one processor to execute the method described in the first aspect.

[0056] A fourth aspect of the present invention provides a computer-readable storage medium storing a computer program, which implements the method described in the first aspect when executed by a processor.

[0057] Compared with the existing technology, the method for predicting heavy metal accumulation in farmland based on material flow described in the present invention has the following beneficial effects:

[0058] The present invention describes a method for predicting heavy metal accumulation in farmland based on material flow. It can simulate multi-cycle accumulation effects by iteratively inputting according to the planting cycle. At the same time, it utilizes historical soil physical and chemical indicators, organically combines the material flow principle with machine learning, and uses the material conservation formula as the framework to improve the accuracy and practicality of the prediction results. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] The accompanying drawings, which constitute part of the present invention, are provided to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are provided to explain the present invention and do not constitute an undue limitation of the present invention. In the accompanying drawings:

[0060] Figure 1 The figure is a flow chart of the method described in the embodiment of the present invention. DETAILED DESCRIPTION

[0061] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0062] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, features defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0063] In the description of the present invention, it should be noted that, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integral connections; mechanical connections or electrical connections; direct connections or indirect connections through an intermediate medium; and internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on specific circumstances.

[0064] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0065] like Figure 1 As shown, a method for predicting heavy metal accumulation in farmland based on material flow includes the following steps:

[0066] S1. Collect historical soil data, crop data, and fertilizer data;

[0067] The historical soil data include: historical soil pH value data, historical soil heavy metal content data, historical soil cation exchange capacity data, and historical soil organic matter content data;

[0068] Historical crop data include: historical crop heavy metal content, variety and yield data;

[0069] Historical fertilizer data include: historical fertilizer heavy metal content and weight data;

[0070] The data of soil heavy metal exceeding the standard is removed from the historical soil data in S1, and the data of crop heavy metal exceeding the standard is removed from the crop data.

[0071] S2, build a machine learning model based on the material flow analysis strategy, use the data obtained in S1 to train the machine learning model, and obtain a prediction model;

[0072] The machine learning model in this embodiment adopts but is not limited to the existing RF model.

[0073] In step S2, a machine learning model is constructed based on the material flow analysis strategy. The material flow formula is:

[0074] Cd re =Cd bac +Cd fer -Cd grain -Cd straw -Cd water ;

[0075] Among them, Cd re The content of heavy metals in soil after planting and harvesting, Cd bac is the content of heavy metals in soil before planting, Cd fer The amount of heavy metals input for fertilization, Cd grain is the amount of crop grain removed, Cd straw is the amount of crop straw removed, Cd water Includes surface runoff and leaching losses, calculated using leaching and runoff coefficients based on local rainfall;

[0076] The amount of heavy metals input by fertilization is:

[0077] Cd fer =X×C Cdf ;

[0078] Where C Cdf is the heavy metal content in the fertilizer (mg / kg), and X is the amount of fertilizer applied (kg).

[0079] The amount removed from crop seeds is:

[0080] Cd grain =A×ML[C cdg ];

[0081] Where A is the crop yield (kg), C cdg is the cadmium content in crops (mg / kg), and ML is the optimal machine learning model selected after training.

[0082] Removed from crop residues:

[0083] Cd straw =r×ML[C cdg ]×d;

[0084] Where r is the crop straw-to-grain ratio, and d is the heavy metal content in crop straw and the coefficient of heavy metal content in crops.

[0085] In S2, the historical data is divided into K pre-training sets and 1 validation set;

[0086] The internal parameter range of the machine learning model is set through grid search, and K+1-fold cross-validation is performed. The validation results are used for parameter optimization and model evaluation.

[0087] For model evaluation, the coefficient of determination (R²) and two loss functions, RMSE and MAE, were used as evaluation metrics. The optimal model was identified by comprehensively evaluating the training set, prediction set, and K+1-fold cross-validation results. Grid search combined with five-fold cross-validation was used to adjust parameters for different objectives (seed removal and straw removal) to maximize the model's potential and prevent overfitting and underfitting. Compared to simple manual parameter setting or single-shot validation, this method significantly improves prediction accuracy and stability.

[0088] S3. Collect soil data, input soil data, planned fertilizer data, and planned crop data into the prediction model. The prediction model performs iterative calculations based on the planting cycle to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles.

[0089] The prediction model performs iterative calculations based on the planting cycle as follows: the heavy metal content of crops in cycle t is predicted based on the soil heavy metal content before planting, crop varieties and yields, fertilizer heavy metal content and weight, soil pH data, soil cation exchange capacity data, and soil organic matter content data in cycle t.

[0090] The heavy metal content in the soil after planting and harvesting in period t is predicted based on the crop varieties and yields, fertilizer heavy metal content and weight, soil pH data, soil cation exchange capacity data, and soil organic matter content data in period t.

[0091] The heavy metal content in the soil after planting and harvesting in cycle t is used as the heavy metal content in the soil before planting in cycle t+1, among which the crop varieties and yields, the planned values ​​of heavy metal content and weight of fertilizers, the soil pH value data, the soil cation exchange capacity data, and the soil organic matter content data are considered constant.

[0092] The process of collecting soil data in step S3 is as follows:

[0093] S31. Collect multiple soil samples within a preset range at the selected point, and calculate the coefficient of variation of soil pH value data, soil heavy metal content data, soil cation exchange capacity data, and soil organic matter content data;

[0094] S32. If the coefficient of variation of three or four data points is less than 5%, the area is determined to be homogeneous, and the specified range is expanded based on the preset range until the coefficient of variation of at least two data points within the final range is not less than 5%. The mean of the last sampling is taken as the model input value;

[0095] Otherwise, the specified range is narrowed based on the preset range until the coefficient of variation of three or four data within the final range is less than 5%, and the mean is taken as the model input value.

[0096] The preset range is a circular range with a diameter of 5-20km. Narrowing the specified range means reducing the diameter by 0.5-1km. Expanding the specified range means increasing the diameter by 0.5-1km.

[0097] In some embodiments, the average value of S32 is directly used as an input value to measure the heavy metal content of crops for a specified number of planting cycles.

[0098] In some other embodiments, S3 further includes the following steps:

[0099] S33, using all soil sample data within the final range in S32 to input into the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles, and calculating the probability of heavy metal exceeding the standard for the crops based on the heavy metal content of multiple crops;

[0100] S34. If the probability of excessive heavy metals in crops exceeds the probability threshold, the final range is narrowed, and step S33 is repeated until the probability of no excessive heavy metals in crops exceeds the probability threshold;

[0101] Otherwise, proceed to step S35;

[0102] S35. The model input value obtained in S32 is input into the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles; the calculation formula for the heavy metal content of crops in S42 is as follows:

[0103] Cd1=Cd2×(1+p);

[0104] Among them, Cd1 is the heavy metal content of crops in S42, Cd2 is the heavy metal content of crops obtained in S35, and p is the probability threshold in S34.

[0105] The coefficient of variation test (5% threshold) was used to determine the regional homogeneity of the soil, expand / contract the sampling range, ensure the spatial consistency of the input data used, and avoid errors in model prediction caused by "sampling blind spots" or "data skewness".

[0106] S4. Compare the soil heavy metal content obtained in S3 with the crop heavy metal content and the threshold value, and determine whether to adjust the planned fertilizer and planned crops based on the comparison results.

[0107] The step S4 comprises the following steps:

[0108] S41. Set soil heavy metal content thresholds and crop heavy metal content thresholds.

[0109] S42. If the soil heavy metal content in a specified planting cycle exceeds the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, it will be judged as a high-risk area; the specified planting cycle is 10-20 planting cycles.

[0110] If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, it will be determined as a specific risk area;

[0111] The threshold value of heavy metal content in soil is 0.3-0.6 mg / kg, and the threshold value of heavy metal content in crops is 0.3-0.6 mg / kg.

[0112] Table 1 Heavy metal content thresholds for different crops

[0113]

[0114] If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, it is determined to be a safe planting area;

[0115] If the soil heavy metal content in a specified planting cycle exceeds the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, the area is determined to be a medium-risk area;

[0116] S43. For high-risk areas, plant low-cadmium-accumulating crops or select crops with larger biomass to replace the original crop planting plan to form new planned crop data;

[0117] For medium-risk areas, shorten the designated number of planting cycles in step S3 to conduct continuous monitoring and plant crops as planned;

[0118] For specific risk areas, fertilizers with lower heavy metal content are selected to replace the original fertilization plan to form new planned fertilizer data;

[0119] Plant crops according to plan in safe planting areas;

[0120] S44. Return the new planned crop data and the new planned fertilizer data obtained in S43 to step S3 to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles, and repeat steps S41-S43.

[0121] After the planting cycle is completed, the model is trained using real data collected after planting.

[0122] The following is a detailed explanation using the example of predicting heavy metal cadmium during wheat planting.

[0123] 275 chemical fertilizer samples and 345 organic fertilizer samples were collected nationwide to measure the heavy metal content and obtain the cadmium content characteristics of different fertilizers.

[0124] The pH, CEC and OM, cadmium content of 135 soils and the cadmium content in wheat grains were collected through literature collection or actual measurement methods, and a database was established, as shown in Table 2.

[0125] Five machine learning models, including RF, SVM, MLP, XGBoost and LightGBM, were selected. The machine learning models were trained using the soil environment database and the wheat farmland system database. The training results were compared with the Freundlich extended model using the R2, RMSE and MAE evaluation criteria to screen out the optimal model. All evaluation indicators showed that the trained RF model was superior to the traditional Freundlich extended model, and it was decided to embed the RF model into the material flow model.

[0126] The machine learning model training process specifically includes the following steps:

[0127] The database data was divided into training set and test set in a 3:2 ratio. The internal parameters of the machine learning model were set through grid search. The optimal parameters of each model were screened out through five-fold cross-validation. After the model was set, it was used to predict the training set and test set data and evaluate the model fitting results.

[0128] Table 1 Database statistical analysis

[0129]

[0130] The cadmium content in the screened sample soil is taken as the initial value, and the model operation time step is set to 10 years. The equation is iterated year by year to obtain the probability density of the cadmium content distribution in the soil in the target year; the cadmium content in the crop in the target year is further predicted based on the cadmium content in the soil.

[0131] Beneficial effects:

[0132] Instead, it iterative input according to the planting cycle can simulate the cumulative effect of multiple cycles, automatically divide the areas into high / medium / specific / safe areas based on the prediction results, and make differentiated adjustments for different risk areas: changing crops, changing fertilizers, shortening monitoring cycles, etc., with closed-loop optimization capabilities.

[0133] At the same time, multi-dimensional data such as historical soil physical and chemical indicators (pH, organic matter, cation exchange capacity), crop yield / variety / heavy metal content, and fertilizer composition are used to supplement the limitations of a single data source (such as only looking at soil or only looking at crops).

[0134] By removing samples that exceed the standard, the training data is ensured to be cleaner and more representative, thereby improving the generalization ability of the model.

[0135] The organic combination of material flow principle and machine learning uses the material conservation formula as the framework, quantifies each link (fertilization, crop absorption, straw removal, water loss), and introduces ML models to fit complex relationships that are difficult to analyze.

[0136] Compared with "pure black box" neural networks or "pure formula" statistical models, the combination of the two not only ensures physical meaning but also has learning capabilities.

[0137] The present invention achieves precise optimization in both model input and output. First, a regional fertilizer heavy metal database is established to reduce the deviation caused by random simulation using methods such as Monte Carlo, thereby improving the practicality of model prediction. Then, regional environmental variables are used to train multiple machine learning models through big data to obtain machine learning models based on regional characteristics, thereby reducing the risk of overfitting of a single machine learning output result and improving the accuracy and robustness of model prediction.

[0138] The present invention specifically describes and visualizes the risk of heavy metal accumulation in farmland systems, which can help decision makers fully and intuitively understand the characteristics of heavy metal pollution in farmland systems after long-term fertilization. Targeted prevention and control strategies can be implemented based on the probability of occurrence of different risk types, thus achieving precise pollution prevention and control.

[0139] Example 2:

[0140] An electronic device includes a processor and a memory communicatively connected to the processor and configured to store instructions executable by the processor, wherein the processor is configured to execute the method described in the first embodiment above.

[0141] Example 3:

[0142] A server includes at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to enable the at least one processor to perform the method described in Example 1.

[0143] Example 4:

[0144] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the method described in embodiment 1.

[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some or all of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and description of the present invention.

[0146] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for predicting heavy metal accumulation in farmland based on material flow, characterized in that: The following steps are involved: S1. Collect historical soil data, crop data, and fertilizer data; S2, build a machine learning model based on the material flow analysis strategy, use the data obtained in S1 to train the machine learning model, and obtain a prediction model; S3. Collect soil data, input soil data, planned fertilizer data, and planned crop data into the prediction model. The prediction model performs iterative calculations based on the planting cycle to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles. S4. Compare the soil heavy metal content obtained in S3 with the crop heavy metal content and the threshold value, and determine whether to adjust the planned fertilizer and planned crops based on the comparison results.

2. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 1, characterized in that: Historical soil data include: historical soil pH data, historical soil heavy metal content data, historical soil cation exchange capacity data, and historical soil organic matter content data; Historical crop data include: historical crop heavy metal content, variety and yield data; Historical fertilizer data include: historical fertilizer heavy metal content and weight data; The data of soil heavy metal exceeding the standard is removed from the historical soil data in S1, and the data of crop heavy metal exceeding the standard is removed from the crop data.

3. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 1, characterized in that: The step S4 comprises the following steps: S41. Set the soil heavy metal content threshold and the crop heavy metal content threshold. S42. If the soil heavy metal content in a specified planting period exceeds the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, the area is determined to be a high-risk area; If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content exceeds the crop heavy metal content threshold, it will be determined as a specific risk area; If the soil heavy metal content in a specified planting cycle does not exceed the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, it is determined to be a safe planting area; If the soil heavy metal content in a specified planting cycle exceeds the soil heavy metal content threshold, and the crop heavy metal content does not exceed the crop heavy metal content threshold, the area is determined to be a medium-risk area; S43. For high-risk areas, plant low-cadmium-accumulating crops or select crops with larger biomass to replace the original crop planting plan to form new planned crop data; For medium-risk areas, shorten the designated number of planting cycles in step S3 to conduct continuous monitoring and plant crops as planned; For specific risk areas, fertilizers with lower heavy metal content are selected to replace the original fertilization plan to form new planned fertilizer data; Plant crops according to plan in safe planting areas; S44. Return the new planned crop data and the new planned fertilizer data obtained in S43 to step S3 to obtain the soil heavy metal content and crop heavy metal content for a specified number of planting cycles, and repeat steps S41-S43.

4. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 3, characterized in that: The process of collecting soil data in step S3 is as follows: S31. Collect multiple soil samples within a preset range at the selected point, and calculate the coefficient of variation of soil pH value data, soil heavy metal content data, soil cation exchange capacity data, and soil organic matter content data; S32. If the coefficient of variation of three or four data points is less than 5%, the area is determined to be homogeneous, and the specified range is expanded based on the preset range until the coefficient of variation of at least two data points within the final range is not less than 5%. The mean of the last sampling is taken as the model input value; Otherwise, the specified range is narrowed based on the preset range until the coefficient of variation of three or four data within the final range is less than 5%, and the mean is taken as the model input value.

5. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 4, characterized in that: The S3 further comprises the following steps: S33, using all soil sample data within the final range in S32 to input into the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles, and calculating the probability of heavy metal exceeding the standard for the crops based on the heavy metal content of multiple crops; S34. If the probability of excessive heavy metals in crops exceeds the probability threshold, the final range is narrowed, and step S33 is repeated until the probability of no excessive heavy metals in crops exceeds the probability threshold; Otherwise, proceed to step S35; S35, using the model input value obtained in S32 to input the model to calculate and predict the heavy metal content of crops for a specified number of planting cycles; The calculation formula for the heavy metal content of crops in S42 is as follows: Cd1=Cd2×(1+p); Among them, Cd1 is the heavy metal content of crops in S42, Cd2 is the heavy metal content of crops obtained in S35, and p is the probability threshold in S34.

6. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 1, characterized in that: In step S2, a machine learning model is constructed based on the material flow analysis strategy. The material flow formula is: CD re =Cd bac +Cd fer -Cd grain -Cd straw -Cd water ; Among them, Cd re The content of heavy metals in soil after planting and harvesting, Cd bac is the content of heavy metals in soil before planting, Cd fer The amount of heavy metals input for fertilization, Cd grain is the amount of crop grain removed, Cd straw is the amount of crop straw removed, Cd water Includes surface runoff and leaching losses, calculated using leaching and runoff coefficients based on local rainfall; The amount of heavy metals input by fertilization is: Cd fer =X×C Cdf ; Where C Cdf is the heavy metal content in the fertilizer (mg / kg), X is the amount of fertilizer applied (kg); The amount removed from crop seeds is: Cont. grain =A×ML[C cdg ]; Where A is the crop yield (kg), C cdg is the cadmium content in crops (mg / kg), ML is the selected optimal machine learning model after training; Removed from crop residues: Cont. straw =r×ML[C cdg ]×d; Where r is the crop straw-to-grain ratio, and d is the heavy metal content in crop straw and the coefficient of heavy metal content in crops.

7. The method for predicting heavy metal accumulation in farmland based on material flow according to claim 1, characterized in that: In S2, the historical data is divided into K pre-training sets and 1 validation set; The internal parameter range of the machine learning model is set through grid search, and K+1-fold cross-validation is performed. The validation results are used for parameter optimization and model evaluation. The coefficient of determination R is used for model evaluation 2 The two loss functions RMSE and MAE are used as evaluation indicators, and the training set, prediction set and K+1 fold cross-validation results are comprehensively judged to screen out the optimal model.

8. An electronic device comprising a processor and a memory in communication with the processor and configured to store instructions executable by the processor, wherein: The processor is configured to execute the method according to any one of claims 1 to 7.

9. A server, characterized in that: The method comprises at least one processor and a memory in communication with the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.