Siehe auch SAR.
PyDLR43¶
22-24 Mai 2023
Python docstring formats https://stackoverflow.com/questions/3898572/what-are-the-most-common-python-docstring-formats
https://stackoverflow.com/questions/9195455/how-to-document-a-method-with-parameters
Jupyter Notebook examples https://cantera.org/examples/jupyter/index.html
A Whirlwind Tour of Python (free) https://github.com/ffisk/books/blob/master/a-whirlwind-tour-of-python.pdf (link is broken: https://www.oreilly.com/programming/free/files/a-whirlwind-tour-of-python.pdf)
IPython Cookbook https://ipython-books.github.io
NumPy
Lev Maximov, NumPy Illustrated: The Visual Guide to NumPy https://betterprogramming.pub/numpy-illustrated-the-visual-guide-to-numpy-3b1d4976de1d
Nicolas P. Rougier, From Python to NumPy https://www.labri.fr/perso/nrougier/from-python-to-numpy/#about-this-book (sources in rst2html)
Uebungen
Lesma paste app (Rust) http://gitlab.com/ogarcia/lesma
PyDLR34¶
Februar 2020
Basemap (Beispiel aus dem Buch von Jake VanderPlas, Python Data Science Handbook https://jakevdp.github.io/PythonDataScienceHandbook/04.13-geographic-data-with-basemap.html)
# Die folgenden Links enthalten Hinweise zum aufgetretenen Fehler
# https://github.com/matplotlib/basemap/issues/420
# https://github.com/conda-forge/basemap-feedstock/issues/30
# https://github.com/conda-forge/basemap-feedstock/issues/45
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
plt.figure(figsize=(8, 8))
m = Basemap(projection='ortho', resolution=None, lat_0=50, lon_0=-100)
m.bluemarble(scale=0.5);
Basemap installieren mit (basemap Version 1.2.0):
conda create -n basemap_test python=3.7.6 proj4=5.2.0 basemap pillow
In Spyder sieht man in der grafischen IPython Shell dann die Erdkugel. Das Problem liegt in höheren Versionen von proj4. Wenn man die Version von proj4 nicht explizit angibt, wird die Version 6.0.0 (oder ähnlich) verwendet. Mit dieser Version gibt es eine Fehlermeldung.
Noch ein Zusatz: Man muss die Umgebungsvariable PROJ_LIB
auf den richtigen Pfad setzen.
Das kann man provisorisch im obigen Python Programm machen durch die Zeilen am Anfang:
import os
os.environ['PROJ_LIB'] = r'c:\Users\schul10\AppData\Local\Continuum\miniconda3\pkgs\proj4-5.2.0-ha925a31_1\Library\share'
Dadurch ist das Programm leider nicht mehr portabel. Besser ist es, wenn man die Umgebungsvariable direkt im Windows Betriebssystem setzt. Bestimmte Teile des Pfades müssen für den konkreten Rechner geändert werden, z.B. der User (schul10) und der Wert hinter proj4-5.2.0-xxx.
Andere 3D-Welten ausser Basemap:
webglearth.com, examples.webglearth.com
saredu.dlr.de/webGLobe
saredu.dlr.de/webGLobe2
github.com/webglearth/webglearth2
https://automating-gis-processes.github.io/2016/Lesson5-World-3D.html (folium)
PyDLR33¶
Oktober 2019
Eric Matthes, Python Crash Course, 2nd edition, 2019, Cheat Sheets https://ehmatthes.github.io/pcc_2e/
f-string, multiline (https://realpython.com/python-f-strings)
name = "Bob" profession = "baker" affiliation = "London" message = ( f"Hi {name}. " f"You are a {profession}. " f"You were in {affiliation}." ) print(message)
Verschiedene Möglichkeiten, um Mehrzeilenstrings zu schreiben: https://www.techbeamers.com/python-multiline-string/
PyDLR32¶
Juli 2019
Python - die Alternative zu Matlab? http://num.math.uni-goettingen.de/~schulz/data/python_talk.pdf
Glumpy is a python library for scientific visualization that is both fast, scalable and beautiful. Glumpy offers an intuitive interface between numpy and modern OpenGL.
Python & OpenGL for Scientific Visualization, Copyright (c) 2018 Nicolas P. Rougier, License: Creative Commons Attribution 4.0 International (CC BY-NC-SA 4.0), Website: http://www.labri.fr/perso/nrougier/python-opengl
Python 4 Everybody by Charles Severance, https://www.py4e.com (free book)
PyDLR31¶
April 2019
# UnboundLocalError: local variable 'D' referenced before assignment
# Python Introductory Course 8.-10. April 2019
# Python 3.7
D = {}
def foo():
if False:
D = {}
D["blue"] = "blau"
print("D local:", D)
return D
D = foo()
print(D)
# shorter:
# 1. Line '*' commented out: NameError: name 'D' is not defined
# 2. With line '*': UnboundLocalError: local variable 'D' referenced before assignment
# 3. With 'if True': works
def g():
if False:
D = {} # (*)
print(D)
g()
Explanation:
PyDLR23¶
Switch/Case with Python
def a():
print("'a' was called")
def b():
print("'b' was called")
def c():
print("'c' was called")
D = { 'a' : a, 'b' : b, 'c' : c}
while True:
s = input("your choice: ")
if s in D:
D[s]()
else:
break
PyDLR22¶
Python 3¶
Jake VanderPlas, A Whirlwind Tour of Python (freier Text mit 100 Seiten plus Jupyter Notebooks)
Kevin Sheppard, Python for Econometrics, 2017 (freier Download)
SciPy¶
http://www.scipy-lectures.org (inkl. Datensaetzen und Aufgaben)
Matplotlib Gallery (viele Beispiele mit Sourcecode)
Hans Petter Langtangen, A very basic introduction to scientific Python programming, 2016
Svein Linge, Hans Petter Langtangen, Programming for Computations - Python A Gentle Introduction to Numerical Simulations with Python, 2016 (Open Access)
Pandas¶
Pandas Homepage, siehe 10 Minutes to Pandas, Tutorials, Lessons for new Pandas users, …
Beispiele aus dem Netz, leicht modifiziert. U.a. Excel Writer, Pandas Reader, Pandas Zeitserie, Numpy: Textdateien einlesen, …
Karlijn Willems, Pandas Tutorial: DataFrames in Python, October 2016
https://www.datacamp.com/community/tutorials/pandas-tutorial-dataframe-python
Wes McKinney, Python for Data Analysis, O’Reilly 2013.
Cheat sheets