USEPA/WNTR

Unhashble type

DanielaBS1 opened this issue · 1 comments

I am new to Python and WNTR.

I am trying to get a sequency of information automatically. I.E. get tank with smaller pressure @ certain time, get the link connecting to the tank and finally the start node of this link.
I can get each information separately, i.e. typing the result of the first question to the next and so on. But as the results to each enquiry is an unhashable type, I haven't been able to use the variables as input to the next function. I have tried several different options, but I am not sure how to the result to the first question an valid input to the next.
I am sending a sample of what I would like to do, however as it is I only get an error messages for 'unhashble type index' (when trying to get the link) and 'unhashble type list' (when trying to get the start node).

min_press = results.node['pressure'][results.node['pressure']==results.node['pressure'].loc[43600,wn.tank_name_list].min()].loc[43600,wn.tank_name_list].dropna()

node_with_minpressure=(min_press.index)

link1=wn.get_links_for_node(node_with_minpressure, flag="ALL")

startnode = wn.get_link(link1_str).start_node.name
print (startnode)

I am using python 3.10.9, (Spyder 5.4.1)

This is possible to compute this in a single line of code, but there are a few things to keep in mind

  1. A tank can have multiple pipes connected to it (that's why get_links_for_node returns a list)
  2. The start node of the link connected to the tank could be the tank
t = 43600

# In multiple lines
tank_with_min_pressure = results.node['pressure'].loc[t, wn.tank_name_list].idxmin()
connected_links = wn.get_links_for_node(tank_with_min_pressure, flag="ALL")
startnode = wn.get_link(connected_links[0]).start_node_name
print (startnode)

# In one line
startnode = wn.get_link(wn.get_links_for_node(results.node['pressure'].loc[t, wn.tank_name_list].idxmin(), flag="ALL")[0]).start_node_name
print (startnode)

In the code you provided, node_with_minpressure ends up being of type Index, but get_links_for_node expects a string.