PROPERTY CHANGEtitle PROPERTY CHANGEdocument-replaced DOCUMENT REPLACED PROPERTY CHANGEdocument-replaced DOCUMENT REPLACED Going to change controls About to perform query: collection()/scenario About to perform query: distinct-values(collection()/scenario/world/*[@type = 'region']/@name) Didn't find builder for Land Allocation query going to use defaults Didn't find builder for Land Allocation in AEZ 9 query going to use defaults Didn't find builder for Aggregated Land Allocation query going to use defaults Didn't find builder for Land Use Change Emission query going to use defaults Didn't find builder for Land Use Change Emission (future) query going to use defaults Didn't find builder for Profit Rate query going to use defaults Didn't find builder for Shares query going to use defaults About to perform query: collection()/singleQueryListCache/cache[@id=1902700668]/text() Time : 8 About to perform query: collection()/singleQueryListCache/cache[@id=1565643772]/text() Time : 6 About to perform query: collection()/singleQueryListCache About to perform query: declare function local:get-singlequery-name($results as node()*, $collapseList as xs:string*) as xs:string* { for $result in $results return fn:substring(fn:string-join((local:get-full-singlequery-name($result/parent::node()/parent::node(), $collapseList), $result), '/'), 2) }; declare function local:get-full-singlequery-name($curr as node(), $collapseList as xs:string*) as xs:string { if($curr and local-name($curr) != 'scenario') then let $type := $curr/@type, $ret := local:get-full-singlequery-name($curr/parent::node(), $collapseList) return if($type and fn:empty(fn:index-of($collapseList, $type))) then fn:string-join(($ret, fn:concat($type,': ', $curr/@name)), '/') else $ret else '' }; declare function local:get-weighted-eff($outputs as node()*) as node()* { unordered { for $year in distinct-values($outputs/physical-output/@vintage) let $eff_unweight := sum(for $res in $outputs/physical-output[@vintage = $year] let $eff_curr := $res/parent::*/following-sibling::input-energy[1]/IO-coefficient[@vintage = $year] (: where $res/physical-output/@vintage = $year :) return $res div $eff_curr), $weight := sum(for $res in $outputs/physical-output[@vintage = $year] (: where $res/physical-output/@vintage = $year :) return $res), $eff_weighted := $eff_unweight div $weight return element efficiency-weighted {attribute year { $year }, text { $eff_weighted }} } }; declare function local:append-heirarchy($parent as node(), $append as node()) as node() { let $scn := $parent/ancestor::scenario, $rgn := $parent/ancestor::region return document { element scenario { $scn/@*, element region { $rgn/@*, $append } } } (: let $new_node := element {local-name($parent)} {$parent/@*, $append} return if(local-name($parent) != 'scenario') then local:append-heirarchy($parent/parent::*, $new_node) else document { $new_node } :) }; declare function local:get-primary-renewable($outputs as node()*, $weighted_effs as node()*) as node()* { unordered { for $output in $outputs (:, $weighted_eff in $weighted_effs :) let $new_output := (: element tempParent { :) element input { attribute type {'input'}, attribute name {$output/parent::*/following-sibling::keyword/@primary-renewable}, element demand-physical { attribute vintage {$output/@vintage}, attribute unit {$output/@unit}, text { $output div $weighted_effs[@year=$output/@vintage] } }(: , element keyword { attribute primary-consumption { (: if($output/parent::*/following-sibling::keyword[fn:exists(@primary-renewable)]) then :) $output/parent::*/following-sibling::keyword/@primary-renewable (: else $output/parent::*/parent::*/@name :) } } :) (: } :) }, $new_root := local:append-heirarchy($output/parent::*/parent::*, $new_output) (:where $output/@vintage = $weighted_eff/@year:) return $new_root//text() } }; declare function local:check-keyword($values as node()*) as node()* { unordered { for $value in $values let $input := $value/parent::*/parent::*, $keyword_name := (: if($input/following-sibling::keyword[fn:exists(@primary-consumption)]) then :) $input/following-sibling::keyword/@primary-consumption (: else $input/@name :), $new_parent := element {local-name($input)} {$input/@*, $value/parent::*, element keyword { attribute primary-consumption {$keyword_name} } }, $new_root := local:append-heirarchy($input/parent::*, $new_parent) return $new_root//text() } }; declare function local:run-primary-energy($scenarios as xs:string*, $regions as xs:string*, $collection as xs:string*) as node()* { (: unordered { :) 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, ' '), $scenario_name := string-join($scenario_split[position() < last()], ' '), $scenario_date := $scenario_split[last()], $currTree := collection($collection)/scenario[@name = $scenario_name and @date = $scenario_date]/world/*[@type = 'region' and @name=$region] return (: get renewables from electricity :) local:get-primary-renewable($currTree/supplysector[@name='electricity' or @name='elect_td_bld']//keyword[fn:exists(@primary-renewable)]/preceding-sibling::output-primary/physical-output, local:get-weighted-eff($currTree/supplysector[@name='electricity']//keyword[fn:exists(@average-fossil-efficiency)]/preceding-sibling::output-primary)) | (: get renewables from H2ProdCS :) local:get-primary-renewable($currTree/supplysector[@name='H2 central production'](: /*[@type='subsector' (: collapse :) and fn:not(@name='electrolysis')] :)//keyword[fn:exists(@primary-renewable)]/preceding-sibling::output-primary/physical-output, local:get-weighted-eff($currTree/supplysector[@name='H2 central production']//keyword[fn:exists(@average-fossil-efficiency)]/preceding-sibling::output-primary)) | (: get renewables from H2ProdDist :) local:get-primary-renewable($currTree/supplysector[@name='H2 forecourt production'](: /*[@type='subsector' (: collapse :) and fn:not(@name='electrolysis')] :)//keyword[fn:exists(@primary-renewable)]/preceding-sibling::output-primary/physical-output, local:get-weighted-eff($currTree/supplysector[@name='H2 forecourt production']//keyword[fn:exists(@average-fossil-efficiency)]/preceding-sibling::output-primary)) | (: get the primaries :) (: local:check-keyword( :) $currTree//keyword[fn:exists(@primary-consumption)]/preceding-sibling::input-energy/demand-physical/text() (: ) :) | (: get traditional biomass :) $currTree//*[@type='input' and @name='traditional biomass']/demand-physical/node() (: } :) }; fn:distinct-values(local:get-singlequery-name(for $n in local:run-primary-energy(('Reference 2018-25-3T21:23:44+20:00'), ('USA', 'Africa_Eastern', 'Africa_Northern', 'Africa_Southern', 'Africa_Western', 'Australia_NZ', 'Brazil', 'Canada', 'Central America and Caribbean', 'Central Asia', 'China', 'EU-12', 'EU-15', 'Europe_Eastern', 'Europe_Non_EU', 'European Free Trade Association', 'India', 'Indonesia', 'Japan', 'Mexico', 'Middle East', 'Pakistan', 'Russia', 'South Africa', 'South America_Northern', 'South America_Southern', 'South Asia', 'South Korea', 'Southeast Asia', 'Taiwan', 'Argentina', 'Colombia', 'Global'), ()) return $n//ancestor::*[@type='input']/@name, ('region','sector','subsector','technology')))