Skip to content

Commit

Permalink
ComDef: land cover
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Nov 13, 2024
1 parent 50f7779 commit 327fbea
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 15 deletions.
4 changes: 2 additions & 2 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1688,11 +1688,11 @@ get_land <- function(GCAM_version = "v7.0") {
value <- unit_conv <- scenario <- region <- year <- var <- land_clean <- landleaf <- NULL

land_clean <-
rgcam::getQuery(prj, "aggregated land allocation") %>%
rgcam::getQuery(prj, "land allocation by crop and water source") %>%
dplyr::filter(grepl('^[a-z]',landleaf)) %>%
left_join_strict(filter_variables(get(paste('land_use_map',GCAM_version,sep='_'), envir = asNamespace("gcamreport")),
"land_clean"),
by = c("landleaf"), mapping = paste('land_use_map',GCAM_version,sep='_'), multiple = "all") %>%
by = c("crop","water"), mapping = paste('land_use_map',GCAM_version,sep='_'), multiple = "all") %>%
dplyr::mutate(value = value * unit_conv) %>%
dplyr::group_by(scenario, region, year, var) %>%
dplyr::summarise(value = sum(value, na.rm = T)) %>%
Expand Down
84 changes: 71 additions & 13 deletions inst/extdata/mappings/GCAM7.1/land_use_map.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,72 @@
# Mapping of crop to land use
landleaf,var1,var2,var3,var4,var5,var6,var7,var8,unit_conv
biomass,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Energy Crops,,,,,,0.1
crops,Land Cover,Land Cover|Cropland,,,,,,,0.1
forest (managed),Land Cover,Land Cover|Forest,Land Cover|Forest|Managed,,,,,,0.1
forest (unmanaged),Land Cover,Land Cover|Forest,Land Cover|Forest|Natural Forest,,,,,,0.1
grass,Land Cover,Land Cover|Pasture,,,,,,,0.1
otherarable,Land Cover,Land Cover|Cropland,,,,,,,0.1
pasture (grazed),Land Cover,Land Cover|Pasture,,,,,,,0.1
pasture (other),Land Cover,Land Cover|Pasture,,,,,,,0.1
rock and desert,Land Cover,Land Cover|Other Land,,,,,,,0.1
shrubs,Land Cover,Land Cover|Pasture,,,,,,,0.1
tundra,Land Cover,Land Cover|Other Land,,,,,,,0.1
urban,Land Cover,Land Cover|Built-up Area,,,,,,,0.1
crop,water,var1,var2,var3,var4,var5,var6,var7,var8,unit_conv,,,,
CornC4,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Irrigated,,,,0.1,,,,
CornC4,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Rainfed,,,,0.1,,,,
FiberCrop,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
FiberCrop,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
FodderGrass,IRR,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
FodderGrass,RFD,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
FodderHerb,IRR,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
FodderHerb,RFD,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
FodderHerbC4,IRR,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
FodderHerbC4,RFD,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
Fruits,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
Fruits,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
FruitsTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
FruitsTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
Grassland,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
Hardwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
Legumes,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
Legumes,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
MiscCrop,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
MiscCrop,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
MiscCropTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
MiscCropTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
NutsSeeds,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
NutsSeeds,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
NutsSeedsTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
NutsSeedsTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
OilCrop,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Irrigated,,,,0.1,,,,
OilCrop,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Rainfed,,,,0.1,,,,
OilCropTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Irrigated,,,,0.1,,,,
OilCropTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Rainfed,,,,0.1,,,,
OilPalmTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Irrigated,,,,0.1,,,,
OilPalmTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Oil Crops,Land Cover|Cropland|Oil Crops|Rainfed,,,,0.1,,,,
OtherArableLand,,Land Cover,Land Cover|Other Natural,,,,,,,0.1,,,,
OtherGrain,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Irrigated,,,,0.1,,,,
OtherGrain,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Rainfed,,,,0.1,,,,
OtherGrainC4,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Irrigated,,,,0.1,,,,
OtherGrainC4,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Rainfed,,,,0.1,,,,
Pasture,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
ProtectedGrassland,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
ProtectedShrubland,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
ProtectedUnmanagedHardwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
ProtectedUnmanagedPasture,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
ProtectedUnmanagedSoftwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
Rice,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Irrigated,,,,0.1,,,,
Rice,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Rainfed,,,,0.1,,,,
RockIceDesert,,Land Cover,Land Cover|Other Natural,,,,,,,0.1,,,,
RootTuber,IRR,Land Cover,Land Cover|Other Natural,,,,,,,0.1,,,,
RootTuber,RFD,Land Cover,Land Cover|Other Natural,,,,,,,0.1,,,,
Shrubland,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
Softwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
Soybean,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
Soybean,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
SugarCrop,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Sugar Crops,Land Cover|Cropland|Sugar Crops|Irrigated,,,,0.1,,,,
SugarCrop,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Sugar Crops,Land Cover|Cropland|Sugar Crops|Rainfed,,,,0.1,,,,
SugarCropC4,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Sugar Crops,Land Cover|Cropland|Sugar Crops|Irrigated,,,,0.1,,,,
SugarCropC4,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Sugar Crops,Land Cover|Cropland|Sugar Crops|Rainfed,,,,0.1,,,,
Tundra,,Land Cover,Land Cover|Other Natural,,,,,,,0.1,,,,
UnmanagedHardwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
UnmanagedPasture,,Land Cover,Land Cover|Pasture,,,,,,,0.1,,,,
UnmanagedSoftwood_Forest,,Land Cover,Land Cover|Forest,,,,,,,0.1,,,,
UrbanLand,,Land Cover,Land Cover|Built-Up Area,,,,,,,0.1,,,,
Vegetables,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Irrigated,,,,0.1,,,,
Vegetables,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Other Crops,Land Cover|Cropland|Other Crops|Rainfed,,,,0.1,,,,
Wheat,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Irrigated,,,,0.1,,,,
Wheat,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Cereals,Land Cover|Cropland|Cereals|Rainfed,,,,0.1,,,,
biomassGrass,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Energy Crops,Land Cover|Cropland|Energy Crops|Irrigated,,,,0.1,,,,
biomassGrass,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Energy Crops,Land Cover|Cropland|Energy Crops|Rainfed,,,,0.1,,,,
biomassTree,IRR,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Irrigated,Land Cover|Cropland|Energy Crops,Land Cover|Cropland|Energy Crops|Irrigated,,,,0.1,,,,
biomassTree,RFD,Land Cover,Land Cover|Cropland,Land Cover|Cropland|Rainfed,Land Cover|Cropland|Energy Crops,Land Cover|Cropland|Energy Crops|Rainfed,,,,0.1,,,,
,,,,,,,,,,,,,,
53 changes: 53 additions & 0 deletions inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,59 @@ output-primary/physical-output/node()</xPath>
<comments/>
</query>
</aQuery>
<aQuery>
<all-regions />
<query title="land allocation by crop and water source">
<axis1 name="water">water[@name]</axis1>
<axis2 name="Year">land-allocation[@year]</axis2>
<xPath buildList="true" dataName="LandLeaf" group="false" sumAll="false"><![CDATA[
declare function local:nest-land-category($leaf as node(), $level as xs:string, $child as node()*) as node() {
let $attrMatch := $leaf/@*[name()=$level],
$attrValue := if(exists($attrMatch)) then string($attrMatch) else "NA"
return element { $level } {
attribute name { $attrValue },
$child
}
};
declare function local:run-nest-land-categories($scenarios as xs:string*, $regions as xs:string*, $collection as xs:string) as node()* {
let $regionsG := if(not($regions[1] = 'Global'))
then $regions
else distinct-values(collection($collection)/scenario/world/*[@type='region']/@name)
return
for $scenario in $scenarios,
$region in $regionsG
let $scenario_split := tokenize($scenario, ' '),
$currTree := collection($collection)/scenario[@name = $scenario_split[1] and @date = $scenario_split[2]]/world/*[@type='region' and @name=$region],
$landLeaves := $currTree//LandNode[@name='root' or @type='LandNode' (:collapse:)]//LandLeaf,
$ret := document {
element scenario {
attribute name { $scenario_split[1] },
attribute date { $scenario_split[2] },
element region {
attribute type { "region" },
attribute name { $region },
for $leaf in $landLeaves
(: TODO: not sure why I have to explicitly copy the land-allocation :)
let $copy := for $landAlloc in $leaf/land-allocation
return element land-allocation {
$landAlloc/@*,
text { $landAlloc/text() }
}
(: A user could choose to nest by recursively calling for any of: ("crop", "land-region", "water", "mgmt-tech") :)
return local:nest-land-category($leaf, "crop", local:nest-land-category($leaf, "water", $copy))
}
}
}
return $ret//text()
};
local:run-nest-land-categories((:scenarios:), (:regions:), (:collection:))
]]></xPath>
<comments/>
</query>
</aQuery>
<aQuery>
<all-regions />
<query title="aggregated land allocation">
Expand Down

0 comments on commit 327fbea

Please sign in to comment.