Small example for Tree

Hi all ,

is there a small example how to create a tree in hops inside the function.
I mean its python and i cant create a GH_Structure also the DataTree doesnt exist so how does it work ?.

Thanks for advice.

Currently, there is no functionality in the ghhops-server implementation to use tree output. Since I have been struggling with this for some weeks now, I tried to implement my own fix for this:

You will have to edit params.py in you ghhops-server installation, and replace the from_result function.

Now your server has the capabilities of putting out trees, which will need to be dictionaries. You can use something like this to convert i.e. a numpy array to a hops-compatbile dict that can be used with tree output:

def np_float_array_to_hops_tree(np_array: np.array, paths: list = []):
    """
    Converts a numpy array to a Hops DataTree (dict with paths as keys).
    """
    if not paths:
        paths = ["{0;" + str(x) + "}" for x in range(np_array.shape[0])]
    tree = {}
    for i, branch in enumerate(np_array):
        tree[paths[i].strip("}{")] = [float(v) for v in branch]
    return tree

@stevebaer I’m really sorry to be bugging with this, but it would be absolutely great if we could get an “official” solution for outputting datatrees through hops python servers. We plan on using a lot of hops stuff with students in the future and would really need it to avoid having them to copy-paste our workaround/hack like described above.

1 Like

Thanks Max; I’m on vacation this week and will try to look at this when I get back to work

1 Like

Hey Steve, sorry to bother again. Any news on this?
I know you’re all super busy with development in different areas but this thing and the missing datatypes in params.py really thwart the usability of hops at our end.

As said before, I’ll gladly be contributing via pull requests, issues or similar if that’s of any help. But I can of course also understand if there are reservations about that. :slight_smile: