<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Machine Characteristics
Machine characteristics such as speed, torque, voltage, currents, frequency etc. can be efficientliy calculated by equivalent circuit models which are included in the module 'femagtools.machine'
Step1:  For example we can calculate the iq and id current for a given torque of 170 Nm
Step2:  Or reversely
Step3:  For the transformation of i1-beta and id-iq components there are corresponding functions
Step4:  Show the torque vs beta curve
Step5:  Calculate the amplitude of the phase voltage at frequency 75 Hz
Step6:  Find the frequency from maximum torque and voltage
Step8:  Plot the speed torque characteristics
Step9:  Show the torque plot with the motor parameters from a Ld-Lq-Identification
Step10:  Display the characteristics with a MTPA Plot
Step11:  With surface
Step12:  The equivalent model can be created with parameters from a ERG file as well
<ASSISTANT_TASK:>
Python Code:
import femagtools.machine
p = 4
r1 = 0.0806
ls = 0.0
ld = [0.0014522728, 0.0014522728]
lq = [0.0038278836, 0.0032154]
psim = [0.11171972, 0.11171972]
i1 = [80.0]
beta = [-41.1, 0]
pm = femagtools.machine.PmRelMachineLdq(3, p, psim, ld, lq, r1, beta, i1, ls)
Explanation: Machine Characteristics
Machine characteristics such as speed, torque, voltage, currents, frequency etc. can be efficientliy calculated by equivalent circuit models which are included in the module 'femagtools.machine':
End of explanation
pm.iqd_torque(170)
Explanation: For example we can calculate the iq and id current for a given torque of 170 Nm:
End of explanation
pm.torque_iqd(87.16183261, -71.16228193)
Explanation: Or reversely: we calculate the torque with given id, iq current:
End of explanation
femagtools.machine.betai1(87.16, -71.16)
femagtools.machine.iqd(-0.685, 79.56)
Explanation: For the transformation of i1-beta and id-iq components there are corresponding functions:
End of explanation
import matplotlib.pylab as plt
import numpy as np
beta=np.linspace(-np.pi/2, 0)
plt.plot(180*beta/np.pi, [pm.torque_iqd(*femagtools.machine.iqd(b, 80)) 
                          for b in beta])
plt.xlabel('Beta')
plt.ylabel('Torque / Nm')
plt.grid()
Explanation: Show the torque vs beta curve:
End of explanation
f1 = 75
w1 = 2*np.pi*f1
np.linalg.norm(pm.uqd(w1, 87.16183261, -71.16228193))
Explanation: Calculate the amplitude of the phase voltage at frequency 75 Hz:
End of explanation
Tmax = 170.0
u1 = 230.0
w1 = pm.w1_umax(u1, *pm.iqd_torque(Tmax))
print("Frequency {}".format(w1/np.pi/2))
Explanation: Find the frequency from maximum torque and voltage:
End of explanation
def torque(T, pmax, wm):
    shaft torque as a function of rotor angular speed
    if wm <= pmax / T:
        return T
    return pmax / wm
nmax = 6000/60
pmax = w1/p*Tmax
n = np.append(np.linspace(0, w1/2/np.pi/p),
              np.linspace(1.1*w1/2/np.pi/p, nmax))
plt.plot(60*n, [torque(Tmax, pmax, 2*np.pi*nx) for nx in n])
plt.ylabel('Torque / Nm')
plt.xlabel('Speed / rpm')
plt.grid()
Explanation: Plot the speed torque characteristics:
End of explanation
bch = femagtools.read_bchfile('LDQ-0-90.BCH')
pm = femagtools.machine.create(bch, r1 = 0, ls = 0)
char = pm.characteristics(Tmax, n=6000/60, u1max=230)
plt.plot([60*n for n in char['n']], char['T'])
plt.xlabel('Speed / rpm')
plt.ylabel('Torque / Nm')
plt.grid()
Explanation: Show the torque plot with the motor parameters from a Ld-Lq-Identification:
End of explanation
import femagtools.plot
femagtools.plot.mtpa(pm, bch.ldq['i1'][-1])
Explanation: Display the characteristics with a MTPA Plot:
End of explanation
femagtools.plot.mtpa(pm, bch.ldq['i1'][-1], projection='3d')
plt.show()
Explanation: With surface
End of explanation
import femagtools.erg
erg = femagtools.erg.read('ldlq.erg')
pm = femagtools.machine.create(erg, r1 = 0, ls = 0, lfe=350)
Tmax = 9500
nmax = 600/60
u1max = 500/np.sqrt(3)
char = pm.characteristics(Tmax, n=nmax, u1max=u1max)
n = np.array(char['n'])
fig, axs = plt.subplots(2, sharex=True)
axs[0].plot(60*n, char['T'], 'b-', label='Torque')
axs[0].set_ylabel("Torque / Nm")
axs[0].grid()
axs[0].legend(loc='upper right')
ax2 = axs[0].twinx()
ax2.plot(60*n, char['i1'], 'r-', label='Current')
ax2.set_ylabel("Current / A")
ax2.legend(loc='lower left')
axs[1].plot(60*n, char['u1'], 'b-', label='Voltage')
axs[1].set_ylabel("Voltage / V",)
axs[1].set_xlabel("Speed / rpm")
axs[1].grid()
axs[1].legend(loc='upper left')
ax3 = axs[1].twinx()
ax3.plot(60*n[1:], char['cosphi'][1:], 'r-', label='Cos Phi')
ax3.set_ylabel("Cos Phi")
ax3.legend(loc='lower right')
fig.tight_layout()
plt.show()
pm.iqd_uqd(w1,0,0)
Explanation: The equivalent model can be created with parameters from a ERG file as well:
End of explanation
<END_TASK>