Skip to content
Snippets Groups Projects
Commit 5eb9d4fd authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

More versatility of function plot_distr_funct in script

distribution_function.py. Plot two distribution functions and two
histograms for positive speed and absolute value of negative speed.
parent 59c85691
No related branches found
No related tags found
No related merge requests found
......@@ -4,27 +4,26 @@ import shapefile
import numpy as np
import matplotlib.pyplot as plt
def plot_distr_funct(X, xlabel):
plt.figure()
plt.hist(X, bins="auto")
plt.xlabel(xlabel)
plt.ylabel("number of occurrences")
def plot_distr_funct(X, xlabel, label = None, ax = None):
"""Sort and plot distribution function."""
X = np.array(X)
X.sort()
nx = np.size(X)
print(xlabel + ":")
if ax is None: ax = plt.gca()
ax.plot(X, (1 + np.arange(nx)) / nx, label = label)
print("minimum value:", X[0])
print("maximum value:", X[-1])
print("number of values:", nx, "\n")
plt.figure()
plt.plot(X, (1 + np.arange(nx)) / nx)
plt.xlabel(xlabel)
plt.ylabel("distribution function")
def read(end_filename):
"""Return speed, radius of outermost contour and radius of maximum speed
contour from three dbf files, as Numpy arrays.
Select valid speed values and valid outermost contour (with
sufficient area).
def get_var(end_filename):
"""
with shapefile.Reader("extremum" + end_filename) as extremum, \
shapefile.Reader("outermost_contour" + end_filename) as outermost_cont:
speed = []
......@@ -42,7 +41,7 @@ def get_var(end_filename):
for rec in max_speed_contour.iterRecords():
if rec.r_eq_area != - 100: r_speed.append(rec.r_eq_area)
return speed, r_outer, r_speed
return np.array(speed), np.array(r_outer), np.array(r_speed)
if __name__ == "__main__":
import argparse
......@@ -54,13 +53,55 @@ if __name__ == "__main__":
default = "")
args = parser.parse_args()
speed, r_outer, r_speed = get_var(args.end_filename)
speed, r_outer, r_speed = read(args.end_filename)
X = speed[speed >= 0]
xlabel = "speed, when positive, in m s-1"
plt.figure()
plt.hist(X, bins = "auto")
plt.xlabel(xlabel)
plt.ylabel("number of occurrences")
plt.figure()
print(xlabel + ":")
plot_distr_funct(X, "speed, in m s-1")
ax_distr_speed = plt.gca()
X = - speed[speed < 0]
xlabel = "- speed, when negative, in m s-1"
plt.figure()
plt.hist(X, bins = "auto")
plt.xlabel(xlabel)
plt.ylabel("number of occurrences")
print(xlabel + ":")
plot_distr_funct(X, xlabel, ax = ax_distr_speed)
xlabel = "equivalent radius of outermost contour, in km"
plot_distr_funct(speed, "speed, in m s-1")
plt.axhline(0.5, linestyle = "--", color = "black")
plt.axvline(linestyle = "--", color = "black")
plt.figure()
plt.hist(r_outer, bins = "auto")
plt.xlabel(xlabel)
plt.ylabel("number of occurrences")
plot_distr_funct(r_outer, "equivalent radius of outermost contour, in km")
plot_distr_funct(r_speed, "equivalent radius of max-speed contour, in km")
plt.figure()
print(xlabel + ":")
plot_distr_funct(r_outer, xlabel)
plt.xlabel(xlabel)
plt.ylabel("distribution function")
xlabel = "equivalent radius of max-speed contour, in km"
plt.figure()
plt.hist(r_speed, bins = "auto")
plt.xlabel(xlabel)
plt.ylabel("number of occurrences")
plt.figure()
print(xlabel + ":")
plot_distr_funct(r_speed, xlabel)
plt.xlabel(xlabel)
plt.ylabel("distribution function")
plt.show()
# This is a makefile for GNU make.
makefile_dir = .
include ${general_compiler_options_dir}/settings.mk
# 1. Source files and libraries
makefile_dir = .
VPATH += ${makefile_dir}/Tests
src_test_local_extrema = test_local_extrema.f local_extrema.f
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment