Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from AnikaBettge/more_parameter
Browse files Browse the repository at this point in the history
add parameter description for parameters in one line/GRASS GIS parameter
  • Loading branch information
anikaweinmann authored Apr 16, 2020
2 parents 0b9284a + 794403c commit b54aecc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
44 changes: 30 additions & 14 deletions actinia_gdi/core/gmodulesActinia.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ def add_param_description(moduleparameter, param, input_dict):
# update description and mention grass module parameter
suffix = " [generated from " + param + "]"
moduleparameter['description'] += suffix
# add comment if there is one in process chain template

# add comment if there is one in process chain template
if not param in input_dict:
for input_dict_key in input_dict:
if param in input_dict_key:
param = input_dict_key
if param in input_dict and 'comment' in input_dict[param]:
comment = input_dict[param]['comment']
moduleparameter['description'] += " - " + comment
# moduleparameter['comment'] = comment
if comment not in moduleparameter['description']:
moduleparameter['description'] += " - " + comment
# moduleparameter['comment'] = comment


def createActiniaModule(self, processchain):
Expand Down Expand Up @@ -182,17 +187,27 @@ def createActiniaModule(self, processchain):
if '{{ ' in val and ' }}' in val and val not in aggregated_vals:
aggregated_vals.append(val)
run_interface_descr = True
input_dict[processid]["gparams"][key] = {}

# matches placeholder in longer value, e.g. in
# 'res = if(input <= {{ my_values }}, 1, null() )'
# beware that in general it is easier to make the whole value
# a placeholder. Might be not possible for e.g. r.mapcalc
placeholder = re.search(r"\{\{(.*?)\}\}", str(val)).groups()[0]
amkey = placeholder.strip(' ')
input_dict[processid]["gparams"][key]['amkey'] = amkey
if 'comment' in j:
input_dict[processid]["gparams"][key]['comment'] = j['comment']
placeholders = re.findall(r"\{\{(.*?)\}\}", str(val))

if len(placeholders) == 1:
input_dict[processid]["gparams"][key] = {}
amkey = placeholders[0].strip(' ')
input_dict[processid]["gparams"][key]['amkey'] = amkey
if 'comment' in j:
input_dict[processid]["gparams"][key]['comment'] = j['comment']
else:
for placeholder in placeholders:
amkey = placeholder.strip(' ')
newkey = "%s_%s" % (key, amkey)
input_dict[processid]["gparams"][newkey] = {}
input_dict[processid]["gparams"][newkey]['amkey'] = amkey
if 'comment' in j:
input_dict[processid]["gparams"][newkey]['comment'] = j['comment']

if 'import_descr' in j:
for key, val in j['import_descr'].items():
Expand Down Expand Up @@ -234,12 +249,13 @@ def createActiniaModule(self, processchain):

if 'parameters' in grass_module:
for param in grass_module['parameters']:
if param in aggregated_keys.keys():
amkey = aggregated_keys[param]['amkey']
virtual_module_params[amkey] = grass_module['parameters'][param]
for aggregated_key in aggregated_keys:
if param in aggregated_key:
amkey = aggregated_keys[aggregated_key]['amkey']
virtual_module_params[amkey] = grass_module['parameters'][param]

add_param_description(
virtual_module_params[amkey], param, aggregated_keys)
add_param_description(
virtual_module_params[amkey], param, aggregated_keys)

if 'returns' in grass_module:
for param in grass_module['returns']:
Expand Down
7 changes: 7 additions & 0 deletions actinia_gdi/core/gmodulesParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ def ParseInterfaceDescription(xml_string, keys=None):
if keys:
# case for actinia modules
key = setVirtualParameterKey(module_id, parameter)
key_exists = False
if key not in keys:
for actiniakey in keys:
if actiniakey.startswith(key):
key_exists = True
else:
key_exists = True
if not key_exists:
continue
else:
# case for GRASS modules
Expand Down
1 change: 1 addition & 0 deletions actinia_gdi/templates/pc_templates/default_value.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"inputs": [
{
"param": "expression",
"comment": "output = r.mapcalc result, string; value = raster value (default=0.428), float",
"value": "{{ output }} = {{ value|default(0.428) }}"
}
]
Expand Down

0 comments on commit b54aecc

Please sign in to comment.