Skip to content
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

Handle single node in PlotLayer #2339

Merged
merged 2 commits into from
Mar 11, 2022
Merged

Conversation

ackurth
Copy link
Contributor

@ackurth ackurth commented Mar 11, 2022

Currently, the following code plotting a single node with spatial metadata with internal plotting routines, fails with a Python level TypeError:

import nest
import matplotlib.pyplot as plt

num_neurons = 1
extent = 2

neuron = nest.Create(
    'iaf_psc_exp',
    num_neurons,
    positions=nest.spatial.free(
        pos=nest.random.uniform(min=-extent / 2, max=extent / 2),
        num_dimensions=2,
        edge_wrap=True)
)
nest.PlotLayer(neuron)

This PR tries to fix this problem.

@clinssen clinssen added T: Bug Wrong statements in the code or documentation S: High Should be handled next I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) labels Mar 11, 2022
Copy link
Contributor

@stinebuu stinebuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

@hakonsbm hakonsbm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the single-node case results in a TypeError, I think it's more straight-forward to have something like

if (len(layer) == 1):
    pos = GetPosition(layer)
else:
    pos = zip(*GetPosition(layer))

or even as a single line

pos = GetPosition(layer) if len(layer) == 1 else zip(*GetPosition(layer))

@hakonsbm hakonsbm added this to In progress in PyNEST via automation Mar 11, 2022
@hakonsbm hakonsbm moved this from In progress to Review in PyNEST Mar 11, 2022
@ackurth
Copy link
Contributor Author

ackurth commented Mar 11, 2022

Although the single-node case results in a TypeError, I think it's more straight-forward to have something like

if (len(layer) == 1):
    pos = GetPosition(layer)
else:
    pos = zip(*GetPosition(layer))

or even as a single line

pos = GetPosition(layer) if len(layer) == 1 else zip(*GetPosition(layer))

I changed the code accordingly.

Copy link
Contributor

@hakonsbm hakonsbm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hakonsbm hakonsbm merged commit 9e8c7f8 into nest:master Mar 11, 2022
PyNEST automation moved this from Review to Done Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: High Should be handled next T: Bug Wrong statements in the code or documentation
Projects
PyNEST
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants