Command line tool

The agrifoodpy command line tool allows you to run a pipeline of functions defined in a YAML configuration file. This is useful for automating workflows and reproducibility. You can specify the configuration file and an output file for the results.

Executing the command line tool

To execute the command line tool, use the following syntax:

$ agrifoodpy <config_file.yml> -o <output_file.json>

The following options are available for the command line tool:

-o --output:

Specify the output file for the results. The output will be saved in JSON format.

--nodes:

Print the nodes and parameters to stdout

--no-run:

Do not run the pipeline

--from-node:

Index of the first node to be executed

--to-node:

Index of the last node to be executed

--skip-nodes:

List of nodes to be skipped in the pipeline execution

Configuration files

Configuration files are YAML files that define a pipeline of functions to be executed by the agrifoodpy command line tool. Each function is specified with its name and parameters, and the pipeline is executed in the order they are defined.

Example of a configuration file for scaling a food balance sheet.
nodes:
  - function: agrifoodpy.utils.nodes.load_dataset
    name: "Load dataset"
    params:
      datablock_path: "food"
      module: "agrifoodpy_data.food"
      data_attr: "FAOSTAT"
      coords: {
            Item: [2731, 2511],
            Year: [2019, 2020],
            Region: 229}

  - function: agrifoodpy.utils.nodes.write_to_datablock
    name: "Add convertion factor from 1000 tonnes to kg"
    params:
      key: "tonnes_to_kg"
      value: 1000000

  - function: agrifoodpy.food.model.fbs_convert
    name: "Convert fbs from 1000 tonnes to kg"
    params:
      fbs: "food"
      convertion_arr: "tonnes_to_kg"

  - function: agrifoodpy.food.model.SSR
    name: "Calculate SSR"
    params:
      fbs: "food"
      out_key: "SSR"

  - function: agrifoodpy.food.model.IDR
    name: "Calculate IDR"
    params:
      fbs: "food"
      out_key: "IDR"

  - function: agrifoodpy.utils.nodes.print_datablock
    name: "Print SSR"
    params:
      key: "SSR"
      method: "to_numpy"
      preffix: "SSR: values "

  - function: agrifoodpy.utils.nodes.add_items
    name: "Add item names to the datablock"
    params:
      dataset: "food"
      copy_from: 2731
      items: {
        "Item": 5000,
        "Item_name": "Cultured meat",
        "Item_group": "Cultured products",
        "Item_origin": "Synthetic origin",
      }

  - function: agrifoodpy.utils.nodes.add_years
    name: "Add years to the fbs"
    params:
      dataset: "food"
      years: [2021, 2025, 2030]
      projection: [1.1, 1.5, 10]

  - function: agrifoodpy.utils.nodes.print_datablock
    name: "Print FBS"
    params:
      key: "food"

Each node is defined with a function to execute, and its parameters and, optionally, a name. The function is specified in the format module.function, where module is the name of the module containing the function, and function is the name of the function to be executed. The parameters are specified as a dictionary of key-value pairs, where the keys are the parameter names.