From 4602daf9bf4aaac935b2c6e16d97b81b5d4fb583 Mon Sep 17 00:00:00 2001 From: awarde96 Date: Thu, 21 Nov 2024 13:47:15 +0000 Subject: [PATCH 1/4] Path now allows inflation on levelist --- covjsonkit/decoder/Path.py | 3 +++ covjsonkit/encoder/Path.py | 34 ++++++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/covjsonkit/decoder/Path.py b/covjsonkit/decoder/Path.py index 4169d3e..561684b 100644 --- a/covjsonkit/decoder/Path.py +++ b/covjsonkit/decoder/Path.py @@ -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 = {} @@ -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), ), ) diff --git a/covjsonkit/encoder/Path.py b/covjsonkit/encoder/Path.py index 01387b1..9a651ba 100644 --- a/covjsonkit/encoder/Path.py +++ b/covjsonkit/encoder/Path.py @@ -109,6 +109,19 @@ def from_polytope(self, result): } ) + 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"]): + 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"]: @@ -122,7 +135,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: @@ -146,23 +159,6 @@ def from_polytope(self, result): 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 = {} @@ -182,6 +178,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 From 938081fef0690a9ad15d794ac9875e6ea38ea048 Mon Sep 17 00:00:00 2001 From: awarde96 Date: Thu, 21 Nov 2024 13:56:28 +0000 Subject: [PATCH 2/4] Fix 4d path --- covjsonkit/encoder/Path.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/covjsonkit/encoder/Path.py b/covjsonkit/encoder/Path.py index 9a651ba..9af1572 100644 --- a/covjsonkit/encoder/Path.py +++ b/covjsonkit/encoder/Path.py @@ -109,17 +109,22 @@ 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"]): - 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 + 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 = {} @@ -151,7 +156,6 @@ 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"]: From dd57fcdd56254ddedfd7d124e08823e28dcb99c4 Mon Sep 17 00:00:00 2001 From: awarde96 Date: Thu, 21 Nov 2024 14:01:54 +0000 Subject: [PATCH 3/4] Bump version --- covjsonkit/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/covjsonkit/version.py b/covjsonkit/version.py index 4d04613..3dc1f76 100644 --- a/covjsonkit/version.py +++ b/covjsonkit/version.py @@ -1 +1 @@ -__version__ = "0.0.28" +__version__ = "0.1.0" From 46270c22ef085f33bb36e0388299fa10db4a40af Mon Sep 17 00:00:00 2001 From: awarde96 Date: Mon, 25 Nov 2024 10:37:08 +0000 Subject: [PATCH 4/4] Remove unneeded print statements --- covjsonkit/decoder/Path.py | 3 --- covjsonkit/encoder/Path.py | 12 ------------ 2 files changed, 15 deletions(-) diff --git a/covjsonkit/decoder/Path.py b/covjsonkit/decoder/Path.py index 561684b..2ce3de9 100644 --- a/covjsonkit/decoder/Path.py +++ b/covjsonkit/decoder/Path.py @@ -117,7 +117,4 @@ def to_xarray(self): for mars_metadata in self.mars_metadata[0]: ds.attrs[mars_metadata] = self.mars_metadata[0][mars_metadata] - # Add date attribute - # ds.attrs["date"] = self.get_coordinates()["t"]["values"][0] - return ds diff --git a/covjsonkit/encoder/Path.py b/covjsonkit/encoder/Path.py index 9af1572..16d9d36 100644 --- a/covjsonkit/encoder/Path.py +++ b/covjsonkit/encoder/Path.py @@ -109,10 +109,6 @@ def from_polytope(self, result): } ) - print(fields) - print(coords) - print(range_dict) - for date in coords.keys(): coord = coords[date]["composite"] coords[date]["composite"] = [] @@ -166,21 +162,13 @@ def from_polytope(self, result): for date in combined_dict.keys(): for num in combined_dict[date].keys(): val_dict = {} - # for step in combined_dict[date][num][self.parameters[0]].keys(): - # val_dict[step] = {} for para in combined_dict[date][num].keys(): if para not in val_dict: val_dict[para] = [] for step in combined_dict[date][num][para].keys(): val_dict[para].extend(combined_dict[date][num][para][step]) - # for step in val_dict.keys(): mm = mars_metadata.copy() mm["number"] = num - # mm["step"] = step - # temp = [] - # for coord in coords[date]["composite"]: - # temp.append([step] + coord) - # coords[date]["composite"] = temp mm["Forecast date"] = date if "levelist" in mm: del mm["levelist"]