Using the Federal LCA Commons Public API #289
dt-woods
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background: The ElectricityLCI relies on the Federal LCA Commons' public API to get GreenDelta's unit groups and flow property data (typically provided in their databases as a radio button when creating a database from scratch, for example, the 'units and flow properties' option). To make the ElectricityLCI's baseline JSON-LD files complete, we opt to include them. Additionally, the EPA's pedrigree matrices for flow and process data quality are also taken from the Federal LCA Commons' USLCI repository. These data calls are handled in the olca_jsonld_writer.py module.
The Federal LCA Commons hosts a user guide for their API1.
It doesn't look like JSON data can be exported directly over the internet for these assets; therefore, we will implement the request for a JSON-LD preparation token, then download the ZIP file over the internet.
The Python dependencies needed for this include:
First, let's define the URL for JSON-LD preparation:
The flow properties and unit groups are available in the Elementary Flow List repository2.
To get a token for downloading the flow property and unit groups, we add to the base URL the group name (
Federal_LCA_Commons
), the repository name (elementary_flow_list
), and query the flow property path, as follows:The token is a string of letters and number provided by the Federal LCA Commons' API service. To get a token, we send a GET request.
With the token, we can now get the JSON-LD ZIP file from the server using the original URL.
We have options on how to handle the content returned: (1) save it to ZIP file locally, or (2) read the ZIP content and extract the data we want. In ElectricityLCI, we choose the latter.
This should give you lists of unit group and flow property olca-schema objects. You can then use the
olca_schema.zipio
class to write these objects to a different JSON-LD file.To get the data quality indicator matrices, we redefine the token URL.
We then repeat the process above to get the token for the JSON-LD data from the server.
Again, we use the token to access the JSON-LD ZIP file from the server.
In this case, we are only getting three files:
This should give you lists of DQ systems (there are two) and a list that includes the source for them.
Footnotes
https://www.lcacommons.gov/lca-commons-api-guide ↩
https://www.lcacommons.gov/lca-collaboration/Federal_LCA_Commons/elementary_flow_list/datasets ↩
Beta Was this translation helpful? Give feedback.
All reactions