コード例 #1
0
def emissions_comparison(process_kwh, locations, year):
    # TODO: Disambiguation of states such as Georgia, US and Georgia
    intl_data = utils.get_data("data/json/energy-mix-intl_" + year + ".json")
    us_data = utils.get_data("data/json/us-emissions_" + year + ".json")
    emissions = []  # list of tuples w/ format (location, emission)

    for location in locations:
        if locate.in_US(location):
            emission = convert.lbs_to_kgs(us_data[location] *
                                          convert.to_MWh(process_kwh))
            emissions.append((location, emission))
        else:
            c = intl_data[location]
            total, breakdown = c['total'], [c['coal'], c['petroleum'], \
            c['naturalGas'], c['lowCarbon']]
            if isinstance(total, float) and float(total) > 0:
                breakdown = list(map(lambda x: 100 * x / total, breakdown))
                coal, petroleum, natural_gas, low_carbon = breakdown
                breakdown = [
                    convert.coal_to_carbon(process_kwh * coal / 100),
                    convert.petroleum_to_carbon(process_kwh * petroleum / 100),
                    convert.natural_gas_to_carbon(process_kwh * natural_gas /
                                                  100), 0
                ]
                emission = sum(breakdown)
                emissions.append((location, emission))

    if emissions != []:
        utils.log('Emissions Comparison', emissions)
    return emissions
コード例 #2
0
def old_emissions_comparison(process_kwh, year, default_location,
                             printToScreen):
    # Calculates emissions in different locations

    intl_data = utils.get_data("data/json/energy-mix-intl_" + year + ".json")
    global_emissions, europe_emissions, us_emissions = [], [], []
    # Handling international
    for country in intl_data:
        c = intl_data[country]
        total, breakdown = c['total'], [c['coal'], c['petroleum'], \
        c['naturalGas'], c['lowCarbon']]
        if isinstance(total, float) and float(total) > 0:
            breakdown = list(map(lambda x: 100 * x / total, breakdown))
            coal, petroleum, natural_gas, low_carbon = breakdown
            breakdown = [
                convert.coal_to_carbon(process_kwh * coal / 100),
                convert.petroleum_to_carbon(process_kwh * petroleum / 100),
                convert.natural_gas_to_carbon(process_kwh * natural_gas / 100),
                0
            ]
            emission = sum(breakdown)
            if locate.in_Europe(country):
                europe_emissions.append((country, emission))
            else:
                global_emissions.append((country, emission))

    global_emissions.sort(key=lambda x: x[1])
    europe_emissions.sort(key=lambda x: x[1])

    # Handling US
    us_data = utils.get_data("data/json/us-emissions_" + year + ".json")
    for state in us_data:
        if ((state != "United States") and state != "_units"):
            if us_data[state] != "lbs/MWh":
                emission = convert.lbs_to_kgs(us_data[state] *
                                              convert.to_MWh(process_kwh))
                us_emissions.append((state, emission))
    us_emissions.sort(key=lambda x: x[1])

    max_global, max_europe, max_us = global_emissions[len(global_emissions)-1], \
        europe_emissions[len(europe_emissions)-1], us_emissions[len(us_emissions)-1]
    median_global, median_europe, median_us = global_emissions[len(global_emissions)//2], \
        europe_emissions[len(europe_emissions)//2], us_emissions[len(us_emissions)//2]
    min_global, min_europe, min_us = global_emissions[0], europe_emissions[
        0], us_emissions[0]
    if default_location and printToScreen:
        utils.log('Emissions Comparison default', max_global, median_global, min_global, max_europe, \
            median_europe, min_europe, max_us, median_us, min_us)
    default_emissions = [max_global, median_global, min_global, max_europe, \
        median_europe, min_europe, max_us, median_us, min_us]
    return default_emissions
コード例 #3
0
def energy_mix(location, location_of_default):
    """ Gets the energy mix information for a specific location

        Parameters:
            location (str): user's location
            location_of_default (str): Specifies which average to use if
            	location cannot be determined

        Returns:
            breakdown (list): percentages of each energy type
    """
    if location == "Unknown":
        if location_of_default == "USAverage":
            location = "United States"
        elif location_of_default == "EuropeAverage":
            location = "Europe"
        else:
            location = "World"

    if locate.in_US(location):
        # Default to U.S. average for unknown location

        data = utils.get_data("data/json/energy-mix-us.json")
        s = data[location]['mix']  # get state
        coal, oil, gas = s['coal'], s['oil'], s['gas']
        nuclear, hydro, biomass, wind, solar, geo, = \
        s['nuclear'], s['hydro'], s['biomass'], s['wind'], \
        s['solar'], s['geothermal']

        low_carbon = sum([nuclear, hydro, biomass, wind, solar, geo])
        breakdown = [coal, oil, gas, low_carbon]

        return breakdown  # list of % of each

    else:
        data = utils.get_data('data/json/energy-mix-intl.json')
        c = data[location]  # get country
        total, breakdown =  c['total'], [c['coal'], c['petroleum'], \
        c['naturalGas'], c['lowCarbon']]

        # Get percentages
        breakdown = list(map(lambda x: 100 * x / total, breakdown))

        return breakdown  # list of % of each
コード例 #4
0
def emissions(process_kwh, breakdown, location, year):
    """ Calculates the CO2 emitted by the program based on the location

        Parameters:
            process_kwh (int): kWhs used by the process
            breakdown (list): energy mix corresponding to user's location
            location (str): location of user

        Returns:
            emission (float): kilograms of CO2 emitted
            state_emission (float): lbs CO2 per MWh; 0 if international location

    """

    if process_kwh < 0:
        raise OSError(
            "Process wattage lower than baseline wattage. Do not run other processes"
            " during the evaluation, or try evaluating a more resource-intensive process."
        )

    utils.log("Energy Data", breakdown, location)
    state_emission = 0

    # Case 1: Unknown location, default to US data
    # Case 2: United States location
    if locate.in_US(location):
        if location == "Unknown":
            location = "United States"
        # US Emissions data is in lbs/Mwh
        data = utils.get_data("data/json/us-emissions_" + year + ".json")
        state_emission = data[location]
        emission = convert.lbs_to_kgs(state_emission *
                                      convert.to_MWh(process_kwh))

    # Case 3: International location
    else:
        # Breaking down energy mix
        coal, petroleum, natural_gas, low_carbon = breakdown
        breakdown = [
            convert.coal_to_carbon(process_kwh * coal / 100),
            convert.petroleum_to_carbon(process_kwh * petroleum / 100),
            convert.natural_gas_to_carbon(process_kwh * natural_gas / 100), 0
        ]
        emission = sum(breakdown)

    utils.log("Emissions", emission)
    return (emission, state_emission)