LCA-ActivityBrowser / activity-browser

GUI for brightway2
GNU Lesser General Public License v3.0
152 stars 58 forks source link

Data in parameter scenario file is not loaded and flow scenario file simply fails #932

Closed mkvdhulst closed 1 year ago

mkvdhulst commented 1 year ago

Dear all,

When running a scenario based LCA using a parameter scenario file, its does not execute and I get the error that the analysis cannot be run without data, even though my parameter scenario file contains multiple rows and columns and is formatted in line with examples.

Loading Scenario file. This may take a while for large files Superstructure: Could not find required headers in given document sheet. Attempting to read as parameter scenario file. <function ScenarioImportWidget.sync_superstructure at 0x0000028D66F04AF0> -- 0.002003192901611328 <function ScenarioImportWidget.load_action at 0x0000028D66F049D0> -- 4.919438123703003 No data in scenario table 1, skipping Traceback (most recent call last): File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 24, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 28, in init assert not df.empty, "Cannot run analysis without data." AssertionError: Cannot run analysis without data.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_results_tab.py", line 56, in generate_setup new_tab = LCAResultsSubTab(data, self) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_results_tabs.py", line 104, in init self.mlca, self.contributions, self.mc = calculations.do_LCA_calculations(data) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 28, in do_LCA_calculations raise BW2CalcError("Scenario LCA failed.", str(e)).with_traceback(e.traceback) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 24, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 28, in init assert not df.empty, "Cannot run analysis without data." bw2calc.errors.BW2CalcError: ('Scenario LCA failed.', 'Cannot run analysis without data.')

When I instead load a flow scenario file, which was generated using premise, the error does not show, but still, no scenario based LCA is executed. In the Anaconda prompt, I get the following message:

Loading Scenario file. This may take a while for large files <function get_header_index at 0x0000028D665C3670> -- 0.4810910224914551 <function import_from_excel at 0x0000028D665C3820> -- 174.35908269882202 <function ScenarioImportWidget.sync_superstructure at 0x0000028D66F04AF0> -- 0.004036903381347656 <function ScenarioImportWidget.load_action at 0x0000028D66F049D0> -- 184.05294799804688 [4440:18376:0209/135214.572:ERROR:dns_config_service_win.cc(785)] DNS config watch failed. Traceback (most recent call last): File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_setup.py", line 211, in start_calculation 'data': self.scenario_panel.combined_dataframe(), File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_setup.py", line 336, in combined_dataframe manager = SuperstructureManager(*data) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\manager.py", line 24, in init SuperstructureManager.format_dataframe(df) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\manager.py", line 114, in format_dataframe df = SuperstructureManager.romain_merge_flows_to_self(df) AttributeError: type object 'SuperstructureManager' has no attribute 'romain_merge_flows_to_self'

I have tried the following things:

Nothing seems to work. Any suggestions for solutions? Thank you in advance!

Zoophobus commented 1 year ago

Hi mkvdhulst,

my apologies, when you tried to use a scenario flow file for your analysis you came across a bug that I made. I've just pushed a correction up to the github repo and will send a request for this to be merged with the conda repo pronto!

As to resolve your first issue that result does seem very weird. I'm not sure what is going on with the importer and I'd like to ask if it would be possible for you to send your scenario file so I can try and debug this further. This could also be helpful as we're currently trying to build up a suite of different errors and messages to try and make the process of debugging these kinds of problems easier

lea-we commented 1 year ago

Hey, i've got a similar problem. I want to run a parameter scenario on a database. for parameters affecting the technosphere it works, but as soon as I change it to biosphere (which is what I need) i get: "Constructed LCA matrix does not contain any exchanges from the superstructure".

Am I not aware of changes to the structure required when applying parameters on biosphere values?

Zoophobus commented 1 year ago

I've just pushed a correction up to the github repo and will send a request for this to be merged with the conda repo pronto!

Hi mkvdhulst,

this has been pushed and a patched version is now available on conda-forge. My apologies and thanks for highlighting the bug. If either of you could provide a SDF for this other issue I would be grateful

Zoophobus commented 1 year ago

@mkvdhulst Could you try with the flow scenario's again? The bug you highlighted should be fixed by now. I'm still going to continue to work on the parameter scenario file, however there are quite a lot of problems surrounding the parameters that make it more of a challenge to solve

mkvdhulst commented 1 year ago

The issue unfortunately is not resolved for me as I get another error for running scenario LCA with a flow scenario file. This time it loads the file, but once executing an LCA with the loaded scenarios, I get the following error:

Loading Scenario file. This may take a while for large files <function get_header_index at 0x00000184321C4790> -- 0.7646543979644775 <function import_from_excel at 0x00000184321C4940> -- 528.3229677677155 <function ScenarioImportWidget.sync_superstructure at 0x0000018432B04CA0> -- 0.007054328918457031 <function ScenarioImportWidget.load_action at 0x0000018432B04B80> -- 540.4063854217529 [16444:11820:0210/104035.979:ERROR:dns_config_service_win.cc(785)] DNS config watch failed. Traceback (most recent call last): File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 27, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 37, in init assert not df.empty, "Filtering unused flows removed all of the scenario data." AssertionError: Filtering unused flows removed all of the scenario data.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_results_tab.py", line 56, in generate_setup new_tab = LCAResultsSubTab(data, self) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\layouts\tabs\LCA_results_tabs.py", line 104, in init self.mlca, self.contributions, self.mc = calculations.do_LCA_calculations(data) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 31, in do_LCA_calculations raise BW2CalcError("Scenario LCA failed.", str(e)).with_traceback(e.traceback) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\calculations.py", line 27, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) File "C:\Users\name\Anaconda3\envs\ab\lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 37, in init assert not df.empty, "Filtering unused flows removed all of the scenario data." bw2calc.errors.BW2CalcError: ('Scenario LCA failed.', 'Filtering unused flows removed all of the scenario data.')

Zoophobus commented 1 year ago

Hi,

I need to improve on the error names, but I can also honestly say that some of the names that I have come up with have also been pretty terrible.

Just to get this case out of the way, can you confirm that the process, or environmental flows you have in your scenario file are also present in your database? Including checking the database? I have often had this problem because I failed to update, or name the database correctly, so when the AB tried to connect the flows in the scenario with the database nothing was left.

Once that is out of the way what would be ideal is a test database and scenario file to figure out what's going wrong with the AB, would that be possible?

mkvdhulst commented 1 year ago

Thank you for this suggestion. It indeed turned out to be a naming issue. I was assessing flows from my foreground database that was linked to background_database using a flow scenarios file for background_database_2. While the keys for each flow in the background databases are exactly the same, this small difference in the name of the database resulted in the removal of all flows when filtering for unused flows. I simply resolved it by relinking my foreground database to background_database_2 and was able to run the scenario analysis without a hitch.

The parameter scenario file still gives me the same issue, but I manually changed it to a flow scenario file and simply use the "addition" option when loading the flow scenario files for the foreground and background. This works without any issues, so I will adjust my workflow accordingly and abandon parameter scenario files for now. I have attached the corresponding parameter and flow scenario files in case it can be of use in debugging the parameter scenario file feature.

Thank you for your support.

P.s. What is an SDF?

parameter_scenario_file.xlsx flow_scenario_file.xlsx

Zoophobus commented 1 year ago

SDF stands for Scenario Difference File. It's synonymous with just scenario file, so now that you ask that question I'm wondering why we include "Difference"?

Zoophobus commented 1 year ago

Hi @lea-we, my apologies for the long delay. I was wondering if you still have the same problem, as I have played around with parameter scenarios but haven't been able to replicate your situation?

Zoophobus commented 1 year ago

@lea-we please feel free to reopen this issue if you still have a problem with your files

cuadragg commented 3 months ago

Hi!

I am experiencing the same issue. I have the last version of AB (2.10.1) and when I tried to upload the parameter scenario files, the following error appears:

Params: ['motor_use_7c2ac00d1abc08d502e817d273df6150', 1, 0] 21:16:29 | INFO | Loading Scenario file. This may take a while for large files 21:16:29 | INFO | Superstructure: Attempting to read as parameter scenario file. 21:16:36 | INFO | <function ScenarioImportWidget.scenario_db_check at 0x0000026898412980> -- 0.0 21:16:36 | INFO | <function SuperstructureManager.fill_empty_process_keys_in_exchanges at 0x00000268952E9580> -- 0.0 21:16:36 | INFO | <function SuperstructureManager.verify_scenario_process_keys at 0x00000268952E96C0> -- 0.0009999275207519531 21:16:36 | INFO | <function SuperstructureManager.check_duplicates at 0x00000268952E9940> -- 0.0 21:16:36 | INFO | <function ScenarioImportWidget.sync_superstructure at 0x0000026898412840> -- 0.007437944412231445 21:16:36 | INFO | <function ScenarioImportWidget.load_action at 0x0000026898412700> -- 32.84086871147156 21:25:59 | INFO | Relinked database 'motor_case', 0 exchange inputs changed from 'biosphere3' to 'motor_case'. 21:28:38 | INFO | Relinked database 'motor_case', 0 exchange inputs changed from 'biosphere3' to 'motor_case'. 21:29:09 | INFO | Relinked database 'motor_case', 0 exchange inputs changed from 'biosphere3' to 'motor_case'. 21:29:17 | INFO | Relinked database 'motor_case', 0 exchange inputs changed from 'biosphere3' to 'motor_case'. 21:30:33 | ERROR | Traceback (most recent call last): File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\bwutils\calculations.py", line 28, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 41, in init assert not df.empty, "Cannot run analysis without data." ^^^^^^^^^^^^ AssertionError: Cannot run analysis without data.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\layouts\tabs\LCA_results_tab.py", line 61, in generate_setup new_tab = LCAResultsSubTab(data, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\layouts\tabs\LCA_results_tabs.py", line 114, in init self.mlca, self.contributions, self.mc = calculations.do_LCA_calculations(data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\bwutils\calculations.py", line 33, in do_LCA_calculations raise BW2CalcError("Scenario LCA failed.", str(e)).with_traceback( File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\bwutils\calculations.py", line 28, in do_LCA_calculations mlca = SuperstructureMLCA(cs_name, df) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\cuadragg\AppData\Local\anaconda3\envs\ab\Lib\site-packages\activity_browser\bwutils\superstructure\mlca.py", line 41, in init assert not df.empty, "Cannot run analysis without data." ^^^^^^^^^^^^ bw2calc.errors.BW2CalcError: ('Scenario LCA failed.', 'Cannot run analysis without data.')

I am using this file for parameter-scenario scenario_table.xlsx

I would highly appreciate your help!

Thanks, Glenda