Skip to content

Commit

Permalink
Merge branch 'release/3.4.0' into main-3.X
Browse files Browse the repository at this point in the history
  • Loading branch information
mpu-creare committed Mar 1, 2024
2 parents 69fa5ee + b6e613c commit bcae0ff
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 41 additions & 0 deletions podpac/core/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 13 additions & 3 deletions podpac/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions podpac/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
## UPDATE VERSION HERE
##############
MAJOR = 3
MINOR = 3
HOTFIX = 1
MINOR = 4
HOTFIX = 0
##############


Expand Down

0 comments on commit bcae0ff

Please sign in to comment.