<?xml version="1.0" encoding="UTF-8"?>
<toolchain saga-version="4.1.0">
	<group>climate_tools</group>
	<identifier>temperature_downscaling</identifier>
	<menu absolute="true">Climate and Weather|Temperature</menu>
	<name>Lapse Rate Based Temperature Downscaling (Bulk Processing)</name>
	<author>O.Conrad (c) 2017</author>
	<description>
		The [[i]]Lapse Rate Based Temperature Downscaling[[/i]] is quite simple, but might perform well for mountainous regions, where the altitudinal gradient is the main driver for local temperature variation. First, a given lapse rate is used to estimate sea level temperatures from elevation and temperature data at a coarse resolution. Second, the same lapse rate is used to estimate the terrain surface temperature using higher resoluted elevation data and the spline interpolated sea level temperatures from the previous step.
	</description>
	
	<parameters>
		<option varname="LORES_GRID_SYSTEM" type="grid_system">
			<name>Coarse Resolution</name>
		</option>
		<input varname="LORES_DEM" type="grid" parent="LORES_GRID_SYSTEM">
			<name>Elevation</name>
		</input>
		<input varname="LORES_LAPSE" type="grid" parent="LORES_GRID_SYSTEM">
			<condition value="2" type="=">LAPSE_METHOD</condition>
			<name>Lapse Rate</name>
		</input>
		<input varname="LORES_T" type="grid_list" parent="LORES_GRID_SYSTEM">
			<name>Temperature</name>
		</input>

		<option varname="HIRES_GRID_SYSTEM" type="grid_system">
			<name>High Resolution</name>
		</option>
		<input varname="HIRES_DEM" type="grid" parent="HIRES_GRID_SYSTEM">
			<name>Elevation</name>
		</input>
		<output varname="HIRES_T" type="grid_list" parent="HIRES_GRID_SYSTEM">
			<name>Temperature</name>
		</output>

		<option varname="LAPSE_METHOD" type="choice">
			<name>Lapse Rate</name>
			<value>1</value>
			<choices>constant lapse rate|constant lapse rate from regression|varying lapse rate from grid</choices>
		</option>
		<option varname="CONST_LAPSE" type="double">
			<condition type="=" value="0">LAPSE_METHOD</condition>
			<name>Constant or Minimum Lapse Rate</name>
			<value min="0.0">0.6</value>
			<description>constant or minimum limit lapse rate in degree of temperature per 100 meter.</description>
		</option>
		<option varname="REGRS_LAPSE" type="choice">
			<condition type="=" value="1">LAPSE_METHOD</condition>
			<name>Regression</name>
			<value>2</value>
			<choices>elevation|elevation and position|elevation and position (2nd order polynom)</choices>
		</option>
		<option varname="LIMIT_LAPSE" type="boolean">
			<condition type="=" value="1">LAPSE_METHOD</condition>
			<name>Limit Minimum Lapse Rate</name>
			<description>If set, lapse rates from regression are limited to a minimum.</description>
			<value>false</value>
		</option>
		<option varname="MINIM_LAPSE" type="double">
			<condition type="=" value="1">LAPSE_METHOD</condition>
			<condition type="=" value="1">LIMIT_LAPSE</condition>
			<name>Minimum Lapse Rate</name>
			<value min="0.0">0.2</value>
			<description>minimum lapse rate in degree of temperature per 100 meter.</description>
		</option>
	</parameters>

	<tools history="false">
		<condition value="0" type="=" variable="LAPSE_METHOD">
			<foreach input="LORES_T">
				<tool library="climate_tools" tool="30" name="Lapse Rate Based Temperature Downscaling (with options)">
					<option varname="true" id="LAPSE_METHOD">LAPSE_METHOD</option>
					<option varname="true" id="CONST_LAPSE" >CONST_LAPSE</option>
					<input                 id="LORES_DEM"   >LORES_DEM</input>
					<input                 id="LORES_T"     >LORES_T</input>
					<input                 id="HIRES_DEM"   >HIRES_DEM</input>
					<output                id="HIRES_T"     >HIRES_T</output>
				</tool>
			</foreach>
		</condition>
		<condition value="1" type="=" variable="LAPSE_METHOD">
			<foreach input="LORES_T">
				<tool library="climate_tools" tool="30" name="Lapse Rate Based Temperature Downscaling (with options)">
					<option varname="true" id="LAPSE_METHOD">LAPSE_METHOD</option>
					<option varname="true" id="REGRS_LAPSE" >REGRS_LAPSE</option>
					<option varname="true" id="LIMIT_LAPSE" >LIMIT_LAPSE</option>
					<option varname="true" id="CONST_LAPSE" >MINIM_LAPSE</option>
					<input                 id="LORES_DEM"   >LORES_DEM</input>
					<input                 id="LORES_T"     >LORES_T</input>
					<input                 id="HIRES_DEM"   >HIRES_DEM</input>
					<output                id="HIRES_T"     >HIRES_T</output>
				</tool>
			</foreach>
		</condition>
		<condition value="2" type="=" variable="LAPSE_METHOD">
			<foreach input="LORES_T">
				<tool library="climate_tools" tool="30" name="Lapse Rate Based Temperature Downscaling (with options)">
					<option varname="true" id="LAPSE_METHOD">LAPSE_METHOD</option>
					<input                 id="LORES_DEM"   >LORES_DEM</input>
					<input                 id="LORES_LAPSE" >LORES_LAPSE</input>
					<input                 id="LORES_T"     >LORES_T</input>
					<input                 id="HIRES_DEM"   >HIRES_DEM</input>
					<output                id="HIRES_T"     >HIRES_T</output>
				</tool>
			</foreach>
		</condition>
	</tools>
</toolchain>
