Re: Fast plotting?

2005-04-28 Thread Patrick Ellis
William Park <[EMAIL PROTECTED]> typed:
> Russell E. Owen <[EMAIL PROTECTED]> wrote:
>> Can anyone recommend a fast cross-platform plotting package for 2-D
>> plots?
>>
>> Our situation:
>> We are driving an instrument that outputs data at 20Hz. Control is
>> via an existing Tkinter application (which is being extended for
>> this new instrument) that runs on unix, mac and windows. We wish to
>> update 5-10 summary plots at approximately 2 Hz and will be offering
>> controls to control the instrument and the plots, preferably (but
>> not necessarily) mixed in with the plots.
>
> That's 10-20 plots per second.  The only GUI plotter that I know is
> 'gnuplot', and I don't know if it will spit out anything at 10-20Hz.
> For character plots (like old days terminal), it has speed but ugly to
> look at.
>
>>
>> Ideally the package would create plots in the Tkinter application.
>> But we realize we're unlikely to get the speed we need that way. So
>> we are willing to have the Tkinter app send data to the plotting
>> package  (e.g. via a socket) and have it display the plots in a
>> separate process.
>>
>> We started out with matplotlib, which is a wonderful package (and
>> well integrated with most or all GUI toolkits). Unfortunately it is
>> just too slow -- at least when driving plots integrated with the
>> Tkinter app. (It is getting faster and so are computers, so at some
>> point this will be a great way to go. But for now...)
>>
>> Any suggestions?
>>
>> -- Russell

disipyl is a wrapper around dislin. It includes a class that lets plots
appear inside tkinter frames. I did a quick test and the first demo plot
(run tkdisipyl.py) of a 180 point sine and cosine plotted at over 100 Hz.

http://kim.bio.upenn.edu/~pmagwene/disipyl.html
http://www.mps.mpg.de/dislin/


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast plotting?

2005-04-29 Thread Patrick Ellis
[EMAIL PROTECTED] <[EMAIL PROTECTED]> typed:
> Are you sure about these numbers?  Most monitors refresh at 70-80Hz,
> so unless you have special display hardware, I'm suspicious of these
> numbers doubt .  I once had a user post to the matplotlib mailing list
> that xplt was refreshing at 1000 Hz.  I think xplt drops plot requests
> while requests are in the queue, so many of the loops in his iteration
> were simply dropped.  If the plotting library puts draw requests in an
> idle event handler, accurate refresh rate numbers can be hard to
> quantify.
>
> JDH

dislin doesn't seem to do that. I varied the number of points in the plot so
the drawing rate went from from 60 Hz to 144 Hz. It scaled linearly above
and below my 85 Hz screen rate. It wouldn't do that if it were dropping
plots. I think that computers are so fast that they can draw to the frame
buffer very quickly, but the slower screen refresh means only some of those
fully drawn frames make it to the monitor.

Even if you are correct, that is still drawing at 85 Hz and thus much faster
than the original poster needed.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Random image downloader for newsgroups (first script)

2006-09-07 Thread Patrick Ellis
Kim wrote:
> Random image downloader for specified newsgroup. Hi I'm writing a
> small script that will download random images from a specified
> newsgroup. I've imported yenc into the script but I can't open the
> image or save it. This is my first script so be gentle!
>
> Heres the script
>
>
> random group downloader
> import nntplib
> import string, random
> import mimetools
> import StringIO
> import rfc822
> import sys, base64
> import os
> import email
> import errno
> import mimetypes
>
>
> SERVER = "news.server.co.uk" #Insert news server here
> GROUP  = "alt.binaries.pictures.blah" #newsgroup will go here
>
> # connect to server
> server = nntplib.NNTP(SERVER)
>
> resp, count, first, last, name = server.group(GROUP)
>
> for i in range(10):
>try:
>id = random.randint(int(first), int(last))
>resp, id, message_id, text = server.article(str(id))
>except (nntplib.error_temp, nntplib.error_perm):
>pass # no such message (maybe it was deleted?)
>else:
>break # found a message!
> else:
>raise SystemExit
>
> text = string.join(text, "\n")
> file = StringIO.StringIO(text)
>
> msg = mimetools.Message(file)
>
> #display message information
> #print "File type", "=>", msg.gettype()
> #print "Encoding", "=>", msg.getencoding()
> #print "plist", "=>", msg.getplist()
>
> message = rfc822.Message(file)
>
> for k, v in message.items():
>print k, "=", v
>
> file = message.fp.read()
>
> def yenc_decode(file):
># find body
>while 1:
>line = file.readline()
>if not line:
>return None
>if line[:7] == "=ybegin":
>break
># extract data
>buffer = []
>while 1:
>line = file.readline()
>if not line or line[:5] == "=yend":
>break
>if line[-2:] == "\r\n":
>line = line[:-2]
>elif line[-1:] in "\r\n":
>line = line[:-1]
>data = string.split(line, "=")
>buffer.append(string.translate(data[0], yenc42))
>for data in data[1:]:
>data = string.translate(data, yenc42)
>buffer.append(string.translate(data[0], yenc64))
>buffer.append(data[1:])
>return buffer
> #the following should write to a text file
> #inp = ("file","r")
> #outp = open("text.txt","w")
> #for line in file:
>#outp.write(line)
> #print file
> #outp.close()
>

The following worked for me. It printed text and even
generated viewable images when I went to a pictures group.

I cleaned it up a little. I'm sure it can be cleaner. That's partly
because I didn't want to drift too far from your original and
partly because I don't get much Python practice.

Don't use "file" as a variable name, it overwrites the built in
file object. It likely didn't matter in this case, but would
eventually cause problems.

random group downloader
import nntplib
import random
import StringIO
import mimetools
import rfc822
import binascii
#import base64
#import sys
#import os
#import email
#import errno
#import mimetypes


SERVER = "news.server.co.uk" #Insert news server here
GROUP  = "alt.binaries.pictures.blah" #newsgroup will go here

# connect to server
server = nntplib.NNTP(SERVER)

resp, count, first, last, name = server.group(GROUP)

for i in range(10):
try:
id = random.randint(int(first), int(last))
resp, id, message_id, text = server.article(str(id))
except (nntplib.error_temp, nntplib.error_perm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

msgFile = StringIO.StringIO("\n".join(text))

# Display mime message information
msg = mimetools.Message(msgFile)
msgFile.seek(0)
print "File type", "=>", msg.gettype()
print "Encoding", "=>", msg.getencoding()
print "plist", "=>", msg.getplist()

# Display rfc822 message information
message = rfc822.Message(msgFile)
msgFile.seek(0)
for k, v in message.items():
print k, "=", v

yenc42 = "".join([chr((i - 42) & 255) for i in range(256)])
yenc64 = "".join([chr((i - 64) & 255) for i in range(256)])

def yenc_decode(fileIn):
# find body
while 1:
line = fileIn.readline()
if not line:
return None
if line[:7] == "=ybegin":
break
# extract data
buffer = []
while 1:
line = fileIn.readline()
if not line or line[:5] == "=yend":
break
if line[-2:] == "\r\n":
line = line[:-2]
elif line[-1:] in "\r\n":
line = line[:-1]
splitData = line.split("=")
buffer.append(splitData[0].translate(yenc42))
for data in splitData[1:]:
buffer.append(data[0].translate(yenc64).translate(yenc42))
buffer.append(data[1:].translate(yenc42))
return buffer

def uu_decode(fileIn):
# find body
while 1:
line = fileIn.readline()
if not line:
return None
if line[:6] == "begin ":
break