diff --git a/covjsonkit/encoder/BoundingBox.py b/covjsonkit/encoder/BoundingBox.py index d7efe27..786b558 100644 --- a/covjsonkit/encoder/BoundingBox.py +++ b/covjsonkit/encoder/BoundingBox.py @@ -123,15 +123,17 @@ def from_polytope(self, result): # 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 + # 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] = range_dict[key] + else: + # Cocatenate arrays + combined_dict[date][num][para][s] += range_dict[key] levels = fields["levels"] + if fields["param"] == 0: + raise ValueError("No parameters were returned, date requested may be out of range") for para in fields["param"]: self.add_parameter(para) diff --git a/covjsonkit/encoder/TimeSeries.py b/covjsonkit/encoder/TimeSeries.py index 1d62a1a..48fb9d5 100644 --- a/covjsonkit/encoder/TimeSeries.py +++ b/covjsonkit/encoder/TimeSeries.py @@ -1,4 +1,5 @@ import logging +import time from datetime import datetime, timedelta import pandas as pd @@ -97,7 +98,16 @@ def from_polytope(self, result): fields["dates"] = [] fields["levels"] = [0] + start = time.time() + logging.debug("Tree walking starts at: %s", start) # noqa: E501 self.walk_tree(result, fields, coords, mars_metadata, range_dict) + end = time.time() + delta = end - start + logging.debug("Tree walking ends at: %s", end) # noqa: E501 + logging.debug("Tree walking takes: %s", delta) # noqa: E501 + + start = time.time() + logging.debug("Coords creation: %s", start) # noqa: E501 self.add_reference( { @@ -112,6 +122,8 @@ def from_polytope(self, result): coordinates = {} levels = fields["levels"] + if fields["param"] == 0: + raise ValueError("No parameters were returned, date requested may be out of range") for para in fields["param"]: self.add_parameter(para) @@ -138,8 +150,16 @@ def from_polytope(self, result): break break - logging.debug("The values returned from walking tree: %s", range_dict) # noqa: E501 - logging.debug("The coordinates returned from walking tree: %s", coordinates) # noqa: E501 + end = time.time() + delta = end - start + logging.debug("Coords creation: %s", end) # noqa: E501 + logging.debug("Coords creation: %s", delta) # noqa: E501 + + # logging.debug("The values returned from walking tree: %s", range_dict) # noqa: E501 + # logging.debug("The coordinates returned from walking tree: %s", coordinates) # noqa: E501 + + start = time.time() + logging.debug("Coverage creation: %s", start) # noqa: E501 for date in fields["dates"]: for level in fields["levels"]: @@ -149,15 +169,21 @@ def from_polytope(self, result): val_dict[para] = [] for step in fields["step"]: key = (date, level, num, para, step) - for k, v in range_dict.items(): - if k == key: - val_dict[para].append(v[0]) + # for k, v in range_dict.items(): + # if k == key: + # val_dict[para].append(v[0]) + val_dict[para].append(range_dict[key][0]) mm = mars_metadata.copy() mm["number"] = num mm["Forecast date"] = date del mm["step"] self.add_coverage(mm, coordinates[date], val_dict) + end = time.time() + delta = end - start + logging.debug("Coverage creation: %s", end) # noqa: E501 + logging.debug("Coverage creation: %s", delta) # noqa: E501 + return self.covjson def from_polytope_step(self, result): diff --git a/covjsonkit/encoder/Wkt.py b/covjsonkit/encoder/Wkt.py index a7300aa..f02d87a 100644 --- a/covjsonkit/encoder/Wkt.py +++ b/covjsonkit/encoder/Wkt.py @@ -123,15 +123,17 @@ def from_polytope(self, result): # 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 + # 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] = range_dict[key] + else: + # Cocatenate arrays + combined_dict[date][num][para][s] += range_dict[key] levels = fields["levels"] + if fields["param"] == 0: + raise ValueError("No parameters were returned, date requested may be out of range") for para in fields["param"]: self.add_parameter(para) diff --git a/covjsonkit/version.py b/covjsonkit/version.py index 479dad0..40b07ef 100644 --- a/covjsonkit/version.py +++ b/covjsonkit/version.py @@ -1 +1 @@ -__version__ = "0.0.22" +__version__ = "0.0.23"