<jupyter_start><jupyter_text>Converting Python TransferFunction objects to Foton expressionIn this tutorial, we will demonstrate how to use `kontrol.foton` to convert transfer functions defined in Python to Foton expressions like `zpk([1;2;3],[4;5;6+i*7;6-i*7],8)`.We will use the following transfer function for an example\begin{equation}    \frac{s(s+1)}{s^2+0.01\pi s + \pi^2}\,.\end{equation}For this transfer function, we should expect to see two zeros at 0 and 1 rad/s and two complex poles at $\pi$ rad/s.Update 2021-10-22:* ``kontrol.TransferFunction`` has a method ``kontrol.TransferFunction.foton()`` and it calls ``kontrol.foton.tf2foton()``. * ``kontrol.foton.tf2foton()`` now works with transfer functions with order higher than 20.<jupyter_code>import control
import numpy as np


s = control.tf("s")
tf = s*(s+1) / (s**2 + 0.01*np.pi*s + np.pi**2)
tf
import kontrol

## By default, it uses zpk([...],[...],...,"s") expression.
foton_expression = kontrol.foton.tf2foton(tf)
print("Default expression:")
print(foton_expression)
print("")

# We can use other format as well.
zpk_s_expression = kontrol.foton.tf2foton(tf, root_location="s")
zpk_f_expression = kontrol.foton.tf2foton(tf, root_location="f")
zpk_n_expression = kontrol.foton.tf2foton(tf, root_location="n")
print("s format:")
print(zpk_s_expression)
print("")
print("f format:")
print(zpk_f_expression)
print("")
print("n format:")
print(zpk_n_expression)
# rpoly expressions are also supported.
rpoly_expression = kontrol.foton.tf2foton(tf, expression="rpoly")
print("rpoly expression:")
print(rpoly_expression)
## kontrol.TransferFunction.foton calls kontrol.foton.tf2foton as well.
kontrol_tf = kontrol.TransferFunction(tf)
kontrol_tf.foton()
## Here's what would happen if we have a transfer function that has 50 order.
tf50 = control.ss2tf(control.rss(50))  # a transfer function with 50 order
kontrol_tf50 = kontrol.TransferFunction(tf50)
print(kontrol_tf50.foton())  # I had to use print() because of the "\n" character.<jupyter_output>17:15 Kontrol WARNING : The transfer function has order higher than 20. This is not supported by KAGRA's Foton software. The Foton expression is splitted into multiple expressions with less order.
{'fraction_non_alphanumeric': 0.13008130081300814, 'fraction_numerical': 0.028455284552845527, 'mean_word_length': 5.87888198757764, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '632791', 'license': 'MIT', 'n_tokens_mistral': 778, 'n_tokens_neox': 729, 'n_words': 220, 'path': 'docs/source/tutorials/tf2foton.ipynb', 'repo_name': 'terrencetec/kontrol', 'size': '2214'}