Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pyMOR
pymor
Commits
f512a914
Commit
f512a914
authored
Jan 12, 2023
by
mohamedadelnaguib
Browse files
Change varible namings along with some code refactorizing
parent
fbe68676
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/pymor/models/transfer_function.py
View file @
f512a914
...
...
@@ -255,26 +255,26 @@ class TransferFunction(CacheableObject, ParametricObject):
artists
List of matplotlib artists added.
"""
num
ber_columns
=
self
.
_cal_plot_dimension
(
input_indices
,
self
.
dim_input
)
num
ber_rows
=
self
.
_cal_plot_dimension
(
output_indices
,
self
.
dim_output
)
num
_input
=
self
.
_cal_plot_dimension
(
input_indices
,
self
.
dim_input
)
num
_output
=
self
.
_cal_plot_dimension
(
output_indices
,
self
.
dim_output
)
print
(
self
.
dim_input
,
self
.
dim_output
)
if
input_indices
is
None
:
input_indices
=
[
*
range
(
self
.
dim_input
)
]
input_indices
=
list
(
range
(
self
.
dim_input
)
)
if
output_indices
is
None
:
output_indices
=
[
*
range
(
self
.
dim_output
)
]
output_indices
=
list
(
range
(
self
.
dim_output
)
)
if
ax
is
None
:
import
matplotlib.pyplot
as
plt
fig
=
plt
.
gcf
()
width
,
height
=
plt
.
rcParams
[
'figure.figsize'
]
fig
.
set_size_inches
(
num
ber_columns
*
width
,
2
*
num
ber_rows
*
height
)
fig
.
set_size_inches
(
num
_input
*
width
,
2
*
num
_output
*
height
)
fig
.
set_constrained_layout
(
True
)
ax
=
fig
.
subplots
(
2
*
num
ber_rows
,
number_columns
,
sharex
=
True
,
squeeze
=
False
)
ax
=
fig
.
subplots
(
2
*
num
_output
,
num_input
,
sharex
=
True
,
squeeze
=
False
)
else
:
assert
isinstance
(
ax
,
np
.
ndarray
)
assert
ax
.
shape
==
(
2
*
num
ber_rows
,
number_columns
),
\
f
'ax.shape=
{
ax
.
shape
}
should be (
{
2
*
num
ber_rows
}
,
{
number_columns
}
)'
assert
ax
.
shape
==
(
2
*
num
_output
,
num_input
),
\
f
'ax.shape=
{
ax
.
shape
}
should be (
{
2
*
num
_output
}
,
{
num_input
}
)'
fig
=
ax
[
0
,
0
].
get_figure
()
if
len
(
w
)
!=
2
:
...
...
@@ -290,8 +290,8 @@ class TransferFunction(CacheableObject, ParametricObject):
freq_label
=
f
'Frequency (
{
"Hz"
if
Hz
else
"rad/s"
}
)'
mag_label
=
f
'Magnitude
{
" (dB)"
if
dB
else
""
}
'
phase_label
=
f
'Phase (
{
"deg"
if
deg
else
"rad"
}
)'
for
i
in
range
(
num
ber_rows
):
for
j
in
range
(
num
ber_columns
):
for
i
in
range
(
num
_output
):
for
j
in
range
(
num
_input
):
if
dB
:
artists
[
2
*
i
,
j
]
=
ax
[
2
*
i
,
j
].
semilogx
(
freq
,
20
*
np
.
log10
(
mag
[:,
output_indices
[
i
],
input_indices
[
j
]]),
**
mpl_kwargs
)
...
...
@@ -300,10 +300,10 @@ class TransferFunction(CacheableObject, ParametricObject):
input_indices
[
j
]],
**
mpl_kwargs
)
artists
[
2
*
i
+
1
,
j
]
=
ax
[
2
*
i
+
1
,
j
].
semilogx
(
freq
,
phase
[:,
output_indices
[
i
],
input_indices
[
j
]],
**
mpl_kwargs
)
for
i
in
range
(
num
ber_rows
):
for
i
in
range
(
num
_output
):
ax
[
2
*
i
,
0
].
set_ylabel
(
mag_label
)
ax
[
2
*
i
+
1
,
0
].
set_ylabel
(
phase_label
)
for
j
in
range
(
num
ber_columns
):
for
j
in
range
(
num
_input
):
ax
[
-
1
,
j
].
set_xlabel
(
freq_label
)
fig
.
suptitle
(
'Bode plot'
)
return
artists
...
...
@@ -313,10 +313,9 @@ class TransferFunction(CacheableObject, ParametricObject):
if
indices
is
None
:
return
dim
else
:
assert
all
([
isinstance
(
item
,
int
)
for
item
in
indices
])
assert
all
([
indices
[
i
]
in
range
(
-
dim
+
1
,
dim
)
for
i
in
range
(
len
(
indices
))]),
\
f
'Indices should be any integer value between
{
-
dim
+
1
}
and
{
dim
-
1
}
'
assert
all
(
isinstance
(
item
,
int
)
for
item
in
indices
)
assert
all
(
-
dim
<=
item
<
dim
for
item
in
indices
),
\
f
'Indices should be any integer value between
{
-
dim
}
and
{
dim
-
1
}
'
return
len
(
indices
)
def
mag_plot
(
self
,
w
,
mu
=
None
,
ax
=
None
,
ord
=
None
,
Hz
=
False
,
dB
=
False
,
adaptive_opts
=
None
,
**
mpl_kwargs
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment