From 8d54ecec4e857dc1d78659966b9a1cd6ab61ade3 Mon Sep 17 00:00:00 2001 From: awarde96 Date: Wed, 18 Sep 2024 08:49:45 +0000 Subject: [PATCH 1/2] Fix wkt feature --- covjsonkit/encoder/Wkt.py | 56 +++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/covjsonkit/encoder/Wkt.py b/covjsonkit/encoder/Wkt.py index fad88e2..a7300aa 100644 --- a/covjsonkit/encoder/Wkt.py +++ b/covjsonkit/encoder/Wkt.py @@ -1,3 +1,5 @@ +import logging + from .encoder import Encoder @@ -83,14 +85,18 @@ def from_polytope(self, result): coords = {} mars_metadata = {} range_dict = {} - lat = 0 - param = 0 - number = [0] - step = 0 - dates = [0] - levels = [0] + fields = {} + fields["lat"] = 0 + fields["param"] = 0 + fields["number"] = [0] + fields["step"] = 0 + fields["dates"] = [] + fields["levels"] = [0] + + self.walk_tree(result, fields, coords, mars_metadata, range_dict) - self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels) + logging.debug("The values returned from walking tree: %s", range_dict) # noqa: E501 + logging.debug("The coordinates returned from walking tree: %s", coords) # noqa: E501 self.add_reference( { @@ -104,28 +110,32 @@ def from_polytope(self, result): combined_dict = {} - for date in range_dict: + for date in fields["dates"]: if date not in combined_dict: combined_dict[date] = {} - for level in range_dict[date]: - for num in range_dict[date][level]: + for level in fields["levels"]: + for num in fields["number"]: if num not in combined_dict[date]: combined_dict[date][num] = {} - for para in range_dict[date][level][num]: + for para in fields["param"]: if para not in combined_dict[date][num]: combined_dict[date][num][para] = {} - for s, value in range_dict[date][level][num][para].items(): - if s not in combined_dict[date][num][para]: - combined_dict[date][num][para][s] = value - else: - # Cocatenate arrays - combined_dict[date][num][para][s] += value - - levels = [] - for date in range_dict.keys(): - for level in range_dict[date].keys(): - levels.append(level) - break + # for s, value in range_dict[date][level][num][para].items(): + for s in fields["step"]: + key = (date, level, num, para, s) + for k, v in range_dict.items(): + if k == key: + if s not in combined_dict[date][num][para]: + combined_dict[date][num][para][s] = v + else: + # Cocatenate arrays + combined_dict[date][num][para][s] += v + + levels = fields["levels"] + for para in fields["param"]: + self.add_parameter(para) + + logging.debug("The parameters added were: %s", self.parameters) # noqa: E501 for date in coords.keys(): coord = coords[date]["composite"] From c092103f07464fe22e3b34ba83728d971daef510 Mon Sep 17 00:00:00 2001 From: awarde96 Date: Wed, 18 Sep 2024 08:58:50 +0000 Subject: [PATCH 2/2] Update frame and shape file with new walk_tree function --- covjsonkit/encoder/Frame.py | 56 +++++++++++++++++++-------------- covjsonkit/encoder/Shapefile.py | 56 +++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 46 deletions(-) diff --git a/covjsonkit/encoder/Frame.py b/covjsonkit/encoder/Frame.py index d48a857..66607cf 100644 --- a/covjsonkit/encoder/Frame.py +++ b/covjsonkit/encoder/Frame.py @@ -1,3 +1,5 @@ +import logging + from .encoder import Encoder @@ -83,14 +85,18 @@ def from_polytope(self, result): coords = {} mars_metadata = {} range_dict = {} - lat = 0 - param = 0 - number = [0] - step = 0 - dates = [0] - levels = [0] + fields = {} + fields["lat"] = 0 + fields["param"] = 0 + fields["number"] = [0] + fields["step"] = 0 + fields["dates"] = [] + fields["levels"] = [0] + + self.walk_tree(result, fields, coords, mars_metadata, range_dict) - self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels) + logging.debug("The values returned from walking tree: %s", range_dict) # noqa: E501 + logging.debug("The coordinates returned from walking tree: %s", coords) # noqa: E501 self.add_reference( { @@ -104,28 +110,32 @@ def from_polytope(self, result): combined_dict = {} - for date in range_dict: + for date in fields["dates"]: if date not in combined_dict: combined_dict[date] = {} - for level in range_dict[date]: - for num in range_dict[date][level]: + for level in fields["levels"]: + for num in fields["number"]: if num not in combined_dict[date]: combined_dict[date][num] = {} - for para in range_dict[date][level][num]: + for para in fields["param"]: if para not in combined_dict[date][num]: combined_dict[date][num][para] = {} - for s, value in range_dict[date][level][num][para].items(): - if s not in combined_dict[date][num][para]: - combined_dict[date][num][para][s] = value - else: - # Cocatenate arrays - combined_dict[date][num][para][s] += value - - levels = [] - for date in range_dict.keys(): - for level in range_dict[date].keys(): - levels.append(level) - break + # for s, value in range_dict[date][level][num][para].items(): + for s in fields["step"]: + key = (date, level, num, para, s) + for k, v in range_dict.items(): + if k == key: + if s not in combined_dict[date][num][para]: + combined_dict[date][num][para][s] = v + else: + # Cocatenate arrays + combined_dict[date][num][para][s] += v + + levels = fields["levels"] + for para in fields["param"]: + self.add_parameter(para) + + logging.debug("The parameters added were: %s", self.parameters) # noqa: E501 for date in coords.keys(): coord = coords[date]["composite"] diff --git a/covjsonkit/encoder/Shapefile.py b/covjsonkit/encoder/Shapefile.py index d7f7775..7882790 100644 --- a/covjsonkit/encoder/Shapefile.py +++ b/covjsonkit/encoder/Shapefile.py @@ -1,3 +1,5 @@ +import logging + from .encoder import Encoder @@ -83,14 +85,18 @@ def from_polytope(self, result): coords = {} mars_metadata = {} range_dict = {} - lat = 0 - param = 0 - number = [0] - step = 0 - dates = [0] - levels = [0] + fields = {} + fields["lat"] = 0 + fields["param"] = 0 + fields["number"] = [0] + fields["step"] = 0 + fields["dates"] = [] + fields["levels"] = [0] + + self.walk_tree(result, fields, coords, mars_metadata, range_dict) - self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels) + logging.debug("The values returned from walking tree: %s", range_dict) # noqa: E501 + logging.debug("The coordinates returned from walking tree: %s", coords) # noqa: E501 self.add_reference( { @@ -104,28 +110,32 @@ def from_polytope(self, result): combined_dict = {} - for date in range_dict: + for date in fields["dates"]: if date not in combined_dict: combined_dict[date] = {} - for level in range_dict[date]: - for num in range_dict[date][level]: + for level in fields["levels"]: + for num in fields["number"]: if num not in combined_dict[date]: combined_dict[date][num] = {} - for para in range_dict[date][level][num]: + for para in fields["param"]: if para not in combined_dict[date][num]: combined_dict[date][num][para] = {} - for s, value in range_dict[date][level][num][para].items(): - if s not in combined_dict[date][num][para]: - combined_dict[date][num][para][s] = value - else: - # Cocatenate arrays - combined_dict[date][num][para][s] += value - - levels = [] - for date in range_dict.keys(): - for level in range_dict[date].keys(): - levels.append(level) - break + # for s, value in range_dict[date][level][num][para].items(): + for s in fields["step"]: + key = (date, level, num, para, s) + for k, v in range_dict.items(): + if k == key: + if s not in combined_dict[date][num][para]: + combined_dict[date][num][para][s] = v + else: + # Cocatenate arrays + combined_dict[date][num][para][s] += v + + levels = fields["levels"] + for para in fields["param"]: + self.add_parameter(para) + + logging.debug("The parameters added were: %s", self.parameters) # noqa: E501 for date in coords.keys(): coord = coords[date]["composite"]