为什么选择python
功能齐全的编程语言,真正面向对象
喜欢可读的代码
出版质量图绘制
轻松读/写netcdf和grib数据
轻松使用Fortran / C / C ++
广泛的库支持数字和非数字工作
科学计算
1.Numpy
Numpy是python科学计算的基础包,它提供以下功能(不限于此):
(1)快速高效的多维数组对象ndarray
(2)用于对数组执行元素级计算以及直接对数组执行数学运算的函数
(3)用于读写硬盘上基于数组的数据集的工具
(4)线性代数运算、傅里叶变换,以及随机数生成
(5)用于将C、C++、Fortran代码集成到python的工具
2.pandas
pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数。pandas兼具Numpy高性能的数组计算功能以及电子表格和关系型数据(如SQL)灵活的数据处理能力。它提供了复杂精细的索引功能,以便更为便捷地完成重塑、切片和切块、聚合以及选取数据子集等操作。
对于金融行业的用户,pandas提供了大量适用于金融数据的高性能时间序列功能和工具。
DataFrame是pandas的一个对象,它是一个面向列的二维表结构,且含有行标和列标。
ps.引用一段网上的话说明DataFrame的强大之处:
Excel 2007及其以后的版本的最大行数是1048576,最大列数是16384,超过这个规模的数据Excel就会弹出个框框“此文本包含多行文本,无法放置在一个工作表中”。Pandas处理上千万的数据是易如反掌的事情,同时随后我们也将看到它比SQL有更强的表达能力,可以做很多复杂的操作,要写的code也更少。 说了一大堆它的好处,要实际感触还得动手码代码。
3.Scipy
一组专门解决科学计算中各种标准问题域的包的集合。
scipy/climpy
4.statsmodels
一个Python模块,它提供对许多不同统计模型估计的类和函数,并且可以进行统计测试和统计数据的探索
5.RPy
An interface to R running embedded in a Python process
sympy
A Python library for symbolic mathematics
7.atmqty
A Python Package for Calculating Atmospheric Quantities
8.PyWavelets
A Python wavelet transforms module
数据处理
To create a NetCDF file:
from Scientific.IO.NetCDF import NetCDFFile
import numpy as np
f = NetCDFFile('scientificio.nc', 'w')
# dimension
f.createDimension('time', 12)
# variable
time = f.createVariable('time', 'd', ('time',))
# data
time[:] = np.random.uniform(size=12)
f.close()
To read the file:
from Scientific.IO.NetCDF import NetCDFFile
import matplotlib.pyplot as plt
f = NetCDFFile('scientificio.nc')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(f.variables['time'])
plt.show()
To create a NetCDF file:
from netCDF4 import Dataset
import numpy as np
root_grp = Dataset('test.nc', 'w', format='NETCDF4')
root_grp.description = 'Example temperature data'
# dimensions
root_grp.createDimension('time', None)
root_grp.createDimension('lat', 72)
root_grp.createDimension('lon', 144)
# variables
times = root_grp.createVariable('time', 'f8', ('time',))
latitudes = root_grp.createVariable('latitude', 'f4', ('lat',))
longitudes = root_grp.createVariable('longitude', 'f4', ('lon',))
temp = root_grp.createVariable('temp', 'f4', ('time', 'lat', 'lon',))
# data
lats = np.arange(-90, 90, 2.5)
lons = np.arange(-180, 180, 2.5)
latitudes[:] = lats
longitudes[:] = lons
for i in range(5):
temp[i,:,:] = np.random.uniform(size=(len(lats), len(lons)))
# group
# my_grp = root_grp.createGroup('my_group')
root_grp.close()
To read the file:
from netCDF4 import Dataset
import pylab as pl
root_grp = Dataset('test.nc')
temp = root_grp.variables['temp']
for i in range(len(temp)):
pl.clf()
pl.contourf(temp[i])
pl.show()
raw_input('Press enter.')
To read a Grib file:
import pygrib
grbs = pygrib.open('sampledata/flux.grb')
grbs.seek(2)
grbs.tell()
grb = grbs.read(1)[0]
print grb
grb = grbs.select(name='Maximum temperature')[0]
To write a Grib file:
import pygrib
grbout = open('test.grb','wb')
grbout.write(msg)
grbout.close()
print pygrib.open('test.grb').readline()
To read a .mat file:
import scipy.io as sio
mat_contents = sio.loadmat('data.mat')
print mat_contents
To write a .mat file:
import numpy as np
import scipy.io as sio
vect = np.arange(10)
print vect.shape
sio.savemat('data.mat', {'vect':vect})
for hdf5
f = h5py.File('foo.hdf5','w')
其他:
绘图
图形的种类
基础绘图类
气象常用类
卫星
其他绘图工具
爬虫
机器学习