input
stringlengths
11
7.65k
target
stringlengths
22
8.26k
def __init__(self,params,parent): self.params=params self.parent=parent
def get_bind(self, mapper=None, **kwargs): return super(MySession, self).get_bind( mapper=mapper, **kwargs )
def __init__(self,params,parent): self.params=params self.parent=parent
def test_reverse_rfc822_datetime(): dates = [ ("Sat, 01 Jan 2011 00:00:00 -0000", datetime(2011, 1, 1, tzinfo=pytz.utc)), ("Sat, 01 Jan 2011 23:59:59 -0000", datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.utc)), ("Sat, 01 Jan 2011 21:59:59 -0200", datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.u...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_reverse_iso8601_datetime(): dates = [ ("2011-01-01T00:00:00+00:00", datetime(2011, 1, 1, tzinfo=pytz.utc)), ("2011-01-01T23:59:59+00:00", datetime(2011, 1, 1, 23, 59, 59, tzinfo=pytz.utc)), ("2011-01-01T23:59:59.001000+00:00", datetime(2011, 1, 1, 23, 59, 59, 1000, tzinfo=pytz.utc))...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_urls(): urls = [ 'http://www.djangoproject.com/', 'http://localhost/', 'http://example.com/', 'http://www.example.com/', 'http://www.example.com:8000/test', 'http://valid-with-hyphens.com/', 'http://subdomain.example.com/', 'http://200.8.9.10/...
def __init__(self,params,parent): self.params=params self.parent=parent
def check_bad_url_raises(value): try: inputs.url(value) assert False, "shouldn't get here" except ValueError as e: assert_equal(six.text_type(e), u"{0} is not a valid URL".format(value))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_bad_urls(): values = [ 'foo', 'http://', 'http://example', 'http://example.', 'http://.com', 'http://invalid-.com', 'http://-invalid.com', 'http://inv-.alid-.com', 'http://inv-.-alid.com', 'foo bar baz', u'foo \u2713', ...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_bad_url_error_message(): values = [ 'google.com', 'domain.google.com', 'kevin:pass@google.com/path?query', u'google.com/path?\u2713', ] for value in values: yield check_url_error_message, value
def __init__(self,params,parent): self.params=params self.parent=parent
def check_url_error_message(value): try: inputs.url(value) assert False, u"inputs.url({0}) should raise an exception".format(value) except ValueError as e: assert_equal(six.text_type(e), (u"{0} is not a valid URL. Did you mean: http://{0}".format(value)))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_regex_bad_input(): cases = ( 'abc', '123abc', 'abc123', '', ) num_only = inputs.regex(r'^[0-9]+$') for value in cases: yield assert_raises, ValueError, lambda: num_only(value)
def __init__(self,params,parent): self.params=params self.parent=parent
def test_regex_good_input(): cases = ( '123', '1234567890', '00000', ) num_only = inputs.regex(r'^[0-9]+$') for value in cases: yield assert_equal, num_only(value), value
def __init__(self,params,parent): self.params=params self.parent=parent
def test_regex_bad_pattern(): """Regex error raised immediately when regex input parser is created.""" assert_raises(re.error, inputs.regex, '[')
def __init__(self,params,parent): self.params=params self.parent=parent
def test_regex_flags_good_input(): cases = ( 'abcd', 'ABCabc', 'ABC', ) case_insensitive = inputs.regex(r'^[A-Z]+$', re.IGNORECASE) for value in cases: yield assert_equal, case_insensitive(value), value
def __init__(self,params,parent): self.params=params self.parent=parent
def test_regex_flags_bad_input(): cases = ( 'abcd', 'ABCabc' ) case_sensitive = inputs.regex(r'^[A-Z]+$') for value in cases: yield assert_raises, ValueError, lambda: case_sensitive(value)
def __init__(self,params,parent): self.params=params self.parent=parent
def test_boolean_with_python_bool(self): """Input that is already a native python `bool` should be passed through without extra processing.""" assert_equal(inputs.boolean(True), True) assert_equal(inputs.boolean(False), False)
def __init__(self,params,parent): self.params=params self.parent=parent
def test_bad_boolean(self): assert_raises(ValueError, lambda: inputs.boolean("blah"))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_date_later_than_1900(self): assert_equal(inputs.date("1900-01-01"), datetime(1900, 1, 1))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_date_input_error(self): assert_raises(ValueError, lambda: inputs.date("2008-13-13"))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_date_input(self): assert_equal(inputs.date("2008-08-01"), datetime(2008, 8, 1))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_natual_negative(self): assert_raises(ValueError, lambda: inputs.natural(-1))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_natural(self): assert_equal(3, inputs.natural(3))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_natual_string(self): assert_raises(ValueError, lambda: inputs.natural('foo'))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_positive(self): assert_equal(1, inputs.positive(1)) assert_equal(10000, inputs.positive(10000))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_positive_zero(self): assert_raises(ValueError, lambda: inputs.positive(0))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_positive_negative_input(self): assert_raises(ValueError, lambda: inputs.positive(-1))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_int_range_good(self): int_range = inputs.int_range(1, 5) assert_equal(3, int_range(3))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_int_range_inclusive(self): int_range = inputs.int_range(1, 5) assert_equal(5, int_range(5))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_int_range_low(self): int_range = inputs.int_range(0, 5) assert_raises(ValueError, lambda: int_range(-1))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_int_range_high(self): int_range = inputs.int_range(0, 5) assert_raises(ValueError, lambda: int_range(6))
def __init__(self,params,parent): self.params=params self.parent=parent
def test_isointerval(): intervals = [ ( # Full precision with explicit UTC. "2013-01-01T12:30:00Z/P1Y2M3DT4H5M6S", ( datetime(2013, 1, 1, 12, 30, 0, tzinfo=pytz.utc), datetime(2014, 3, 5, 16, 35, 6, tzinfo=pytz.utc), ), ...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_invalid_isointerval_error(): try: inputs.iso8601interval('2013-01-01/blah') except ValueError as error: assert_equal( str(error), "Invalid argument: 2013-01-01/blah. argument must be a valid ISO8601 " "date/time interval.", ) return ...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_bad_isointervals(): bad_intervals = [ '2013-01T14:', '', 'asdf', '01/01/2013', ] for bad_interval in bad_intervals: yield ( assert_raises, Exception, inputs.iso8601interval, bad_interval, )
def __init__(self,params,parent): self.params=params self.parent=parent
def _create_3d_axis(): """creates a subplot with 3d projection if one does not already exist""" from matplotlib.projections import get_projection_class from matplotlib import _pylab_helpers create_axis = True if _pylab_helpers.Gcf.get_active() is not None: if isinstance(plt.gca(), get_proje...
def __init__(self,params,parent): self.params=params self.parent=parent
def _plot_surface(ax, x, y, z, labels, azim=None): """helper function for surface plots""" # ax.tick_params(axis='both', which='major', pad=-3) assert np.size(x) > 1 and np.size(y) > 1 and np.size(z) > 1 if azim is not None: ax.azim = azim X, Y = np.meshgrid(x, y) Z = np.ma.masked_invali...
def __init__(self,params,parent): self.params=params self.parent=parent
def label_line(ax, X, Y, U, V, label, color='k', size=8): """Add a label to a line, at the proper angle. Arguments --------- line : matplotlib.lines.Line2D object, label : str x : float x-position to place center of text (in data coordinated y : float ...
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_phasor(up, i1, beta, r1, xd, xq, ax=0): """creates a phasor plot up: internal voltage i1: current beta: angle i1 vs up [deg] r1: resistance xd: reactance in direct axis xq: reactance in quadrature axis""" i1d, i1q = (i1*np.sin(beta/180*np.pi), i1*np.cos(beta/180*np.pi)) u...
def __init__(self,params,parent): self.params=params self.parent=parent
def iqd_phasor(up, iqd, uqd, ax=0): """creates a phasor plot up: internal voltage iqd: current uqd: terminal voltage""" uxdq = (uqd[1]/np.sqrt(2), (uqd[0]/np.sqrt(2)-up)) __phasor_plot(ax, up, (iqd[1]/np.sqrt(2), iqd[0]/np.sqrt(2)), uxdq)
def __init__(self,params,parent): self.params=params self.parent=parent
def phasor(bch, ax=0): """create phasor plot from bch""" f1 = bch.machine['p']*bch.dqPar['speed'] w1 = 2*np.pi*f1 xd = w1*bch.dqPar['ld'][-1] xq = w1*bch.dqPar['lq'][-1] r1 = bch.machine['r1'] i1beta_phasor(bch.dqPar['up'][-1], bch.dqPar['i1'][-1], bch.dqPar['beta'][-1], ...
def __init__(self,params,parent): self.params=params self.parent=parent
def airgap(airgap, ax=0): """creates plot of flux density in airgap""" if ax == 0: ax = plt.gca() ax.set_title('Airgap Flux Density [T]') ax.plot(airgap['pos'], airgap['B'], label='Max {:4.2f} T'.format(max(airgap['B']))) ax.plot(airgap['pos'], airgap['B_fft'], label=...
def __init__(self,params,parent): self.params=params self.parent=parent
def airgap_fft(airgap, bmin=1e-2, ax=0): """plot airgap harmonics""" unit = 'T' if ax == 0: ax = plt.gca() ax.set_title('Airgap Flux Density Harmonics / {}'.format(unit)) ax.grid(True) order, fluxdens = np.array([(n, b) for n, b in zip(airgap['nue'], ...
def __init__(self,params,parent): self.params=params self.parent=parent
def torque(pos, torque, ax=0): """creates plot from torque vs position""" k = 20 alpha = np.linspace(pos[0], pos[-1], k*len(torque)) f = ip.interp1d(pos, torque, kind='quadratic') unit = 'Nm' scale = 1 if np.min(torque) < -9.9e3 or np.max(torque) > 9.9e3: scal...
def __init__(self,params,parent): self.params=params self.parent=parent
def torque_fft(order, torque, ax=0): """plot torque harmonics""" unit = 'Nm' scale = 1 if np.min(torque) < -9.9e3 or np.max(torque) > 9.9e3: scale = 1e-3 unit = 'kNm' if ax == 0: ax = plt.gca() ax.set_title('Torque Harmonics / {}'.format(unit)) ax.grid(True) try:...
def __init__(self,params,parent): self.params=params self.parent=parent
def force(title, pos, force, xlabel='', ax=0): """plot force vs position""" unit = 'N' scale = 1 if min(force) < -9.9e3 or max(force) > 9.9e3: scale = 1e-3 unit = 'kN' if ax == 0: ax = plt.gca() ax.set_title('{} / {}'.format(title, unit)) ax.grid(True) ax.plot(pos...
def __init__(self,params,parent): self.params=params self.parent=parent
def force_fft(order, force, ax=0): """plot force harmonics""" unit = 'N' scale = 1 if min(force) < -9.9e3 or max(force) > 9.9e3: scale = 1e-3 unit = 'kN' if ax == 0: ax = plt.gca() ax.set_title('Force Harmonics / {}'.format(unit)) ax.grid(True) try: bw = 2...
def __init__(self,params,parent): self.params=params self.parent=parent
def forcedens(title, pos, fdens, ax=0): """plot force densities""" if ax == 0: ax = plt.gca() ax.set_title(title) ax.grid(True) ax.plot(pos, [1e-3*ft for ft in fdens[0]], label='F tang') ax.plot(pos, [1e-3*fn for fn in fdens[1]], label='F norm') ax.legend() ax.set_xlabel('Pos / ...
def __init__(self,params,parent): self.params=params self.parent=parent
def forcedens_surface(fdens, ax=0): if ax == 0: _create_3d_axis() ax = plt.gca() xpos = [p for p in fdens.positions[0]['X']] ypos = [p['position'] for p in fdens.positions] z = 1e-3*np.array([p['FN'] for p in fdens.positions]) _plot_surface(ax, xpos, ypos, z, ...
def __init__(self,params,parent): self.params=params self.parent=parent
def forcedens_fft(title, fdens, ax=0): """plot force densities FFT Args: title: plot title fdens: force density object """ if ax == 0: ax = plt.axes(projection="3d") F = 1e-3*fdens.fft() fmin = 0.2 num_bars = F.shape[0] + 1 _xx, _yy = np.meshgrid(np.arange(1, num_bar...
def __init__(self,params,parent): self.params=params self.parent=parent
def winding_flux(pos, flux, ax=0): """plot flux vs position""" if ax == 0: ax = plt.gca() ax.set_title('Winding Flux / Vs') ax.grid(True) for p, f in zip(pos, flux): ax.plot(p, f)
def __init__(self,params,parent): self.params=params self.parent=parent
def winding_current(pos, current, ax=0): """plot winding currents""" if ax == 0: ax = plt.gca() ax.set_title('Winding Currents / A') ax.grid(True) for p, i in zip(pos, current): ax.plot(p, i)
def __init__(self,params,parent): self.params=params self.parent=parent
def voltage(title, pos, voltage, ax=0): """plot voltage vs. position""" if ax == 0: ax = plt.gca() ax.set_title('{} / V'.format(title)) ax.grid(True) ax.plot(pos, voltage)
def __init__(self,params,parent): self.params=params self.parent=parent
def voltage_fft(title, order, voltage, ax=0): """plot FFT harmonics of voltage""" if ax == 0: ax = plt.gca() ax.set_title('{} / V'.format(title)) ax.grid(True) if max(order) < 5: order += [5] voltage += [0] try: bw = 2.5E-2*max(order) ax.bar(order, voltage...
def __init__(self,params,parent): self.params=params self.parent=parent
def mcv_hbj(mcv, log=True, ax=0): """plot H, B, J of mcv dict""" import femagtools.mcv MUE0 = 4e-7*np.pi ji = [] csiz = len(mcv['curve']) if ax == 0: ax = plt.gca() ax.set_title(mcv['name']) for k, c in enumerate(mcv['curve']): bh = [(bi, hi*1e-3) for bi, h...
def __init__(self,params,parent): self.params=params self.parent=parent
def mcv_muer(mcv, ax=0): """plot rel. permeability vs. B of mcv dict""" MUE0 = 4e-7*np.pi bi, ur = zip(*[(bx, bx/hx/MUE0) for bx, hx in zip(mcv['curve'][0]['bi'], mcv['curve'][0]['hi']) if not hx == 0]) if ax == 0: ax = plt.gca() ax.plo...
def __init__(self,params,parent): self.params=params self.parent=parent
def mtpa(pmrel, i1max, title='', projection='', ax=0): """create a line or surface plot with torque and mtpa curve""" nsamples = 10 i1 = np.linspace(0, i1max, nsamples) iopt = np.array([pmrel.mtpa(x) for x in i1]).T iqmax, idmax = pmrel.iqdmax(i1max) iqmin, idmin = pmrel.iqdmin(i1max) if p...
def __init__(self,params,parent): self.params=params self.parent=parent
def mtpv(pmrel, u1max, i1max, title='', projection='', ax=0): """create a line or surface plot with voltage and mtpv curve""" w1 = pmrel.w2_imax_umax(i1max, u1max) nsamples = 20 if projection == '3d': nsamples = 50 iqmax, idmax = pmrel.iqdmax(i1max) iqmin, idmin = pmrel.iqdmin(i1max) ...
def __init__(self,params,parent): self.params=params self.parent=parent
def __get_linearForce_title_keys(lf): if 'force_r' in lf: return ['Force r', 'Force z'], ['force_r', 'force_z'] return ['Force x', 'Force y'], ['force_x', 'force_y']
def __init__(self,params,parent): self.params=params self.parent=parent
def pmrelsim(bch, title=''): """creates a plot of a PM/Rel motor simulation""" cols = 2 rows = 4 if len(bch.flux['1']) > 1: rows += 1 htitle = 1.5 if title else 0 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 3*rows + htitle)) if title: ...
def __init__(self,params,parent): self.params=params self.parent=parent
def multcal(bch, title=''): """creates a plot of a MULT CAL simulation""" cols = 2 rows = 4 htitle = 1.5 if title else 0 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 3*rows + htitle)) if title: fig.suptitle(title, fontsize=16) row = 1 pl...
def __init__(self,params,parent): self.params=params self.parent=parent
def fasttorque(bch, title=''): """creates a plot of a Fast Torque simulation""" cols = 2 rows = 4 if len(bch.flux['1']) > 1: rows += 1 htitle = 1.5 if title else 0 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 3*rows + htitle)) if title: ...
def __init__(self,params,parent): self.params=params self.parent=parent
def cogging(bch, title=''): """creates a cogging plot""" cols = 2 rows = 3 htitle = 1.5 if title else 0 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 3*rows + htitle)) if title: fig.suptitle(title, fontsize=16) row = 1 plt.subplot(rows, ...
def __init__(self,params,parent): self.params=params self.parent=parent
def transientsc(bch, title=''): """creates a transient short circuit plot""" cols = 1 rows = 2 htitle = 1.5 if title else 0 fig, ax = plt.subplots(nrows=rows, ncols=cols, figsize=(10, 3*rows + htitle)) if title: fig.suptitle(title, fontsize=16) row = 1 ...
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_torque(i1, beta, torque, title='', ax=0): """creates a surface plot of torque vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() azim = 210 if 0 < np.mean(beta) or -90 > np.mean(beta): azim = -60 unit = 'Nm' scale = 1 if np.min(torque) < -9.9e3 or ...
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_ld(i1, beta, ld, ax=0): """creates a surface plot of ld vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, i1, beta, np.asarray(ld)*1e3, (u'I1/A', u'Beta/°', u'Ld/mH'), azim=60)
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_lq(i1, beta, lq, ax=0): """creates a surface plot of ld vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() azim = 60 if 0 < np.mean(beta) or -90 > np.mean(beta): azim = -120 _plot_surface(ax, i1, beta, np.asarray(lq)*1e3, (u'I1/A', u'Beta...
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_psim(i1, beta, psim, ax=0): """creates a surface plot of psim vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, i1, beta, psim, (u'I1/A', u'Beta/°', u'Psi m/Vs'), azim=60)
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_up(i1, beta, up, ax=0): """creates a surface plot of up vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, i1, beta, up, (u'I1/A', u'Beta/°', u'Up/V'), azim=60)
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_psid(i1, beta, psid, ax=0): """creates a surface plot of psid vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() azim = -60 if 0 < np.mean(beta) or -90 > np.mean(beta): azim = 60 _plot_surface(ax, i1, beta, psid, (u'I1/A', u'Beta/°', u'Ps...
def __init__(self,params,parent): self.params=params self.parent=parent
def i1beta_psiq(i1, beta, psiq, ax=0): """creates a surface plot of psiq vs i1, beta""" if ax == 0: _create_3d_axis() ax = plt.gca() azim = 210 if 0 < np.mean(beta) or -90 > np.mean(beta): azim = -60 _plot_surface(ax, i1, beta, psiq, (u'I1/A', u'Beta/°', u'P...
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_torque(id, iq, torque, ax=0): """creates a surface plot of torque vs id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() unit = 'Nm' scale = 1 if np.min(torque) < -9.9e3 or np.max(torque) > 9.9e3: scale = 1e-3 unit = 'kNm' _plot_surface(ax, id, iq, scal...
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_psid(id, iq, psid, ax=0): """creates a surface plot of psid vs id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, id, iq, psid, (u'Id/A', u'Iq/A', u'Psi d/Vs'), azim=210)
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_psiq(id, iq, psiq, ax=0): """creates a surface plot of psiq vs id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, id, iq, psiq, (u'Id/A', u'Iq/A', u'Psi q/Vs'), azim=210)
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_psim(id, iq, psim, ax=0): """creates a surface plot of psim vs. id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, id, iq, psim, (u'Id/A', u'Iq/A', u'Psi m [Vs]'), azim=120)
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_ld(id, iq, ld, ax=0): """creates a surface plot of ld vs. id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, id, iq, np.asarray(ld)*1e3, (u'Id/A', u'Iq/A', u'L d/mH'), azim=120)
def __init__(self,params,parent): self.params=params self.parent=parent
def idq_lq(id, iq, lq, ax=0): """creates a surface plot of lq vs. id, iq""" if ax == 0: _create_3d_axis() ax = plt.gca() _plot_surface(ax, id, iq, np.asarray(lq)*1e3, (u'Id/A', u'Iq/A', u'L q/mH'), azim=120)
def __init__(self,params,parent): self.params=params self.parent=parent
def ldlq(bch): """creates the surface plots of a BCH reader object with a ld-lq identification""" beta = bch.ldq['beta'] i1 = bch.ldq['i1'] torque = bch.ldq['torque'] ld = np.array(bch.ldq['ld']) lq = np.array(bch.ldq['lq']) psid = bch.ldq['psid'] psiq = bch.ldq['psiq'] rows = 3...
def __init__(self,params,parent): self.params=params self.parent=parent
def psidq(bch): """creates the surface plots of a BCH reader object with a psid-psiq identification""" id = bch.psidq['id'] iq = bch.psidq['iq'] torque = bch.psidq['torque'] ld = np.array(bch.psidq_ldq['ld']) lq = np.array(bch.psidq_ldq['lq']) psim = bch.psidq_ldq['psim'] psid = bch....
def __init__(self,params,parent): self.params=params self.parent=parent
def felosses(losses, coeffs, title='', log=True, ax=0): """plot iron losses with steinmetz or jordan approximation Args: losses: dict with f, B, pfe values coeffs: list with steinmetz (cw, alpha, beta) or jordan (cw, alpha, ch, beta, gamma) coeffs title: title string log: l...
def __init__(self,params,parent): self.params=params self.parent=parent
def spel(isa, with_axis=False, ax=0): """plot super elements of I7/ISA7 model Args: isa: Isa7 object """ from matplotlib.patches import Polygon if ax == 0: ax = plt.gca() ax.set_aspect('equal') for se in isa.superelements: ax.add_patch(Polygon([n.xy ...
def __init__(self,params,parent): self.params=params self.parent=parent
def mesh(isa, with_axis=False, ax=0): """plot mesh of I7/ISA7 model Args: isa: Isa7 object """ from matplotlib.lines import Line2D if ax == 0: ax = plt.gca() ax.set_aspect('equal') for el in isa.elements: pts = [list(i) for i in zip(*[v.xy for v in el.vertices])] ...
def __init__(self,params,parent): self.params=params self.parent=parent
def _contour(ax, title, elements, values, label='', isa=None): from matplotlib.patches import Polygon from matplotlib.collections import PatchCollection if ax == 0: ax = plt.gca() ax.set_aspect('equal') ax.set_title(title, fontsize=18) if isa: for se in isa.superelements: ...
def __init__(self,params,parent): self.params=params self.parent=parent
def demag(isa, ax=0): """plot demag of NC/I7/ISA7 model Args: isa: Isa7/NC object """ emag = [e for e in isa.elements if e.is_magnet()] demag = np.array([e.demagnetization(isa.MAGN_TEMPERATURE) for e in emag]) _contour(ax, f'Demagnetization at {isa.MAGN_TEMPERATURE} °C', emag,...
def __init__(self,params,parent): self.params=params self.parent=parent
def demag_pos(isa, pos, icur=-1, ibeta=-1, ax=0): """plot demag of NC/I7/ISA7 model at rotor position Args: isa: Isa7/NC object pos: rotor position in degree icur: cur amplitude index or last index if -1 ibeta: beta angle index or last index if -1 """ emag = [e for e in isa.eleme...
def __init__(self,params,parent): self.params=params self.parent=parent
def flux_density(isa, subreg=[], ax=0): """plot flux density of NC/I7/ISA7 model Args: isa: Isa7/NC object """ if subreg: if isinstance(subreg, list): sr = subreg else: sr = [subreg] elements = [e for s in sr for se in isa.get_subregion(s).elements()...
def __init__(self,params,parent): self.params=params self.parent=parent
def loss_density(isa, subreg=[], ax=0): """plot loss density of NC/I7/ISA7 model Args: isa: Isa7/NC object """ if subreg: if isinstance(subreg, list): sr = subreg else: sr = [subreg] elements = [e for s in sr for sre in isa.get_subregion(s).elements(...
def __init__(self,params,parent): self.params=params self.parent=parent
def mmf(f, title='', ax=0): """plot magnetomotive force (mmf) of winding""" if ax == 0: ax = plt.gca() if title: ax.set_title(title) ax.plot(np.array(f['pos'])/np.pi*180, f['mmf']) ax.plot(np.array(f['pos_fft'])/np.pi*180, f['mmf_fft']) ax.set_xlabel('Position / Deg') phi = ...
def __init__(self,params,parent): self.params=params self.parent=parent
def mmf_fft(f, title='', mmfmin=1e-2, ax=0): """plot winding mmf harmonics""" if ax == 0: ax = plt.gca() if title: ax.set_title(title) else: ax.set_title('MMF Harmonics') ax.grid(True) order, mmf = np.array([(n, m) for n, m in zip(f['nue'], ...
def __init__(self,params,parent): self.params=params self.parent=parent
def zoneplan(wdg, ax=0): """plot zone plan of winding wdg""" from matplotlib.patches import Rectangle upper, lower = wdg.zoneplan() Qb = len([n for l in upper for n in l]) from femagtools.windings import coil_color rh = 0.5 if lower: yl = rh ymax = 2*rh + 0.2 else: ...
def __init__(self,params,parent): self.params=params self.parent=parent
def winding_factors(wdg, n=8, ax=0): """plot winding factors""" ax = plt.gca() ax.set_title(f'Winding factors Q={wdg.Q}, p={wdg.p}, q={round(wdg.q,4)}') ax.grid(True) order, kwp, kwd, kw = np.array([(n, k1, k2, k3) for n, k1, k2, k3 in zip(wdg.kw_order(n), ...
def __init__(self,params,parent): self.params=params self.parent=parent
def winding(wdg, ax=0): """plot coils of windings wdg""" from matplotlib.patches import Rectangle from matplotlib.lines import Line2D from femagtools.windings import coil_color coil_len = 25 coil_height = 4 dslot = 8 arrow_head_length = 2 arrow_head_width = 2 if ax == 0: ...
def __init__(self,params,parent): self.params=params self.parent=parent
def main(): import io import sys import argparse from .__init__ import __version__ from femagtools.bch import Reader argparser = argparse.ArgumentParser( description='Read BCH/BATCH/PLT file and create a plot') argparser.add_argument('filename', help='name...
def __init__(self,params,parent): self.params=params self.parent=parent
def characteristics(char, title=''): fig, axs = plt.subplots(2, 2, figsize=(10, 8), sharex=True) if title: fig.suptitle(title) n = np.array(char['n'])*60 pmech = np.array(char['pmech'])*1e-3 axs[0, 0].plot(n, np.array(char['T']), 'C0-', label='Torque') axs[0, 0].set_ylabel("Torque / Nm...
def __init__(self,params,parent): self.params=params self.parent=parent
def runcmd(cmd, **kw): # same code as in getlino.py """Run the cmd similar as os.system(), but stop when Ctrl-C.""" # kw.update(stdout=subprocess.PIPE) # kw.update(stderr=subprocess.STDOUT) kw.update(shell=True) kw.update(universal_newlines=True) kw.update(check=True) # subprocess.check_out...
def __init__(self,params,parent): self.params=params self.parent=parent
def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, help='Do not prompt for input of any kind.') parser.add_argument('-l', '--list', action='store_true', ...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_watch_task(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-watch", args=(task.id,)) client.login(user) response = client.post(url) assert respons...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_unwatch_task(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-watch", args=(task.id,)) client.login(user) response = client.post(url) assert respo...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_list_task_watchers(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) f.WatchedFactory.create(content_object=task, user=user) url = reverse("task-watchers-list", args=(task.id,)) client.logi...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_get_task_watcher(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) watch = f.WatchedFactory.create(content_object=task, user=user) url = reverse("task-watchers-detail", args=(task.id, watch.user...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_get_task_watchers(client): user = f.UserFactory.create() task = f.TaskFactory(owner=user) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url = reverse("tasks-detail", args=(task.id,)) f.WatchedFactory.create(content_object=task, user=user) client.login(user...
def __init__(self,params,parent): self.params=params self.parent=parent
def test_get_task_is_watcher(client): user = f.UserFactory.create() task = f.create_task(owner=user, milestone=None) f.MembershipFactory.create(project=task.project, user=user, is_admin=True) url_detail = reverse("tasks-detail", args=(task.id,)) url_watch = reverse("tasks-watch", args=(task.id,)) ...
def __init__(self,params,parent): self.params=params self.parent=parent
def __init__(self): self.var = 0
def __init__(self,params,parent): self.params=params self.parent=parent
def connect (): ''' Create the connection to the MongoDB and create 3 collections needed ''' try: # Create the connection to the local host conn = pymongo.MongoClient() print 'MongoDB Connection Successful' except pymongo.errors.ConnectionFailure, err: print 'MongoDB...