def create_local_evs(self): """Create LDV activities for REMIND regions and relink existing electricity exchanges for BEVs and PHEVs to REMIND-compatible (regional) market groups. """ print("Creating local BEV and PHEV activities") bevs = list(ws.get_many( self.db, ws.either( ws.contains("name", "BEV,"), ws.contains("name", "PHEV")))) self._delete_non_global(bevs) old_supply = ws.get_one( self.db, ws.startswith( "name", "electricity supply for electric vehicles")) for region in self.remind_regions: # create local electricity supply supply = self._create_local_copy(old_supply, region) # replace electricity input for sup in ws.technosphere( supply, ws.equals("product", "electricity, low voltage")): sup.update({ "name": "market group for electricity, low voltage", "location": region }) print("Relinking electricity markets for BEVs in {}".format(region)) for bev in bevs: new_bev = self._create_local_copy(bev, region) # update fuel market oldex = list(ws.technosphere( new_bev, ws.startswith( "name", "electricity supply for electric vehicles"))) # should only be one if len(oldex) != 1: raise ValueError( "Zero or more than one electricity " "markets for fuel production found for {} in {}" .format(new_bev["name"], new_bev["location"])) elif len(oldex) == 1: # reference the new supply oldex[0].update({ "location": region }) self.db.append(new_bev) self.db.append(supply)
def update_pollutant_emissions(self, ds): """ Update pollutant emissions based on GAINS data. :return: """ # Update biosphere exchanges according to GAINS emission values for exc in ws.biosphere( ds, ws.either( *[ws.contains("name", x) for x in self.emissions_map])): iam_emission_label = self.emissions_map[exc["name"]] try: iam_emission = self.iam_data.cement_emissions.loc[dict( region=ds["location"], pollutant=iam_emission_label)].values.item(0) except KeyError: # TODO: fix this. # GAINS does not have a 'World' region, hence we use Europe as a temporary fix iam_emission = self.iam_data.cement_emissions.loc[dict( region=self.geo.iam_to_GAINS_region("World"), pollutant=iam_emission_label)].values.item(0) if exc["amount"] == 0: wurst.rescale_exchange(exc, iam_emission / 1, remove_uncertainty=True) else: wurst.rescale_exchange(exc, iam_emission / exc["amount"]) return ds
def get_suppliers_of_a_region(self, iam_region, ecoinvent_technologies, reference_product, unit="kilogram", look_for_locations_in="ecoinvent"): """ Return a list of datasets which location and name correspond to the region, name and reference product given, respectively. :param unit: unit of the dataset. If not specified, "kilogram" is used. :param look_for_locations_in: whether it should look for a supplier in ecoinvent locations or IAM locations. :param iam_region: an IAM region :type iam_region: str :param ecoinvent_technologies: list of names of ecoinvent dataset :type ecoinvent_technologies: list :param reference_product: reference product :type reference_product: str :return: list of wurst datasets :rtype: list """ if look_for_locations_in == "ecoinvent": return ws.get_many( self.db, *[ ws.either(*[ ws.contains("name", supplier) for supplier in ecoinvent_technologies ]), ws.either(*[ ws.equals("location", loc) for loc in self.geo.iam_to_ecoinvent_location(iam_region) ]), ws.equals("unit", unit), ws.equals("reference product", reference_product), ]) else: return ws.get_many( self.db, *[ ws.either(*[ ws.contains("name", supplier) for supplier in ecoinvent_technologies ]), ws.equals("location", look_for_locations_in), ws.equals("unit", unit), ws.equals("reference product", reference_product), ])
def update_efficiency_of_solar_PV(self): """ Update the efficiency of solar PV modules. We look at how many square meters are needed per kilowatt of installed capacity to obtain the current efficiency. Then we update the surface needed according to the projected efficiency. :return: """ ds = ws.get_many( self.db, *[ ws.contains("name", "photovoltaic"), ws.either( ws.contains("name", "installation"), ws.contains("name", "construction"), ), ws.doesnt_contain_any("name", ["market", "factory"]), ws.equals("unit", "unit"), ]) for d in ds: power = float(re.findall("\d+", d["name"])[0]) for exc in ws.technosphere( d, *[ ws.contains("name", "photovoltaic"), ws.equals("unit", "square meter"), ]): surface = float(exc["amount"]) max_power = surface # in kW, since we assume a constant 1,000W/m^2 current_eff = power / max_power new_eff = get_efficiency_ratio_solar_PV(self.year, power).values # We only update the efficiency if it is higher than the current one. if new_eff > current_eff: exc["amount"] *= float(current_eff / new_eff) d["parameters"] = {"efficiency": new_eff} return self.db
def adjust_recycled_steel_share(self, dict_act): """ Adjust the supply shares of primary and secondary steel, based on REMIND data. :param dict_act: dictionary with REMIND region as keys and datasets as values. :type dict_act: dict :return: same dictionary, with modified exchanges :rtype: dict """ dict_act = self.remove_exchanges(dict_act, ['steel production']) for d, act in dict_act.items(): remind_region = d total_production_volume = self.steel_data.sel(region=remind_region, variables='Production|Industry|Steel') primary_share = (self.steel_data.sel(region=remind_region, variables='Production|Industry|Steel|Primary') / total_production_volume).values secondary_share = 1 - primary_share ds = ws.get_one(self.db, ws.equals('reference product', act['reference product']), ws.contains('name', 'steel production'), ws.contains('name', 'converter'), ws.contains('location', 'RoW')) act['exchanges'].append( { "uncertainty type": 0, "loc": 1, "amount": primary_share, "type": "technosphere", "production volume": 1, "product": ds['reference product'], "name": ds['name'], "unit": ds['unit'], "location": remind_region, } ) ds = ws.get_one(self.db, ws.equals('reference product', act['reference product']), ws.contains('name', 'steel production'), ws.contains('name', 'electric'), ws.contains('location', 'RoW')) act['exchanges'].append( { "uncertainty type": 0, "loc": 1, "amount": secondary_share, "type": "technosphere", "production volume": 1, "product": ds['reference product'], "name": ds['name'], "unit": ds['unit'], "location": remind_region, } ) return dict_act
def add_negative_CO2_flows_for_biomass_CCS(self): """ Rescale the amount of all exchanges of carbon dioxide, non-fossil by a factor -9 (.9/-.1), to account for sequestered CO2. All CO2 capture and storage in the Carma datasets is assumed to be 90% efficient. Thus, we can simply find out what the new CO2 emission is and then we know how much gets stored in the ground. It's very important that we ONLY do this for biomass CCS plants, as only they will have negative emissions! Modifies in place (does not return anything). """ for ds in ws.get_many(self.db, ws.contains('name', 'storage'), ws.equals('database', 'Carma CCS')): for exc in ws.biosphere(ds, ws.equals('name', 'Carbon dioxide, non-fossil')): wurst.rescale_exchange(exc, (0.9 / -0.1), remove_uncertainty=True)
def create_local_fcevs(self): """Create LDV activities for REMIND regions and relink existing electricity exchanges for FCEVs to REMIND-compatible (regional) market groups. """ print("Creating local FCEV activities") fcevs = list(ws.get_many( self.db, ws.contains("name", "FCEV,"))) self._delete_non_global(fcevs) old_supply = ws.get_one( self.db, ws.startswith( "name", "fuel supply for hydrogen vehicles")) for region in self.remind_regions: print("Relinking hydrogen markets for FCEVs in {}".format(region)) # create local hydrogen supply supply = self._create_local_copy(old_supply, region) # remove explicit electricity input elmark = next(ws.technosphere(supply, ws.startswith( "name", "electricity market for fuel preparation"))) elmark["amount"] = 0 wurst.delete_zero_amount_exchanges([supply]) # find hydrogen supply nearby h2sups = ws.technosphere( supply, ws.startswith("product", "Hydrogen")) for h2sup in h2sups: prod = self._find_local_supplier(region, h2sup["name"]) h2sup["location"] = prod["location"] h2sup["name"] = prod["name"] # create local fcev for fcev in fcevs: # create local fcevs local_fcev = self._create_local_copy(fcev, region) # link correct market fuel_ex = next(ws.technosphere( local_fcev, ws.startswith("name", "fuel supply for hydrogen vehicles"))) fuel_ex["location"] = region self.db.append(local_fcev) self.db.append(supply)
def create_local_icevs(self): """ Use REMIND fuel markets to update the mix of bio-, syn- and fossil liquids in gasoline and diesel. """ print("Creating local ICEV activities") icevs = list(ws.get_many( self.db, ws.either( ws.contains("name", "ICEV-"), ws.contains("name", "HEV-")) )) old_suppliers = { fuel: ws.get_one( self.db, ws.startswith( "name", "fuel supply for {} vehicles".format(fuel))) for fuel in ["diesel", "gasoline"]} new_producers = { "diesel": { # biodiesel is only from cooking oil from RER, # as this is not the focus for now # to be improved! "Biomass": ws.get_one( self.db, ws.equals("name", "Biodiesel from cooking oil")) }, "gasoline": { # only ethanol from European wheat straw as biofuel "Biomass": ws.get_one( self.db, ws.equals("name", "Ethanol from wheat straw pellets"), ws.equals("location", "RER")) } } data = self.rmd.get_remind_fuel_mix_for_ldvs() for region in self.remind_regions: # two regions for gasoline and diesel production if region == "EUR": new_producers["gasoline"]["Fossil"] = ws.get_one( self.db, ws.equals("name", "market for petrol, low-sulfur"), ws.equals("location", "Europe without Switzerland")) new_producers["diesel"]["Fossil"] = ws.get_one( self.db, ws.equals("name", "market group for diesel"), ws.equals("location", "RER")) else: new_producers["gasoline"]["Fossil"] = ws.get_one( self.db, ws.equals("name", "market for petrol, low-sulfur"), ws.equals("location", "RoW")) new_producers["diesel"]["Fossil"] = ws.get_one( self.db, ws.equals("name", "market group for diesel"), ws.equals("location", "GLO")) # local syndiesel new_producers["diesel"]["Hydrogen"] = self._find_local_supplier( region, "Diesel production, synthetic, Fischer Tropsch process") new_producers["gasoline"]["Hydrogen"] = self._find_local_supplier( region, "Gasoline production, synthetic, from methanol") print("Relinking fuel markets for ICEVs in {}".format(region)) for ftype in new_producers: new_supp = self._create_local_copy( old_suppliers[ftype], region) new_supp["exchanges"] = [{ "amount": data.loc[region, suptype].values.item(), "name": new_producers[ftype][suptype]["name"], "location": new_producers[ftype][suptype]["location"], "unit": "kilogram", "type": "technosphere", "reference product": new_producers[ftype][suptype]["reference product"], "product": new_producers[ftype][suptype]["reference product"] } for suptype in new_producers[ftype]] new_supp["exchanges"].append({ "amount": 1, "name": new_supp["name"], "location": region, "unit": "kilogram", "type": "production", "reference product": "fuel", "product": "fuel" }) self.db.append(new_supp) shortcuts = { "diesel": "EV-d", "gasoline": "EV-p" } for ftype in shortcuts: # diesel cars cars = list(ws.get_many( icevs, ws.contains("name", shortcuts[ftype]))) for car in cars: # some local activities might already exist local_dcar = self._get_local_act_or_copy( cars, car, region) # replace diesel supplier fuel_ex = next(ws.technosphere( local_dcar, ws.startswith( "name", "fuel supply for {} vehicles".format(ftype)))) fuel_ex["location"] = region