Skip to content
Snippets Groups Projects
Commit 2f693bfc authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added common line argument parser, to avoid having to edit the file change user parameters.

parent 94103ebe
Branches
No related tags found
No related merge requests found
...@@ -23,25 +23,33 @@ ...@@ -23,25 +23,33 @@
"""Try histogram """Try histogram
Usage: Usage:
> python try_histogram.py > python try_histogram.py -h
""" """
import argparse
import numpy as np import numpy as np
import matplotlib.pylab as plt import matplotlib.pylab as plt
figNr = 1 figNr = 1
# Parameters # Parse arguments to derive user parameters
Nbins = 100 _parser = argparse.ArgumentParser('try_histogram')
dc = 0 _parser.add_argument('--Nbins', default=100, type=int, help='Number of bins in historgram')
mu = 100 _parser.add_argument('--dc', default=0.0, type=float, help='DC offset of the data')
sigma = 15 _parser.add_argument('--ampl', default=1.0, type=float, help='Amplitude of the sinus data')
_parser.add_argument('--sigma', default=15.0, type=float, help='Standard deviation of the random data')
args = _parser.parse_args()
Nbins = args.Nbins
dc = args.dc
ampl = args.ampl
sigma = args.sigma
# Sinus # Sinus
N = Nbins * 100 N = Nbins * 100
t = 2 * np.pi * np.arange(0, N) / N t = 2 * np.pi * np.arange(0, N) / N
a = dc + np.sin(t) a = dc + ampl*np.sin(t)
# Plot histogram # Plot histogram
plt.figure(figNr) plt.figure(figNr)
...@@ -53,7 +61,7 @@ plt.grid(True) ...@@ -53,7 +61,7 @@ plt.grid(True)
figNr += 1 figNr += 1
# Gaussian noise # Gaussian noise
x = mu + sigma * np.random.randn(N) x = dc + sigma * np.random.randn(N)
# Plot histogram # Plot histogram
plt.figure(figNr) plt.figure(figNr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment