USEPA / ElectricityLCI

Creative Commons Zero v1.0 Universal
24 stars 10 forks source link

What does the if-statement do? #205

Open dt-woods opened 9 months ago

dt-woods commented 9 months ago

In egrid_emissions_and_waste_by_facility.py (development branch), there's an if-statement where model_specs.inventories_of_interest.keys() is called, which should be, for ELCI_1, the list of:

So, this module, when imported, will succeed in the first if-statement, checking if 'eGRID' is in keys, set base_inventory = 'eGRID' and run combineInventoriesforFacilitiesinBaseInventory once; however, there are three other inventories of interest that appear to be skipped.

That doesn't seem right, does it?

https://github.com/USEPA/ElectricityLCI/blob/980867632bafcb2079c381c4ed2edf0c1643d626/electricitylci/egrid_emissions_and_waste_by_facility.py#L16

m-jamieson commented 9 months ago

The if statement is just setting the base inventory, and the order of the if statement is just setting the preferred order. StEWI will still process the other three inventories because "model_specs.inventories_of_interest" is passed to stewicombo.combineInventoriesforFacilitiesinBaseInventory. It's been a while since I looked at it, but I believe the base inventory provides the facility ID numbers that are used to match the other inventories to since those datasets have their own unique facilitiy IDs. @bl-young might be able to confirm.

bl-young commented 9 months ago

Yes that's right. The base inventory serves as the source of the facility list I believe, but the rest of the inventories are brought in and matched to facilities in the base inventory

dt-woods commented 9 months ago

Could I trouble you for a few sentences that capture this behavior? @bl-young, is there more documentation on what filter_for_lci does? It's a little hard to discern without documentation, but it seems to trigger 5 other filters (in filters.yaml). Is that right?

Correct me if I'm wrong, but what I'm hearing so far is the following:

Assign the reference inventory (e.g., eGRID, NEI, TRI, RCRAInfo) to be used for defining the facility-level inventories gathered from each of the inventories of interest (as defined in the model's configuration file) using USEPA's stewi package. Data are filtered for LCI (whatever that means).

dt-woods commented 9 months ago

@m-jamieson, the documentation in the wiki for this module reads,

This module will either use an existing inventory determined from the inventories_of_interest specified in the configuration file or create one by calling stewicombo from Standardized Emission and Waste Inventories (StEWI). If there is no existing CSV file the call to stewicombo to generate the inventory can take some time. It should be noted that this module is executed immediately upon import, which may cause some unexpected delays if the CSV file is not present.

Reading the code, it looks like from the first sentence, you are actually looking for an existing inventory determined by model_specs.stewicombo_file and not inventories_of_interest and that inventories_of_interest are used to gather inventories from stewi. Am I reading this correctly?

m-jamieson commented 9 months ago

You're more than likely reading that correctly. A lot of this wiki was developed concurrently with the final version of model_specs. I suspect that rather than "calcuating" a string name from the inventories_of_interest, we opted just to have a variable to specify it.

bl-young commented 9 months ago

If there is no existing CSV file the call to stewicombo to generate the inventory can take some time. It should be noted that this module is executed immediately upon import, which may cause some unexpected delays if the CSV file is not present.

I will add that we now have the ability to point to a locally stored, or externally sourced via data commons, combined inventory file (via stewicombo_file), as a replacement for the csvs in the repository. The wiki likely predates that entirely