Comments (11)
That has to happen in openLCA itself. I use an openLCA IPC script for that. I haven't run this in a while, and it would've been using an older version of IPC but should give you an idea.
Additionally
import olca
import regex as re
from datetime import datetime
import pytz
#The port is set within openLCA when you start IPC
#The default port (8080) is likely used by something else.
olca_client=olca.Client(port=60000)
matching_regex=[
"Electricity - .+ - .+", #Technology processes (COAL plants)
"Electricity; at user; consumption mix - .+ - BA", #BA consumption mixes
"Electricity; at user; consumption mix - .+ - FERC", #FERC consumption mixes
"Electricity; at grid; generation mix - .+", #BA generation mixes
]
combined = "(" + ")|(".join(matching_regex) + ")"
systems = olca_client.get_all(model_type=olca.Process) #I think to speed this up can use something like .get_descriptor
matching_processes = [x.name for x in systems if re.match(combined,x.name)]
for process in matching_processes:
olca_process = olca_client.find(model_type=olca.Process,name=process)
new_system_ref = olca_client.create_product_system(
process_id=olca_process.id,
default_providers="only",
preferred_type="SYSTEM_PROCESS",
) #This returns a reference, not an olca.ProductSystem
new_system=olca_client.get(olca.ProductSystem,new_system_ref.id)
new_system.olca_type = olca.schema.ProductSystem.__name__
new_system.description = (
f"Generated using OLCA-IPC."
)
#name the product system the same as your process
new_system.name = olca_process.name
model_type_str = f"{olca.ModelType.PRODUCT_SYSTEM}"
new_system.version = "1.0.0"
new_system.olca_type = olca.schema.ProductSystem.__name__
new_system.category_path = []
datetime_str = datetime.now(pytz.utc).isoformat()
new_system.last_change=datetime_str
olca_client.update(new_system)
I also executed some SQL in openLCA to clean some things up for posting to the federal LCA commons:
#deleting flows that aren't used in any processes to reduce the size of the database.
delete
from tbl_flows
where not exists
(select f_flow from
(select distinct f_flow
from tbl_exchanges) b2
where tbl_flows.id=b2.f_flow);
#deleting impact factors that link to now deleted flows.
delete
from tbl_impact_factors
where not exists
(select id from tbl_flows
where tbl_impact_factors.f_flow=tbl_flows.id);
#updating the product system description to provide a bit more metadata.
update
tbl_product_systems
set tbl_product_systems.description = 'This product system was created in openLCA by linking default providers. The processes were generated by ElectricityLCI (https://github.com/USEPA/ElectricityLCI) version 1.0.1 using the ELCI_1 configuration. First created: 2020-08-03T14:51:32 Linking approach during creation: Only link default providers; Preferred process type: System process'
where tbl_product_systems.name like 'Electricity; at user; consumption mix - %';
#Setting the product system version to align with the version of eLCI.
update
tbl_product_systems
set tbl_product_systems.version = 4294967297;
update
tbl_processes
set tbl_processes.version = 4294967297;
from electricitylci.
Got it. Thanks, Matt. Looks outdated by the first import statement, but it's not my first time updating olca calls to version 2 😜.
Our new NetlOlca class can handle both JSON-LD zip file and openLCA IPC projects as they provide essentially the same functionality, just different syntax. I don't see anything inhibiting this to be done in electricityLCI.
from electricitylci.
I am a little worried about the two-hour runtime, though.
from electricitylci.
2 hours just to generate the product systems or 2 hours to run the anlaysis portion in the notebook I sent? 2 hours does seem excessive. I recall maybe 20-30 seconds per product system just to create and save them. And I should say the bulk of this time is waiting for openLCA to do it's thing.
from electricitylci.
I was responding to the comment in the Jupyter notebook you sent, Matt. Haven't tested these methods out yet, but am working on their implementation, along with #217.
from electricitylci.
I thought I could be clever and implement the Product System without the IPC server, but it's more fuss than fun. Therefore, we will endeavor to use olca-ipc's create_product_system
in openLCA. I will move this task over the NetlOlca Python package as a new use case, as that is the tool we're using for interfacing with openLCA.
from electricitylci.
That has to happen in openLCA itself. I use an openLCA IPC script for that. I haven't run this in a while, and it would've been using an older version of IPC but should give you an idea.
Additionally
import olca import regex as re from datetime import datetime import pytz #The port is set within openLCA when you start IPC #The default port (8080) is likely used by something else. olca_client=olca.Client(port=60000) matching_regex=[ "Electricity - .+ - .+", #Technology processes (COAL plants) "Electricity; at user; consumption mix - .+ - BA", #BA consumption mixes "Electricity; at user; consumption mix - .+ - FERC", #FERC consumption mixes "Electricity; at grid; generation mix - .+", #BA generation mixes ] combined = "(" + ")|(".join(matching_regex) + ")" systems = olca_client.get_all(model_type=olca.Process) #I think to speed this up can use something like .get_descriptor matching_processes = [x.name for x in systems if re.match(combined,x.name)] for process in matching_processes: olca_process = olca_client.find(model_type=olca.Process,name=process) new_system_ref = olca_client.create_product_system( process_id=olca_process.id, default_providers="only", preferred_type="SYSTEM_PROCESS", # <-- HERE ) #This returns a reference, not an olca.ProductSystem new_system=olca_client.get(olca.ProductSystem,new_system_ref.id) new_system.olca_type = olca.schema.ProductSystem.__name__ new_system.description = ( f"Generated using OLCA-IPC." ) #name the product system the same as your process new_system.name = olca_process.name model_type_str = f"{olca.ModelType.PRODUCT_SYSTEM}" new_system.version = "1.0.0" new_system.olca_type = olca.schema.ProductSystem.__name__ new_system.category_path = [] datetime_str = datetime.now(pytz.utc).isoformat() new_system.last_change=datetime_str olca_client.update(new_system)
@m-jamieson, in the example code you provided above, when creating the product systems you select preferred type to be SYSTEM_PROCESS. I'm finding that all processes in the baseline are of type UNIT_PROCESS, and I'm failing the linking. Should the baseline processes be LCI processes or unit processes? I thought system processes were roll-ups, so I may be missing something here.
from electricitylci.
Things like coal and natural gas rollups should be of type system_process because they are rollups of other systems. That being said, it's only preferred. I don't think we should run into any collisions where the name of a sytem_process = name of a unit_process. Maybe something changed with olca 2.0 though that makes this only use system_process?
from electricitylci.
Okay. I'll keep testing.
from electricitylci.
I wasn't able to generate the linkages for a product system using the IPC. I posed the question to GreenDelta; see GreenDelta/olca-ipc.py#31.
We'll see if they provide us with a better solution; if not, the likeliest option is to generate the product systems programmatically, then manually go through them and generate the complete supply chains in openLCA.
from electricitylci.
Back to the process of automating product systems with ElectricityLCI. The problem with building the supply chain was recently solved in the NetlOlca class, which is now being copied over into olca_jsonld_writer.py.
from electricitylci.
Related Issues (20)
- What impact assessment method? HOT 4
- Globals, references to globals, and editing references of globals
- Forced BA aggregation for FERC and US, but what about eGRID? HOT 3
- Should PC link to petcoke UP? HOT 2
- KeyError in fill_default_provider_uuids
- Missing data file reference in Wiki
- No fuel category in Stewi's getInventoryFacilities for eGRID 2020 HOT 1
- _exchange_table_creation_ref missing renewables HOT 1
- EIA coalpublic2021.xls Excel file format cannot be determined HOT 1
- Missing International Mix data for 2021 onward HOT 3
- Addressing the Industrial Cogeneration Problem and Implementing the filter in model_config HOT 1
- Fix output exchange flows mislabeled as resources HOT 5
- Mexican balancing authority labeled as Canada in BA_Codes_930.xlsx HOT 7
- No 2022 EIA transmission and distribution loss data HOT 3
- Missing Canadian Exports for 2021 and beyond HOT 1
- Fix region mis-match between consumption and distribution mixes
- Incorrect output flow for "at grid; consumption mix" HOT 2
- Issues with the electricity column in generate_plant_water_use() HOT 1
- Update coal model inventories
- Set temporal representativeness attribute for processes to inventory vintage, not target year
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electricitylci.