-
Notifications
You must be signed in to change notification settings - Fork 438
Display Connection Matrix #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you @SoundsSerious for the submission! I had been stuck on how to best represent connections for explicitly connected systems and the complexity of signal names with sub components and I think you have come up with a simple and most elegant solution. It would be great to have something like this in the library. A few thoughts.
|
@sawyerbfuller Ah glad you like it, happy to give back to a framework I've been getting alot of use out of! I agree the formatting sucks but this is something I put together in about 15 minutes so there is lots of room for improvement.
|
I have actually broken this down into two functions one to index the states & IO by global name and one to plot.
def make_connection_plot(self):
iinx,oinx,sinx = system_index(self)
cmm = self.connect_map.copy()
cmm[cmm==0] = np.nan
imshow(cmm)
grid()
title(f'Connection Map: {self.name}')
xticks(ticks=list(oinx.keys()),labels=list(oinx.values()),rotation=90)
yticks(ticks=list(sinx.keys()),labels=list(sinx.values()))
xlabel('Outputs')
ylabel('Inputs')
tight_layout()
def system_index(self):
iinx = {}
oinx = {}
sinx = {}
# Go through the system list and keep track of counts, offsets
for sysidx, sys in enumerate(self.syslist):
for st in range(sys.nstates):
sinx[ max(sinx.keys())+1 if sinx else 0 ] = f'{sys.name}.{sys.state_labels[st]}'
for st in range(sys.noutputs):
oinx[ max(oinx.keys())+1 if oinx else 0] = f'{sys.name}.{sys.output_labels[st]}'
for st in range(sys.ninputs):
iinx[max(iinx.keys())+1 if iinx else 0] = f'{sys.name}.{sys.input_labels[st]}'
return iinx,oinx,sinx |
@SoundsSerious yes, no need to worry about a matplotlib dependency, that's already part of the library as you noted. Sometimes I like having the option of not spawning a new plot : ) I am not aware of an existing function for def system_index(self):
istate = 0
state_index = {}
for sys in self.syslist:
for i in range(sys.nstates):
state_index[istate] = f'{sys.name}.{sys.state_labels[i]}'
istate += 1
# and same for inputs and outputs |
Ha yes sometimes you can have too many plots! Not sure if you ever tried jupyter qtconsole but it has the ability to do in or out of terminal plots as well as a bunch of neat tricks such as bash commands and navigation. I like that formulation much more, it is alot clearer whats going on! |
@sawyerbfuller Not sure you want another dependency but alternatively you could make a soft dependency (import function local and fail with a message to install it) or you could just copy the code from one of the IO modules |
@SoundsSerious I thought about that in #925, e.g. whether to use that one or e.g. https://github.com/petercorke/ansitable. I decided in that case that the table requirements weren't too onerous and could get away with just rolling my own by hand to reduce dependencies. But if we start making lots of tables like this, then it starts to make more sense. What do you think? |
I'm not sure about your needs, but from a dependency perspective, rich would probably be the better maintained project. |
Hi,
I wanted to expand on #925 and display a sparse graph of all the system connections, some of which had the same signal name, which is a case I found the new connection table feature a bit confusing for so I wrote this short function to display the connection matrix directly using matplotlib imshow.
This code results in this plot, displaying the gain via color as well as the scoped input and output names.

The text was updated successfully, but these errors were encountered: