To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 548681c6 authored by Cyrill Mast's avatar Cyrill Mast
Browse files

extended plotting lib

parent 181db385
from plotting import plot_Acoustofluidics
import matplotlib.pyplot as plt
import numpy as np
class PlotGeneral:
def __init__(self):
self.resolution = 100
self.x_data = np.linspace(0, self.resolution - 1, self.resolution)
self.y_data = np.zeros(self.resolution)
self.x_label = ""
self.y_label = ""
self.fig, self.ax = plt.subplots()
self.plot()
self.update_labels("x_label", "y_label", "title")
"""
implement design options here
"""
def rescale(self, resolution=None):
"""
Implement this function
"""
def plot(self):
self.ax.plot(self.x_data, self.y_data)
def update_labels(self, x_label=None, y_label=None, title=None):
self.ax.set_title(title)
self.ax.set_xlabel(x_label, fontsize=10)
self.ax.set_ylabel(y_label, fontsize=10)
import matplotlib.pyplot as plt
import numpy as np
from .plot_General import PlotGeneral
class PlotARF:
class PlotARF(PlotGeneral):
def __init__(self, ARF) -> None:
PlotGeneral.__init__(self)
self.arf = ARF
def plot_ARF(self):
self.R = np.linspace(0, )
self.arf.compute_acoustic_radiation_force()
plt.show()
import matplotlib.pyplot as plt
import numpy as np
from gorkov import pi
class PlotScatteringField:
from .plot_General import PlotGeneral
class PlotScatteringField(PlotGeneral):
def __init__(self, scatteringfield) -> None:
self.sf = scatteringfield
def plot_scatteringfield(self):
self.gridpoints = 100
self.R = np.linspace(0, 1e-4, self.gridpoints)
self.Theta = np.linspace(0, 2 * pi, self.gridpoints)
self.R, self.Theta = np.meshgrid(self.R, self.Theta)
def plot_Phi_1(self) -> None:
phi = np.zeros((self.gridpoints, self.gridpoints))
for r in self.R:
for theta in self.Theta:
phi[r][theta] = self.sf.Phi_1()
plt.plot(self.R, self.Theta, phi)
plt.show()
def plot_Phi_i(self) -> None:
phi = np.zeros((self.gridpoints, self.gridpoints))
for r in self.R:
for theta in self.Theta:
phi[r][theta] = self.sf.Phi_i()
plt.plot(self.R, self.Theta, phi)
plt.show()
def plot_Phi_s(self) -> None:
phi = np.zeros((self.gridpoints, self.gridpoints))
for r in self.R:
for theta in self.Theta:
phi[r][theta] = self.sf.Phi_s()
plt.plot(self.R, self.Theta, phi)
plt.show()
def plot_Phi_star(self) -> None:
phi = np.zeros((self.gridpoints, self.gridpoints))
for r in self.R:
for theta in self.Theta:
phi[r][theta] = self.sf.Phi_star()
plt.plot(self.R, self.Theta, phi)
plt.show()
def plot_scatteringfield(self) -> None:
a = self.sf.radial_acoustic_particle_velocity()
plt.plot(a)
def plot_radial_acoustic_fluid_velocity(self) -> None:
plt.show()
def plot_tangential_acoustic_fluid_velocity(self) -> None:
plt.show()
def plot_radial_particle_velocity(self) -> None:
plt.show()
def plot_tangential_particle_velocity(self) -> None:
plt.show()
import matplotlib.pyplot as plt
class PlotStreamingField:
from .plot_General import PlotGeneral
class PlotStreamingField(PlotGeneral):
def __init__(self, streamingfield) -> None:
PlotGeneral.__init__(self)
self.sf = streamingfield
def plot_streamingfield(self):
......
import matplotlib.pyplot as plt
import numpy as np
from .plot_General import PlotGeneral
class PlotVarious:
def __init__(self, baseclass) -> None:
class PlotVarious(PlotGeneral):
def __init__(self, baseclass, resolution) -> None:
PlotGeneral.__init__(self)
self.b = baseclass
self.res = resolution
def plot_A_n(self, res=None) -> None:
"""
plots the first n coefficients of A_n
"""
if res is not None:
self.rescale(res)
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.A_n(n) for n in self.x_data]
self.update_labels(
"n",
"A_n",
"The first {} coefficients of A_n".format(self.res))
self.plot()
plt.show()
def plot_B_n(self, res=None) -> None:
"""
plots the first n coefficients of B_n
"""
if res is not None:
self.res = res
self.y_data = np.linspace(0, self.res - 1, self.res)
self.x_data = [self.b.B_n(n) for n in self.x_data]
self.update_labels(
"n",
"B_n",
"The first {} coefficients of B_n".format(self.res))
self.plot()
plt.show()
def plot_K_n(self, res=None) -> None:
"""
plots the first n coefficients of K_n
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.K_n(n) for n in self.x_data]
self.update_labels(
"n",
"K_n",
"The first {} coefficients of K_n".format(self.res))
self.plot()
plt.show()
def plot_M_n(self, res=None) -> None:
"""
plots the first n coefficients of M_n
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.K_n(n) for n in self.x_data]
self.update_labels(
"n",
"M_n",
"The first {} coefficients of M_n".format(self.res))
def plot_coeff(self) -> None:
self.plot()
plt.show()
from plotting.plot_Acoustofluidics import PlotAcoustofluidics
from tests.basetest_composite import BaseTest
from gorkov import Gorkov1962
class TestPlotVarious(BaseTest):
def setUp(self) -> None:
super().setUp()
self.c_f = 1500
self.rho_f = 1000
self.rho_s = 1e3
self.c_s = 5968
self.f = 1e6
self.p0 = 1e3
self.pos = 1e-5
self.R0 = 1e-3
self.cls = Gorkov1962.ARF(self.f,
self.R0, self.rho_s, self.c_s,
self.rho_f, self.c_f,
'standing', self.p0, self.pos)
def randomly_change_parameters(self) -> None:
self.f = self.randomly_change_number(self.f)
self.c_f = self.randomly_change_number(self.c_f)
self.rho_f = self.randomly_change_number(self.rho_f)
self.rho_s = self.randomly_change_number(self.rho_s)
self.c_s = self.randomly_change_number(self.c_s)
self.p0 = self.randomly_change_number(self.p0)
self.pos = self.randomly_change_number(self.pos)
self.R0 = self.randomly_change_number(self.R0)
def assign_parameters(self) -> None:
# standing wave
self.cls.f = self.f
self.cls.c_f = self.c_f
self.cls.rho_f = self.rho_f
self.cls.rho_s = self.rho_s
self.cls.c_s = self.c_s
self.cls.p_0 = self.p0
self.cls.position = self.pos
self.cls.R_0 = self.R0
def test_plot_various(self) -> None:
a = PlotAcoustofluidics(baseclass=self.cls, ARF=self.cls)
a.plot_A_n(10)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment