diff --git a/src/scientific_plots/data_analysis.py b/src/scientific_plots/data_analysis.py deleted file mode 100644 index 683e2505ea02cf6c8cbc351cd4a6602142469461..0000000000000000000000000000000000000000 --- a/src/scientific_plots/data_analysis.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -"""this module contains functions, which are useful for -analysing data """ -from __future__ import annotations -from math import sqrt -from typing import Union, overload - -from scipy.stats import linregress -import numpy as np - -from .types_ import Vector, Matrix - - -ArrayLike = Union[list[float], Vector] -MatrixLike = Union[list[list[float]], Matrix] - - -@overload -def get_hrms(X: ArrayLike, Y: ArrayLike) -> float: ... - - -@overload -def get_hrms(X: ArrayLike, Y: MatrixLike) -> Vector: ... - - -def get_hrms(X: ArrayLike, Y: Union[ArrayLike, MatrixLike])\ - -> Union[float, Vector]: - """calculate R_q or h_rms based on real space data - calculate a single R_q if Y is a plain - array and take the average if it is an array of arrays""" - if isinstance(Y, list): - Y = np.array(Y) - if isinstance(X, list): - X = np.array(X) - if Y.ndim == 1: - Y = np.array([Y]) - h_rms = [] - for y in Y: - res = linregress(X, y) - alpha = res[0] - beta = res[0] - y_lin = [y_i - alpha * x - beta for x, y_i in zip(X, y)] - mean_y = sum(y_lin) / len(y_lin) - y_lin = [y_i - mean_y for y_i in y_lin] - h_rms += [sqrt(sum(y_lin_i ** 2 for y_lin_i in y_lin))] - mean_h_rms = sum(h_rms) / len(h_rms) - return mean_h_rms diff --git a/src/scientific_plots/two_d_plot.py b/src/scientific_plots/two_d_plot.py index 3ad755d736ccfa42f13830cb1d1fd186787bcb57..d816c5b6ac0b5c2a0e9f411ec443f96d1cd8f870 100644 --- a/src/scientific_plots/two_d_plot.py +++ b/src/scientific_plots/two_d_plot.py @@ -86,107 +86,3 @@ def create_two_d_surface_plot( plt.tight_layout() plt.savefig(join(folder, plot_title.replace(" ", "_") + ".pdf")) - - -def get_leakage(data: Iterable[Any], var: str = "density", - surface_file: Optional[str] = None) -> list[float]: - """calculate the leakage for a given set of data - @param data enumerable set of valve-objects - which allow the determination of the leakage - @return list of the same dimension for the leakage""" - if surface_file is None: - surface_path = join(SURFACEFOLDER, "c_q.dat") - else: - surface_path = surface_file - leakage_bin = join(".", "subroutines", "bin", "test_leakage") - Y: list[float] = [] - X: list[float] = [] - q: Queue[Any] = Queue() - # run every call of the fortran-code in parallel - for d in data: # put the data into the - # queue to access them later as needed - q.put(d) - - def work_of_queue() -> None: - nonlocal X - nonlocal Y - while True: - d = q.get() - if d is None: - return # last data-point - pressure = max(d.short.p) - print(pressure) - print(d.angle, d.wobble) - C = float(check_output([leakage_bin, "-i", surface_path, "-P", - f"{pressure}"])) - # A=d.short.unroundness2 - A = d.short.sigma - R = d.valve.seat.radius - delta_p = d.dictionary["fluid-pressure"]["value"] - Y += [delta_p * 2.0 * pi * R / A * C] - X += [getattr(d, var)] - - threads = [Thread(target=work_of_queue) for i in range(16)] - for thread in threads: # start all threads - thread.start() - q.put(None) - for thread in threads: # wait for all threads to finish - thread.join() - return Y - - -def plot_2d_surface( - data: Iterable[Any], - folder: str = "simulation", - var1: str = "angle", - var2: str = "wobble", - xlabel1: Optional[str] = None, - xlabel2: Optional[str] = None, - surface_file: Optional[str] = None, -) -> None: - """create the two d surface plots of two given variables""" - X = [getattr(d, var1) for d in data] - Y = [getattr(d, var2) for d in data] - pressure = [max(d.short.p) for d in data] - A = [d.short.unroundness for d in data] - leakage = get_leakage(data, surface_file=surface_file) - - create_two_d_scatter_plot( - X, Y, pressure, folder, "two d pressure", - xlabel1, xlabel2, "maximal pressure [MPa]" - ) - create_two_d_scatter_plot( - X, Y, A, folder, "two d area", xlabel1, xlabel2, "contact area [mm]" - ) - create_two_d_scatter_plot( - X, Y, leakage, folder, - "two d leakage", xlabel2, xlabel2, "leakage [ml/s]" - ) - create_two_d_surface_plot( - X, - Y, - pressure, - folder, - "two d pressure surface", - xlabel1, - xlabel2, - "maximal pressure [MPa]", - ) - create_two_d_surface_plot( - X, Y, A, folder, "two d area surface", - xlabel1, xlabel2, "contact area [mm]" - ) - create_two_d_surface_plot( - X, - Y, - pressure, - folder, - "two d pressure surface", - xlabel1, - xlabel2, - "maximal pressure [MPa]", - ) - create_two_d_surface_plot( - X, Y, leakage, folder, "two d leakage surface", - xlabel2, xlabel2, "leakage [ml/s]" - ) diff --git a/src/scientific_plots/utilities.py b/src/scientific_plots/utilities.py index 9faa8b3de6f0c03f0a681cfbf6a9daaab9d441ef..512d61f1a47c15398ab1e4d10737e03a90155846 100644 --- a/src/scientific_plots/utilities.py +++ b/src/scientific_plots/utilities.py @@ -169,7 +169,7 @@ def mkdir_p(foldername: str) -> None: mkdir_p(foldername) -def trash_remover(func: Callable[..., tuple[Return, ...]])\ +def trash_remover(func: Callable[..., Tuple[Return, ...]])\ -> Callable[..., Return]: """only keeps the first output of a given function"""