create_context#
- deeptrack.backend.units.create_context(xpixel: float | None = None, ypixel: float | None = None, zpixel: float | None = None, xscale: int | None = None, yscale: int | None = None, zscale: int | None = None) Context#
Create a pint context for unit conversions between pixel and simulation units.
This function returns a context mapping pixel units (xpixel, ypixel, zpixel) and simulation pixel units (simulation_xpixel, etc.) to corresponding metric units (meters). If xpixel, ypixel, or zpixel is not provided, the active values from the unit registry are used. Likewise, if xscale, yscale, or zscale is provided, it multiplies the current scale to yield the new simulation scale.
Parameters#
- xpixel, ypixel, zpixelfloat or None, optional
Size of a pixel in meters along x, y, and z axes. If None, the currently active values are used.
- xscale, yscale, zscaleint or None, optional
Upscaling factors for internal simulation. If None, the current scaling is used.
Returns#
- Context
A pint.Context object that defines pixel-to-meter mappings.
Examples#
>>> from deeptrack.backend.units import create_context
Create a context where one optical pixel is 1 µm and the y-direction is upscaled by a factor of 2 in the simulation: >>> ctx = create_context( … xpixel=1e-6, … ypixel=1e-6, … zpixel=1e-6, … yscale=2, … )
Load the unit registry: >>> from deeptrack import units_registry as u
Use the context to convert 1 simulation y-pixel to meters: >>> with u.context(ctx): … print((1 * u.simulation_ypixel).to(“meter”)) 5e-07 meter
Outside the context: >>> print((1 * u.simulation_ypixel).to(“meter”)) 1e-06 meter