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

Violin Plot AttributeError: 'list' object has no attribute 'shape' #5

Open
User559180 opened this issue Dec 16, 2024 · 2 comments
Open

Comments

@User559180
Copy link

Hi,
I used the following code to create a violin plot (I tried it in both Brightway2 and Brightway2.5 with the same result):

from polyviz import chord, violin
db_ecoinvent = bd.Database('ecoinvent-3.11-apos')
violin(
activities=[a for a in db_ecoinvent if a["unit"] == "ton kilometer"][:3],
method=('EF v3.1', 'climate change', 'global warming potential (GWP100)'),
iterations=100,
title = "violin test 1"
)

However, I encountered this AttributeError:
violin

Could you please help me figure out what might be causing this issue? Did I do something wrong, or is there an error in your code?
Thank you in advance!

@romainsacchi
Copy link
Collaborator

I do not have a direct idea.
Did you check that the GWP LCIA method you use is indeed present in bw2data.methods ?

try:

('EF v3.1', 'climate change', 'global warming potential (GWP100)') in bw2data.methods

@User559180
Copy link
Author

Thank you very much for your quick response!

Yes, the EF v3.1 climate change LCIA method is indeed present in Brightway methods. I successfully created a chord diagram using this method, and here is the code I used:

chord(
activity=my_activity,
level=4,
cutoff=0.01,
#flow_type="kilogram",
method=('EF v3.1', 'climate change', 'global warming potential (GWP100)'),
notebook = True,
figsize = (720, 720)
)

I am not an expert, but I tested your violin.py code and noticed something that might be causing the issue. In the section with the if MultipleMonteCarlo ... else ... logic: If the if condition is True, the line res = MultiMonteCarlo() generates a python list.
In the else block, res is assigned as an np.array. However, in the if block, res remains a list and still needs to be converted into an np.array.

Could you please look into this and fix the problem? I would be very grateful for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants