Go to advanced search

by paddyg
Wed Jun 19, 2019 8:00 pm
Forum: Python
Topic: Problem with function set_background or set_material in pi3d
Replies: 3
Views: 90

Re: Problem with function set_background or set_material in pi3d

glad you sorted it. It is a bit inconsistent but the reason it evolved that way is because the GPU colour and alpha values are floats 0.0 to 1.0 so the numbers you feed into Display.create() just get passed on in opengles functions. Textures, however, generally get their values from image files or P...
by paddyg
Tue Jun 18, 2019 8:45 am
Forum: Python
Topic: Importing python code from a sub-folder
Replies: 6
Views: 195

Re: Importing python code from a sub-folder

The 'neateast' way is probably using python module structure but it's additional complexity if you've not worked with modules before.
by paddyg
Mon Jun 17, 2019 2:55 pm
Forum: Python
Topic: Snap an object to the camera in pi3d
Replies: 2
Views: 120

Re: Snap an object to the camera in pi3d

Good question, and also a good - not so obvious - reason for Unity's system of structuring GameObjects, Rigidbodies etc. In pi3d the Camera object doesn't have the GameObject functionality that Shape class has i.e. the parent/child hierarchy. This is because, under the skin, the matrices for convert...
by paddyg
Fri Jun 14, 2019 11:07 am
Forum: Python
Topic: [Solved] Is it possible to control OMXplayer based on time in Python?
Replies: 4
Views: 202

Re: Is it possible to control OMXplayer based on time in Python?

Hi, back at a normal computer now so can type more than one garbled sentence! I'm not sure the most efficient way to do the non-blocking key input. I've used curses in the past which is pretty easy but sometimes seems to produce odd side-effects. As you intend to do this with GPIO input in your 'pro...
by paddyg
Wed Jun 12, 2019 9:05 pm
Forum: Python
Topic: [Solved] Is it possible to control OMXplayer based on time in Python?
Replies: 4
Views: 202

Re: Is it possible to control OMXplayer based on time in Python?

Not got a computer so can't really look at your code properly but does your input() block execution until it gets an enter key?
by paddyg
Sun Jun 02, 2019 1:05 pm
Forum: Python
Topic: controlling number of times loop is executed?
Replies: 12
Views: 615

Re: controlling number of times loop is executed?

I don't think python 2 has built in symbolic maths (but might be wrong) so it must be built in formatting in the implementation of print. Normally that's good but sometimes it might be bad so they changed it... The python3 version is probably what the floats actually are, so less scope for confusion.
by paddyg
Sun Jun 02, 2019 12:43 pm
Forum: Python
Topic: Emergency Action Required by RPi Foundation
Replies: 31
Views: 1195

Re: Emergency Action Required by RPi Foundation

OK I admit it's not really an emergency as such. It's just that an awful lot of people getting into 'making' aren't coders and choose python because it's accessible and (relatively) easy to get the hang of. A non-negligible proportion of questions I've answered on this forum and elsewhere have had t...
by paddyg
Sun Jun 02, 2019 11:35 am
Forum: Python
Topic: Trying to make a speedometer using hall effect sensor and a neodym magnet
Replies: 7
Views: 195

Re: Trying to make a speedometer using hall effect sensor and a neodym magnet

I once had one of those wheels where the hub rotates at a different frequency from the rim, but I was flying through the air at the time so couldn't study it. The wheel was a write-off but I escaped with only a broken finger.
by paddyg
Sat Jun 01, 2019 4:51 pm
Forum: Python
Topic: Little help needed to convert a date string
Replies: 4
Views: 186

Re: Little help needed to convert a date string

I tend to use time.localtime() which has tm_year, tm_mon etc that you can use as you want, along the lines of

Code: Select all

dt = time.time() - 7 * 24 * 3600
dt_s = time.localtime(dt)
print("seven days ago would be {}:{}:{}".format(dt_s.tm_year, dt_s.tm_mon, dt_s.tm_mday))
by paddyg
Sat Jun 01, 2019 3:16 pm
Forum: Python
Topic: Emergency Action Required by RPi Foundation
Replies: 31
Views: 1195

Re: Emergency Action Required by RPi Foundation

So when I used the word lunacy I meant a policy that can say The long term goal for Debian is to reduce this to one stack, dropping the Python 2 stack at some time; the binary package python will represent the current default Debian Python 2 version Presumably that means that in the near future peop...
by paddyg
Sat Jun 01, 2019 2:50 pm
Forum: Python
Topic: Emergency Action Required by RPi Foundation
Replies: 31
Views: 1195

Re: Emergency Action Required by RPi Foundation

But on page 2 they say ``the binary package python will represent the current default Debian Python 2 version.`` how does that fit with their intention to just support the python3 stack!!?? But other flavours of linux ( redhat , arch , etc) don't necessarily follow the same line and python users don...
by paddyg
Sat Jun 01, 2019 2:15 pm
Forum: Python
Topic: Emergency Action Required by RPi Foundation
Replies: 31
Views: 1195

Emergency Action Required by RPi Foundation

see https://pythonclock.org/ I had assumed that, at some point early in 2019, typing ``python`` on the command line would stop producing python2 and start producing python3. Similarly ``pip`` would stop meaning pip2 and start meaning pip3, idle would mean idle3 etc etc. Presumably that's what will h...
by paddyg
Sat Jun 01, 2019 1:49 pm
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

Essentially doesn't make any difference, in this case - sometimes the python syntax is quicker, sometimes slower! See import timeit setup = ''' import numpy as np a = np.random.rand(24_000) + np.random.rand(24_000) * 1j ''' fns = [''' b = a.real ** 2 + a.imag ** 2 ''', ''' c = np.add(np.square(a.rea...
by paddyg
Sat Jun 01, 2019 8:13 am
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

Installing modules is the worst aspect of python by a long way: complicated by the fact that there are two incompatible versions maintained in parallel, and that the default (if you type 'python' on raspbian it uses python2) is not going to be supported in a few months time! Your data looks pretty c...
by paddyg
Fri May 31, 2019 11:42 pm
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

Hi, that looks interesting. What are the characteristics of the data stream and the pulse? i.e. how much noise is there and can the pulse be determined by looking at a short length (10 values) or do you have to check that it remains high for 2048 values as you say? Is the pulse always relative to th...
by paddyg
Fri May 31, 2019 1:44 pm
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

Ah, now you mention *that* it sounds like convolution might be what you want! There's numpy.convolve and various scipy functions. By using something like that you can get round the for loop over value of m (and therefor speed things up. If you have to upgrade your processor to make the loop system f...
by paddyg
Fri May 31, 2019 7:32 am
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

PS python can use ranges that count backwards using step -1 and just as with positive steps it starts with the first value and stops the iteration before equaling the last value... but the way you are doing it will run into problems getting to the zeroth index: # if m == 12 pwr[m-9:m] #=> pwr[3:12:1...
by paddyg
Thu May 30, 2019 11:17 pm
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

Hi, yes, if you find yourself using loops then probably you should not use numpy - apart from things like the moving sum thing you're using. If your final problem is along the lines of your example (2,2,2,20) array then using standard python arrays will be simpler and faster (though time obviously i...
by paddyg
Tue May 28, 2019 11:33 pm
Forum: Python
Topic: trouble adding a subset of matrix elements (numpy)
Replies: 13
Views: 511

Re: trouble adding a subset of matrix elements (numpy)

You basically don't use loops with numpy. If you do it is much less efficient and is slower than standard python. #you can create a view on your array like this pwr_slice = pwr[:,:,:,9:] #and an index of all the values > 5 like this ix = pwr_slice < 4 # and sum the slice at those indexes like this n...
by paddyg
Wed May 22, 2019 5:12 pm
Forum: Python
Topic: Using C code on python: GPU_FFT
Replies: 1
Views: 114

Re: Using C code on python: GPU_FFT

Hi, I don't know about that library specifically but, generally speaking, linking shared objects (i.e. C functions compiled to executable code) from python is pretty easy using ctypes seem some examples of linking in different versions of the same code in different ways https://github.com/paddywwoof...
by paddyg
Fri Apr 26, 2019 11:41 am
Forum: Python
Topic: Get filter kernel from output signal?
Replies: 1
Views: 100

Re: Get filter kernel from output signal?

I think that it's possible because it acts linearly so 'just' a matter of solving simultaneous equations. Things that would make it difficult would be a) knowing the size of the kernel b) edge behavior, which is related to a. as the default edge behavior would tell you the size of the kernel. c) lac...
by paddyg
Thu Apr 25, 2019 1:43 pm
Forum: Python
Topic: How can I convert x axis from sample to time?
Replies: 5
Views: 241

Re: How can I convert x axis from sample to time?

Yep that's what the first line means: linspace(... produces 500 values linearly spaced between 0.0 and 3.0 which is your time axis. I'm not sure how you intend to determine pulse rate (I would have thought the specially designed module you mentioned in another post would have been a good option) but...
by paddyg
Tue Apr 23, 2019 8:30 pm
Forum: Python
Topic: How can I convert x axis from sample to time?
Replies: 5
Views: 241

Re: How can I convert x axis from sample to time?

The best thing to do is stick some print() statements in and see what data you're getting and what's happening to it. As a guess from where I stand I would see if the x scale of the plot was set up to match the time values you are generating. I would probably try x = np.linspace(0.0, 3.0, 500) y = n...
by paddyg
Mon Apr 22, 2019 11:55 am
Forum: Python
Topic: openCV2 putText for certain time only
Replies: 1
Views: 84

Re: openCV2 putText for certain time only

there is probably some more code for your application which would be relevant to an actual answer. But in general something like SHOW_TM = 3.0 ... while do_loop: if check_condition_a(): # whatever triggers showing of text cv2.putText(... text_showing = True text_off = time.time() + SHOW_TM ... if te...
by paddyg
Mon Apr 22, 2019 11:45 am
Forum: Python
Topic: How can I convert x axis from sample to time?
Replies: 5
Views: 241

Re: How can I convert x axis from sample to time?

I think I would use time.time() to get actual times as time.sleep() is rather vague and there's lots of other stuff to delay the loop. Something along the lines of: def St(): ylist = [] tlist = [] for _ in range(500): reading = analog_read(0) voltage = reading * 3.3 / 4096 time.sleep(0.005) ylist.ap...

Go to advanced search