Csound Csound-dev Csound-tekno Search About

[Csnd] python question

Date2012-02-04 01:24
Fromluis jure
Subject[Csnd] python question

hello list, i hope this is not completely OT, since python is so well 
integrated into csound.

be warned that i'm a complete beginner, i'm just trying to teach myself the
basics reading a few tutorials.

here's my question: i defined a function with a list as its only
parameter, and at certain point i need to retrieve the actual name of the
list passed as argument.

for example:

def my_function(my_list):
	# some code processing the list

when i call my_function(foo), foo being a list, i need to print the name
"foo" as a string, but i have no idea how. any hints from the gurus?

thank you,

lj

Date2012-02-04 02:01
FromOlivier Bélanger
SubjectRe: [Csnd] python question
Hi Luis,

There is no easy way to retrieve a variable's name as a string. What I would do in this case is to create my own class
inherited from the class "list" and add an attribute for the name of the variable:

class MyList(list):
    def __init__(self, name, val):
        list.__init__(self, val)
        self.__name__ = name

Now, when you create your list, you give the actual list as "val" argument and the name of the variable, as a string, to "name":

foo = MyList("foo", [1,2,3,4,5])

In your function, you can use your variable like a normal list and you can print the content of the attribute __name__:

def some_function(l):
    print "value =", l
    print "name =", l.__name__

some_function(foo)

value = [1, 2, 3, 4, 5]
name = foo

Hope that helps,

Olivier

2012/2/3 luis jure <ljc@internet.com.uy>


hello list, i hope this is not completely OT, since python is so well
integrated into csound.

be warned that i'm a complete beginner, i'm just trying to teach myself the
basics reading a few tutorials.

here's my question: i defined a function with a list as its only
parameter, and at certain point i need to retrieve the actual name of the
list passed as argument.

for example:

def my_function(my_list):
       # some code processing the list

when i call my_function(foo), foo being a list, i need to print the name
"foo" as a string, but i have no idea how. any hints from the gurus?

thank you,

lj


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-02-04 08:32
FromDennis Raddle
SubjectRe: [Csnd] python question
You should probably tell us more about your problem because it is very likely you are thinking about this problem in a way that is not natural to the language.

Dennis

On Fri, Feb 3, 2012 at 5:24 PM, luis jure <ljc@internet.com.uy> wrote:


hello list, i hope this is not completely OT, since python is so well
integrated into csound.

be warned that i'm a complete beginner, i'm just trying to teach myself the
basics reading a few tutorials.

here's my question: i defined a function with a list as its only
parameter, and at certain point i need to retrieve the actual name of the
list passed as argument.

for example:

def my_function(my_list):
       # some code processing the list

when i call my_function(foo), foo being a list, i need to print the name
"foo" as a string, but i have no idea how. any hints from the gurus?

thank you,

lj


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-02-04 10:56
Fromluis jure
SubjectRe: [Csnd] python question
on 2012-02-04 at 00:32 Dennis Raddle wrote:

>You should probably tell us more about your problem because it is very
>likely you are thinking about this problem in a way that is not natural to
>the language.

well, independently of the language, i want to perform a certain task,
that i tried to describe in my previous mail: i have a list of values, and
i need a function that processes the list in some way and outputs a string
of text. this string has to include the name of the list. i prefer to
think about this problem in general terms: i could be processing text to
generate csound scores, or lilypond code, or whatever. apparently, there's
no direct and trivial way to do this in python. i searched quite a lot
before asking on the list, and olivier's answer seems to confirm my
impression.

best,

lj

Date2012-02-04 10:57
Fromluis jure
SubjectRe: [Csnd] python question
on 2012-02-03 at 21:01 Olivier Bélanger wrote:

>There is no easy way to retrieve a variable's name as a string. 

i see... 

well, thanks a lot olivier for your example, it was very instructive. but
since it's not easy to retrieve the name of the variable, i think i might
just as well pass two arguments to the function: the list, and a string
with its name. and that's that... not very elegant, but it'll do.

best,

lj


Date2012-02-04 12:28
FromRichard Dobson
SubjectRe: [Csnd] python question
On 04/02/2012 10:57, luis jure wrote:
>
> on 2012-02-03 at 21:01 Olivier Bélanger wrote:
>
>> There is no easy way to retrieve a variable's name as a string.
>
> i see...
>
> well, thanks a lot olivier for your example, it was very instructive. but
> since it's not easy to retrieve the name of the variable, i think i might
> just as well pass two arguments to the function: the list, and a string
> with its name. and that's that... not very elegant, but it'll do.
>

The namespaces problem makes this more than a little tricky (same names 
used in different scopes or namespaces - think of how many places you 
may be using the name 'i'). It is discussed (with proposed solution) here:

http://pythonic.pocoo.org/2009/5/30/finding-objects-names

Which is enough to suggest to me that your solution combining a list 
with its name really is the most elegant option.

Richard Dobson


Date2012-02-04 12:59
Fromluis jure
SubjectRe: [Csnd] python question
on 2012-02-04 at 12:28 Richard Dobson wrote:

>Which is enough to suggest to me that your solution combining a list 
>with its name really is the most elegant option.

by now i'm totally convinced of that. mainly because at my newbie stage,
i'm in no condition to even think of anything more sophisticated than
that...

thanks to all that responded! i think it would be a good idea to subscribe
to a python-specific mailing list. i'm having great fun learning the
language, and i'm liking it very much so far. this is the first problem i
encounter where i would have wished for a more direct and elegant solution.

best,


lj


Date2012-02-04 14:12
FromOlivier Bélanger
SubjectRe: [Csnd] python question
A simpler solution could be to put your name into the list and split it inside your function:

foo = ["foo", 1, 2, 3, 4, 5]

def my_func(lst):
    name = lst[0]
    data = lst[1:]

Olivier

2012/2/4 luis jure <ljc@internet.com.uy>

on 2012-02-04 at 12:28 Richard Dobson wrote:

>Which is enough to suggest to me that your solution combining a list
>with its name really is the most elegant option.

by now i'm totally convinced of that. mainly because at my newbie stage,
i'm in no condition to even think of anything more sophisticated than
that...

thanks to all that responded! i think it would be a good idea to subscribe
to a python-specific mailing list. i'm having great fun learning the
language, and i'm liking it very much so far. this is the first problem i
encounter where i would have wished for a more direct and elegant solution.

best,


lj



Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-02-04 22:15
FromDennis Raddle
SubjectRe: [Csnd] python question
Hi Luis,
What I mean is that it's not very common to organize python code in such a way that you need the name of a variable at runtime.

Let's say you had this function:

def process(inputData):
  result1 = do_some_stuff(inputData)
  output_the_data(result1)
  result2 = some_more_processing(result1)
  output_the_data(result2)

The variable names "inputData", "result1", "result2" describe the way those variables relate to the structure of the code *in the local function*. A principle called "encapsulation" means that you want different local areas to know as little about the other parts of the program as possible. So the function "process" knows something about the structure of the data, but it has no need to know from where that data originated. The variables names usually should not be tied to any higher meaning of the data but rather to their function *in a local area*.

The dictionary solution proposed by vallste (as well as Olivier's solution of annotating the data as a list element) are better ways to organize the code.

Let me clarify-- the principle of "encapsulation" is used to make code more robust-- less likely to have bugs, easier to maintain and easier to analyze/understand. It isn't necessarily faster to write the code at first, but it saves a lot of time in the long run.

Dennis

On Sat, Feb 4, 2012 at 2:56 AM, luis jure <ljc@internet.com.uy> wrote:

on 2012-02-04 at 00:32 Dennis Raddle wrote:

>You should probably tell us more about your problem because it is very
>likely you are thinking about this problem in a way that is not natural to
>the language.

well, independently of the language, i want to perform a certain task,
that i tried to describe in my previous mail: i have a list of values, and
i need a function that processes the list in some way and outputs a string
of text. this string has to include the name of the list. i prefer to
think about this problem in general terms: i could be processing text to
generate csound scores, or lilypond code, or whatever. apparently, there's
no direct and trivial way to do this in python. i searched quite a lot
before asking on the list, and olivier's answer seems to confirm my
impression.

best,

lj


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-02-05 10:57
FromDavidW
SubjectRe: [Csnd] python question
xhttp://pythonic.pocoo.org/2009/5/30/finding-objects-names


On 04/02/2012, at 9:57 PM, luis jure wrote:


on 2012-02-03 at 21:01 Olivier Bélanger wrote:

There is no easy way to retrieve a variable's name as a string.

i see...

well, thanks a lot olivier for your example, it was very instructive. but
since it's not easy to retrieve the name of the variable, i think i might
just as well pass two arguments to the function: the list, and a string
with its name. and that's that... not very elegant, but it'll do.

best,

lj


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


________________________________________________
Dr David Worrall.
- Experimental Polymedia:   worrall.avatar.com.au
- Sonification: www.sonification.com.au
- Education for Financial Independence: www.mindthemarkets.com.au








Date2012-02-05 20:08
FromDennis Raddle
SubjectRe: [Csnd] python question


On Sat, Feb 4, 2012 at 2:57 AM, luis jure <ljc@internet.com.uy> wrote:

on 2012-02-03 at 21:01 Olivier Bélanger wrote:

>There is no easy way to retrieve a variable's name as a string.

i see...

well, thanks a lot olivier for your example, it was very instructive. but
since it's not easy to retrieve the name of the variable, i think i might
just as well pass two arguments to the function: the list, and a string
with its name. and that's that... not very elegant, but it'll do.


As I explained a bit in my other post, actually it *IS* more elegant because it provides greater encapsulation. One of these days you are going to modify this code and discover you need a new system for naming and organizing these arrays, and if you tied their function to their variable names you're going to find you have to modify a lot of the code. But if don't tie their function to their variable names it will be easier to modify.

Dennis

Date2012-02-05 20:45
Fromluis jure
SubjectRe: [Csnd] python question
on 2012-02-05 at 12:08 Dennis Raddle wrote:

>As I explained a bit in my other post, actually it *IS* more elegant

yes, i realized that already, it's simpler and more flexible.

thank you dennis, and all of you who took your time to answer my question.



Date2012-02-05 20:45
Fromandreas russo
Subject[Csnd] Hilbert-Huang transform
Hello folks,

as a Csounder, I find the streaming phase vocoder opcodes to be an amazing musical tool.
in a conversation with my father, the Hilbert-Huang transform popped up, and I started thinking about the musical implications it might have.
unlike the FFT, HHT "[...] is designed to work well for data that are nonstationary and nonlinear."

http://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform

that line right there clicked something in my brain.
anybody knows of musical applications of the HHT or even of opcodes under developement?

cheers!

Andreas

Date2012-02-05 20:56
FromVictor Lazzarini
SubjectRe: [Csnd] Hilbert-Huang transform
Well, the Hilbert transform part of this can be performed with 
http://www.csounds.com/manual/html/hilbert.html

Victor
On 5 Feb 2012, at 20:45, andreas russo wrote:

> Hello folks,
> 
> as a Csounder, I find the streaming phase vocoder opcodes to be an amazing musical tool.
> in a conversation with my father, the Hilbert-Huang transform popped up, and I started thinking about the musical implications it might have.
> unlike the FFT, HHT "[...] is designed to work well for data that are nonstationary and nonlinear."
> 
> http://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform
> 
> that line right there clicked something in my brain.
> anybody knows of musical applications of the HHT or even of opcodes under developement?
> 
> cheers!
> 
> Andreas
> 
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie





Date2012-02-05 23:26
FromRichard Dobson
SubjectRe: [Csnd] Hilbert-Huang transform
On first glance, it looks like it would not fit a pvs style 
implementation as it appears not to have an inverse (it is described as 
an adaptive and  "empirically based" algorithm, not as a formula as 
such); it might be more applicable to  a partial-tracking style of 
analysis. I am not competent to follow the maths, but a related issue is 
whether it can be implemented in the pvoc manner of short-time 
overlapping frames. While it is called a transform, which suggests some 
relation to the FFT and HT (etc), it seems really to be a decomposition 
(into amp/freq tracks plus a residual), a different model altogether.


Richard Dobson


On 05/02/2012 20:45, andreas russo wrote:
> Hello folks,
>
> as a Csounder, I find the streaming phase vocoder opcodes to be an amazing musical tool.
> in a conversation with my father, the Hilbert-Huang transform popped up, and I started thinking about the musical implications it might have.
> unlike the FFT, HHT "[...] is designed to work well for data that are nonstationary and nonlinear."
>
> http://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform
>
> that line right there clicked something in my brain.
> anybody knows of musical applications of the HHT or even of opcodes under developement?
>
> cheers!
>
> Andreas
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>


Date2012-02-05 23:44
FromDennis Raddle
SubjectRe: [Csnd] python question


On Sun, Feb 5, 2012 at 12:45 PM, luis jure <ljc@internet.com.uy> wrote:

on 2012-02-05 at 12:08 Dennis Raddle wrote:

>As I explained a bit in my other post, actually it *IS* more elegant

yes, i realized that already, it's simpler and more flexible.

thank you dennis, and all of you who took your time to answer my question.





Okay, sorry I posted again when you already understood it.

I just want to see a beginning programmer headed in the right direction! Programming is a barrel of fun.. you'll probably feel very satisfied as you come to grasp the organizational concepts. Programming -- done well, that is -- is an exercise in organization and thinking clearly about your problem.

Dennis


Date2012-02-06 01:26
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] Hilbert-Huang transform
it would be wonderful to have this as an opcode.

what about wavelets?

Csound 6?

___________________________________

Dr. Richard Boulanger, Ph.D.

Professor of Electronic Production and Design
Professional Writing and Music Technology Division
Berklee College of Music
1140 Boylston Street
Boston, MA 02215-3693

617-747-2485 (office)
774-488-9166 (cell)

____________________________________

____________________________________

____________________________________

On Feb 5, 2012, at 6:26 PM, Richard Dobson wrote:

On first glance, it looks like it would not fit a pvs style implementation as it appears not to have an inverse (it is described as an adaptive and  "empirically based" algorithm, not as a formula as such); it might be more applicable to  a partial-tracking style of analysis. I am not competent to follow the maths, but a related issue is whether it can be implemented in the pvoc manner of short-time overlapping frames. While it is called a transform, which suggests some relation to the FFT and HT (etc), it seems really to be a decomposition (into amp/freq tracks plus a residual), a different model altogether.


Richard Dobson


On 05/02/2012 20:45, andreas russo wrote:
Hello folks,

as a Csounder, I find the streaming phase vocoder opcodes to be an amazing musical tool.
in a conversation with my father, the Hilbert-Huang transform popped up, and I started thinking about the musical implications it might have.
unlike the FFT, HHT "[...] is designed to work well for data that are nonstationary and nonlinear."

http://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform

that line right there clicked something in my brain.
anybody knows of musical applications of the HHT or even of opcodes under developement?

cheers!

Andreas

Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





Send bugs reports to the Sourceforge bug tracker
          https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-02-06 20:52
FromNick Suda
SubjectRe: [Csnd] Hilbert-Huang transform
Relevant:

Found this thread in the Cycling forum when I was doing some research:


User maxplanck makes a convincing argument for Hilbert being the basis of Peter Neubacker's algorithm used in DNA (Melodyne) being Hilbert.

So you're definitely on the same wavelength (no pun intended) in terms of Fourier alternatives.

-Nick

On Sun, Feb 5, 2012 at 5:26 PM, Dr. Richard Boulanger <rboulanger@berklee.edu> wrote:
it would be wonderful to have this as an opcode.

what about wavelets?

Csound 6?

___________________________________

Dr. Richard Boulanger, Ph.D.

Professor of Electronic Production and Design
Professional Writing and Music Technology Division
Berklee College of Music
1140 Boylston Street
Boston, MA 02215-3693

617-747-2485 (office)
774-488-9166 (cell)

____________________________________

____________________________________

____________________________________

On Feb 5, 2012, at 6:26 PM, Richard Dobson wrote:

On first glance, it looks like it would not fit a pvs style implementation as it appears not to have an inverse (it is described as an adaptive and  "empirically based" algorithm, not as a formula as such); it might be more applicable to  a partial-tracking style of analysis. I am not competent to follow the maths, but a related issue is whether it can be implemented in the pvoc manner of short-time overlapping frames. While it is called a transform, which suggests some relation to the FFT and HT (etc), it seems really to be a decomposition (into amp/freq tracks plus a residual), a different model altogether.


Richard Dobson


On 05/02/2012 20:45, andreas russo wrote:
Hello folks,

as a Csounder, I find the streaming phase vocoder opcodes to be an amazing musical tool.
in a conversation with my father, the Hilbert-Huang transform popped up, and I started thinking about the musical implications it might have.
unlike the FFT, HHT "[...] is designed to work well for data that are nonstationary and nonlinear."

http://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform

that line right there clicked something in my brain.
anybody knows of musical applications of the HHT or even of opcodes under developement?

cheers!

Andreas

Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





Send bugs reports to the Sourceforge bug tracker
          https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





--
---------------------------------------------------
Nick Suda ¦ nick.suda@gmail.com
Renton, WA ¦ (425) 941-0093
http://www.nicksuda.com
---------------------------------------------------
--