GreenDelta / openlca-python-tutorial

Explains the usage of the openLCA API from Python (Jython)
Other
59 stars 17 forks source link

Getting contribution tree results #24

Open Luigi-Cala opened 3 years ago

Luigi-Cala commented 3 years ago

Hi, i'm new here and I am trying to calculate a Product System using Contribution_Analysis calculation. As said in the title, I would like to export to an Excel Sheet the results in a form similar to the contribution tree obtained with the actual OpenLCA application when run an analisys calculation of the product system (doing all by hand, without the python developer tool).

I already tried to do it by my self but with poor results. The main problem is that as i i run the Contribution_calculation, it seem like the results provided are the same obtained with the Simple_calculation, which are basically the total impact (according to the impact category chosen) and the LCI and impact results related to the flow. While what i'm searching for are the impact realated to process used in the product system (as provided in the contribution tree results).

I hope that i explained my issue correctly and by the way I am working with the developer tool, already installed in OpenLCA. Do you perhaps have any advice on how to do this, without having to install other program or plug-in?

Thank you so much!

Luigi-Cala commented 3 years ago

Hello! Just an update if anyone is reading. I managed to get the contribution tree results of my product system using the following calculation method and selecting the field upstreamImpactResults in the FullResultclass, exporting all on a .csv file:

f = FileChooser.forExport('*.csv', 'test.csv')
with open(f.getAbsolutePath(), 'wb') as stream:
writer = csv.writer(stream, delimiter=',')

solver = DenseSolver()
calculator = SystemCalculator(m_cache, solver)
setup = CalculationSetup(CalculationType.UPSTREAM_ANALYSIS, system)
setup.impactMethod = method
result = calculator.calculateFull(setup)

test= result.upstreamImpactResults 
col = test.columns()
roww = test.rows()
for i in range(roww):
     writer.writerow(test.getRow(i))

but now i come up with another problem, i can't find a way to "link" the result to the correct process. I have both results and the process descriptors of all the product system processes, but i really don't understand the order i which the results are provided. there is someone that has alredy deal with it? or at least know hot to sort correctly the upstreamImpactResults in such a way that i can create a table on the .csv file with named column? Just to clarify the final table will have named rows with the impact categories selected and named columns with all the process in the product system.

Thanks in advance Luigi