diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6bd013..9d9f2260 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 3.4.0 Point Probe Value Format for Enumerated Legends + +### Features +* Adds the label next to the value for enumerated legends in the point prober. + * Before: "value": 1.0 + * After: "value": "1 (Sand)" + ## 3.3.1 ### Hotfix diff --git a/podpac/core/test/test_utils.py b/podpac/core/test/test_utils.py index 481d3151..ed9f7e2f 100644 --- a/podpac/core/test/test_utils.py +++ b/podpac/core/test/test_utils.py @@ -707,3 +707,44 @@ def test_composited_prober_nested(self): } out = probe_node(a, lat=1, lon=1, nested=True) assert out == expected + + def test_prober_with_enumerated_legends(self): + enumeration_style = podpac.style.Style( + name="composited", + units="my_units", + enumeration_legend={0: "dirt", 1: "sand"}, + enumeration_colors={0: (0, 0, 0), 1: (0.5, 0.5, 0.5)}, + ) + one = podpac.data.Array(source=np.ones((3, 3), int), coordinates=self.coords, style=enumeration_style) + zero = podpac.data.Array(source=np.zeros((3, 3), int), coordinates=self.coords, style=enumeration_style) + a = podpac.compositor.OrderedCompositor(sources=[one, zero], style=enumeration_style) + + expected = { + "name": "composited", + "value": "1 (sand) my_units", + "active": True, + "node_id": a.hash, + "params": {}, + "inputs": { + "inputs": [ + { + "name": "composited", + "value": "1 (sand) my_units", + "active": True, + "node_id": one.hash, + "params": {}, + "inputs": {}, + }, + { + "name": "composited", + "value": "0 (dirt) my_units", + "active": False, + "node_id": zero.hash, + "params": {}, + "inputs": {}, + }, + ] + }, + } + out = probe_node(a, lat=1, lon=1, nested=True, add_enumeration_labels=True) + assert out == expected diff --git a/podpac/core/utils.py b/podpac/core/utils.py index 4871e092..ae9e6181 100644 --- a/podpac/core/utils.py +++ b/podpac/core/utils.py @@ -492,7 +492,7 @@ def resolve_bbox_order(bbox, crs, size): return {"lat": [lat_start, lat_stop, size[0]], "lon": [lon_start, lon_stop, size[1]]} -def probe_node(node, lat=None, lon=None, time=None, alt=None, crs=None, nested=False): +def probe_node(node, lat=None, lon=None, time=None, alt=None, crs=None, nested=False, add_enumeration_labels=True): """Evaluates every part of a node / pipeline at a point and records which nodes are actively being used. @@ -513,6 +513,9 @@ def probe_node(node, lat=None, lon=None, time=None, alt=None, crs=None, nested=F nested : bool, optional Default is False. If True, will return a nested version of the output dictionary isntead + add_enumeration_labels : bool, optional + Default is True. If True, the "value" will be replaced by str(value) + "({})".format(node.style.enumeration_legend[int(value)]) + if node.style.enumeration_legend is specified by the style. Returns dict @@ -563,11 +566,17 @@ def get_entry(key, out, definition): entry["inputs"] = {} return entry + def format_value(value, style, add_enumeration_labels): + if not add_enumeration_labels or style.enumeration_legend is None: + return value + return str(int(value)) + " ({})".format(style.enumeration_legend[int(value)]) + c = [(v, d) for v, d in zip([lat, lon, time, alt], ["lat", "lon", "time", "alt"]) if v is not None] coords = podpac.Coordinates([[v[0]] for v in c], [[d[1]] for d in c], crs=crs) v = float(node.eval(coords)) definition = node.definition out = OrderedDict() + raw_values = {} # Need this to keep track of actual value for evaluating active nodes in compositors for item in definition: if item == "podpac_version": continue @@ -582,18 +591,19 @@ def get_entry(key, out, definition): active = True out[item] = { "active": active, - "value": value, + "value": format_value(value, n.style, add_enumeration_labels), "units": n.style.units, "inputs": inputs, "name": n.style.name if n.style.name else item, "node_hash": n.hash, } + raw_values[item] = value # Fix sources for Compositors if isinstance(n, podpac.compositor.OrderedCompositor): searching_for_active = True for inp in inputs: out[inp]["active"] = False - if out[inp]["value"] == out[item]["value"] and np.isfinite(out[inp]["value"]) and searching_for_active: + if raw_values[inp] == raw_values[item] and np.isfinite(raw_values[inp]) and searching_for_active: out[inp]["active"] = True searching_for_active = False diff --git a/podpac/version.py b/podpac/version.py index 59e8ed3a..d94e5a53 100644 --- a/podpac/version.py +++ b/podpac/version.py @@ -16,8 +16,8 @@ ## UPDATE VERSION HERE ############## MAJOR = 3 -MINOR = 3 -HOTFIX = 1 +MINOR = 4 +HOTFIX = 0 ##############