From f23d50412a7050c270d20fe4301590539f1d56cf Mon Sep 17 00:00:00 2001 From: abidwael <103003638+abidwael@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:38:53 -0700 Subject: [PATCH] Reducing verbosity when importing Reducing verbosity when calling load_regions_with_bounding_boxes --- experiment_impact_tracker/emissions/constants.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/experiment_impact_tracker/emissions/constants.py b/experiment_impact_tracker/emissions/constants.py index 2030418..9f86129 100644 --- a/experiment_impact_tracker/emissions/constants.py +++ b/experiment_impact_tracker/emissions/constants.py @@ -6,7 +6,7 @@ from shapely.geometry import shape -def read_terrible_json(path): +def read_terrible_json(path, verbose=1): """Reads a slightly malformed json file where each line is a different json dict. @@ -19,7 +19,7 @@ def read_terrible_json(path): with open(path, "rt") as f: lines = [] test_read_lines = [x for x in f.readlines()] - for x in ProgIter(test_read_lines): + for x in ProgIter(test_read_lines, verbose=verbose): if x: x = x.replace("/", "\/") x = json.loads(x) @@ -51,20 +51,21 @@ def _load_zone_names(): return x -def load_regions_with_bounding_boxes(): +def load_regions_with_bounding_boxes(verbose=0): """Loads bounding boxes as shapely objects. Returns: list: list of shapely objects containing regional geometries """ - print( - "loading region bounding boxes for computing carbon emissions region, this may take a moment..." - ) + if verbose != 0: + print( + "loading region bounding boxes for computing carbon emissions region, this may take a moment..." + ) dir_path = os.path.dirname(os.path.realpath(__file__)) all_geoms = [] # with open('data/zone_geometries.json') as f: - all_geoms = read_terrible_json(os.path.join(dir_path, "data/zonegeometries.json")) + all_geoms = read_terrible_json(os.path.join(dir_path, "data/zonegeometries.json"), verbose=0) for i, geom in enumerate(all_geoms): all_geoms[i]["geometry"] = shape(geom["geometry"])