Skip to content

Measurement

A Measurement is a reference to a measurement stored on the server. A reference is a GUID without any additional data. Get the data with Measurement.get_data. This returns an xarray.Dataset (single run) or xarray.DataTree (stacked runs). The getters only work while the measurement reference is attached to a live session. You can re-attach with session.get_measurement(ref) before calling Measurement.get_data.

A MeasurementJob is a handle to a measurement in progress. It consists of a reference (GUID) and is attached to a Session. Starting a measurement returns the job immediately. You can await the job to block until it finishes and receive a Measurement.

job = await claim.start_measurement(method=method)  #(1)!
measurement = await job  #(2)!
data = await measurement.get_data()
  1. returns immediately
  2. blocks until it finishes

The current job status is reported via is_finished. Jobs can be interrupted with abort, pause, and resume.

The measurement data API is still work in progress.

Classes:

pypalmsens.lablink.Measurement

Measurement(guid: str, *, session: Session | None = None)

A reference to a measurement.

Holds the GUID of a stored measurement and an optional session link.

Methods:

  • delete –

    Delete this measurement from the server.

  • get_data –

    Retrieve recorded data for this measurement.

  • get_info –

    Get metadata for this measurement (not yet implemented).

Attributes:

  • guid (str) –

    The unique identifier of the measurement.

Source code in src/pypalmsens/lablink/_measurement.py
32
33
34
def __init__(self, guid: str, *, session: Session | None = None):
    self._guid: str = guid
    self._session: Session | None = session

guid property

guid: str

The unique identifier of the measurement.

Returns:

  • str –

    Measurement GUID.

delete async

delete() -> None

Delete this measurement from the server.

Raises:

Source code in src/pypalmsens/lablink/_measurement.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
async def delete(self) -> None:
    """
    Delete this measurement from the server.

    Raises
    ------
    ConnectionError
        If this reference is detached from a session.
    """
    if self._session is None:
        raise ConnectionError(
            f'This {type(self).__name__} is detached. Reattach it via '
            '`ref = session.get_measurement(ref)` before fetching data.'
        )
    return await self._session._http.delete(f'/Measurements/{self.guid}/Delete')

get_data async

get_data() -> Dataset | DataTree

Retrieve recorded data for this measurement.

Returns:

  • Dataset or DataTree –

    Measurement data. A Dataset is returned for a single measurement, a DataTree when the measurement contains repeated/stacked runs.

Raises:

Source code in src/pypalmsens/lablink/_measurement.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
async def get_data(self) -> xr.Dataset | xr.DataTree:
    """
    Retrieve recorded data for this measurement.

    Returns
    -------
    xarray.Dataset or xarray.DataTree
        Measurement data. A `Dataset` is returned for a single
        measurement, a `DataTree` when the measurement contains
        repeated/stacked runs.

    Raises
    ------
    ConnectionError
        If this reference is detached from a session.
    """
    if self._session is None:
        raise ConnectionError(
            f'This {type(self).__name__} is detached. Reattach it via '
            'ref = session.get_measurement(ref) before fetching data.'
        )
    return await self._session.get_measurement(self)

get_info async

get_info() -> None

Get metadata for this measurement (not yet implemented).

Raises:

  • ConnectionError –

    If no session is attached. Reattach via session.get_measurement(ref) before calling.

Source code in src/pypalmsens/lablink/_measurement.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
async def get_info(self) -> None:
    """
    Get metadata for this measurement (not yet implemented).

    Raises
    ------
    ConnectionError
        If no session is attached. Reattach via
        `session.get_measurement(ref)` before calling.
    """
    if self._session is None:
        raise ConnectionError(
            f'This {type(self).__name__} is detached. Reattach it via '
            'ref = session.get_measurement(ref) before fetching data.'
        )
    raise NotImplementedError

pypalmsens.lablink.MeasurementJob

MeasurementJob(guid: str, *, claim: InstrumentClaim)

A job representing an ongoing measurement.

Holds the GUID of a measurement in progress and its instrument claim.

Methods:

  • abort –

    Abort the measurement.

  • pause –

    Pause the measurement.

  • result –

    Wait for the measurement to finish and return a reference.

  • resume –

    Resume the measurement.

Attributes:

  • claim (InstrumentClaim) –

    The instrument claim associated with the measurement job.

  • guid (str) –

    The unique identifier of the measurement being performed.

  • is_finished (bool) –

    True if the measurement has finished.

  • serial_number (str) –

    Serial number of the instrument carrying out the measurement.

Source code in src/pypalmsens/lablink/_measurement.py
115
116
117
118
def __init__(self, guid: str, *, claim: InstrumentClaim) -> None:
    self._guid: str = guid
    self._claim: InstrumentClaim = claim
    self._is_finished: bool = False

claim property

The instrument claim associated with the measurement job.

guid property

guid: str

The unique identifier of the measurement being performed.

Returns:

  • str –

    Measurement GUID.

is_finished property

is_finished: bool

True if the measurement has finished.

serial_number property

serial_number: str

Serial number of the instrument carrying out the measurement.

abort async

abort() -> None

Abort the measurement.

Source code in src/pypalmsens/lablink/_measurement.py
216
217
218
async def abort(self) -> None:
    """Abort the measurement."""
    return await self._claim.abort_measurement()

pause async

pause() -> None

Pause the measurement.

Source code in src/pypalmsens/lablink/_measurement.py
220
221
222
async def pause(self) -> None:
    """Pause the measurement."""
    return await self._claim.pause_measurement()

result async

result(*, initial: float = 1.0, cap: float = 30.0, factor: float = 2.0, jitter: float = 0.15, timeout: float | None = None) -> Measurement

Wait for the measurement to finish and return a reference.

Polls claim.get_active_measurement() with exponential backoff so short jobs are caught quickly while long ones stay cheap.

Parameters:

  • initial

    (float, default: 1.0 ) –

    Delay before the first retry, in seconds. Defaults to 1.0.

  • cap

    (float, default: 30.0 ) –

    Maximum delay between polls, in seconds. Defaults to 30.0.

  • factor

    (float, default: 2.0 ) –

    Multiplier applied to the delay after each poll. Defaults to 2.0.

  • jitter

    (float, default: 0.15 ) –

    Fractional randomness added to each delay (e.g., 0.15 for +/-15%). Defaults to 0.15.

  • timeout

    (float or None, default: None ) –

    Total seconds to wait before giving up; None waits indefinitely. Defaults to None.

Returns:

  • MeasurementRef –

    A reference to the finished measurement.

Raises:

  • TimeoutError –

    If timeout is set and the measurement does not finish in time.

Source code in src/pypalmsens/lablink/_measurement.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
async def result(
    self,
    *,
    initial: float = 1.0,
    cap: float = 30.0,
    factor: float = 2.0,
    jitter: float = 0.15,
    timeout: float | None = None,
) -> Measurement:
    """
    Wait for the measurement to finish and return a reference.

    Polls `claim.get_active_measurement()` with exponential backoff so
    short jobs are caught quickly while long ones stay cheap.

    Parameters
    ----------
    initial : float, optional
        Delay before the first retry, in seconds. Defaults to 1.0.
    cap : float, optional
        Maximum delay between polls, in seconds. Defaults to 30.0.
    factor : float, optional
        Multiplier applied to the delay after each poll. Defaults to 2.0.
    jitter : float, optional
        Fractional randomness added to each delay (e.g., 0.15 for +/-15%).
        Defaults to 0.15.
    timeout : float or None, optional
        Total seconds to wait before giving up; None waits indefinitely.
        Defaults to None.

    Returns
    -------
    MeasurementRef
        A reference to the finished measurement.

    Raises
    ------
    TimeoutError
        If `timeout` is set and the measurement does not finish in time.
    """
    loop = asyncio.get_running_loop()
    deadline = loop.time() + timeout if timeout else None
    delay = initial

    while True:
        await asyncio.sleep(delay * (1 + random.uniform(-jitter, jitter)))
        delay = min(delay * factor, cap)

        try:
            active = await self._claim.get_active_measurement()
        except NoActiveMeasurementError:
            break

        if not active or active.guid != self.guid:
            break

        if deadline and loop.time() >= deadline:
            raise TimeoutError(f'measurement {self.guid} did not finish in {timeout}s')

    self._is_finished = True

    return Measurement(self.guid, session=self._claim._session)

resume async

resume() -> None

Resume the measurement.

Source code in src/pypalmsens/lablink/_measurement.py
224
225
226
async def resume(self) -> None:
    """Resume the measurement."""
    return await self._claim.resume_measurement()