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