Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 3.42 KB

File metadata and controls

59 lines (46 loc) · 3.42 KB

spikesafe-python API Overview | Compensation | Compensation.load_custom_compensation_table(file_path)

Compensation.load_custom_compensation_table(file_path)

Definition

Returns a custom compensation table from a UTF-8 JSON file.

Parameters

file_path string
Path to the UTF-8 JSON file containing the custom compensation table.

The file is decoded explicitly as UTF-8, independent of the system's default encoding. ASCII-only JSON files remain compatible. Convert files saved in legacy encodings, such as Windows-1252, to UTF-8 before loading them. JSON numbers must use a period (.) as the decimal separator, regardless of the application's locale.

Returns

list list([])
Custom compensation table as a list of dictionaries conforming to the custom_compensation_table_schema

Raises

FileNotFoundError
If the file does not exist

IOError
If an error occurs while loading the file

ValueError
If the file contains invalid JSON, schema validation error, or custom compensation table validation error

Examples

The following example demonstrates the load_custom_compensation_table() function. It determines the custom compensation settings to use based off the SpikeSafe's set current setting, maximum settable current, and pulse on time.

# set Channel 1's Pulse On Time to 1ms and check for all events
pulse_on_time: float = 0.001
tcp_socket.send_scpi_command(f'SOUR1:PULS:TON {spikesafe_python.Precision.get_precise_time_command_argument(pulse_on_time)}')
spikesafe_python.ReadAllEvents.read_all_events(tcp_socket, enable_logging=True) 

# set Channel 1's current to 100 mA and check for all events
set_current: float = 0.1
tcp_socket.send_scpi_command(f'SOUR1:CURR {spikesafe_python.Precision.get_precise_current_command_argument(set_current)}')   
spikesafe_python.ReadAllEvents.read_all_events(tcp_socket, enable_logging=True)  

# set Channel 1's compensation settings to their default values and check for all events
# For higher power loads or shorter pulses, these settings may have to be adjusted to obtain ideal pulse shape
tcp_socket.send_scpi_command('SOUR1:CURR? MAX')
spikesafe_model_max_current = float(tcp_socket.read_data())

# load custom_compensation_table from /test_compensation_files/valid.json
custom_compensation_table = spikesafe_python.Compensation.load_custom_compensation_table(os.path.join(os.path.dirname(__file__), 'test_compensation_files', 'valid.json')
device_types = spikesafe_python.Compensation.load_custom_compensation_unique_device_types(custom_compensation_table)
load_impedance, rise_time = spikesafe_python.Compensation.get_custom_compensation(spikesafe_model_max_current, set_current, device_types[0], pulse_on_time)
tcp_socket.send_scpi_command(f'SOUR1:PULS:CCOM {load_impedance}')
spikesafe_python.ReadAllEvents.read_all_events(tcp_socket, enable_logging=True) 
tcp_socket.send_scpi_command(f'SOUR1:PULS:RCOM {rise_time}')
spikesafe_python.ReadAllEvents.read_all_events(tcp_socket, enable_logging=True) 

Examples In Action