Proposal for configuration management

New to posting a proposal, so let me know if this is the correct place and form.

I do not have funding for this proposal and I do not have the necessary development skills to do the development myself. So I am hoping someone would be interested in implementing this proposal with me.

If you have any questions or follow up let me know.

Thanks

Steven

Here is the proposal.

Is your feature request related to a problem? Please describe.

I have multiple definitions of parameters created for a GRASS function and I have to
enter them at run time. I often forget the definitions and key them in incorrectly which
is frustrating. It is also difficult to try out various options as all the parameters have to
be entered each time. This would also provide stored parameter files for working in the
modelling domain.

Describe the solution you’d like

Use parameter configuration files for all the GRASS functions.
Provide the ability to use runtime overrides.
The configuration file creation, saving and editing would be done with a text editor
The configuration file create, save, edit operations could also be done using the cfgsave parameter
The configuration file would have:

  • Header information with a user defined description.
  • Parameters for the function name and configuration file name.
  • The flags and parameter definitions for the specific function.

Describe alternatives you’ve considered

I create text files with parameters and flags that I then use for reference when I type in the
command line parameters.

Additional context

The example below is a definition of r.relief for a terrain with ridges running NE to SW. This
configuration (MyMapShade.cfg) will run using the specified flags and parameters and defaults for
the rest of them.

This configuration is defined for MyMap which has ridges running NE to SW

function =r.relief
configuration=MyMapShade.cfg
input=DEM20
output=Shade
altitude=65
azimuth=135
zscal=3
scale=1
units=intl
#cfgsave=MyMapShade.cfg
–overwrite
#–help
#–verbose
–quiet
#–ui

This file would be defined as a concatenation of the function file name as:

  • r.relief.MyMapSghade.cfg

This would provide easy searching for function specific configuration files.

The configuration file can then be assigned to the function with the following GRASS command:

read directly from file

r.relief cfg=MyMapShade.cfg

It would execute as.
r.relief input=DEM20 output=Shade10AM altitude=65 azimuth=135 zscal=3 scale=1
units=intl --overwrite --quiet

Runtime overrides could be used to allow easy what if executions without overwriting the
configuration file. Any parameter or flag added to the command would override the value from the
configuration file at run time. For example, a user could vary the sun direction and height to find the
combination that shows the best shading for their area of interest.

r.relief cfg=MyMapShade azimuth=120 altitude=45

This lets a user simply vary the parameter they want to investigate until they are ready to update the
configuration file or create a new one.

If a user wanted to save the existing command line configuration they could use the cfgsave parameter to define the name of an output configuration file. The cfgsave will take the existing command line configuration and write it out to the named configuration file. The cfgsave parameter could be used to create a new configuration file with a new file name as well as edit an existing configuration file by using the current configuration file name.

Configuration files would provide a way to store parameters for any function for later reuse in the command line environment.

It should also be possible to use the configuration files in the modelling environment to define the execution of a function in the modelling process definition.

The full implementation into the GUI environment for all functions would require the addition of a scrolling edit field for configuration files and a save button. There would also need to be some
additional behavior added to the GUI code behind to handle the read and write of parameter definitions in the GUI fields.

Here is the reported enhancement:

I think this is a reasonable idea I would support, but probably won’t have time for this. As a workaround, you can still do it, although it’s obviously not as elegant solution. This is what chatGPT gave me (I didn’t test):

1. Save your parameters in a JSON file

For example, MyMapShade.json:

{
  "input": "DEM20",
  "output": "Shade",
  "altitude": 65,
  "azimuth": 135,
  "zscale": 3,
  "scale": 1,
  "units": "intl",
  "flags": ["overwrite", "quiet"]
}

2. Python script to read the config and call the GRASS module

import json
import grass.script as gs

def run_module_from_config(module_name, config_file, overrides=None):
    with open(config_file, 'r') as f:
        config = json.load(f)

    # Apply any runtime overrides
    if overrides:
        config.update(overrides)

    # Separate flags from other parameters
    flags = config.pop("flags", [])
    gs.run_command(module_name, flags=flags, **config)

# Example usage
run_module_from_config("r.relief", "MyMapShade.json", overrides={"azimuth": 120, "altitude": 45})

Thanks for the review. I like the idea of using a json file and taking advantage of the json functionality. This looks like it will work on a one off basis and will make my learning curve a lot easier.

I think this would be useful for many users and I would still like to see this fully developed, possibly as a GRASS extension or plugin for general use in the product.
Do I just leave this as is to see if someone wants to pick it up. Is there anything else I should do to accomplish this?