Skip to main content

Connect to remote laboratory experiments hosted on a github.com/practable service

Project description

practable-python

a library for connecting to experiments in python

Example Usage

import matplotlib.pyplot as plt
import numpy as np
from practable.core import Experiment
import time

messages = []
   
#modify with actual group code and experiment name
with Experiment('g-open-x3fca8','Spinner 51 (Open Days)', exact=True) as expt:
    
    # Command a step of 2 radians & collect the data
    expt.command('{"set":"mode","to":"stop"}')
    expt.command('{"set":"mode","to":"position"}')
    expt.command('{"set":"parameters","kp":1,"ki":0,"kd":0}')

    time.sleep(0.5)
        
    expt.command('{"set":"position","to":2}')    
    
    expt.ignore(0.5)
    messages = expt.collect(1.5)
    
    # Process the data
    ts = expt.extract_series(messages, "t")
    ds = expt.extract_series(messages, "d")
    cs = expt.extract_series(messages, "c")
    
    t = np.array(ts)
    t = t - t[0]
    
    # Plot the data
    plt.figure()        
    plt.plot(t/1e3,ds,'-b',label="position")
    plt.plot(t/1e3,cs,':r',label="set point")
    plt.xlabel("time(s)")
    plt.ylabel("position(rad)")
    plt.legend()

This script produces the following text output

Command: {"set":"mode","to":"stop"}
Command: {"set":"mode","to":"position"}
Command: {"set":"parameters","kp":1,"ki":0,"kd":0}
Command: {"set":"position","to":2}
Ignoring messages for 0.5 seconds |██████████████████████████████████████████████████| 100.0% Complete

Collecting messages for 1.5 seconds |██████████████████████████████████████████████████| 100.0% Complete

An a graph:

Example graphic from a spinner

Additional information

A user name is obtained and stored locally.

Bookings last only as long as the experiment is needed, because they are cancelled when the with environment exits. The default booking duration is 3 min.

You can use an existing booking by specifying user="cxxxxxxxxxx" where the username is found on the user tab of the booking system that holds the booking.

Other practable instances can be accessed by specifying it e.g. booking-server="https://some.booking.server"

Requirements

Recommend python >= 3.8 because we're using websockets 12.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

practable-0.0.25.tar.gz (79.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

practable-0.0.25-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file practable-0.0.25.tar.gz.

File metadata

  • Download URL: practable-0.0.25.tar.gz
  • Upload date:
  • Size: 79.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for practable-0.0.25.tar.gz
Algorithm Hash digest
SHA256 df4aef11abb218fb039a490faf485f35195d87c3410cd511732f7972fab09e0f
MD5 3e199f6cb48505dd7b26038564be8b91
BLAKE2b-256 28de4267c21d52374c2631c3a205c881e1f130301fbf7c194016a9695a9207e4

See more details on using hashes here.

File details

Details for the file practable-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: practable-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for practable-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 add4e38848c7b117f41a110653983eff3d04a0151e10625af5bdacbacb815a5e
MD5 81bc5de6b1d9814ebc9c26a00bbaaf4d
BLAKE2b-256 a1f5bad3d426326adb120ea8f7b3b587e9dc55bcbf45711d3e0681d7803cbbda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page