This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Wednesday, August 13, 2014

Set figure size after creating image

fig = plt.gcf() #Gets the current figure
fig.set_size_inches(10,10, forward=True) # changes size of figure. Forward must equal True to make the change

Python Subplots (some with different sizes)

http://matplotlib.org/users/tight_layout_guide.html

Plotting netCDF data in Python

http://www.hydro.washington.edu/~jhamman/hydro-logic/blog/2013/10/12/plot-netcdf-data/

Tuesday, August 12, 2014

Symbols in labels

To put a symbol or label, such as a degree sign.

pl.xlabel('Temperature ($^{\circ}\!$ C)')

Thursday, August 7, 2014

advances in computing will benefit weather forecasts

news about advances in computing abilities is always exciting news fore weather forecasters. Check out this article...

http://www.engadget.com/2014/08/07/ibm-synapse-supercomputing-chip-mimics-human-brain/?ncid=txtlnkusaolp00000618

Relative Maximun and MInimum

It's easy to find the max and min of an array, but sometimes you want to find all local max an mins.

From post here:

import numpy as np
from scipy.signal import argrelextrema

x = np.random.random(12)

# for local maxima
argrelextrema(x, np.greater)

# for local minima
argrelextrema(x, np.less)
Produces
>>> x
array([ 0.56660112,  0.76309473,  0.69597908,  0.38260156,  0.24346445,
    0.56021785,  0.24109326,  0.41884061,  0.35461957,  0.54398472,
    0.59572658,  0.92377974])
>>> argrelextrema(x, np.greater)
(array([1, 5, 7]),)
>>> argrelextrema(x, np.less)
(array([4, 6, 8]),)
Note, these are the indices of x that are local max/min. To get the values, try:
>>> x[argrelextrema(x, np.greater)[0]]