Re: [Tutor] Introduction to modelling with Python
Eike Welk wrote: On Saturday March 27 2010 16:21:26 AG wrote: I apologise in advance for the vagueness of this query, but I am looking for a decent modern introduction to modelling using Python. Specifically, I want something that is a good introduction (i.e. doesn't expect one to already be a maths/ statistics or a programming guru) and that has an ecology/ environmental science orientation. You should look at the book Python Scripting for Computational Science by Hans Petter Langtangen: http://www.amazon.com/Python-Scripting-Computational-Science- Engineering/dp/3540435085 http://books.google.com/books?id=YEoiYr4H2A0Cprintsec=frontcoverdq=Python+Scripting+for+Computational+Sciencesource=blots=ovp_JKREiYsig=tJkigCLDqS6voOOjmL4xDxw0roMhl=enei=OlWvS8PmE4r94Aa42vzgDwsa=Xoi=book_resultct=resultresnum=5ved=0CBEQ6AEwBA#v=onepageq=f=false It is an introduction to the Python language, and to a big number of tools for numerical computations. The book assumes that you have already some practice in writing computer programs. The book is not oriented towards ecology, the examples are from mechanical engineering. The book is however a bit dated, it's from 2004. Therefore many examples will need to be slightly altered to work with the current versions of the libraries that they use. Alternatively you could ask your question on the Numpy/Scipy mailing lists. These lists are frequented by scientists that use Python for their computations. http://www.scipy.org/Mailing_Lists Eike. ___ Eike I just wanted to come back to you on the book recommendation you made Python scripting for computational science - I tracked down a cheapish copy of the 3rd edition from 2009 and flipping through it (it only arrived yesterday), it seems like it is going to be very useful. Certainly it draws a lot on numpy, goes into using Tcl for GUIs, and a number of recipes for scripting, regular expressions and so on ... lots to get my head around. With respect to my original question then, equipped with this book you recommended, a book on differential equations, and one on an intro to environmental modelling, that should give me enough to work on for the time being. So, just wanted to close the circle by letting you know that I took your recommendation, and it looks like it will pay off in time. Thank you. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Introduction to modelling with Python
Modulok wrote: Could you further define 'modeling' in context? Are you referring to using python in the context of 3D modeling, i.e. computer aided design? If that be the case, python serves as an embedded language for many 3D computer graphics programs. Everything from Maya to Houdini use it as a command interface to automate things. See the developer's documentation for whatever software you're using. What kind of modeling? -Modulok- On 3/27/10, AG computing.acco...@googlemail.com wrote: Hi List I apologise in advance for the vagueness of this query, but I am looking for a decent modern introduction to modelling using Python. Specifically, I want something that is a good introduction (i.e. doesn't expect one to already be a maths/ statistics or a programming guru) and that has an ecology/ environmental science orientation. The latter is desirable but not essential, as I suspect that once one understands the process of data abstraction and the other steps involved in modelling processes and scenarios, the thinking and skill sets are likely transferable. However, if my assumption about this is incorrect, please let me know. If anyone knows of any resource (book or on-line) with a Python bent, please let me know. I am preparing to begin applications to Ph.D. programs and most of what I am interested in doing requires some knowledge of modelling and Python also seems to be widely accepted as a programming language, so I am happy with that as I am in the process of teaching myself Python anyway. Thanks for any help, advice, etc. Cheers AG ___ Modulok The modelling I was referring to is not about 3-D design, but about scenario modelling. For example, to understand the impacts of climate change on particular bodies of water, given different circumstances (e.g. x% of rain in the preceding year, or prevailing winds, or y number of herd animals using the water resource, and/ or upstream engineering developments, etc.), the idea would be to (a) identify those aspects most relevant and least relevant and (b) to programme those elements according to certain parameters of fluctuation (perhaps OOP might be useful here), and then (c) to manipulate those values according to different scenarios. These manipulations can then be replayed any number of times (e.g. a Monte Carlo treatment) to obtain their statistical average and probabilities. The foregoing is possibly not the most elegant example, but hopefully gives you a clearer idea of what I was asking about. Thanks for your interest. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Introduction to modelling with Python
Eike Welk wrote: On Saturday March 27 2010 16:21:26 AG wrote: I apologise in advance for the vagueness of this query, but I am looking for a decent modern introduction to modelling using Python. Specifically, I want something that is a good introduction (i.e. doesn't expect one to already be a maths/ statistics or a programming guru) and that has an ecology/ environmental science orientation. You should look at the book Python Scripting for Computational Science by Hans Petter Langtangen: http://www.amazon.com/Python-Scripting-Computational-Science- Engineering/dp/3540435085 http://books.google.com/books?id=YEoiYr4H2A0Cprintsec=frontcoverdq=Python+Scripting+for+Computational+Sciencesource=blots=ovp_JKREiYsig=tJkigCLDqS6voOOjmL4xDxw0roMhl=enei=OlWvS8PmE4r94Aa42vzgDwsa=Xoi=book_resultct=resultresnum=5ved=0CBEQ6AEwBA#v=onepageq=f=false It is an introduction to the Python language, and to a big number of tools for numerical computations. The book assumes that you have already some practice in writing computer programs. The book is not oriented towards ecology, the examples are from mechanical engineering. The book is however a bit dated, it's from 2004. Therefore many examples will need to be slightly altered to work with the current versions of the libraries that they use. Alternatively you could ask your question on the Numpy/Scipy mailing lists. These lists are frequented by scientists that use Python for their computations. http://www.scipy.org/Mailing_Lists Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Now that's looking very much along the lines of what I had in mind Eike. Very pricey ... might have to sit on that one for a while and scout around for a used copy. I can certainly use the on-line resource for as many pages as it allows one to access until I either find a cheaper version or perhaps win a lottery!! But, yep, this looks like what I had in mind - so anything else like this would be good as well. Cheers AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Introduction to modelling with Python
Eike Welk wrote: On Sunday March 28 2010 19:37:41 AG wrote: Now that's looking very much along the lines of what I had in mind Eike. Very pricey ... might have to sit on that one for a while and scout around for a used copy. I can certainly use the on-line resource for as many pages as it allows one to access until I either find a cheaper version or perhaps win a lottery!! Maybe you can get it as an inter library loan. Buying it is unnecessary; once you have some knowledge of the tools, you get everywhere you want with the online documentation and some questions in the relevant mailing lists. The idea of an inter-library loan is a sound one. I hadn't thought of that, so will give that a try. As an alternative you could try the online documentation at the Scipy website. Numpy and Scipy are the basic libraries for numerical computation with Python. The material at the website is not as good as the Langtangen book, and it covers far fewer different subjects, but it might be good enough to get you started. I've just begun with numpy and matlibplot (pyplot), so these are good suggestions. First read the Getting Started section. Then look at the Cookbook articles and study some that are relevant for you. http://www.scipy.org/ Thanks. These are leads worth following up on. Additionally subscribe to the Numpy/Scipy mailing lists. You could ask questions how to solve specific problems. The people there are usually very helpful. But, yep, this looks like what I had in mind - so anything else like this would be good as well. I'm very glad that I could be helpful. Eike. Thank you again. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Introduction to modelling with Python
Hi List I apologise in advance for the vagueness of this query, but I am looking for a decent modern introduction to modelling using Python. Specifically, I want something that is a good introduction (i.e. doesn't expect one to already be a maths/ statistics or a programming guru) and that has an ecology/ environmental science orientation. The latter is desirable but not essential, as I suspect that once one understands the process of data abstraction and the other steps involved in modelling processes and scenarios, the thinking and skill sets are likely transferable. However, if my assumption about this is incorrect, please let me know. If anyone knows of any resource (book or on-line) with a Python bent, please let me know. I am preparing to begin applications to Ph.D. programs and most of what I am interested in doing requires some knowledge of modelling and Python also seems to be widely accepted as a programming language, so I am happy with that as I am in the process of teaching myself Python anyway. Thanks for any help, advice, etc. Cheers AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Over-riding radians as default for trig calculations
After importing the math module and running math.cos( x ) the result is in radians. Is there a way of setting this so that it results in degrees? I don't want to over-ride this permanently for my Python settings, so am happy to specifically do it per equation or per program. Thanks in advance. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Using Matplotlib - program still running when graph window is closed
How does one ensure that once a graph has been produced by Matplotlib and that graph has been closed by the user that the program itself stops? What I am currently getting is that when I close the graph pop-up window and then close IDLE, I get a message that the program is still running and am I sure that I want to stop it. Yes, I am sure, but I don't want to have to keep killing the IDLE interpreter window in order to do so, but if I don't, then I am seemingly unable to produce another graph pop-up window. How do I control this from within the script itself? TIA AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] List append method: St Petersburg Game
Hi Pythonistas I am having difficulty with applying the list.append(x) method to produce a list that will contain outputs which will become coordinates for a later call to Matplotlib. Perhaps someone here can help me figure this out? The basic program is below: # St Petersburg Game: v. 2: # Toss a coin. If it is heads, win $2, if not keep # tossing it until it falls heads. # Heads first toss = H = $2 # Heads third toss = TTH = $8 # Heads fifth toss = H = $32 # The game is to win more by not scoring Heads print St Petersburg Game: win multiples of $2 the more you land Tails # Required libraries import random import matplotlib.pyplot as plt #Main function: def flipCoin(): coinToss = random.randrange(1, 3) return coinToss # Storage of output toss_list = [] # Get things going flipCoin() # Want to capture the coin lands heads (2) while flipCoin() != 2: toss_list.append(Tails) flipCoin() # Heads lands show output print print Heads print toss_list # Interpret results 'reward' print You flipped %d tails before landing Heads % len(toss_list) if toss_list == 0: print You won $2 else: toss_list.append( Tail ) print You won $%d % 2 ** len(toss_list) The overall purpose of the game is, for this discussion, irrelevant, but some background info will be helpful I think. The above program will give one run only and produces the output I expect. When I take this to the next level of complexity I run into problems. 1. I have tried to make this program run a given number of times, and use the for repetition loop to do this, basically: for i in range( 0, 10 ): and then the above program is appropriately indented. 2. Collecting the number of coin tosses into a list appends these to a list just fine. However, what this does is adds the numbers together so that one ends up like this: [0, 1, 2, 4, 5, 6, 8, 10, 11, 15] With a corresponding increase in the values derived from multiplying the exponent, thus: [2, 4, 8, 32, 64, 128, 512, 2048, 4096, 65536] Both are correct applications of the method, but I am unable to get the list to not sum the values up in the first list, these are not accumulative values, but discrete. If I am understanding what is currently happening, the values are being accumulated, and I want to stop that from happening. If this isn't clear, please let me know how I can clarify my question to help shape the relevance of the responses. Thanks for any ideas. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List append method: St Petersburg Game
bob gailer wrote: On 2/20/2010 7:43 AM, AG wrote: snip Please let me know how I can clarify my question 1 - You are giving way too much information. We do not need to know the rules of the game or all the code. Our time to read email is limited. The less you tell us that is not relevant the better. Thanks Bob. Also you don't show the code for the next level of complexity. Here it is, then: import random import matplotlib.pyplot as plt import math def flipCoin(): coinToss = random.randrange(1, 3) return coinToss toss_list = [] tosscounts = [] winnings = [] for i in range(0, 10): while flipCoin() != 2: toss_list.append(Tails) flipCoin() print print Heads tosscounts.append( len(toss_list)) if toss_list == 0: print You won $2 winnings += 2 else: toss_list.append( Tail ) winnings += [2 ** len( toss_list )] print print tosscounts print winnings print Here's the graph: for i in winnings: # Convert int to float for log i * 1.0 plt.plot( [tosscounts], [winnings] ) plt.ylabel( how often ) plt.xlabel( how much ) plt.show() snip The result of the first call to flipCoin is ignored. Each cycle of the loop results in 2 calls to flipCoin. The result of the 2nd call is ignored. Aha! Thanks for spotting that. Now fixed in the code cited above, but still gives the same problem. Thanks for any further ideas. AG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor