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

Path now allows inflation on levelist #55

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions covjsonkit/decoder/Path.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def to_xarray(self):
# Get coordinates
x = []
y = []
z = []
t = []
for coord in self.get_coordinates()["composite"]["values"]:
x.append(float(coord[1]))
y.append(float(coord[2]))
z.append(float(coord[3]))
t.append(coord[0])

values = {}
Expand Down Expand Up @@ -108,6 +110,7 @@ def to_xarray(self):
points=(["points"], list(range(0, len(x)))),
x=(["points"], x),
y=(["points"], y),
z=(["points"], z),
t=(["points"], t),
),
)
Expand Down
40 changes: 21 additions & 19 deletions covjsonkit/encoder/Path.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ def from_polytope(self, result):
}
)

print(fields)
print(coords)
print(range_dict)

for date in coords.keys():
coord = coords[date]["composite"]
coords[date]["composite"] = []
start = 0
for level in set(fields["l"]):
for s in set(fields["s"]):
if (date, level, fields["number"][0], fields["param"][0], s) in range_dict:
cor_len = len(range_dict[(date, level, fields["number"][0], fields["param"][0], s)])
end = start + cor_len
for cor in coord[int(start) : int(end)]:
coords[date]["composite"].append([s, cor[0], cor[1], level])
start = end
logging.debug("The coordinates returned from walking tree: %s", coords) # noqa: E501

combined_dict = {}

for date in fields["dates"]:
Expand All @@ -122,7 +140,7 @@ def from_polytope(self, result):
if para not in combined_dict[date][num]:
combined_dict[date][num][para] = {}
# for s, value in range_dict[date][level][num][para].items():
for s in fields["s"]:
for s in set(fields["s"]):
key = (date, level, num, para, s)
# for k, v in range_dict.items():
# if k == key:
Expand All @@ -138,31 +156,13 @@ def from_polytope(self, result):

logging.debug("The values returned from combined dicts: %s", combined_dict) # noqa: E501

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)

logging.debug("The parameters added were: %s", self.parameters) # noqa: E501

for date in coords.keys():
coord = coords[date]["composite"]
coords[date]["composite"] = []
for level in levels:
start = 0
for i, s in enumerate(fields["s"]):
end = start + len(coord) / len(fields["s"])
for cor in coord[int(start) : int(end)]:
if len(fields["l"]) == 1:
coords[date]["composite"].append([s, cor[0], cor[1], fields["l"][0]])
elif len(fields["l"]) == 0:
coords[date]["composite"].append([s, cor[0], cor[1], level])
else:
coords[date]["composite"].append([s, cor[0], cor[1], fields["l"][i]])
start = end
logging.debug("The coordinates returned from walking tree: %s", coords) # noqa: E501

for date in combined_dict.keys():
for num in combined_dict[date].keys():
val_dict = {}
Expand All @@ -182,6 +182,8 @@ def from_polytope(self, result):
# temp.append([step] + coord)
# coords[date]["composite"] = temp
mm["Forecast date"] = date
if "levelist" in mm:
del mm["levelist"]
self.add_coverage(mm, coords[date], val_dict)

return self.covjson
2 changes: 1 addition & 1 deletion covjsonkit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.28"
__version__ = "0.1.0"
Loading