|
8 | 8 | import logging |
9 | 9 | import argparse |
10 | 10 | import warnings |
11 | | -import matplotlib.pyplot as plt |
12 | 11 |
|
13 | | -from cybench.util.geo import get_shapes_from_polygons, get_area_km2 |
14 | | -from cybench.config import PATH_DATA_DIR |
| 12 | +from cybench.util.geo import get_shapes_from_polygons |
| 13 | +from cybench.config import PATH_DATA_DIR, REPO_DIR |
15 | 14 |
|
16 | 15 | warnings.filterwarnings("ignore") |
17 | 16 |
|
| 17 | +def init_worker_logging(): |
| 18 | + """Disable file logging in worker processes to avoid RotatingFileHandler races.""" |
| 19 | + root = logging.getLogger() |
| 20 | + # remove all handlers inherited from the parent |
| 21 | + for h in root.handlers[:]: |
| 22 | + root.removeHandler(h) |
| 23 | + # optional: silence workers completely |
| 24 | + root.addHandler(logging.NullHandler()) |
18 | 25 |
|
19 | 26 | log = logging.getLogger(__name__) |
20 | 27 |
|
|
23 | 30 | # Directory paths |
24 | 31 | ################## |
25 | 32 |
|
26 | | -AGML_ROOT = r"/path_to_raw_data" |
27 | | -DATA_DIR = os.path.join(AGML_ROOT, "predictors") |
28 | | -OUTPUT_DIR = os.path.join(AGML_ROOT, "python-output") |
| 33 | +DATA_DIR = r"/path_to_raw_data/predictors" |
| 34 | +OUTPUT_DIR = r"/path_to_raw_data/python-output" |
29 | 35 |
|
30 | 36 | ##################### |
31 | 37 | # Start and end years |
@@ -847,7 +853,7 @@ def process_file( |
847 | 853 | else: |
848 | 854 | crop_mask_file = "crop_mask_generic_asap.tif" |
849 | 855 |
|
850 | | - crop_mask_path = os.path.join(AGML_ROOT, "crop_masks", crop_mask_file) |
| 856 | + crop_mask_path = os.path.join(REPO_DIR, "data_preparation", "global_crop_AFIs_ESA_WC", crop_mask_file) |
851 | 857 |
|
852 | 858 | basename = os.path.basename(indicator_file) |
853 | 859 | fname, ext = os.path.splitext(basename) |
@@ -952,7 +958,7 @@ def process_indicators(crop, region, sel_indicators): |
952 | 958 | continue |
953 | 959 | start_time = time.time() |
954 | 960 | files = sorted([os.path.join(indicator_dir, f) for f in files]) |
955 | | - with mp.Pool(processes=None) as pool: |
| 961 | + with mp.Pool(processes=None, initializer=init_worker_logging) as pool: |
956 | 962 | # NOTE: multiprocessing using a target function with multiple arguments. |
957 | 963 | # Based on the answer to |
958 | 964 | # https://stackoverflow.com/questions/5442910/how-to-use-multiprocessing-pool-map-with-multiple-arguments |
|
0 commit comments