Giter Site home page Giter Site logo

Comments (6)

bl-young avatar bl-young commented on July 18, 2024 1

stewi.getInventory('eGRID', year, stewiformat='flowbyfacility') will return a dataframe that includes emissions and Electricity output as a flow.

Note also that stewi.getInventoryFacilities('eGRID', year) includes the fuel type by facility.

My guess is some combination of these generated the files originally but I do not know.

from electricitylci.

dt-woods avatar dt-woods commented on July 18, 2024

https://github.com/USEPA/ElectricityLCI/blob/master/electricitylci/data/egrid_subregion_generation_by_fuelcategory_reference_2016.csv

from electricitylci.

dt-woods avatar dt-woods commented on July 18, 2024

Note that it does not appear that StEWI has the facility generation data from eGRID. Tried the various formats with "getInventory," but failed to find 'Electricity' data.

Found it here:

from electricitylci.

dt-woods avatar dt-woods commented on July 18, 2024

Example code:

import os

import pandas as pd

from stewi import getInventoryFacilities 
from stewi import getInventory 

def make_egrid_subregion_ref(year):
    """Generate the 'egrid_subregion_generation_inventory_reference' CSV data
    file for a given year (if it does not already exist).

    Parameters
    ----------
    year : ing
        Data year.
    """
    # Define the output file, which should be in data directory of package.
    ref_name = "egrid_subregion_generation_by_fuelcategory_reference_%s.csv" % year
    ref_path = os.path.join(data_dir, ref_name)

    if os.path.exists(ref_path):
        logging.info(
            "eGRID subregion generation inventory %s reference exists" % year)
    else:
        logging.info(
            "Creating eGRID subregion generation inventory "
            "%s reference CSV" % year)

        # Pull the inventory data from stewi.
        a = stewi.getInventory("eGRID", year)

        # Pull facility meta data from stewi.
        meta_cols = [
            'FacilityID',
            'eGRID subregion acronym',
            'Plant primary coal/oil/gas/ other fossil fuel category'
        ]
        b = stewi.getInventoryFacilities("eGRID", 2018)[meta_cols]

        # Merge two data frames together to get inventory + facility metadata.
        c = pd.merge(
            left=a.query("FlowName == 'Electricity'"),
            right=b,
            on="FacilityID",
        )

        # Group by and sum by FacilityID and FuelCategory to get total
        # electricity generation. Update column names to match existing
        # CSV files in the repo.
        c = c.groupby(
            by=[
                'eGRID subregion acronym',
                'Plant primary coal/oil/gas/ other fossil fuel category']
        )['FlowAmount'].agg('sum').reset_index()
        c = c.rename(columns={
                'eGRID subregion acronym': 'Subregion',
                'Plant primary coal/oil/gas/ other fossil fuel category': 'FuelCategory',
                'FlowAmount': 'Electricity'
        })
        # Convert Electricity from MJ to MWh; and order
        c['Electricity'] /= 3600.0
        c = c.sort_values(by=['FuelCategory', 'Subregion'])
        c.to_csv(ref_path, index=False)

from electricitylci.

dt-woods avatar dt-woods commented on July 18, 2024

^^^ The method above will be added to egrid_facilities.py to create the reference CSV when called in the global space of egrid_energy.py right before the file is accessed to avoid FileNotFound Error.

from electricitylci.

dt-woods avatar dt-woods commented on July 18, 2024

NOTE: I found no reference to either "egrid_subregion_totals_reference_2016.csv" or "egrid_subregion_totals_reference_2014.csv" so I omitted their creation.

from electricitylci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.