Skip to content

Instantly share code, notes, and snippets.

@gadamc
Created August 26, 2011 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadamc/1173082 to your computer and use it in GitHub Desktop.
Save gadamc/1173082 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import struct
class ipebb21mode(object):
def __init__ (self, filename):
self.pulses = []
self.pulses.append([])
self.pulses.append([])
self.pulses.append([])
#self.pulses.append([])
self.file = open(filename, 'rb')
self.read()
plt.ion()
def read(self):
del self.pulses
self.pulses = []
self.pulses.append([])
self.pulses.append([])
self.pulses.append([])
#self.pulses.append([])
try:
while True:
word = self.file.read(4)
if struct.unpack('<I',word)[0] == 12567:
self.file.seek(12 + self.file.tell()) #move ahead another 12 bytes
word = self.file.read(4)
self.pulses[0].append(struct.unpack_from('<h', word, offset=2)[0])
self.pulses[1].append(struct.unpack_from('<h', self.file.read(4), offset=2)[0])
self.pulses[2].append(struct.unpack_from('<h', self.file.read(4), offset=2)[0])
#self.pulses[3].append(struct.unpack_from('<h', self.file.read(4), offset=2)[0])
except:
pass
def plot(self, pulseNumber, figurenumber = 1):
x = np.array(self.pulses[pulseNumber])
plt.figure(figurenumber)
plt.plot(x)
plt.show()
class samba(object):
def __init__ (self, filename, startpos = 26439):
self.pulse = []
self.file = open(filename, 'rb')
self.mustread = True
self.sp = startpos
self.file.seek(self.sp)
plt.ion()
def selectpulse(self, num):
self.file.seek(self.sp)
self.mustread = True
self.file.seek(2*num + self.file.tell())
def read(self):
del self.pulse
self.pulse = []
try:
while True:
self.pulse.append(struct.unpack_from('<h', self.file.read(2))[0])
self.file.seek(14 + self.file.tell())
except:
pass
self.mustread = False
def plot(self, figurenumber = 2):
plt.figure(figurenumber)
if self.mustread:
self.read()
x = np.array(self.pulse)
plt.plot(x)
plt.show()
from pulsereader import *
myipe = ipebb21mode('ipe4cew2-utc1200534412-len30.binary')
myipe.plot(0)
myipe.plot(1)
myipe.plot(2)
mysamba = samba('lg25f005_000')
mysamba.selectpulse(2)
mysamba.plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment