| Title: | Process LUH2 Land Use Data for IMPACT Model Integration |
|---|---|
| Description: | Tools for processing LUH2 land use data, computing spatial weights, and generating GDX inputs for the LUMEN land use optimization model driven by IMPACT scenario outputs. |
| Authors: | Abhijeet Mishra [aut, cre], Claude [aut] (Anthropic AI assistant) |
| Maintainer: | Abhijeet Mishra <[email protected]> |
| License: | CC BY 4.0 |
| Version: | 2.2.0 |
| Built: | 2026-05-28 06:21:33 UTC |
| Source: | https://github.com/IFPRI/luh2impact |
Rasterizes the IMPACT country shapefile to match the shares grid, merges all raster data into a pixel-level data frame, computes land pool areas, available land, and spatial weights for each pool.
luh2_build_pixels( luh, shares, crop_trend, natfor_trend, other_trend, cellarea, icwtr, cty_shp, landx0 )luh2_build_pixels( luh, shares, crop_trend, natfor_trend, other_trend, cellarea, icwtr, cty_shp, landx0 )
luh |
A 'SpatRaster' of historical land use shares returned by [luh2_load()]. |
shares |
A 'SpatRaster' of adjusted land use shares returned by [luh2_merge_planted()]. |
crop_trend |
A single-layer 'SpatRaster' of crop slope returned by [luh2_pool_trend()]. |
natfor_trend |
A single-layer 'SpatRaster' of natural forest slope returned by [luh2_pool_trend()]. |
other_trend |
A single-layer 'SpatRaster' of other land slope returned by [luh2_pool_trend()]. |
cellarea |
A single-layer 'SpatRaster' of cell areas in km². |
icwtr |
A single-layer 'SpatRaster' of ice/water fraction. |
cty_shp |
Path to the IMPACT regions shapefile. Must contain a 'NEW_REGION' field used as the country identifier. |
landx0 |
A data frame of IMPACT land use results with columns 'cty', 'fland', 'yrs', 'value'. |
A data frame with one row per pixel containing areas, shares, weights, and country assignments.
Abhijeet Mishra, Claude Code
Fits a linear trend over time for the sum of crop land use shares across five crop types ('c3ann', 'c4ann', 'c3per', 'c4per', 'c3nfx'), returning the slope (change per year) for each pixel.
luh2_crop_trend(luh, year_start, year_end)luh2_crop_trend(luh, year_start, year_end)
luh |
A 'SpatRaster' returned by [luh2_load()]. |
year_start |
Integer. First year of the trend period (e.g. 1990). |
year_end |
Integer. Last year of the trend period (e.g. 2015). |
A single-layer 'SpatRaster' named '"crop_slope"'.
Abhijeet Mishra, Claude Code
Writes all sets and parameters required by the LUMEN GAMS model into a single GDX file using 'gamstransfer'.
luh2_export_gdx(df, landx0, output_gdx)luh2_export_gdx(df, landx0, output_gdx)
df |
A pixel-level data frame returned by [luh2_build_pixels()]. |
landx0 |
A data frame of IMPACT land use results with columns 'cty', 'fland', 'yrs', 'value'. |
output_gdx |
Path to write the output GDX file. |
Invisibly returns 'output_gdx'. Called for its side effect.
Abhijeet Mishra, Claude Code
Subsets the LUH2 raster to a single year, multiplies shares by cell area, and returns both the raw area raster and the 'cellarea' layer for downstream use.
luh2_extract_year(luh, static_nc, year)luh2_extract_year(luh, static_nc, year)
luh |
A 'SpatRaster' returned by [luh2_load()]. |
static_nc |
Path to the LUH2 'staticData_quarterdeg.nc' file. |
year |
Integer. Target year (e.g. 2015). |
A named list:
'SpatRaster' of land use areas in km² per pool.
Single-layer 'SpatRaster' of cell areas in km².
Single-layer 'SpatRaster' of ice/water fraction.
Abhijeet Mishra, Claude Code
Reads the LUH2 'states.nc' file and removes non-share layers ('secma', 'secmb').
luh2_load(states_nc)luh2_load(states_nc)
states_nc |
Path to the LUH2 'states.nc' file. |
A 'SpatRaster' with all land use state share layers.
Abhijeet Mishra, Claude Code
Loads a planted forest raster (e.g. from SDPT), carves out area first from 'other', then from 'natfor', and caps any residual planted share at the remaining space after all LUH2 categories. Returns adjusted share rasters.
luh2_merge_planted(luarea, cellarea, planted_tif, fstnf, cty_shp)luh2_merge_planted(luarea, cellarea, planted_tif, fstnf, cty_shp)
luarea |
A 'SpatRaster' of land use areas (km²) returned inside the list from [luh2_extract_year()]. |
cellarea |
A single-layer 'SpatRaster' of cell areas in km² (also from [luh2_extract_year()]). |
planted_tif |
Path to the planted forest GeoTIFF (e.g. 'sdpt_global.tif'). |
fstnf |
Flag if a pixel is forested or not. |
cty_shp |
Path to the IMPACT regions shapefile. Must contain a 'NEW_REGION' field used as the country identifier. |
A 'SpatRaster' of adjusted land use shares (one layer per pool, including 'planted_forest_share').
Abhijeet Mishra, Claude Code
Reads GeoTIFFs written by [luh2_write_tifs()] and produces three plots:
Faceted map of land use change vs 2021 for years 2035 and 2050, one panel per pool. Diverging red-blue palette, symmetric scale.
Faceted map of land use shares for 2021 and 2050, faceted by pool and year.
Map of dominant land use pool per pixel for 2021 and 2050, coloured by pool with alpha proportional to share.
luh2_plot_results(output_dir, cty_shp, save_png = TRUE)luh2_plot_results(output_dir, cty_shp, save_png = TRUE)
output_dir |
Path to directory containing 'lu_<pool>.tif' files and the solution GDX. Country name is derived via 'basename(output_dir)'. |
cty_shp |
Path to the IMPACT regions shapefile. |
save_png |
Logical. If 'TRUE' (default), saves each plot as a PNG file in 'output_dir'. |
A named list of 'ggplot' objects: 'changes', 'shares', 'dominant'.
Abhijeet Mishra, Claude Code
Sums the specified LUH2 layers for each year in the range and fits a per-pixel linear trend, returning the slope (change per year).
luh2_pool_trend(luh, pool_vars, year_start, year_end)luh2_pool_trend(luh, pool_vars, year_start, year_end)
luh |
A 'SpatRaster' returned by [luh2_load()]. |
pool_vars |
Character vector of LUH2 layer name prefixes to sum (e.g. 'c("c3ann", "c4ann", "c3per", "c4per", "c3nfx")' for crop, 'c("primf", "primn", "secdf")' for natural forest, 'c("secdn")' for other). |
year_start |
Integer. First year of the trend period (e.g. 1990). |
year_end |
Integer. Last year of the trend period (e.g. 2015). |
A single-layer 'SpatRaster' named '"pool_slope"'.
Abhijeet Mishra, Claude Code
Computes a suitability index for each land pool by averaging historical land use shares over a specified time window. Pixels with consistently high shares of a given land type over centuries are considered more suitable for that land type in future projections.
luh2_suitability(luh, year_start = 1715, year_end = 2015, subsample = 10)luh2_suitability(luh, year_start = 1715, year_end = 2015, subsample = 10)
luh |
SpatRaster from [luh2_load()]. |
year_start |
Integer. Start year for suitability window (e.g. 1700). |
year_end |
Integer. End year for suitability window (e.g. 2015). |
subsample |
Integer. Step size for subsampling years to speed up computation. Default is 10 (every 10th year). |
Land pool definitions follow LUH2 variable groupings:
crop: c3ann, c4ann, c3per, c4per, c3nfx
natfor: primf, secdf
past: pastr, range
other: primn, secdn
Within each year, variables are summed across pool members before averaging across years.
SpatRaster with 4 layers: suit_crop, suit_natfor,
suit_past, suit_other. Values range from 0 to 1,
representing the mean share of each land pool over the specified window.
## Not run: luh <- luh2_load("states.nc") suit <- luh2_suitability(luh, year_start = 1700, year_end = 2015) plot(suit) ## End(Not run)## Not run: luh <- luh2_load("states.nc") suit <- luh2_suitability(luh, year_start = 1700, year_end = 2015) plot(suit) ## End(Not run)
Reads the LUMEN solution GDX and writes one multi-layer GeoTIFF per land pool, with one layer per year. Output files are named 'lu_<pool>.tif' and written to 'output_dir'.
luh2_write_tifs(gdx_path, output_dir)luh2_write_tifs(gdx_path, output_dir)
gdx_path |
Path to the LUMEN solution GDX file (e.g. '"outputs/CHM/solution_lu.gdx"'). |
output_dir |
Path to the directory where GeoTIFFs will be written. Also used to derive the country name via 'basename(output_dir)'. |
Invisibly returns a named list of 'SpatRaster' objects, one per pool.
Abhijeet Mishra, Claude Code
Convenience wrapper that calls all processing steps in sequence and writes the final GDX file. Each intermediate step can be run and tested individually using the underlying functions.
luh2gdx( states_nc, static_nc, planted_tif, cty_shp, impact_gdx, output_gdx, year = 2015, year_start = 1990, year_end = 2015 )luh2gdx( states_nc, static_nc, planted_tif, cty_shp, impact_gdx, output_gdx, year = 2015, year_start = 1990, year_end = 2015 )
states_nc |
Path to the LUH2 'states.nc' file. |
static_nc |
Path to the LUH2 'staticData_quarterdeg.nc' file. |
planted_tif |
Path to the planted forest GeoTIFF (e.g. 'sdpt_global.tif'). |
cty_shp |
Path to the IMPACT regions shapefile. |
impact_gdx |
Path to the IMPACT scenario GDX file. |
output_gdx |
Path to write the output GDX file. |
year |
Integer. Target baseline year to extract from LUH2 (e.g. 2015). |
year_start |
Integer. Start year for trend estimation (e.g. 1990). |
year_end |
Integer. End year for trend estimation (e.g. 2015). |
Invisibly returns the path to the written GDX file.
Abhijeet Mishra, Claude Code