Skip to content

Commit a7e3591

Browse files
cbyrohlclaude
andauthored
Fix unbound particle masking in haloquantity lookup and support 2D halo quantities (#233)
The unbound particle check in get_haloquantity_daskwrap compared against -1, but get_hidx marks unbound particles with index_unbound (int64 max by default). This caused unbound particles to be incorrectly looked up. Also adds support for 2D halo quantities (e.g. positions/velocities) via drop_axis/new_axis. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d398ccd commit a7e3591

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎src/scida/customs/arepo/dataset.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,12 @@ def get_hidx_daskwrap(gidx, halocelloffsets, index_unbound=None):
11091109
)
11101110

11111111

1112-
def get_haloquantity_daskwrap(gidx, halocelloffsets, valarr):
1113-
hidx = get_hidx_daskwrap(gidx, halocelloffsets)
1112+
def get_haloquantity_daskwrap(
1113+
gidx, halocelloffsets, valarr, index_unbound=9223372036854775807
1114+
):
1115+
hidx = get_hidx_daskwrap(gidx, halocelloffsets, index_unbound=index_unbound)
11141116
dmax = np.iinfo(hidx.dtype).max
1115-
mask = ~((hidx == -1) | (hidx == dmax))
1117+
mask = ~((hidx == index_unbound) | (hidx == dmax))
11161118
result = -1.0 * np.ones(hidx.shape, dtype=valarr.dtype)
11171119
result[mask] = valarr[hidx[mask]]
11181120
return result
@@ -1134,13 +1136,18 @@ def compute_haloquantity(gidx, halocelloffsets, hvals, *args):
11341136
units = None
11351137
if hasattr(hvals, "units"):
11361138
units = hvals.units
1139+
hvals = hvals.magnitude
1140+
kw = dict()
1141+
if len(hvals.shape) == 2:
1142+
kw = dict(drop_axis=0, new_axis=0)
11371143
res = map_blocks(
11381144
get_haloquantity_daskwrap,
11391145
gidx,
11401146
halocelloffsets,
11411147
hvals,
1142-
meta=np.array((), dtype=hvals.dtype),
1148+
dtype=hvals.dtype,
11431149
output_units=units,
1150+
**kw,
11441151
)
11451152
return res
11461153

0 commit comments

Comments
 (0)