Animation Nodes - how to remove with python command

As far as I know, you can run a command in the bar button to remove animation node trees. But I would like to automate this with another script, for rigging purposes.

This doesn't work:

bpy.ops.an.remove_node_tree("nodetreename")


As far as I know, there is an error Invoking the right window?

Any clue how to script this?

bpy.data.node_groups.remove(bpy.data.node_groups["tree name"])