Go to advanced search

by paddyg
Wed May 22, 2019 5:12 pm
Forum: Python
Topic: Using C code on python: GPU_FFT
Replies: 1
Views: 78

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: 87

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: 208

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: 208

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: 64

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: 208

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...
by paddyg
Sun Apr 14, 2019 10:09 am
Forum: Python
Topic: Creating array for filtered data
Replies: 4
Views: 211

Re: Creating array for filtered data

OK I've looked a bit harder at your question and understand that you want to use the BioSPPy module. That is much more sensible than my suggestion to DIY filter with numpy or scipy. In answer to your questions. You can indeed write to elements of a numpy array one at a time but it's also very quick ...
by paddyg
Sat Apr 13, 2019 6:23 pm
Forum: Python
Topic: Creating array for filtered data
Replies: 4
Views: 211

Re: Creating array for filtered data

make y a numpy ndarray then use numpy fft. But.. you will need to take a short timeout to get used to numpy if you are new to it.
by paddyg
Wed Apr 03, 2019 9:49 pm
Forum: Python
Topic: Create Bounding Boxes in pi3d
Replies: 1
Views: 101

Re: Create Bounding Boxes in pi3d

In case anyone arrives here via a web search - there is some discussion and answers on github here

Paddy
by paddyg
Tue Apr 02, 2019 7:55 am
Forum: Python
Topic: Play tone without generating wave data beforehand
Replies: 7
Views: 223

Re: Play tone without generating wave data beforehand

Duh - I've just noticed that there's a comment in the original code explaining that the mixer is initiated to use sixteen bit signed values :oops: !! So that uint32 should be int16 and the shuffling to keep positive isn't needed. I will repost a revised version here in a bit... here import pygame, t...
by paddyg
Mon Apr 01, 2019 9:57 pm
Forum: Python
Topic: Play tone without generating wave data beforehand
Replies: 7
Views: 223

Re: Play tone without generating wave data beforehand

numpy could generate the array quickly, and output the result as raw bytes with very little overhead. I'm not sure of the internals of pygame mixer but I think it can create a Sound object from a bytes buffer. I will have a quick look at the docs for you. this is some modified code I found on the py...
by paddyg
Tue Mar 19, 2019 8:43 am
Forum: Python
Topic: [SOLVED] Handling Ctrl-C / Kill in threads
Replies: 6
Views: 482

Re: Handling Ctrl-C / Kill in threads

Not sure if it's applicable wrt signal stuff but I usually either set daemon = True or try catch KeyboardInterrupt depending on what tidying up needs doing. import time import threading def f1(): while True: time.sleep(1.0) print('stopping because of daemon kill') # will never get here def f2(a): wh...
by paddyg
Thu Mar 07, 2019 9:01 am
Forum: Other programming languages
Topic: Anyone using Rust on a PI ?
Replies: 24
Views: 1978

Re: Anyone using Rust on a PI ?

For further clarification (of the "drinking more tea produces better code" variety), despite @gavin's assertion, I found rust build times universally longer than gcc... but not long enough to put the kettle on.
by paddyg
Tue Mar 05, 2019 8:59 am
Forum: Other programming languages
Topic: Anyone using Rust on a PI ?
Replies: 24
Views: 1978

Re: Anyone using Rust on a PI ?

Rust is hard to start with but it's worth sticking it out (imo). To make myself fight my way through it I started the process of converting the pi3d python module to Rust. see here https://github.com/paddywwoof/rust_pi3d I also did a test compiling an image processing thing for python access here ht...
by paddyg
Wed Feb 27, 2019 10:39 pm
Forum: Python
Topic: Part Of Script Not Writing To a File
Replies: 3
Views: 211

Re: Part Of Script Not Writing To a File

As a general point; it's much better to use the 'with open(...) as file:' structure (as you do to read the csv file). That way you won't forget to close the file. Not sure that's what the problem is but better to tidy that up. PS, in my opinion it's much nicer to use the format with curly brackets s...
by paddyg
Mon Feb 25, 2019 10:28 pm
Forum: Python
Topic: Low FPS, Rasberrry 3b+, CSI camera V2.1
Replies: 1
Views: 397

Re: Low FPS, Rasberrry 3b+, CSI camera V2.1

Probably alternative simpler methods but I did something a while ago (based on the picam docs I think) that used a io.BytesIO and a thread pool to up the frame rate. https://github.com/pi3d/pi3d_demos/blob/master/camera_envsphere_fast.py I wanted to get the frames as numpy arrays so there's complica...
by paddyg
Sun Feb 17, 2019 10:59 pm
Forum: Python
Topic: What is a dot operator in Python? And how powerful is it!?
Replies: 1
Views: 164

Re: What is a dot operator in Python? And how powerful is it!?

yes. but I suggest you read the docs as there is a confusion where dots can also be used as dividers in module structures. but can't be mixed in the same statement ie
PIL.Image.load()
by paddyg
Tue Feb 12, 2019 7:24 pm
Forum: Python
Topic: ACS712+MCP3008 - Need help to convert bit values to current values
Replies: 14
Views: 610

Re: ACS712+MCP3008 - Need help to convert bit values to current values

@stef1571, well done for getting it working - more involved than you (or I) first appreciated. Hopefully you've not cooked your spi pin by feeding it 5V! This might not matter much for your app but may be relevant to others following you. In your code you round the voltage to two places before using...
by paddyg
Sun Feb 10, 2019 10:10 pm
Forum: Python
Topic: tkinter Drop Down Menu Program (convert to Python 3)
Replies: 5
Views: 463

Re: tkinter Drop Down Menu Program (convert to Python 3)

I think the idea of "import ... *" is a grave mistake anyway. https://www.python.org/dev/peps/pep-0008/#imports better to make it clear where things come from rather than making them 'just' appear.. import tkinter as tk root = tk.Tk() root.title("Tk Drop Down Menu") mainframe = tk.Frame(root) mainfr...
by paddyg
Sun Feb 10, 2019 6:36 pm
Forum: Python
Topic: Read from CSV to part of my code (attached)
Replies: 32
Views: 1219

Re: Read from CSV to part of my code (attached)

As @B.Goode says the error is almost certainly because of badly formed json file... If you trustingly copied my example then this will definitely be the case because I stupidly copied the text from the python console - rather than the actual file - where the double quotes had been converted to singl...
by paddyg
Sat Feb 09, 2019 10:26 pm
Forum: Python
Topic: subprocess question
Replies: 3
Views: 195

Re: subprocess question

Hi, critically you don't show the run() statements for A and B options. You might get the behavior you describe if you kept 'shell=True', which you probably don't want for passing a list of strings. i.e.

Code: Select all

subprocess.run(a)
should work
by paddyg
Sat Feb 09, 2019 9:26 pm
Forum: Python
Topic: Read from CSV to part of my code (attached)
Replies: 32
Views: 1219

Re: Read from CSV to part of my code (attached)

Hi, the simplest way would be to just use very basic csv with the first commas dividing the parts of the uid and subsequent ones used for name, number, phone etc. i.e. 77, 106, 39, 242, 242, A44B, Smith, +44 7654 123456 237, 30, 40, 160, 123, U13Z, Jones, +44 7777 654321 However this then restricts ...
by paddyg
Sat Feb 09, 2019 7:17 am
Forum: Python
Topic: Finishing list iteration before exception
Replies: 2
Views: 125

Re: Finishing list iteration before exception

put pass in the except (really you should only pass for the specific exception not generally) then move driver.refresh() to after the for loop.
by paddyg
Fri Feb 08, 2019 10:27 pm
Forum: Python
Topic: Read from CSV to part of my code (attached)
Replies: 32
Views: 1219

Re: Read from CSV to part of my code (attached)

Well that structure is pretty unhelpful for parsing. Are you stuck with that or could you simplify it, or switch to json? Anyway if stuck you could do something along the lines of my_uids = [] with open("csv.txt", "r") as file: line = file.readline() csv = line.split(',')[:5] my_uids.append([int(n.s...
by paddyg
Fri Feb 08, 2019 8:53 pm
Forum: Python
Topic: Read from CSV to part of my code (attached)
Replies: 32
Views: 1219

Re: Read from CSV to part of my code (attached)

maybe post an example of the csv file and what you want extract. There are python modules to parsing csv but what you describe sounds pretty simple. If you only want the first four 'bits' of the csv line you can do this kind of thing ... csv = line.split(',')[:4] my_uids.append(list(map(int, csv)))

Go to advanced search