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 317cb462 authored by mastc's avatar mastc 🎯
Browse files

make attributes private

add matplotlib to requirements
parent 1eea8b60
from plotting import plot_Acoustofluidics
from .plot_arf import PlotARF
from .plot_scatteringfield import PlotScatteringField
from .plot_streamingfield import PlotStreamingField
from .plot_various import PlotVarious
class PlotAcoustofluidics(
PlotVarious,
PlotARF,
PlotScatteringField,
PlotStreamingField
):
"""
Plotting-Library with different plotting modules,
depending on the arguments
"""
def __init__(
self,
baseclass=None,
ARF=None,
scatteringfield=None,
streamingfield=None) -> None:
if baseclass is not None:
PlotVarious.__init__(self, baseclass)
if ARF is not None:
PlotARF.__init__(self, ARF)
if scatteringfield is not None:
PlotScatteringField.__init__(self, scatteringfield)
if streamingfield is not None:
PlotStreamingField.__init__(self, streamingfield)
import matplotlib.pyplot as plt
import numpy as np
from gorkov import PassiveVariable
class PlotGeneral:
def __init__(self):
self.resolution = 100
self._x_data = PassiveVariable(
np.linspace(0, self.resolution - 1, self.resolution),
"The data in the x direction")
self._y_data = PassiveVariable(
np.zeros(self.resolution),
"The data in the x direction")
self._x_label = PassiveVariable(
"", "The label in the x-direction")
self._y_label = PassiveVariable(
"", "The label in the y-direction")
self._title = PassiveVariable(
"", "The title")
self._fig, self._ax = plt.subplots()
self._ax.plot(self.x_data, self.y_data)
plt.style.use('ggplot')
"""
Define style options here
"""
@property
def x_data(self):
return self._x_data.value
@x_data.setter
def x_data(self, value):
self._ax.lines[0].set_xdata(value)
self._ax.set_xlim(min(value), max(value))
self._x_data.value = value
@property
def y_data(self):
return self._y_data.value
@y_data.setter
def y_data(self, value):
self._ax.lines[0].set_ydata(value)
self._ax.set_ylim(min(value), max(value))
self._y_data.value = value
@property
def x_label(self) -> str:
return self._x_label.value
@x_label.setter
def x_label(self, value):
self._ax.set_xlabel(value)
self._x_label.value = value
@property
def y_label(self) -> str:
return self._y_label.value
@y_label.setter
def y_label(self, value):
self._ax.set_ylabel(value)
self._y_label.value = value
@property
def title(self) -> str:
return self._title.value
@title.setter
def title(self, value):
self._ax.set_title(value)
self._title.value = value
def rescale(self, resolution=None):
"""
Implement this function
"""
def normalize_data(self, d_in):
"""
Implement this function
"""
d_out = d_in
return d_out
def figshow(self, figure):
for i in plt.get_fignums():
if figure != plt.figure(i):
plt.close(plt.figure(i))
plt.show()
import matplotlib.pyplot as plt
import numpy as np
from .plot_General import PlotGeneral
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
from .plot_General import PlotGeneral
class PlotScatteringField(PlotGeneral):
def __init__(self, scatteringfield) -> None:
PlotGeneral.__init__(self)
self.sf = scatteringfield
self.gridpoints = 100
# init axes, create meshgrid
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)
# init potentials
self.Phi = np.zeros((len(self.R), len(self.Theta)))
self.Phi_1 = np.zeros((len(self.R), len(self.Theta)))
self.Phi_i = np.zeros((len(self.R), len(self.Theta)))
self.Phi_s = np.zeros((len(self.R), len(self.Theta)))
self.Phi_star = np.zeros((len(self.R), len(self.Theta)))
# init velocities
self.radial_particle_velocities = np.zeros(
(len(self.R), len(self.Theta)))
self.tangential_particle_velocities = np.zeros(
(len(self.R), len(self.Theta)))
self.radial_acoustic_fluid_velocities = np.zeros(
(len(self.R), len(self.Theta)))
self.tangential_acoustic_fluid_velocities = np.zeros(
(len(self.R), len(self.Theta)))
def compute_velocities(self) -> None:
"""
implement this method
"""
def compute_potentials(self):
"""
implement this method
"""
for theta in self.Theta:
for r in self.R:
if r > self.sf.R_0:
self.Phi[r][theta] = self.sf.Phi_1(r, theta)
else:
self.Phi[r][theta] = self.sf.Phi_star(r, theta)
def plot_Phi_1(self) -> None:
plt.plot(self.R, self.Theta, self.Phi_1)
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
from .plot_General import PlotGeneral
class PlotStreamingField(PlotGeneral):
def __init__(self, streamingfield) -> None:
PlotGeneral.__init__(self)
self.sf = streamingfield
def plot_streamingfield(self):
a = self.sf.radial_acoustic_particle_velocity()
plt.plot(a)
import numpy as np
from .plot_General import PlotGeneral
class PlotVarious(PlotGeneral):
def __init__(self, baseclass) -> None:
PlotGeneral.__init__(self)
self.b = baseclass
self.res = 10
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.x_label = "n"
self.y_label = "A_n"
self.title = "The first {} coefficients of A_n".format(self.res)
self.figshow(self._fig)
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.x_label = "n"
self.y_label = "B_n"
self.title = "The first {} coefficients of B_n".format(self.res)
self.figshow(self._fig)
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.x_label = "n"
self.y_label = "K_n"
self.title = "The first {} coefficients of K_n".format(self.res)
self.figshow(self._fig)
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.x_label = "n"
self.y_label = "M_n"
self.title = "The first {} coefficients of M_n".format(self.res)
self.figshow(self._fig)
def plot_f1(self, res=None) -> None:
"""
plots the first n coefficients of f1
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.f1 for n in self.x_data]
self.x_label = "n"
self.y_label = "f1"
self.title = "The first {} coefficients of f1".format(self.res)
self.figshow(self._fig)
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)
print(a.x_data)
a.plot_f1()
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