Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducing verbosity when importing #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions experiment_impact_tracker/emissions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
Expand Down Expand Up @@ -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"])
Expand Down