Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Mar 24, 2024
2 parents 5031781 + b6f1bf0 commit 964ca27
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
13 changes: 7 additions & 6 deletions pathways/data_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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])}"
)

19 changes: 11 additions & 8 deletions pathways/lca.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]:
Expand Down Expand Up @@ -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

Expand Down
39 changes: 23 additions & 16 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -481,7 +487,7 @@ def _calculate_year(args):
reverse_technosphere_index,
lca,
characterization_matrix,
debug
debug,
)
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -802,7 +809,7 @@ def calculate(
self.classifications,
self.scenarios,
self.reverse_classifications,
self.debug
self.debug,
)
for year in years
]
Expand Down Expand Up @@ -835,7 +842,7 @@ def calculate(
self.classifications,
self.scenarios,
self.reverse_classifications,
self.debug
self.debug,
)
)
for year in years
Expand Down

0 comments on commit 964ca27

Please sign in to comment.