Python

Mercurial

Parallelität mit joblib

   1 from joblib import Parallel, delayed
   2 
   3 Parallel(n_jobs=-1)(delayed(plot_all)(cg) for cg in cluster_groups)

Liste von Dictionaries

   1 d = []
   2 d.append({})
   3 d[0].setdefault(bsl[0].split()[0],[])

Integer mit führender Null

   1 "%(a)02d" % {"a":1}

Beautify log y-axis

   1 from matplotlib.ticker import FormatStrFormatter
   2 ...
   3 ax1.yaxis.set_major_formatter(FormatStrFormatter('%0.0f'))

Reading GRIB

   1 gribs = pygrib.open('./forecast/GRIDHSTTESTA01+0000')
   2 
   3 for grib in gribs:
   4     print grib
   5 
   6 grib = gribs.select(name='Temperature')[0] # or grib = gribs.message(1)
   7 
   8 lats, lons = grib.latlons()

Websites

http://www.johnloomis.org/python/

http://learnpython.pbworks.com/w/page/15956556/WebApplication

http://www.astro.cornell.edu/staff/loredo/statpy/

http://mercurial.selenic.com/wiki/CGIinstall

CGIHTTPServer

   1 python -m CGIHTTPServer

   1 import CGIHTTPServer
   2 
   3 import BaseHTTPServer
   4 
   5 class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
   6 
   7     cgi_directories = ["/cgi-bin"]
   8 
   9 PORT = 8000
  10 
  11 httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
  12 
  13 print "serving at port", PORT
  14 
  15 httpd.serve_forever()

Encoding

# -*- coding: utf-8 -*-

Plotting

   1 import matplotlib.pyplot as plt
   2 import numpy as n
   3 
   4 x=n.arange(-n.pi,n.pi,0.01)
   5 y=n.sin(x)
   6 plt.ylabel('sin(x)')
   7 plt.xlabel('x')
   8 plt.title('Sinus of x')
   9 plt.plot(x,y)
  10 plt.show()
  11 #plt.savefile('sinus_x.png')

ScientificPython

ScientificPython

ScientificPythonManual

http://scipy-central.org/

genutils

statistics

   1 import genutil.statistics

http://www2-pcmdi.llnl.gov/cdat/source/api-reference/genutil.statistics.html

statusbar

   1 import genutil.statusbar
   2 
   3 prevall=0
   4 previ=0
   5 prevj=0
   6 prevtxt=0
   7 ni=100
   8 nj=20
   9 for i in range(ni):
  10    previ=statusbar(float(i)/ni,prev=previ,tk=1)
  11 for j in range(nj):
  12     prevj=statusbar(float(j)/nj,prev=prevj,tk=1)
  13     prevall=statusbar([float(i)/ni,float(j)/nj],prev=prevall,tk=1,title='Test')
  14     prevtxt=statusbar(float(j)/nj,prev=prevtxt,tk=None,title='Test')

Cool modules

Wikinger: Python (zuletzt geändert am 2016-10-22 18:29:18 durch Robert)