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

Scale pixels to SI units #366

Open
sfmig opened this issue Dec 13, 2024 · 1 comment
Open

Scale pixels to SI units #366

sfmig opened this issue Dec 13, 2024 · 1 comment
Labels
enhancement New optional feature

Comments

@sfmig
Copy link
Contributor

sfmig commented Dec 13, 2024

Is your feature request related to a problem? Please describe.
We would like to make it possible for users to express the arrays expressed in pixels in a dataset (or per array?) to SI units.

Additional context
Somewhat linked to this issue on unit-aware xarrays

@niksirbi
Copy link
Member

One way to achieve this in a more general way would be via the envisioned transforms module.

An example follows:

from movement.transforms import scale

# Convert pixels to cm (assume 10 pix/cm)
# Passing a float/int as a factor results in uniform scaling across all `space` dims
ds.position = scale(ds.position, factor=0.1, space_unit="cm")  # store space_unit in position.attributes

The advantage of this approach is that it would also allow arbitrary scaling factors, not necessarily to metric units.

# Normalise coordinates to a 0-1 range covering a ROI named "arena"
arena = {"xmin": 10, "xmax": 690, "ymin": 20, "ymax": 580}
arena["xsize"] = arena["xmax"] - arena["xmin"]
arena["ysize"] = arena["ymax"] - arena["ymin"]
 # move origin to arena corner
ds.position = translate(ds.position, to=[arena.xmin, arena.ymin])
# scale so that arena extents are in [0, 1] range
ds.position = scale(ds.position, factor=[1/xsize, 1/ysize])

If factor is a scalar, we could interpret it as uniform scale (all 2 or 3 spatial dimensions)
If factor is a list/array-like we could interpret it as 1 factor per x, y, (z) dimensions (length of factor should match number of spatial dimensions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New optional feature
Projects
Status: 🤔 Triage
Development

No branches or pull requests

2 participants