Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Nov 10, 2023
1 parent 2e0fdf6 commit d72d15b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pathways/data_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def validate_mapping(
# Check that all values for `scenario variable` are unique
scenario_variables = [item["scenario variable"] for item in mapping.values()]
if len(scenario_variables) != len(set(scenario_variables)):
print("All values for `scenario variable` must be unique. "
print(
"All values for `scenario variable` must be unique. "
f"Duplicate values: {set([x for x in scenario_variables if scenario_variables.count(x) > 1])}"
)

Expand Down
4 changes: 3 additions & 1 deletion pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def get_lca_matrices(
:rtype: Tuple[sparse.csr_matrix, sparse.csr_matrix, Dict, Dict]
"""
dirpath = Path(datapackage).parent / "inventories" / model.lower() / scenario / str(year)
dirpath = (
Path(datapackage).parent / "inventories" / model.lower() / scenario / str(year)
)

# check that files exist
if not dirpath.exists():
Expand Down
18 changes: 11 additions & 7 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def check_unclassified_activities(A_index, classifications):
with open("missing_classifications.csv", "a") as f:
writer = csv.writer(f)
writer.writerows(missing_classifications)


def csv_to_dict(filename):
output_dict = {}

Expand Down Expand Up @@ -204,7 +206,7 @@ def process_region(data: Tuple) -> Union[None, Dict[str, Any]]:
lcia_matrix,
reverse_classifications,
lca_results_coords,
flows
flows,
) = data

# Generate a list of activity indices for each activity category
Expand All @@ -227,7 +229,6 @@ def process_region(data: Tuple) -> Union[None, Dict[str, Any]]:
else:
target = np.zeros((len(act_categories), len(list(vars_idx)), len(B_index)))


for v, variable in enumerate(variables):
idx, dataset = vars_idx[variable]["idx"], vars_idx[variable]["dataset"]

Expand Down Expand Up @@ -323,7 +324,7 @@ class Pathways:

def __init__(self, datapackage):
self.datapackage = datapackage
#self.data = validate_datapackage(self.read_datapackage())
# self.data = validate_datapackage(self.read_datapackage())
self.data = self.read_datapackage()
self.mapping = self.get_mapping()
self.mapping.update(self.get_final_energy_mapping())
Expand Down Expand Up @@ -469,7 +470,8 @@ def get_scenarios(self):
units = {}
for variable in data.coords["variables"].values:
units[variable] = scenario_data[
scenario_data["variables"] == self.mapping[variable]["scenario variable"]
scenario_data["variables"]
== self.mapping[variable]["scenario variable"]
].iloc[0]["unit"]

data.attrs["units"] = units
Expand Down Expand Up @@ -565,7 +567,9 @@ def calculate(

except FileNotFoundError:
# If LCA matrices can't be loaded, skip to the next iteration
print("LCA matrices not found for the given model, scenario, and year.")
print(
"LCA matrices not found for the given model, scenario, and year."
)
continue

# Fetch indices
Expand All @@ -590,7 +594,7 @@ def calculate(
scenarios,
self.classifications,
self.mapping,
flows
flows,
)

# Fill characterization factor matrix for the given methods
Expand Down Expand Up @@ -623,7 +627,7 @@ def calculate(
self.lcia_matrix if characterization else None,
self.reverse_classifications,
self.lca_results.coords,
flows
flows,
)
for region in regions
]
Expand Down
4 changes: 1 addition & 3 deletions pathways/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def _get_activity_indices(
)
break # Exit the loop as the index was found
if idx is None:
print(
f"Activity {activity} not found in the technosphere matrix."
)
print(f"Activity {activity} not found in the technosphere matrix.")

return indices # Return the list of indices

Expand Down

0 comments on commit d72d15b

Please sign in to comment.