Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

help with python

  • 14-07-2010 2:28pm
    #1
    Closed Accounts Posts: 2


    i'm new to using python and am strugglin to write a script which in general needs to calculate the derrivative of two velocities u*v with respect to phi, the main goal of my script will be to calculate the eddy stress from climatological mean velocities u and v but hopefully if anyone can give me a general idea of how to find the simplified derivative above i can apply this to the more specific case, thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Post your existing code.


  • Closed Accounts Posts: 2 climo


    def getStress(U,V):

    up = U - U.mean(axis=2)
    vp = V - V.mean(axis=2)

    upvp = (up*vp).mean(axis=2)

    phi = lat*pi/180.

    S = zeros((np,ny))*0.

    for j in range(ny):
    for k in range(1,np):

    return S

    further on in my script i've defined the particular variables such as np and ny which i needed to do so in order to calculate a stream function, another problem which fortunately i managed to figure out. This was an integral which i've had more experience with in recent times using matlab. Unfortunately the script manager i am using is not allowing me to copy my script and paste it here to post which is why i have only typed out this small section of it. I have tried to work out how to do this derivative for some time but still can seem to get my head around how to even start it. Programing really isn't my strength. The actual equation i need to solve is given by

    S = (1/cosphi^2) * a * d/dphi (( upvp ) * cosphi^2 )

    phi represents each degree of latitude, ny being the total length in latitude from -90 to 90 degrees, and np represents the total height using pressure co-ordinates as i divide it up into pressure levels dp, also a is the radius of the earth. If could help me in any way even to get started i would really appreciate it, i am struggling quite a bit with the coding side of things. thanks


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    Based on what you wrote (code tags for the win!):
    def getStress(U,V):
    	up = U - U.mean(axis=2)
    	vp = V - V.mean(axis=2)
    	
    	upvp = (up*vp).mean(axis=2)
    	
    	phi = lat*pi/180.
    	
    	S = zeros((np,ny))*0.
    	
    	for j in range(ny):
    		for k in range(1,np):
    			<??? what goes here ???>
    	return S
    

    Apart from the gap describing what the inner loop does, which is problematic, are up or vp available within the scope of the function? Either they're globals (not recommended...) or they need to be passed in somehow, I would have thought? My Python's a little rusty, but I think I'm right...


  • Registered Users, Registered Users 2 Posts: 339 ✭✭duffman85


    S = (1/cosphi^2) * a * d/dphi (( upvp ) * cosphi^2 )

    differentiate the bit in bold and then use it in the calculation for S inside your for loops
    i.e.
    d/dΦ of (upvp*cos (Φ^2)) is upvp*(-sin(Φ^2))*2Φ

    Is S a ny*np matrix?you're setting all the values to zero and then calculating S for each pressure level np at each latitude ny?
    you can also specify a step for the range() function,range() function - Python Documentation
    other wise range(ny) will go from 0 to ny in steps of 1. you could do steps of 10° by using a step of ny/16 etc.
    def getStress(U,V):
    
        up = U - U.mean(axis=2)
        vp = V - V.mean(axis=2)
    
        upvp = (up*vp).mean(axis=2)
    
        phi = lat*pi/180.
    
        S = zeros((np,ny))*0.
    
        for j in range(ny):
            for k in range(1,np):
                #calculation for S for each value of np,ny goes here
        
        
        return S
    


Advertisement