EAPS 42200 fall 2018

spherical coords

skeleton python code for HW


import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline

# set up range of x-axis and y-axis values
x = np.arange(-100000., 100000.1, 10000.)
y = np.arange(-100000., 100000.1, 10000.)
# create a grid of x,y values using ranges
xx,yy = np.meshgrid(x, y)

# set up xx_km and yy_km for plotting mesh in units of km instead of m
xx_km = xx/1000.
yy_km = yy/1000.

# initialize arrays for T, u, v
T=np.zeros_like(xx)
u=np.zeros_like(xx)
v=np.zeros_like(xx)

# demonstrate numpy how to do sin and cos
print(np.pi)
print((np.pi)**2.0)
print(np.cos(np.pi/2.0))
print(np.sin(np.pi/2.0))


# create wind field using functions of xx and yy
u=xx/(2000.)
v=yy/(2000.)
# could set this up like in notes u=u0+(D1+div)*xx/2.+(D2-zeta)*yy/2.

# plot streamlines axes are in km
plt.figure(figsize=(12,9))
plt.streamplot(xx_km,yy_km,u,v)
plt.xlabel('x km')
plt.ylabel('y km')
plt.title('streamlines u=x/2 v=y/2')

# plot wind vectors
plt.figure(figsize=(12,9))
plt.quiver(xx_km,yy_km,u,v)
plt.xlabel('x km')
plt.ylabel('y km')
plt.title('vectors m/s u=x/2 v=y/2')

# convert u and v from m/s to kts
u_kt=u*1.94
v_kt=v*1.94

# plot wind barbs which are usually in kts
plt.figure(figsize=(12,9))
plt.barbs(xx_km,yy_km,u_kt,v_kt)
plt.xlabel('x km')
plt.ylabel('y km')
plt.title('barbs kts u=x/2 v=y/2')

# set up T field using function
T=273.15+xx/10000.-yy/10000.
print(np.max(T))
print(np.min(T))

# plot and label isotherms
intervals=np.arange(250.,295.,5.)
plt.figure(figsize=(12,9))
CS=plt.contour(xx_km,yy_km,T,intervals)
plt.clabel(CS)
plt.xlabel('x km')
plt.ylabel('y km')
plt.title('T deg K = 273.15+xx/10-yy/10')