Skip to content

Client

The Mef3Client provides a high-level, Pythonic interface to the MEF3 gRPC server. For a task-oriented walkthrough see the Python client guide.

mef3io_server.client

Mef3Client

Mef3Client(address='localhost:50052', client_id=None)

Client for interacting with the MEF3 gRPC server.

Every data call is oriented purely in channels and time: open a file, inspect its metadata (channel names, per-channel sampling rates and per-channel start/end timestamps via :meth:get_file_info), then read any channels over any [start_uutc, end_uutc) window with :meth:get_signal_range.

Example::

client = Mef3Client("localhost:50052")
client.open_file("/path/to/file.mefd")
info = client.get_file_info("/path/to/file.mefd")
data = client.get_signal_range("/path/to/file.mefd",
                               info["channel_names"][:4],
                               info["start_uutc"],
                               info["start_uutc"] + 60_000_000)
client.shutdown()

Sessions. Each client sends a client_id with every call (a random one unless you choose it). The server keeps one session per client and file: opening the same file again reuses it, and closing it does not affect other clients reading the same file. The id is a name tag, not authentication: a web app serving several users can pass one per user.

Initialize the Mef3Client and connect to the gRPC server.

Parameters:

Name Type Description Default
address str

Address of the gRPC server (default: "localhost:50052").

'localhost:50052'
client_id str or None

This client's id, up to 128 printable characters. None (default) makes a random one, so each client object has its own sessions.

None

open_file

open_file(file_path, cache_fs=None, allow_mixed_rates=False)

Open a MEF3 file on the server.

Parameters:

Name Type Description Default
file_path str

Path to the MEF3 file.

required
cache_fs float or None

Serve (and cache and prefetch) this client's reads of the file at this rate, Hz: order-preserving min-max of the original, so spikes are kept. None: each channel's own rate. Opening again with other settings replaces them.

None
allow_mixed_rates bool

With cache_fs: serve a channel recorded below cache_fs at its own rate. Without it, such a channel makes the open fail (file_opened False, error_message names the channels).

False

Returns: dict: File info including file_path, file_opened, number_of_channels, channel_names, channel_served_sampling_rates (the rate each channel is served at) and cache_fs.

close_file

close_file(file_path)

Close a MEF3 file on the server.

Parameters:

Name Type Description Default
file_path str

Path to the MEF3 file.

required

Returns: dict: Contains file_path and file_opened status.

get_file_info

get_file_info(file_path)

Get metadata for an open MEF3 file.

Parameters:

Name Type Description Default
file_path str

Path to the MEF3 file.

required

Returns: dict: File metadata -- channel_names, channel_sampling_rates, channel_start_uutc and channel_end_uutc (parallel per-channel lists), plus the global start_uutc/end_uutc/duration_s.

get_signal_range

get_signal_range(file_path, channels, start_uutc, end_uutc, n_points=None)

Read arbitrary channels over an arbitrary [start_uutc, end_uutc) window.

This is the server's data-access method -- every read is oriented in channels and time. The server serves the data from its per-channel tile cache (reading only what is missing, decoding missing tiles in parallel across worker processes) and prefetches neighboring windows for smooth forward/backward paging.

Parameters:

Name Type Description Default
file_path str

Path to the MEF3 file.

required
channels list[str] or None

Channels to read. None/empty means all channels in the file.

required
start_uutc int

Inclusive window start in microseconds (uUTC).

required
end_uutc int

Exclusive window end in microseconds (uUTC).

required
n_points int or None

Return exactly this many points per channel, e.g. one per pixel of the view. Each is a real sample (its bucket's minimum or maximum, chosen by MinMaxLTTB to keep the line's shape; each channel's overall max and min are always included), evenly spaced: fs is then n_points / window. A window with fewer samples comes back unchanged (never upsampled). None: the session's rate.

None

Returns:

Type Description
dict

A dict with keys array (np.ndarray of shape (n_channels, n_samples), float32), channel_names, fs, start_uutc, end_uutc, dtype, shape and error_message.

list_open_files

list_open_files()

List all currently open MEF3 files on the server.

Returns:

Type Description
list

List of file paths for open files.

shutdown

shutdown()

Close the gRPC channel and clean up resources.