The following scripts are used to recreate data and figures required for the paper titled Byrnes, D. K., Van Meter, K. J., Chang, S. Y., & Basu, N. B. (2026). Balancing Legacy and Efficiency: Present and Historical Phosphorus Management Across the United States. Global Biogeochemical Cycles. https://doi.org/10.1029/2025GB008893
The analysis of phosphorus use across the US from 1930 to 2017 using the newly published gTREND-Phosphorus dataset.
- gTREND-phosphorus data: Available on Figshare
In all cases, set working directory to project root. Eg:
cd /home/username/repo_root/
These scripts must be executed first to generate the required data files for subsequent analysis and figure generation. All geospatial TIF files are projected in EPSG:5070 - NAD83 / Conus Albers.
- Purpose: Moving crop uptake, livestock manure P inputs, fertilizer, and aggregating components to calculate agricultural surplus from raw gTREND data.
- Input: gTREND data layers (annual fertilizer P input, manure P input, and crop P removal TIF files).
- Output: Annual (1930-2017) geospatial TIF files of the components and surplus. Maps in Figure 1 are produced in QGIS.
- Language: MATLAB
- Purpose: Generates gridded phosphorus use efficiency (PUE) data.
- Input: gTREND data layers (annual fertilizer P input, manure P input, and crop P removal TIF files).
- Output: Annual (1930-2017) geospatial TIF files of PUE (ratio of crop P removal to total manure P and fertilizer P inputs). Maps in Figure 2 are produced in QGIS.
- Language: MATLAB
- Purpose: Generates gridded cumulative phosphorus surplus data.
- Input: gTREND data layers (annual fertilizer P input, manure P input, and crop P removal TIF files).
- Output: Annual (1930-2017) geospatial TIF files of cumulative surplus (summation of manure P inputs, fertilizer P inputs, and crop P removal). Maps in Figure 7 are produced in QGIS.
- Language: MATALB
- Purpose: Extacts regional-level surplus, components, and PUE.
- Input: gTREND components, agricultural surplus, and PUE TIF files.
- Output: Text file of annual mean and median statistics (1930-2017) by region for P components, agricultural surplus, and PUE.
- Language: R
- Purpose: Extacts regional-level cumulative surplus.
- Input: Cumulative surplus 1980 and 2017 TIF files and region shapefiles.
- Output: Text file containing mean and median cumulative surplus statistics by region for 1980 and 2017.
- Language: R
- Purpose: Extacts regional-level agricultural land use. This script can only be run if you have the land use rasters. Otherwise you can skip this step and download required data file
- Input: Annual agricultural land use TIF text file.
- Output: Text file (RegionLandUse_frac.txt) of percent agricultural land use (1930-2017) by region.
- Language: R
- Purpose: Extacts regional-level proportion of total P-input from manure inputs.
- Input: Proportion of total input fom manure 1980 and 2017 TIF files and region shapefiles.
- Output: Text file of percent agricultural land use (1930-2017) by region.
- Language: R
- Purpose: Categorizes agricultural parcels for framework analysis.
- Input: PUE and cumulative surplus TIF files for 1980 and 2017.
- Output: Matlab file with vectorized grid-cell in 1980 and 2017.
- Language: MATLAB
- Purpose: Categorizes agricultural parcels for framework analysis.
- Input: PUE and cumulative surplus TIF files for 1980 and 2017.
- Output: TIF files of categorized land use parcels in 1980 and 2017. Final maps are produced in QGIS.
- Language: MATLAB
- Purpose: Analysis of quadrants distribution by region used in Section 3.5.
- Input: TIF files of categorized land use parcels in 1980 and 2017.
- Language: Python
- Purpose: Analysis of fertilizer use by state for the four main field crops (corn, soy, wheat, cotton) to support analysis in Section 3.3.
- Input: Mosheim, R. (2025). Fertilizer Use and Price - Documentation and Data Sources. https://www.ers.usda.gov/data-products/fertilizer-use-and-price/documentation-and-data-sources
- Language: Python
- Purpose: Analysis of 2017 PUE distribution in Region 3 and 8 used in Section 3.2 (Supplemental Figure 2).
- Input: gTREND 2017 crop and pasture P removal TIF files.
- Language: Python
- Purpose: Generates figure of national-scale statistical summaries and time series.
- Input: Annual PUE and surplus TIF files
- Output: Figures 1j-i and 5b - Plots showing national median, IQR, and 5th-95th percentile for PUE and surplus.
- Language: MATLAB
- Purpose: Generates figure of PUE versus the proportion of manure-derived phosphorus inputs.
- Input: National TIF files and regional medians of manure P, fertilizer P, and PUE data.
- Output: Figure 2d - PUE vs. proportion of manure-derived P inputs (hexplot or scatter plot). Using function 'hexscatter.m'.
- Requirements: >64GB RAM for hexplot generation. Scatter plot can be used as an alternative if hexplot function cannot be run.
- Language: MATLAB
- Purpose: Generates figure to showcase the relationship between surplus and PUE.
- Input: Gridded 2017 PUE and surplus data TIF files and regional medians.
- Output: Figure 6 - Phosphorus surplus vs. (1-PUE) plot with regional data.
- Language: MATLAB
- Purpose: Generates figures for framework quadrant analysis and transitions of land parcels betwen 1980 and 2017.
- Input: Gridded PUE and cumulative surplus TIF files and regional medians in 1980 and 2017.
- Output: Figures 8b, 8e-f - Quadrant plots and Sankey diagram; .mat file of vectorized data. Uses function 'plotSankeyFlowChart.m'.
- Language: MATLAB
- Purpose: Generates regional summary visualizations.
- Input: Regional median data for surplus, PUE, and cumulative surplus in 1930, 1980, and 2017.
- Output: Figures 2c, 5c, 7c - Lollipop charts of median surplus, PUE, and cumulative surplus.
- Language: MATLAB
- Purpose: Generates regional time series of PUE, manure, fertilizer, and crop removal.
- Input: Regional median PUE, component, and agricultural land use percentage data.
- Output: Figures 3 and 4 - Time series of PUE, components and agricultural land use.
- Language: MATLAB
- Purpose: Generates supplemental figure showcasing the relationship between surplus and cumulative surplus.
- Input: Gridded 2017 surplus and cumulative surplus TIF files and regional medians.
- Output: Supplemental Figure 3 - Phosphorus surplus vs. cumulative surplus plot
- Language: MATLAB
- Purpose: Generating figure of crop phosphorus uptake and pasture phosphorus uptake to compare regional magnitudes.
- Input: Regional crop and pasture P uptake data in 1930, 1980, and 2017.
- Output: Supplemental Figure 1 - Figure of P removal by crop and pasture (used in Section 3.2).
- Language: Python
- Purpose: Compiles all numerical metrics reported in the manuscript.
- Input: .mat Component quadrant summary, .mat file of vectorized data .txt of region median PUE, agricultural surplus, and cumulative surplus, .mat file of vectorized data, regional quadrant .txt.
- Output: Text file of all the statistics and metrics reported in the manucript.
- Language: MATLAB
If you use this dataset or its derived indicators, please cite the accompanying paper: Byrnes, D. K., Van Meter, K. J., Chang, S. Y., & Basu, N. B. (2026). Balancing Legacy and Efficiency: Present and Historical Phosphorus Management Across the United States. Global Biogeochemical Cycles. https://doi.org/10.1029/2025GB008893
If you are specifically reusing or adapting the code, please also cite this repository:
If you have any questions, please direct questions to danyka[dot]byrnes[at]proton[dot]me.