Skip to content

Commit

Permalink
Merge pull request #41 from ecmwf/feature/fix_features
Browse files Browse the repository at this point in the history
Feature/fix features
  • Loading branch information
awarde96 authored Sep 18, 2024
2 parents a30a13b + c092103 commit f06dbff
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 69 deletions.
56 changes: 33 additions & 23 deletions covjsonkit/encoder/Frame.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from .encoder import Encoder


Expand Down Expand Up @@ -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(
{
Expand All @@ -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"]
Expand Down
56 changes: 33 additions & 23 deletions covjsonkit/encoder/Shapefile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from .encoder import Encoder


Expand Down Expand Up @@ -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(
{
Expand All @@ -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"]
Expand Down
56 changes: 33 additions & 23 deletions covjsonkit/encoder/Wkt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from .encoder import Encoder


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

0 comments on commit f06dbff

Please sign in to comment.