From b6f1bf085eea5306b06adc3502deccbed6501bcb Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 24 Mar 2024 07:27:10 +0000 Subject: [PATCH] Black reformating --- pathways/data_validation.py | 13 +++++++------ pathways/lca.py | 19 ++++++++++-------- pathways/pathways.py | 39 ++++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/pathways/data_validation.py b/pathways/data_validation.py index cfcf355..16f108a 100644 --- a/pathways/data_validation.py +++ b/pathways/data_validation.py @@ -10,11 +10,13 @@ import yaml from datapackage import DataPackageException, validate -logging.basicConfig(level=logging.DEBUG, - filename='pathways.log', # Log file to save the entries - filemode='a', # Append to the log file if it exists, 'w' to overwrite - format='%(asctime)s - %(levelname)s - %(module)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') +logging.basicConfig( + level=logging.DEBUG, + filename="pathways.log", # Log file to save the entries + filemode="a", # Append to the log file if it exists, 'w' to overwrite + format="%(asctime)s - %(levelname)s - %(module)s - %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", +) def validate_datapackage(datapackage: datapackage.DataPackage): @@ -125,4 +127,3 @@ def validate_mapping(resource: datapackage.Resource, dataframe: pd.DataFrame): "All values for `scenario variable` must be unique. " f"Duplicate values: {set([x for x in scenario_variables if scenario_variables.count(x) > 1])}" ) - diff --git a/pathways/lca.py b/pathways/lca.py index bf01a54..350f3cd 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -1,7 +1,7 @@ import csv +import logging from pathlib import Path from typing import Any, Dict, List, Tuple -import logging import bw_processing as bwp import numpy as np @@ -22,12 +22,13 @@ print("Solver: scikits.umfpack") -logging.basicConfig(level=logging.DEBUG, - filename='pathways.log', # Log file to save the entries - filemode='a', # Append to the log file if it exists, 'w' to overwrite - format='%(asctime)s - %(levelname)s - %(module)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') - +logging.basicConfig( + level=logging.DEBUG, + filename="pathways.log", # Log file to save the entries + filemode="a", # Append to the log file if it exists, 'w' to overwrite + format="%(asctime)s - %(levelname)s - %(module)s - %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", +) def read_indices_csv(file_path: Path) -> Dict[Tuple[str, str, str, str], str]: @@ -168,7 +169,9 @@ def fill_characterization_factors_matrices( l = sorted(l, key=lambda x: (x[0], x[1])) for x in l: method, flow, f, value = x - logging.info(f"LCIA method: {method}, Flow: {flow}, Index: {f}, Value: {value}") + logging.info( + f"LCIA method: {method}, Flow: {flow}, Index: {f}, Value: {value}" + ) return matrix diff --git a/pathways/pathways.py b/pathways/pathways.py index 9aa7348..91ba85f 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -5,12 +5,12 @@ """ import csv +import logging import uuid import warnings from collections import defaultdict from multiprocessing import Pool, cpu_count from typing import Any, Dict, List, Optional, Tuple -import logging import bw2calc as bc import numpy as np @@ -268,7 +268,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int rev_A_index, lca, characterization_matrix, - debug + debug, ) = data variables_demand = {} @@ -357,9 +357,11 @@ def _calculate_year(args): print(f"------ Calculating LCA results for {year}...") if debug: - logging.info(f"############################### " - f"{model}, {scenario}, {year} " - f"###############################") + logging.info( + f"############################### " + f"{model}, {scenario}, {year} " + f"###############################" + ) geo = Geomap(model=model) @@ -382,7 +384,9 @@ def _calculate_year(args): # A = remove_double_counting(A, vars_info) # check unclassified activities - missing_classifications = check_unclassified_activities(technosphere_indices, classifications) + missing_classifications = check_unclassified_activities( + technosphere_indices, classifications + ) if missing_classifications: if debug: @@ -453,7 +457,9 @@ def _calculate_year(args): ) if debug: - logging.info(f"Characterization matrix created. Shape: {characterization_matrix.shape}") + logging.info( + f"Characterization matrix created. Shape: {characterization_matrix.shape}" + ) bar = pyprind.ProgBar(len(regions)) for region in regions: @@ -481,7 +487,7 @@ def _calculate_year(args): reverse_technosphere_index, lca, characterization_matrix, - debug + debug, ) ) @@ -520,15 +526,16 @@ def __init__(self, datapackage, debug=False): clean_cache_directory() if self.debug: - logging.basicConfig(level=logging.DEBUG, - filename='pathways.log', # Log file to save the entries - filemode='a', # Append to the log file if it exists, 'w' to overwrite - format='%(asctime)s - %(levelname)s - %(module)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') + logging.basicConfig( + level=logging.DEBUG, + filename="pathways.log", # Log file to save the entries + filemode="a", # Append to the log file if it exists, 'w' to overwrite + format="%(asctime)s - %(levelname)s - %(module)s - %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + ) logging.info("#" * 600) logging.info(f"Pathways initialized with datapackage: {datapackage}") - def read_datapackage(self) -> DataPackage: """Read the datapackage.json file. @@ -802,7 +809,7 @@ def calculate( self.classifications, self.scenarios, self.reverse_classifications, - self.debug + self.debug, ) for year in years ] @@ -835,7 +842,7 @@ def calculate( self.classifications, self.scenarios, self.reverse_classifications, - self.debug + self.debug, ) ) for year in years