Python tools used at the SMC for data processing

Roger Veciana i Rovira

@rveciana
GeoExamples

Python: What is it

Python: Some advantages

Python basic instructions

a = 3
b = 4
a + b

Conditions

if b > a:
    print "b is bigger than a"

Iterations

for i in range(10):
    print "Iteration number " + str(i)

NumPy for matrix calculations

Open the ipython console

import numpy
a = numpy.ones((20,10)) -> 20x10 array filled with 1
a * 23 -> 20x10 array filled with 23
a + 1 -> 20x10 array filled with 2
a.sum() -> 200
a[3:6,4:8] = 2 -> Fills the selected cells with 2
a[[2,3],[4,4]] -> Returns the selected cells

Try

GDAL/OGR

Geospatial Data Abstraction Library

VAISALA IRIS format

Basemap

Basemap code example

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

map = Basemap()
 
map.drawcoastlines()
 
plt.show()

Basemap examples

Scipy

Scipy example

from scipy.interpolate import interp1d
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 10)
y = np.cos(-x**2/8.0)
f = interp1d(x, y)
f2 = interp1d(x, y, kind='cubic')

xnew = np.linspace(0, 10, 40)

plt.plot(x,y,'o',xnew,f(xnew),'-', xnew, f2(xnew),'--')
plt.legend(['data', 'linear', 'cubic'], loc='best')
plt.show()

Scikit-learn

Interpolating station data

Interpolating station data: results

MOS

  • Model Output Statistics
  • Input: WRF model output + station data (years)
  • Scikit-learn multilinear regression / Scikit-learn classification
  • Forecast at station locations (interpolable)
  • Viamet

    More information

    GIS and other calculations

    /

    #