Create an App with Python & Win $5000

2013-08-21 Thread yigit
Hi all,

JotForm just announced its developer contest with their newly released API with 
a grand prize of $5000 to the best app and $500 for other categories. The API 
library can be used with Python so you can create endless apps with it.

The deadline for the contest is September 24, 2013.

Apply to the contest from http://developers.jotform.com/competition/
-- 
http://mail.python.org/mailman/listinfo/python-list


os.system()

2012-04-19 Thread Yigit Turgut
When I use os.system() function, script waits for termination of the
windows that is opened by os.system() to continue thus throwing errors
and etc. How can i tell Python to let it go and keep on with the next
execution after os.system() ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system()

2012-04-20 Thread Yigit Turgut
On Apr 19, 11:02 pm, "Steve"  wrote:
> > "Yigit Turgut"  wrote in message
> >news:b9a8bb28-3003-4a36-86fb-339ef697b...@i2g2000vbd.googlegroups.com...
> > When I use os.system() function, script waits for termination of the
>
> windows that is opened by os.system() to continue thus throwing errors
> and etc. How can i tell Python to let it go and keep on with the next
> execution after os.system() ?
>
> Can you make use of subprocess.Popen() ?

Still waits for the new windows to kill.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Screen Control Fullscreen ON/OFF

2011-12-15 Thread Yigit Turgut
On Dec 15, 4:19 pm, Ulrich Eckhardt 
wrote:
> Am 15.12.2011 12:12, schrieb yeet:
>
> > My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/
> > OFF (white/black) thus seems to fit my 1-40Hz range.
>
> You might want to ask Santa for a new calculator, as in my book a
> response time of 2ms would be enough for 250Hz (period = 2 * 2ms).
>
> Reminds me of a hack that used a special pattern on a CRT to emit DCF77
> signals, reprogramming any suitable radio-controlled clock in range.
> What are you trying to do, just out of curiosity?
>
> (c:
>
> Uli

Yes that's correct, 50Hz limit is the limit of NVIDIA CUDA Linux
drivers limit. Screen can go higher rates on sucky windows.
I am trying to generate a visual stimulus that will be used for fNIR
and EEG captures.

On Dec 15, 2:18 pm, Nizamov Shawkat  wrote:
> > It depends on whether you want sync to vblank or not. If not, that is
> > pretty easy - use sleep() or something similar. If you have to use
> > sync (screen is always either black or white, never partly black and
> > white) then it is much much more difficult. Actually I do not know of
> > any way to sync to it.
>
> But you do not have to sync to vblank anyway. So you can turn on
> vblank sync for the videocard and then you will have either completely
> black or completely white screen at each single time point, but this
> will be delayed in regard to what you set in python.
>
> Hope this helps,
> S.Nizamov

It's not easy to do this basing on time, I think doing per frames is a
much better option. It's sounded like a very simple task at first but
I realize it's not that easy.Maybe I should write the screen blinker
in C or Assembly then call it from Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Text Processing

2011-12-20 Thread Yigit Turgut
Hi all,

I have a text file containing such data ;

ABC
---
-2.0100e-018.000e-028.000e-05
-2.e-010.000e+00   4.800e-04
-1.9900e-014.000e-021.600e-04

But I only need Section B, and I need to change the notation to ;

8.000e-02 = 0.08
0.000e+00 = 0.00
4.000e-02 = 0.04

Text file is approximately 10MB in size. I looked around to see if
there is a quick and dirty workaround but there are lots of modules,
lots of options.. I am confused.

Which module is most suitable for this task ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text Processing

2011-12-22 Thread Yigit Turgut
On Dec 21, 2:01 am, Alexander Kapps  wrote:
> On 20.12.2011 22:04, Nick Dokos wrote:
>
>
>
>
>
>
>
>
>
> >>> I have a text file containing such data ;
>
> >>>          A                B                C
> >>> ---
> >>> -2.0100e-01    8.000e-02    8.000e-05
> >>> -2.e-01    0.000e+00   4.800e-04
> >>> -1.9900e-01    4.000e-02    1.600e-04
>
> >>> But I only need Section B, and I need to change the notation to ;
>
> >>> 8.000e-02 = 0.08
> >>> 0.000e+00 = 0.00
> >>> 4.000e-02 = 0.04
> > Does it have to be python? If not, I'd go with something similar to
>
> >     sed 1,2d foo.data | awk '{printf("%.2f\n", $2);}'
>
> Why sed and awk:
>
> awk 'NR>2 {printf("%.2f\n", $2);}' data.txt
>
> And in Python:
>
> f = open("data.txt")
> f.readline()    # skip header
> f.readline()    # skip header
> for line in f:
>      print "%02s" % float(line.split()[1])

@Jerome ; Your suggestion provided floating point error, it might need
some slight modificiation.

@Nick ; Sorry mate, it needs to be in Python. But I noted solution in
case if I need for another case.

@Alexander ; Works as expected.

Thank you all for the replies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Plot seems weird

2011-12-25 Thread Yigit Turgut
Hi all,

I have a text file as following;

0.2000470.00
0.2000530.16
0.2000590.00
0.2000650.08
0.2000720.00
0.2000780.16

And I am trying to plot it with ;

filenames = sys.argv[1:]
if len(filenames) == 0:
filenames = [sys.stdin]
for filename in filenames:
t,y1 = numpy.genfromtxt(filename, unpack=True)
pyplot.plot(t,y1)
pyplot.show()

But graph seems weird, not as it supposed to be. Any ideas ?


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


Re: Plot seems weird

2011-12-25 Thread Yigit Turgut
On Dec 25, 7:06 pm, Rick Johnson  wrote:
> On Dec 25, 9:33 am, Yigit Turgut  wrote:
> > Hi all,
>
> > I have a text file as following;
>
> > 0.200047        0.00
> > 0.200053        0.16
> > 0.200059        0.00
> > 0.200065        0.08
> > 0.200072        0.00
> > 0.200078        0.16
>
> > And I am trying to plot it with ;
>
> > filenames = sys.argv[1:]
> > if len(filenames) == 0:
> >     filenames = [sys.stdin]
> > for filename in filenames:
> >     t,y1 = numpy.genfromtxt(filename, unpack=True)
> >     pyplot.plot(t,y1)
> >     pyplot.show()
>
> > But graph seems weird, not as it supposed to be. Any ideas ?
>
> Interesting. Of course "weird" leaves a LOT to be desired. On a scale
> of 1-10, how "weird" is the result?

I apply a 1Khz test signal just to see if things run smoothly, but I
see spikes at lower and higher ends (logic 0,1) where I should see a
clean rectangle pwm signal. By the look of it I say weirdness is
around 3/10.

>
> But seriously. Have you tried debugging yet? If not, test these
> points:
Yes I double checked it, there seems to be nothing wrong in debug.

>  * What is the value of "filenames" BEFORE the loop?

Filename is argument 1 of the startup action.

>  * What is the value of "t" and "y1" for each iteration?

I test with both low and mid frequency signals (50Hz - 1Khz), same
inconsistency.

>
> Also observe this wonderful phenomenon:
>
> py> [] or [1,2,3]
> [1, 2, 3]
> py> [] or None or '' or () or {} or [1,2,3] or "1,2,3"
> [1, 2, 3]

Beautiful. I convert my arrays to string before writing to file.
Original post contains a fragment of the whole file. Data is
fluctuating, not a linear behavior.

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


Re: Plot seems weird

2011-12-26 Thread Yigit Turgut
On Dec 26, 11:28 am, Lie Ryan  wrote:
> On 12/26/2011 05:27 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
>
>
> > On Dec 25, 7:06 pm, Rick Johnson  wrote:
> >> On Dec 25, 9:33 am, Yigit Turgut  wrote:
> >>> Hi all,
>
> >>> I have a text file as following;
>
> >>> 0.200047        0.00
> >>> 0.200053        0.16
> >>> 0.200059        0.00
> >>> 0.200065        0.08
> >>> 0.200072        0.00
> >>> 0.200078        0.16
>
> >>> And I am trying to plot it with ;
>
> >>> filenames = sys.argv[1:]
> >>> if len(filenames) == 0:
> >>>      filenames = [sys.stdin]
> >>> for filename in filenames:
> >>>      t,y1 = numpy.genfromtxt(filename, unpack=True)
> >>>      pyplot.plot(t,y1)
> >>>      pyplot.show()
>
> >>> But graph seems weird, not as it supposed to be. Any ideas ?
>
> >> Interesting. Of course "weird" leaves a LOT to be desired. On a scale
> >> of 1-10, how "weird" is the result?
>
> > I apply a 1Khz test signal just to see if things run smoothly, but I
> > see spikes at lower and higher ends (logic 0,1) where I should see a
> > clean rectangle pwm signal. By the look of it I say weirdness is
> > around 3/10.
>
> What are you expecting? Your data produces something that looks like the
> plot on the right of this screenshot
> (http://i44.tinypic.com/wwhlvp.jpg), I don't see anything weird with
> that; if you are expecting a square-wave-like plot (like on the left),
> then you should use a square-wave-like data, pyplot wouldn't magically
> transform a spiked-plot to squared-plot.
>
> Here's what I use to convert the data on right plot to data on left
> plot, I don't know much about numpy so it might be possible to do it
> more efficiently or numpy might even have something like it already.
>
> from itertools import izip_longest
> def to_square(t, y1):
>      sq_data = [[], []]
>      for x,y, xn in izip_longest(data[0], data[1], data[0][1:]):
>          sq_data[0].append(x)
>          sq_data[1].append(y)
>          sq_data[0].append(xn)
>          sq_data[1].append(y)
>      return numpy.array(sq_data, dtype=float)

Thanks for the tip. I know that I feed a square wave signal and record
this data. Thus I believe the situation can be related to sampling
frequency.
Couldn't get your code working, maybe because I import the data from
file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Multithreading

2011-12-26 Thread Yigit Turgut
I have a loop as following ;

start = time.time()
end = time.time() - start
 while(endhttp://mail.python.org/mailman/listinfo/python-list


Re: Plot seems weird

2011-12-26 Thread Yigit Turgut
On Dec 26, 8:58 pm, Lie Ryan  wrote:
> On 12/27/2011 04:08 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
>
>
> > On Dec 26, 11:28 am, Lie Ryan  wrote:
> >> On 12/26/2011 05:27 AM, Yigit Turgut wrote:
>
> >>> On Dec 25, 7:06 pm, Rick Johnson    wrote:
> >>>> On Dec 25, 9:33 am, Yigit Turgut    wrote:
> >>>>> Hi all,
>
> >>>>> I have a text file as following;
>
> >>>>> 0.200047        0.00
> >>>>> 0.200053        0.16
> >>>>> 0.200059        0.00
> >>>>> 0.200065        0.08
> >>>>> 0.200072        0.00
> >>>>> 0.200078        0.16
>
> >>>>> And I am trying to plot it with ;
>
> >>>>> filenames = sys.argv[1:]
> >>>>> if len(filenames) == 0:
> >>>>>       filenames = [sys.stdin]
> >>>>> for filename in filenames:
> >>>>>       t,y1 = numpy.genfromtxt(filename, unpack=True)
> >>>>>       pyplot.plot(t,y1)
> >>>>>       pyplot.show()
>
> >>>>> But graph seems weird, not as it supposed to be. Any ideas ?
>
> >>>> Interesting. Of course "weird" leaves a LOT to be desired. On a scale
> >>>> of 1-10, how "weird" is the result?
>
> >>> I apply a 1Khz test signal just to see if things run smoothly, but I
> >>> see spikes at lower and higher ends (logic 0,1) where I should see a
> >>> clean rectangle pwm signal. By the look of it I say weirdness is
> >>> around 3/10.
>
> >> What are you expecting? Your data produces something that looks like the
> >> plot on the right of this screenshot
> >> (http://i44.tinypic.com/wwhlvp.jpg), I don't see anything weird with
> >> that; if you are expecting a square-wave-like plot (like on the left),
> >> then you should use a square-wave-like data, pyplot wouldn't magically
> >> transform a spiked-plot to squared-plot.
>
> >> Here's what I use to convert the data on right plot to data on left
> >> plot, I don't know much about numpy so it might be possible to do it
> >> more efficiently or numpy might even have something like it already.
>
> >> from itertools import izip_longest
> >> def to_square(t, y1):
> >>       sq_data = [[], []]
> >>       for x,y, xn in izip_longest(data[0], data[1], data[0][1:]):
> >>           sq_data[0].append(x)
> >>           sq_data[1].append(y)
> >>           sq_data[0].append(xn)
> >>           sq_data[1].append(y)
> >>       return numpy.array(sq_data, dtype=float)
>
> > Thanks for the tip. I know that I feed a square wave signal and record
> > this data. Thus I believe the situation can be related to sampling
> > frequency.
>
> It is due to sampling frequency, but also because you cannot sample a
> square wave perfectly because square wave has infinite steepness at the
> transitions. Although if you know the exact timing of the transitions,
> it may be possible to reconstruct the transitions perfectly.
>
> > Couldn't get your code working, maybe because I import the data from
> > file.
>
> not your fault, I made a mistake when copy-pasteing the code, here's the
> fixed code:
>
> from itertools import izip_longest
> def to_square(data):
>       sq_data = [[], []]
>       for x,y, xn in izip_longest(data[0], data[1], data[0][1:]):
>           sq_data[0].append(x)
>           sq_data[1].append(y)
>           sq_data[0].append(xn)
>           sq_data[1].append(y)
>       return numpy.array(sq_data, dtype=float)
>
> use it like this:
>
> t,y1 = to_square(numpy.genfromtxt(filename, unpack=True))
> pyplot.plot(t,y1)
> pyplot.show()

Significant improvement on the plot, pretty interesting. It runs ok
but I need to know how?! (:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multithreading

2011-12-26 Thread Yigit Turgut
On Dec 26, 10:03 pm, Ian Kelly  wrote:
> On Mon, Dec 26, 2011 at 1:01 PM, Ian Kelly  wrote:
> > You essentially have two completely independent loops that need to run
> > simultaneously with different timings.  Sounds like a good case for
> > multiple threads (or processes if you prefer, but these aren:
>
> I accidentally sent before I was finished.  I was saying "or processes
> if you prefer, but these aren't CPU-bound, so why complicate things?"
>
> Cheers,
> Ian

I had thought the same workaround but unfortunately loop is already
under a def ;

def writeWaveform(self, fo, header=''):
data1 = numpy.zeros(self.size)
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
fo.write(header)
start = time.time()
end = time.time() - start
while(end<10):
  data1 = self.chan1.getWaveform()
  end = time.time() - start
  timer.tick(10) #FPS
  screen.fill((255,255,255) if white else(0,0,0))
  white = not white
  pygame.display.update()
  for i in range(self.size):
  end = time.time() - start
  f.write("%3.8f\t%f\n"%(end,data1[i]))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multithreading

2011-12-26 Thread Yigit Turgut
On Dec 26, 10:01 pm, Ian Kelly  wrote:
> On Mon, Dec 26, 2011 at 11:31 AM, Yigit Turgut  wrote:
> > I have a loop as following ;
>
> > start = time.time()
> > end = time.time() - start
> >  while(end >          data1 = self.chan1.getWaveform()
> >          end = time.time() - start
> >          timer.tick(10)  #FPS
> >          screen.fill((255,255,255) if white else(0,0,0))
> >          white = not white
> >          pygame.display.update()
> >          for i in range(self.size):
> >              end = time.time() - start
> >              f.write("%3.8f\t%f\n"%(end,data1[i]))
>
> > Roughly speaking, this loop displays something at 10 frames per second
> > and writes data1 to a file with timestamps.
>
> > At first loop data1 is grabbed but to grab the second value (second
> > loop) it needs to wait for timer.tick to complete. When I change FPS
> > value [timer.tick()], capturing period (time interval between loops)
> > of data1 also changes. What I need is to run ;
>
> >          timer.tick(10)  #FPS
> >          screen.fill((255,255,255) if white else(0,0,0))
> >          white = not white
> >          pygame.display.update()
>
> > for N seconds but this shouldn't effect the interval between loops
> > thus I will be able to continuously grab data while displaying
> > something at X fps.
>
> > What would be an effective workaround for this situation ?
>
> You essentially have two completely independent loops that need to run
> simultaneously with different timings.  Sounds like a good case for
> multiple threads (or processes if you prefer, but these aren:
>
> def write_data(self, f, N):
>     start = time.time()
>     while self.has_more_data():
>         data1 = self.chan1.getWaveform()
>         time.sleep(N)
>         for i in range(self.size):
>             end = time.time() - start
>             f.write("%3.8f\t%f\n" % (end, data[i]))

Why is there N variable in write_data function ? N is related to
timer.tick(N) which is related to display function ? time.sleep(N)
will pause writing to file for specified amount of time which is
exactly what I am trying to avoid.
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling a variable inside a function of another class

2012-01-07 Thread Yigit Turgut
class test(test1):

def __init__(self, device):
  .
  .
  .
def _something(self, x=1)
 self.dt = data


if __name__ == "__main__":
 test.something.dt ???

I am trying to call a variable located in a function of a class from
main but couldn't succeed.Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling a variable inside a function of another class

2012-01-07 Thread Yigit Turgut
On Jan 7, 6:01 pm, Steven D'Aprano  wrote:
> On Sat, 07 Jan 2012 07:00:57 -0800, Yigit Turgut wrote:
> > I am trying to call a variable located in a function of a class from
> > main but couldn't succeed.Any ideas?
>
> You cannot access local variables from outside their function. That's why
> they are called *local* variables.
>
> You probably want to access *attributes* of the class or the instance.
> You have to define them first -- you can't access something that doesn't
> exist.
>
> class Test:
>     shared = 42  # Shared, class attribute
>     def __init__(self):
>         self.dt = 23  # Instance attribute, not shared.
>
> print(Test.shared)  # prints 42
>
> However, print(Test.dt) fails because no instance has been created yet,
> and so there is no dt attribute. You have to create an instance first,
> then __init__ will run and create the attribute:
>
> instance = Test()
> print(instance.dt)  # prints 23
>
> --
> Steven

How about assigning the variable as global, wouldn't it be more
effective?
-- 
http://mail.python.org/mailman/listinfo/python-list


Parallel Processing

2012-01-08 Thread Yigit Turgut
Hi all,

I am trying to run two functions at the same time with Parallel
Processing (pp) as following ;

import pygame
import sys
import time
import math
import pp

screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
start = time.time()
end = time.time() - start

def test1():
  global end
  while(end<5):
end = time.time() - start
timer.tick(4) #FPS
screen.fill((255,255,255) if white else (0, 0, 0))
white = not white
pygame.display.update()

def test2():
  global end
  while(end2<5):
end2 = time.time() - start
print end

ppservers = ()

if len(sys.argv) > 1:
ncpus = int(sys.argv[1])
# Creates jobserver with ncpus workers
job_server = pp.Server(ncpus, ppservers=ppservers)
else:
# Creates jobserver with automatically detected number of workers
job_server = pp.Server(ppservers=ppservers)
print "Starting PP with", job_server.get_ncpus(), "workers"

job1 = job_server.submit(test1,test2)
result = job1()

And the output is ;

Starting PP with 2 workers
Traceback (most recent call last):
  File "fl.py", line 46, in 
job1 = job_server.submit(test1,test2)
  File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
raise TypeError("args argument must be a tuple")
TypeError: args argument must be a tuple


When I change job1 to just to see if it will run one function only;
job1 = job_server.submit(test1)

I get an output of;

NameError: global name 'end' is not defined

end variable is defined as global but I get a NameError. Anyone has an
idea what's going on ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 8, 4:34 pm, Dave Angel  wrote:
> On 01/08/2012 08:23 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I am trying to run two functions at the same time with Parallel
> > Processing (pp) as following ;
>
> > import pygame
> > import sys
> > import time
> > import math
> > import pp
>
> > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
> > timer = pygame.time.Clock()
> > white = True
> > start = time.time()
> > end = time.time() - start
>
> > def test1():
> >    global end
> >    while(end<5):
> >      end = time.time() - start
> >      timer.tick(4) #FPS
> >      screen.fill((255,255,255) if white else (0, 0, 0))
> >      white = not white
> >      pygame.display.update()
>
> > def test2():
> >    global end
> >    while(end2<5):
> >      end2 = time.time() - start
> >      print end
>
> > ppservers = ()
>
> > if len(sys.argv)>  1:
> >      ncpus = int(sys.argv[1])
> >      # Creates jobserver with ncpus workers
> >      job_server = pp.Server(ncpus, ppservers=ppservers)
> > else:
> >      # Creates jobserver with automatically detected number of workers
> >      job_server = pp.Server(ppservers=ppservers)
> > print "Starting PP with", job_server.get_ncpus(), "workers"
>
> > job1 = job_server.submit(test1,test2)
> > result = job1()
>
> > And the output is ;
>
> > Starting PP with 2 workers
> > Traceback (most recent call last):
> >    File "fl.py", line 46, in
> >      job1 = job_server.submit(test1,test2)
> >    File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
> >      raise TypeError("args argument must be a tuple")
> > TypeError: args argument must be a tuple
>
> > When I change job1 to just to see if it will run one function only;
> > job1 = job_server.submit(test1)
>
> > I get an output of;
>
> > NameError: global name 'end' is not defined
>
> > end variable is defined as global but I get a NameError. Anyone has an
> > idea what's going on ?
>
> First, please tell us about any external dependencies (eg. imports).
> Pygame may not matter, since there are many people here using it, but
> each of us has to hunt down something that does parallel processing with
> an interface similar to what you're using.  For the next person, the
> most likely candidate out of the dozens available 
> is:http://www.parallelpython.com/
>
> Your problem, as stated in the raise statement, is that the submit
> method is expecting a tuple for its "args argument".  Now I had to go to
> the website to find an example, but it appears that your second argument
> should have been a tuple of the arguments for your function.  See
> *      submit*(self, func, args=(), depfuncs=(), modules=(),
> callback=None, callbackargs=(), group='default', globals=None)
>
> on page:http://www.parallelpython.com/content/view/15/30/#API
>
> So you're passing it two function objects, and the second one is in the
> place where it's expecting a tuple of arguments.  Apparently you should
> be calling submit multiple times, once for each function.
>
> As for the error you get when you do that, please post the full
> traceback. I suspect that the message you did post has a typo in it, or
> that the error occurred when your source code was not as you show it
> here.  You have two variables end and end2, and only the first one is
> ever declared global.  func2() should get a different error when you run
> it; since it tries to use a local end2 before defining it.
>
> I recommend always testing your code with a single thread before trying
> to launch more complex multithread stuff.  Just call func() and func2(),
> and see if they complete, and get reasonable answers.
>
> --
>
> DaveA

There are no imports other than defined on the script, which are;

import pygame
import sys
import time
import math
import pp

You are correct about  trying to pass two functions and second one is
in place where a tuple of arguments supposed to be. But what if these
functions don't have any arguments ? I tested functions test1() and
test2() seperately ; they work. Once I figure out how to run these
functions simultaneously, I will add an argument to test2 and try then
on. My main goal is to simultaneously run two functions, one of them
has one argument the other doesn't. To get familiar with parallel
processing I am experimenting now without arguments and then I will
embed the code to my application. I am experimenting with the
following 

Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 8, 6:00 pm, Chris Angelico  wrote:
> On Mon, Jan 9, 2012 at 2:45 AM, Yigit Turgut  wrote:
> > job1 = job_server.submit(test1,())
> > job2 = job_server.submit(test2())
>
> The first of these passes test1 and an empty tuple as arguments to
> submit(). The second calls test2 with no arguments, then passes its
> return value to submit(), which is not what you want to do.
>
> Chris Angelico

Yes that's correct but (test1,()) doesn't do any good since it doesn't
execute the loop.

screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
start = time.time()
end = time.time() - start
end2= time.time() - start

def test1():
  global end
  global white
  while(end<5):
end = time.time() - start
timer.tick(4) #FPS
screen.fill((255,255,255) if white else (0, 0, 0))
white = not white
pygame.display.update()

def test2():
  global end2
  while(end2<5):
end2 = time.time() - start
print end2

ppservers = ()
job_server = pp.Server(ppservers=ppservers)

job1 = job_server.submit(test1, (), globals=globals())
job2 = job_server.submit(test2, (), globals=globals())
result = job1()
result2 = job2()

print  result2

job_server.print_stats()

This *supposed to* print values of 'end' and simultaneously execute
test1. Eventhough I set globals parameter and nothing seems to be
wrong this code generates the following traceback ;

Starting pp with 2 workers
An error has occured during the function execution
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
__result = __f(*__args)
  File "", line 4, in test1
NameError: global name 'end' is not defined
An error has occured during the function execution
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
__result = __f(*__args)
  File "", line 3, in test2
NameError: global name 'end2' is not defined

How can this be, what am I missing ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 9, 12:02 am, Dave Angel  wrote:
> On 01/08/2012 11:39 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
>
>
> > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
> > timer = pygame.time.Clock()
> > white = True
> > start = time.time()
> > end = time.time() - start
> > end2= time.time() - start
>
> > def test1():
> >global end
> >global white
> >while(end<5):
> >  end = time.time() - start
> >  timer.tick(4) #FPS
> >  screen.fill((255,255,255) if white else (0, 0, 0))
> >  white = not white
> >  pygame.display.update()
>
> > def test2():
> >global end2
> >while(end2<5):
> >  end2 = time.time() - start
> >  print end2
>
> > ppservers = ()
> > job_server = pp.Server(ppservers=ppservers)
>
> > job1 = job_server.submit(test1, (), globals=globals())
> > job2 = job_server.submit(test2, (), globals=globals())
> > result = job1()
> > result2 = job2()
>
> > print  result2
>
> > job_server.print_stats()
>
> > This *supposed to* print values of 'end' and simultaneously execute
> > test1. Eventhough I set globals parameter and nothing seems to be
> > wrong this code generates the following traceback ;
>
> > Starting pp with 2 workers
> > An error has occured during the function execution
> > Traceback (most recent call last):
> >File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
> >  __result = __f(*__args)
> >File "", line 4, in test1
> > NameError: global name 'end' is not defined
> > An error has occured during the function execution
> > Traceback (most recent call last):
> >File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
> >  __result = __f(*__args)
> >File "", line 3, in test2
> > NameError: global name 'end2' is not defined
>
> > How can this be, what am I missing ?
>
> I don't see anything on thehttp://www.parallelpython.com
> <http://www.parallelpython.com/> website that indicates how it handles
> globals.  Remember this is creating a separate process, so it can't
> literally share the globals you have.  i would have expected it to
> pickle them when you say globals=globals(), but I dunno. In any case, I
> can't see any value in making end global with the "global" statement.
> I'd move the end= line inside the function, and forget about making it
> global.

globals=globals() works but not for each variable (lol). Some of them
gets recognized and some don't for some reason I couldn't figure out
yet. But that's the main scheme.
>
> The other thing you don't supply is a list of functions that might be
> called by your function.  See the depfuncs argument.  It probably
> handles all the system libraries, but I can't see how it'd be expected
> to handle pygame.

depfuncs passes the dependent functions that will/might be used at the
execution phase of the called function. PP doesn't require to set
modules for basic I/O,sys etc. Only 3rd party ones like numpy, scipy
and so on.
>
> With the limited information supplied by the website, I'd experiment
> first with simpler things.  Make two functions that are self-contained,
> and try them first.  No global statements, and no calls to pygame.
> After that much worked, then I'd try adding arguments, and then return
> values.
>

That's what I did. After investigating similar approaches to achieve
the task, I unconsciously developed an idea that 'this is not going to
be easy' and approached with that perception. Now I realize that it's
much more simple than I thought. The work it does is complex but it
requires very little effort to operate functionally.

> Then i'd try calling separate functions (declaring them in depfuncs).
> And finally I'd try some 3rd party library.

Don't think will try another package for the same task. I am now
moving on to PP + PyCUDA to harness GPU available CPU cores.

Thank you for the guidance.

On Jan 9, 2:02 am, David Hoese  wrote:
> On 1/8/12 1:45 PM, Yigit Turgut  wrote:
>
> > There are no imports other than defined on the script, which are;
>
> > import pygame
> > import sys
> > import time
> > import math
> > import pp
>
> > You are correct about  trying to pass two functions and second one is
> > in place where a tuple of arguments supposed to be. But what if these
> > functions don't have any arguments ? I tested functions test1() and
> > test2() seperately ; th

Plot square wave

2012-01-18 Thread Yigit Turgut
Hi all,

I am trying to generate a pseudo pwm signal, low-high transition will
take place when screen goes from black to white and high-low
transition when white to black. As a result I am trying to plot the
signal. Here is my code;

import time, pylab, numpy, scipy, pygame

def _func1():
 global end
 global white
 global k
 global t
 global i
 k = numpy.arange(4)
 t = numpy.arange(4)
 i = 0
 f = open("test.txt", "w")
 white = True
 start = time.time()
 end = time.time() - start
 screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
 timer = pygame.time.Clock()
 test = repr(time.time())
 while(end<8.00):
  end = time.time() - start
  if white:
screen.fill((255, 255, 255))
time.sleep(1)
k[i] = 0
t[i] = end
f.write(str(t[i]) + "\t" + str(k[i]) + "\n")
i = i + 1
print repr(end)

  else:
screen.fill((0, 0, 0))
time.sleep(1)
k[i] = 1
t[i] = end
f.write(str(t[i]) + "\t" + str(k[i]) + "\n")
i =  i+ 1
print repr(end)

  white = not white
  pygame.display.update()
 pygame.quit()

if __name__ == "__main__":
  _func1()
  time,data = numpy.loadtxt('test.txt', unpack=True)
  print k
  print t
  print i
  pylab.plot(time,data)
  pylab.show()


Problem is I get a sawtooth instead of a square wave. I know that I
need to define points between 0,1,2 time integer values to achieve
this. But I hope there is a python trick that will yield this
time,data plot to a square wave?

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


Weird Loop Behaviour

2012-01-20 Thread Yigit Turgut
Hi,

In the following code, I am trying to run "black" screen for 3 seconds
and respectively 2 seconds "white" screen. Black routine takes 3
seconds and white 2 seconds, 2 x black + white = 8 seconds which
should be the expected value but when I run it I get black-white-black-
white   instead of black-white-black. Couldn't figure out what is
wrong thus sharing the code as well ;

white = False
 while(end<8.00):
  end = time.time() - start
  if white:
   screen.fill((255, 255, 255))
time.sleep(2)
  else:
screen.fill((0, 0, 0))
time.sleep(3)
  white = not white
  pygame.display.update()
 pygame.quit()
-- 
http://mail.python.org/mailman/listinfo/python-list


Splitting a file from specific column content

2012-01-22 Thread Yigit Turgut
Hi all,

I have a text file approximately 20mb in size and contains about one
million lines. I was doing some processing on the data but then the
data rate increased and it takes very long time to process. I import
using numpy.loadtxt, here is a fragment of the data ;

0.06 -0.0004
0.71 0.0028
0.79 0.0044
0.86 0.0104
.
.
.

First column is the timestamp in seconds and second column is the
data. File contains 8seconds of measurement, and I would like to be
able to split the file into 3 parts seperated from specific time
locations. For example I want to divide the file into 3 parts, first
part containing 3 seconds of data, second containing 2 seconds of data
and third containing 3 seconds. Splitting based on file size doesn't
work that accurately for this specific data, some columns become
missing and etc. I need to split depending on the column content ;

1 - read file until first character of column1 is 3 (3 seconds)
2 - save this region to another file
3 - read the file where first characters  of column1 are between 3 to
5 (2 seconds)
4 - save this region to another file
5 - read the file where first characters  of column1 are between 5 to
5 (3 seconds)
6 - save this region to another file

I need to do this exactly because numpy.loadtxt or genfromtxt doesn't
get well with missing columns / rows. I even tried the invalidraise
parameter of genfromtxt but no luck.

I am sure it's a few lines of code for experienced users and I would
appreciate some guidance.

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


Re: Splitting a file from specific column content

2012-01-22 Thread Yigit Turgut
On Jan 22, 4:45 pm, Roy Smith  wrote:
> In article
> ,
>  Yigit Turgut  wrote:

> > Hi all,
>
> > I have a text file approximately 20mb in size and contains about one
> > million lines. I was doing some processing on the data but then the
> > data rate increased and it takes very long time to process. I import
> > using numpy.loadtxt, here is a fragment of the data ;
>
> > 0.06-0.0004
> > 0.710.0028
> > 0.790.0044
> > 0.860.0104
> > .
> > .
> > .
>
> > First column is the timestamp in seconds and second column is the
> > data. File contains 8seconds of measurement, and I would like to be
> > able to split the file into 3 parts seperated from specific time
> > locations. For example I want to divide the file into 3 parts, first
> > part containing 3 seconds of data, second containing 2 seconds of data
> > and third containing 3 seconds.
>
> I would do this with standard unix tools:
>
> grep '^[012]' input.txt > first-three-seconds.txt
> grep '^[34]' input.txt > next-two-seconds.txt
> grep '^[567]' input.txt > next-three-seconds.txt
>
> Sure, it makes three passes over the data, but for 20 MB of data, you
> could have the whole job done in less time than it took me to type this.
>
> As a sanity check, I would run "wc -l" on each of the files and confirm
> that they add up to the original line count.

This works and is very fast but it missed a few hundred lines
unfortunately.

On Jan 22, 5:19 pm, MRAB  wrote:
> On 22/01/2012 14:32, Yigit Turgut wrote:
> > Hi all,
>
> > I have a text file approximately 20mb in size and contains about one
> > million lines. I was doing some processing on the data but then the
> > data rate increased and it takes very long time to process. I import
> > using numpy.loadtxt, here is a fragment of the data ;
>
> > 0.06-0.0004
> > 0.710.0028
> > 0.790.0044
> > 0.860.0104
> > .
> > .
> > .
>
> > First column is the timestamp in seconds and second column is the
> > data. File contains 8seconds of measurement, and I would like to be
> > able to split the file into 3 parts seperated from specific time
> > locations. For example I want to divide the file into 3 parts, first
> > part containing 3 seconds of data, second containing 2 seconds of data
> > and third containing 3 seconds. Splitting based on file size doesn't
> > work that accurately for this specific data, some columns become
> > missing and etc. I need to split depending on the column content ;
>
> > 1 - read file until first character of column1 is 3 (3 seconds)
> > 2 - save this region to another file
> > 3 - read the file where first characters  of column1 are between 3 to
> > 5 (2 seconds)
> > 4 - save this region to another file
> > 5 - read the file where first characters  of column1 are between 5 to
> > 5 (3 seconds)
> > 6 - save this region to another file
>
> > I need to do this exactly because numpy.loadtxt or genfromtxt doesn't
> > get well with missing columns / rows. I even tried the invalidraise
> > parameter of genfromtxt but no luck.
>
> > I am sure it's a few lines of code for experienced users and I would
> > appreciate some guidance.
>
> Here's a solution in Python 3:
>
> input_path = "..."
> section_1_path = "..."
> section_2_path = "..."
> section_3_path = "..."
>
> with open(input_path) as input_file:
>  try:
>  line = next(input_file)
>
>  # Copy section 1.
>  with open(section_1_path, "w") as output_file:
>  while line[0] < "3":
>  output_file.write(line)
>  line = next(input_file)
>
>  # Copy section 2.
>  with open(section_2_path, "w") as output_file:
>  while line[5] < "5":
>  output_file.write(line)
>  line = next(input_file)
>
>  # Copy section 3.
>  with open(section_3_path, "w") as output_file:
>  while True:
>  output_file.write(line)
>  line = next(input_file)
>  except StopIteration:
>  pass

With the following correction ;

while line[5] < "5":
should be
while line[0] < "5":

This works well.

On Jan 22, 5:39 pm, Arnaud Delobelle  wrote:
> On 22 January 2012 15:19, MRAB  wrote:
> > Here's a solution in Python 3:
>
> > input_path = "..."
>

Re: Splitting a file from specific column content

2012-01-22 Thread Yigit Turgut
On Jan 22, 6:56 pm, MRAB  wrote:
> On 22/01/2012 16:17, Yigit Turgut wrote:
> [snip]
>
>
>
>
>
>
>
> > On Jan 22, 5:39 pm, Arnaud Delobelle  wrote:
> [snip]
> >>  Or more succintly (but not tested):
>
> >>  sections = [
> >>      ("3", "section_1")
> >>      ("5", "section_2")
> >>      ("\xFF", "section_3")
> >>  ]
>
> >>  with open(input_path) as input_file:
> >>      lines = iter(input_file)
> >>      for end, path in sections:
> >>          with open(path, "w") as output_file:
> >>              for line in lines:
> >>                  if line>= end:
> >>                      break
> >>                  output_file.write(line)
>
> >>  --
> >>  Arnaud
>
> > Good idea. Especially when dealing with variable numbers of sections.
> > But somehow  I got ;
>
> >      ("5", "section_2")
> > TypeError: 'tuple' object is not callable
>
> That's due to missing commas:
>
> sections = [
>      ("3", "section_1"),
>      ("5", "section_2"),
>      ("\xFF", "section_3")
> ]

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


Re: Splitting a file from specific column content

2012-01-22 Thread Yigit Turgut
On Jan 22, 9:37 pm, Roy Smith  wrote:
> On Jan 22, 2012, at 2:34 PM, Tim Chase wrote:
>
> > On 01/22/12 13:26, Roy Smith wrote:
> >>> If you wanted to do it in one pass using standard unix
> >>> tools, you can use:
>
> >>> sed -n -e'/^[0-2]/w first-three.txt' -e'/^[34]/w
> >>> next-two.txt' -e'/^[5-7]/w next-three.txt'
>
> >> I stand humbled.
>
> > In all likelyhood, you stand *younger*, not so much humbled ;-)
>
> Oh, yeah?  That must explain my grey hair and bifocals.   I go back to Unix 
> v6 in 1977.  Humbled it is.

Those times were much better IMHO (:
-- 
http://mail.python.org/mailman/listinfo/python-list