Skip to content

Commit

Permalink
Merge pull request #44 from ecmwf/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
awarde96 authored Sep 26, 2024
2 parents e951f62 + 36191dd commit 32ce22e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
16 changes: 9 additions & 7 deletions covjsonkit/encoder/BoundingBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
36 changes: 31 additions & 5 deletions covjsonkit/encoder/TimeSeries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from datetime import datetime, timedelta

import pandas as pd
Expand Down Expand Up @@ -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(
{
Expand All @@ -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)

Expand All @@ -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"]:
Expand All @@ -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):
Expand Down
16 changes: 9 additions & 7 deletions covjsonkit/encoder/Wkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion covjsonkit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.22"
__version__ = "0.0.23"

0 comments on commit 32ce22e

Please sign in to comment.