Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 5, 2023
1 parent 1807e33 commit 837d1c3
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 49 deletions.
6 changes: 3 additions & 3 deletions premise/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _update_cement(scenario, version, system_model, modified_datasets, cache):
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)

if scenario["iam data"].cement_markets is not None:
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None
cache: dict = None,
):
super().__init__(
database,
Expand All @@ -87,7 +87,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
cache,
)
self.version = version

Expand Down
4 changes: 2 additions & 2 deletions premise/direct_air_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _update_dac(scenario, version, system_model, modified_datasets, cache=None):
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)

if scenario["iam data"].dac_markets is not None:
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
cache,
)
self.database = database
self.iam_data = iam_data
Expand Down
12 changes: 6 additions & 6 deletions premise/ecoinvent_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,43 +420,43 @@ def _update_all(
vehicle_type=vehicle_type,
version=version,
system_model=system_model,
modified_datasets=modified_datasets
modified_datasets=modified_datasets,
)
scenario, modified_datasets, cache = _update_electricity(
scenario=scenario,
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
use_absolute_efficiency=use_absolute_efficiency,
cache=cache
cache=cache,
)
scenario, modified_datasets, cache = _update_dac(
scenario=scenario,
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)
scenario, modified_datasets, cache = _update_cement(
scenario=scenario,
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)
scenario, modified_datasets, cache = _update_steel(
scenario=scenario,
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)
scenario, modified_datasets, cache = _update_fuels(
scenario=scenario,
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)
scenario, modified_datasets = _update_emissions(
scenario, version, system_model, gains_scenario, modified_datasets
Expand Down
9 changes: 7 additions & 2 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ def get_production_weighted_losses(


def _update_electricity(
scenario, version, system_model, modified_datasets, use_absolute_efficiency, cache=None
scenario,
version,
system_model,
modified_datasets,
use_absolute_efficiency,
cache=None,
):
electricity = Electricity(
database=scenario["database"],
Expand Down Expand Up @@ -248,7 +253,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
cache,
)
mapping = InventorySet(self.database)
self.powerplant_map = mapping.generate_powerplant_map()
Expand Down
6 changes: 3 additions & 3 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _update_fuels(scenario, version, system_model, modified_datasets, cache):
version=version,
system_model=system_model,
modified_datasets=modified_datasets,
cache=cache
cache=cache,
)

if any(
Expand Down Expand Up @@ -321,7 +321,7 @@ def __init__(
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None
cache: dict = None,
):
super().__init__(
database,
Expand All @@ -332,7 +332,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
cache,
)
# ecoinvent version
self.version = version
Expand Down
52 changes: 32 additions & 20 deletions premise/metals.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ def get_geo_mapping(self, df: pd.DataFrame, new_locations: dict) -> dict:
return mapping

def create_region_specific_markets(self, df: pd.DataFrame) -> List[dict]:

new_exchanges = []

# iterate through unique pair of process - reference product in df:
# for each pair, create a new mining activity

for (name, ref_prod), group in df.groupby(["Process", "Reference product"]):

new_locations = {c: self.convert_long_to_short_country_name(c) for c in group["Country"].unique()}
new_locations = {
c: self.convert_long_to_short_country_name(c)
for c in group["Country"].unique()
}
# remove None values
new_locations = {k: v for k, v in new_locations.items() if v}
# fetch shares for each location in df
Expand All @@ -455,20 +456,24 @@ def create_region_specific_markets(self, df: pd.DataFrame) -> List[dict]:
dataset["reference product"],
dataset["location"],
dataset["unit"],
) for dataset in datasets.values()
)
for dataset in datasets.values()
]
)

new_exchanges.extend([
{
"name": dataset["name"],
"product": dataset["reference product"],
"location": dataset["location"],
"unit": dataset["unit"],
"amount": shares[(name, ref_prod, dataset["location"])],
"type": "technosphere",
} for dataset in datasets.values()
])
new_exchanges.extend(
[
{
"name": dataset["name"],
"product": dataset["reference product"],
"location": dataset["location"],
"unit": dataset["unit"],
"amount": shares[(name, ref_prod, dataset["location"])],
"type": "technosphere",
}
for dataset in datasets.values()
]
)

return new_exchanges

Expand All @@ -489,7 +494,7 @@ def create_market(self, metal, df):
ds["unit"],
)
)
#self.database.remove(ds)
# self.database.remove(ds)

dataset = {
"name": f"market for {metal[0].lower() + metal[1:]}",
Expand Down Expand Up @@ -555,11 +560,17 @@ def create_metal_markets(self):
for metal in dataframe_parent["Metal"].unique():
df_metal = dataframe_parent.loc[dataframe["Metal"] == metal]

for (name, ref_prod), group in df_metal.groupby(["Process", "Reference product"]):

new_locations = {c: self.convert_long_to_short_country_name(c) for c in group["Country"].unique()}
for (name, ref_prod), group in df_metal.groupby(
["Process", "Reference product"]
):
new_locations = {
c: self.convert_long_to_short_country_name(c)
for c in group["Country"].unique()
}
# remove None
new_locations = {k: v for k, v in new_locations.items() if v is not None}
new_locations = {
k: v for k, v in new_locations.items() if v is not None
}

geography_mapping = self.get_geo_mapping(group, new_locations)

Expand All @@ -580,7 +591,8 @@ def create_metal_markets(self):
dataset["reference product"],
dataset["location"],
dataset["unit"],
) for dataset in datasets.values()
)
for dataset in datasets.values()
]
)

Expand Down
4 changes: 2 additions & 2 deletions premise/steel.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
version: str,
system_model: str,
modified_datasets: dict,
cache: dict = None
cache: dict = None,
) -> None:
super().__init__(
database,
Expand All @@ -72,7 +72,7 @@ def __init__(
version,
system_model,
modified_datasets,
cache
cache,
)
self.version = version

Expand Down
7 changes: 2 additions & 5 deletions premise/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,7 @@ def fetch_proxies(
*filters,
)
except ws.NoResults:
print(
f"No dataset found for: {name, ref_prod, d_iam_to_eco[region]}."
)
print(f"No dataset found for: {name, ref_prod, d_iam_to_eco[region]}.")
continue
except ws.MultipleResults as err:
print(
Expand Down Expand Up @@ -689,8 +687,7 @@ def fetch_proxies(
ds
for ds in self.database
if not (
ds["name"] == ds_name
and ds["reference product"] == ds_ref_prod
ds["name"] == ds_name and ds["reference product"] == ds_ref_prod
)
]

Expand Down
12 changes: 6 additions & 6 deletions premise/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@


def _update_vehicles(
scenario,
vehicle_type,
version,
system_model,
modified_datasets,
cache=None,
scenario,
vehicle_type,
version,
system_model,
modified_datasets,
cache=None,
):
trspt = Transport(
database=scenario["database"],
Expand Down

0 comments on commit 837d1c3

Please sign in to comment.