Group list in FISH and Python

I’m trying to get the full list of groups that exist in the model, both in Fish and in Python, so I can check how many zones there are in it and delete empty groups. What is the recommended way of doing this? Thank you in advance,

You can export a list of the group for each zone in the model using the file.all command as described in forum post here. e.g.

[file.all("test.txt","text") = zone.group(::zone.list)]

However, you might also need to consider the slots of your groups, and therefore might want an output file with more structure, which you can then manipulate? If so, something like the following might get you started in python:

import itasca as it
import json
it.command("python-reset-state false")
it.command("""
model restore "test"
""")

output_dict = {}

for z in it.zone.list():
        slot_def    = z.group()
        slot_example_1  = z.group("Example 1")
        slot_example_2  = z.group("Example 2")
        output_dict[z.id()] = {
            "slot = default" : slot_def,
            "slot = 1" : slot_example_1,
            "slot = 2" : slot_example_2
            }
    
output_file = "test.json"
with open(output_file, 'w') as fout:
    json.dump(output_dict, fout)
2 Likes

juantello:
There is a hidden command in the code - GROUP LIST -COUNT
This lists of summary of (for examples) the total number of zones, the number of zones with a group in a given slot, and the number of zones using a given group/slot combination.
This could be logged to a file and then imported back for processing either in FISH or Python.

I’m a bit confused about the idea deleting groups however. Groups cannot be deleted, but empty groups cause no overhead so there is no real reason to.

1 Like