Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 526887140d4e
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9bfc2070d4f5
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 30, 2015

  1. Copy the full SHA
    0ebe56f View commit details
  2. Copy the full SHA
    9bfc207 View commit details
Showing with 101 additions and 63 deletions.
  1. +79 −0 artiq/gui/rt_result_views.py
  2. +12 −58 artiq/gui/rt_results.py
  3. +10 −5 examples/rtio_skew.py
79 changes: 79 additions & 0 deletions artiq/gui/rt_result_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from gi.repository import Gtk
import cairoplot

from artiq.gui.tools import Window


class RawWindow(Window):
def __init__(self, set_names):
self.labels = dict()

Window.__init__(self, title="Raw values",
default_size=(200, 150))

grid = Gtk.Grid(row_spacing=6, column_spacing=6)
self.add(grid)
for i, name in enumerate(set_names):
grid.attach(Gtk.Label(name), 0, i, 1, 1)
label = Gtk.Label("-")
self.labels[name] = label
grid.attach(label, 1, i, 1, 1)

def delete(self):
self.close()

def set_data(self, data):
for name, label in self.labels.items():
if name in data:
label.set_text(str(data[name]))


class PlotWindow(Window):
def __init__(self, set_names):
self.set_names = set_names
self.data = None

Window.__init__(self, title="/".join(set_names),
default_size=(700, 500))

self.darea = Gtk.DrawingArea()
self.darea.set_size_request(100, 100)
self.darea.connect("draw", self.on_draw)
self.add(self.darea)

def delete(self):
self.close()


class XYWindow(PlotWindow):
def on_draw(self, widget, ctx):
if self.data is not None:
data = self.filter_data()
cairoplot.scatter_plot(
ctx,
data=data,
width=widget.get_allocated_width(),
height=widget.get_allocated_height(),
x_bounds=(min(data[0])*0.98, max(data[0])*1.02),
y_bounds=(min(data[1])*0.98, max(data[1])*1.02),
border=20, axis=True, grid=True,
dots=1, discrete=True,
series_colors=[(0.0, 0.0, 0.0)],
background="white"
)

def filter_data(self):
return [
self.data[self.set_names[0]],
self.data[self.set_names[1]],
]

def set_data(self, data):
self.data = data
if not self.data:
return
# The two axes are not updated simultaneously.
# Redraw only after receiving a new point for each.
x, y = self.filter_data()
if len(x) == len(y):
self.darea.queue_draw()
70 changes: 12 additions & 58 deletions artiq/gui/rt_results.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,17 @@
import asyncio
from collections import defaultdict

from gi.repository import Gtk
import cairoplot

from artiq.protocols.sync_struct import Subscriber
from artiq.gui.tools import Window


class _PlotWindow(Window):
def __init__(self, set_names):
self.set_names = set_names
self.data = None

Window.__init__(self, title="/".join(set_names),
default_size=(700, 500))

self.darea = Gtk.DrawingArea()
self.darea.set_size_request(100, 100)
self.darea.connect("draw", self.on_draw)
self.add(self.darea)

def delete(self):
self.close()


class XYWindow(_PlotWindow):
def on_draw(self, widget, ctx):
if self.data is not None:
data = self.filter_data()
cairoplot.scatter_plot(
ctx,
data=data,
width=widget.get_allocated_width(),
height=widget.get_allocated_height(),
x_bounds=(min(data[0])*0.98, max(data[0])*1.02),
y_bounds=(min(data[1])*0.98, max(data[1])*1.02),
border=20, axis=True, grid=True,
dots=1, discrete=True,
series_colors=[(0.0, 0.0, 0.0)],
background="white"
)

def filter_data(self):
return [
self.data[self.set_names[0]],
self.data[self.set_names[1]],
]

def set_data(self, data):
self.data = data
if not self.data:
return
# The two axes are not updated simultaneously.
# Redraw only after receiving a new point for each.
x, y = self.filter_data()
if len(x) == len(y):
self.darea.queue_draw()
from artiq.gui.rt_result_views import RawWindow, XYWindow


def _create_view(set_names, view_description):
r = XYWindow(set_names)
if view_description == "raw":
r = RawWindow(set_names)
elif view_description == "xy":
r = XYWindow(set_names)
else:
raise ValueError("Unknown view description: " + view_description)
r.show_all()
return r

@@ -158,8 +109,11 @@ def init_groups(self, init):
return self.current_groups

def on_mod(self, mod):
if mod["action"] != "init" and len(mod["path"]) >= 3:
if mod["action"] != "init" and len(mod["path"]) >= 2:
path = mod["path"]
group = self.current_groups[path[0]]
if path[1] == "data":
group.on_data_modified(path[2])
if len(mod["path"]) >= 3:
group.on_data_modified(path[2])
else:
group.on_data_modified(mod["key"])
15 changes: 10 additions & 5 deletions examples/rtio_skew.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from artiq import *


def print_failed():
print("Pulse was not received back")
class PulseNotReceived(Exception):
pass


class RTIOSkew(AutoDB):
@@ -11,6 +11,12 @@ class DBKeys:
ttl0 = Device()
io_skew = Result()

@staticmethod
def realtime_results():
return {
"io_skew": "raw"
}

@kernel
def run(self):
with parallel:
@@ -21,6 +27,5 @@ def run(self):
self.ttl0.pulse(5*us)
in_t = self.pmt0.timestamp()
if in_t < 0*s:
print_failed()
else:
self.io_skew = out_t - in_t
raise PulseNotReceived
self.io_skew = out_t - in_t