Skope NYOX SDK. Contains data reader for skope-fx session files and protocol definitions to directly connect to the NYOX controller
Project description
NYOX SDK for Python
A Python SDK for reading Skope NYOX session files and communicating with NYOX controllers.
Features
- Data Reader: Read and parse skope-fx session files (.h5 format) to access complete system configuration, field models, and scan data
- Protocol Client: Direct communication interface with NYOX controllers
- Cross-platform Support: Works on Windows and Linux with compiled extension modules for performance
Requirements
- Python 3.10 - 3.13
- h5py (HDF5 support)
- numpy
- cachetools
- jsonschema
Installation
pip install nyox-sdk
Quick Start
Reading Session Data
Please refer to the User Manual for detailed instructions on using the data reader.
from nyox_sdk import reader
# Load a session file
session = reader.Session("path/to/session.h5")
# Access system configuration
print(session.system_config.nucleus)
print(session.system_config.B0)
# Read scans
for scan in session.scans:
print(f"Scan ID: {scan.id}")
Protocol Client
from nyox_sdk.protocol import NyoxClient
# Connect and send commands to controller
client = NyoxClient()
Examples Usage
Reader
from nyox_sdk import reader
# load and print session
session_file = "Path/To/SessionFile.h5"
session = reader.Session(session_file)
print(session)
# iterate through scans
for scan in session.scans:
nr_datapoints = f"{scan.nr_samples * scan.nr_channels * scan.nr_acquisitions:,}"
print(str(scan.scan_nr) + " - " + nr_datapoints)
# select a specific scan
scan = session.get_scan(3)
# get information from the scan
print(scan)
print(scan.name)
print(scan.nr_acquisitions)
print(scan.dt)
# get trigger information
trigger = scan.trigger
# accessing raw data
raw_data_0 = scan.load_raw_data(0) # load raw data for first acquisition only
raw_data_all = scan.raw # access all raw data and save it to cache
data = scan.load_raw_data(1) # using cached raw data -> faster access
# accessing phase data
phase_data_0 = scan.load_phase(0) # calculating the phase for the first acquisition only
phase_data_all = scan.phase # get all phase data -> this will load all raw data if not cached before
# access the trajectory data
traj_0 = scan.calculate_trajectory(0) # calculate the trajectory for the first acquisition only
traj_all = scan.trajectory # calculate all trajectories and save it to cache
traj_1 = scan.calculate_trajectory(1) # using cached trajectories -> no recalculating needed
# change the field model
field_model = scan.get_field_model()
field_model.selected_spatial_basis = [True, True, True, True]
field_model.includes_coco_terms = False
scan.set_field_model(field_model)
# reset the field model to the original
scan.reset_field_model()
Protocol Client
import asyncio
import os
from nyox_sdk.protocol import NyoxClient
from nyox_sdk.protocol import protocol_json as jsp
from nyox_sdk.reader.skope_processing import skope_processing_python as spp
print('skope-processing version ' + spp.version())
import numpy as np
import matplotlib.pyplot as plt
###############################################
## NYOX sxstem configuration parameters
###############################################
DEVICE_ADDR = "127.0.0.1" # IP address of NYOX unit
dataFolder = 'data/' # folder to put streaming data
baseName = 'example_stream' # name or product n as string
NRCHANNELS = 16
acqDur = 100e-3
nrAcq = 2
async def acquire_crosstalk(ctl: NyoxClient):
# get default short scan def from system
resp = await ctl.get_defaultShortScanDef()
# modify shortScanDef according to your needs
shortScanDef = jsp.parse_shortscandef(resp)
shortScanDef['nrAcquisitions'] = nrAcq
shortScanDef['acqDuration'] = acqDur
# start scans
await ctl.start_scan(shortScanDef)
await ctl.wait_for_stream_done()
print('Measurements done - disconnecting')
await ctl.disconnect()
def do_plot(data: np.ndarray):
fig, ax = plt.subplots()
for j in range (data.shape[2]):
for i in range(data.shape[1]):
ax.plot(data[:,i,j], label=f"channel {i} - acq {j}")
ax.set(xlabel='sample#', ylabel='value (raw)',
title='Skope data acquisition')
plt.legend()
plt.show()
if __name__ =="__main__":
tc = NyoxClient(DEVICE_ADDR, acquire_crosstalk, outfile_prefix=os.path.join(dataFolder, baseName))
asyncio.run(tc.run())
raw_data = np.fromfile(os.path.join(dataFolder, f"{baseName}-0000.bin"), dtype=np.uint32)
raw_data = raw_data.reshape(-1,NRCHANNELS,nrAcq)
mag_data: np.ndarray = spp.pm_raw_to_magnitude(raw_data)
phase_data: np.ndarray = spp.pm_raw_to_phase(raw_data,0)
do_plot(phase_data)
License
See End User License Agreement for details.
Documentation
Please refer to the User Manual for detailed instructions on using the data reader.
For more information, visit skope.swiss/software
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nyox_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: nyox_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 103.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfec432c38e8eb3fc4e18c38e04c7805ae58d6fa1a61be4f5e8d508d73e26b78
|
|
| MD5 |
54b39b4f6340b1c0020cbeae9e3c5e6b
|
|
| BLAKE2b-256 |
86a33b21904ddb46dc4551608c8676f9a50b098e2dea6a64a11c8ce1885d962d
|