femagtools package

Subpackages

Submodules

femagtools.airgap module

femagtools.airgap

Read airgap dat file

femagtools.airgap.read(filename)[source]

read dat file with columns (phi, Br, Bphi) returns samples, values, amplitude and phase of base harmonic

Parameters:filename – the ame of the file to be processed

femagtools.amazon module

femagtools.amazon

Running FEMAG on Amazon Cloud EC2

class femagtools.amazon.Engine(buckets=None, configfile='config.ini')[source]

Bases: object

config_class

alias of Config

create_job(workdir)[source]

Create a FEMAG CloudJob

Parameters:workdir (str) – The workdir where the calculation files are stored
Returns:Cloud job (CloudJob)
default_config = {'FINISH_TASK_FILENAME': 'exit_code', 'INSTANCE_TYPE': 't2.micro', 'ACL': 'authenticated-read', 'ENGINE': 'amazon', 'IMAGE_ID': 'ami-b0cc23df', 'SERVER_LOCATION': 'eu-central-1', 'COMPANY_NAME': 'femag'}

The Amazon Engine

This engine uses the boto3 Python module to interact
with the amazon ec2 and s3 services
Parameters:
  • buckets (list) – Existing buckets with femag calculation files
  • configfile (str) – Filename of config file
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error) (list)
submit()[source]

Starts the FEMAG calculation(s) on Amazon

Returns:length of started tasks (int)
exception femagtools.amazon.MissingConfigurationException(message)[source]

Bases: Exception

femagtools.bch module

femagtools.bch

Reading BCH/BATCH files

class femagtools.bch.Reader[source]

Bases: object

Reads a BCH/BATCH-File

get(name, r=None)[source]

return value of key name name can be a list such as [‘torque[1]’, ‘ripple’] or a string: ‘dqPar’

getStep()[source]

@returns displacement step of flux values

items()[source]
read(lines)[source]

read bch file

Parameters:lines (list of str) –
femagtools.bch.floatnan(s)[source]

converts string to float returns NaN on conversion error

femagtools.bch.get_si_factor(contentline)[source]

extract the first pattern and return conversion factor for SI unit

femagtools.bch.r1_20(r1, theta)[source]
femagtools.bch.splitindex(name)[source]

returns listname and index if name contains index

femagtools.bchxml module

femagtools.bchxml.dict_to_xml(tag, d)[source]

Turn a simple dict of key/value pairs into XML

femagtools.bchxml.list_to_xml(tag, l)[source]

Turn a list into XML

femagtools.bchxml.usage()[source]

femagtools.condor module

femagtools.condor

Creating and managing condor jobs

class femagtools.condor.CondorCluster(userdir)[source]

Bases: object

manages condor cluster directories

getAvailableClusters()[source]
getClusterData(directory)[source]
getClusterDirectories()[source]
getClusterList(clusterIds=[])[source]
status(clusterId=None)[source]
class femagtools.condor.Engine[source]

Bases: object

manages calculation tasks in a HTCondor environment

create_job(workdir)[source]
dumpData(workdir, parameters)[source]
dumpData2(femag, opt, pmMachine, operatingConditions)[source]
history(clusterId)[source]
join()[source]

wait for all tasks to be terminated and return status

queue(clusterId)[source]
status(userdir=None)[source]
statusDir(userdir, directory)[source]
submit()[source]
femagtools.condor.getDateTime(date, time)[source]

complete date with year: m/d –> y/m/d

femagtools.config module

femagtools.config

Config FEMAG

class femagtools.config.Config(defaults=None, configfile=None)[source]

Bases: dict

from_ini_file(ini_file)[source]
from_ini_file_all(ini_file)[source]
femagtools.config.get_executable()[source]

returns platform specific pathname of femag executable

femagtools.config.get_femag()[source]

returns femag command

femagtools.config.is_exe(fpath)[source]
femagtools.config.which(program)[source]

returns complete pathname of program or None if not found

femagtools.erg module

femagtools.erg

Reading ERG files

femagtools.erg.read(filename)[source]

read ERG file returns dict with array values

femagtools.femag module

femagtools.femag

Running FEMAG

class femagtools.femag.BaseFemag(workdir, cmd, magnetizingCurves, magnets)[source]

Bases: object

copy_magnetizing_curves(model, dir=None)[source]

extract mc names from model and write files into workdir or dir if given

Returns:list of extracted mc names (list)
create_fsl(pmMachine, operatingConditions)[source]

create list of fsl commands

get_log_value(pattern, modelname='FEMAG-FSL.log')[source]
read_airgap_induction()[source]

read airgap induction

read_bch(modelname=None)[source]

read most recent BCH/BATCH file and return result

read_los(modelname=None)[source]

read most recent LOS file and return result

class femagtools.femag.Femag(workdir, cmd=None, magnetizingCurves=None, magnets=None)[source]

Bases: femagtools.femag.BaseFemag

Invoke and control execution of FEMAG

Parameters:
  • workdir – name of working directory
  • cmd – name of femag program
  • magnetizingCurves – collection of lamination material curves
  • magnets – collection of magnet material
cleanup()[source]

removes all created files in workdir

run(filename, options=['-b'], fsl_args=[])[source]

invoke FEMAG in current workdir

Parameters:
  • filename – name of file to execute
  • options – list of FEMAG options
  • fsl_args – list of FSL argument options
Raises:

FemagError

exception femagtools.femag.FemagError[source]

Bases: Exception

class femagtools.femag.FemagReadStream(sub_socket, callback)[source]

Bases: threading.Thread

dummy_callback(data)[source]

This dummy method is used when no callback is defined.

run()[source]

Listen for messages from femag as long as the continue_loop is True the sub_socket has a timeout to finish the loop and thread after the continue_loop is set to False and no messages are arrived.

class femagtools.femag.ZmqFemag(workdir, port, host='localhost', cmd=None, magnetizingCurves=None, magnets=None)[source]

Bases: femagtools.femag.BaseFemag

Invoke and control execution of FEMAG with ZeroMQ

Parameters:
  • workdir – name of working directory
  • cmd – name of femag program
quit(save_model=False)[source]

terminates femag

run(options=['-b'], restart=False, procId=None)[source]

invokes FEMAG in current workdir and returns pid

Parameters:options – list of FEMAG options
Raises:FemagError
send_fsl(fsl, callback=None, header='FSL')[source]

sends FSL commands in ZMQ mode and blocks until commands are processed

Parameters:fsl – FSL commands
Returns:response

femagtools.fsl module

femagtools.fsl

Creating FSL Scripts

class femagtools.fsl.Builder[source]

Bases: object

create(model, fea, magnets=None)[source]

create model and analysis function

create_airgap_induc()[source]
create_analysis(model)[source]
create_colorgrad(model)[source]
create_common(model)[source]
create_connect_models(model)[source]

return connect_model if rotating machine

create_magnet(model, magnetMat)[source]
create_magnet_model(model)[source]
create_model(model, magnets=None)[source]
create_new_model(model)[source]
create_open(model)[source]
create_stator_model(model)[source]
load_model(model, magnets=None)[source]
open_model(model, magnets=None)[source]
read(fslfile)[source]

extracts parameters from content and creates template

render_template(content_template, parameters)[source]
set_modpar(model)[source]
exception femagtools.fsl.FslBuilderError[source]

Bases: Exception

femagtools.google module

Author: Nicolas Mauchle <mauchle@semafor.ch> To use this class you have to install:

  • gcloud
  • googleapiclient
Also you have to configure your google account with
gcloud init

The google cloud module for femag in short: 1. Create for every calculation a bucket 2. Upload the files for the calculation in the specific bucket 3. Start for every calculation one instance with a femag image 4. Wait until a exit_code file is stored in the bucket 5. Terminate instance 6. Sync back the results files

The connection between the buckets and the calculation are stored in the job dict

class femagtools.google.Engine(buckets=None)[source]

Bases: object

config_class

alias of Config

create_job(workdir)[source]

Create a FEMAG CloudJob

Parameters:workdir (str) – The workdir where the calculation files are stored
Returns:Cloud job (CloudJob)
default_config = {'FINISH_TASK_FILENAME': 'exit_code', 'INSTANCE_TYPE': 'n1-standard-1', 'ENGINE': 'google', 'IMAGE_ID': 'femag-v1', 'SERVER_LOCATION': 'us-east1-b', 'COMPANY_NAME': 'femag'}
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error) (list)
submit()[source]

Starts the FEMAG calculation(s) on Google Cloud

Returns:length of started tasks (int)
exception femagtools.google.IllegalNumberOfBuckets[source]

Bases: Exception

femagtools.grid module

femagtools.grid

Parameter range calculation

class femagtools.grid.Grid(workdir, magnetizingCurves=None, magnets=None)[source]

Bases: object

Parameter variation calculation

addBchMapperData(bchData)[source]
getBchMapperData()[source]
setup_model(builder, model)[source]

builds model in current workdir and returns its filenames

stop = None

the “owner” of the Grid have to take care to terminate all running xfemag64 or wfemagw64 processes after setting stop to True For example:

def killFemagThreads():
if sys.platform.startswith(‘linux’):
os.system(“kill $(ps aux | grep ‘[x]femag64’ | awk ‘{print $2}’)”)
else:
os.system(“taskkill /f /im wfemagw64.exe”)

thomas.maier/OSWALD

femagtools.grid.baskets(items, basketsize=10)[source]

generates balanced baskets from iterable, contiguous items

femagtools.grid.chunks(l, n)[source]

Yield successive n-sized chunks from l.

femagtools.grid.create_parameter_range(domain)[source]

returns the transposed array of the combined domain values

femagtools.jhb module

class femagtools.jhb.Reader(filename)[source]

Bases: object

getValues()[source]

return values as mcv dict

femagtools.jhb.read(filename)[source]

read JHB File and return mc dict

femagtools.job module

femagtools.job

Creating and managing calculation jobs.

class femagtools.job.CloudJob(basedir)[source]

Bases: femagtools.job.Job

Inheritance of Job

Represents a femag amazon job

add_task()[source]

adds a new AmazonTask to this job

class femagtools.job.CloudTask(id, directory)[source]

Bases: femagtools.job.Task

add_file(fname, content=None)[source]
class femagtools.job.CondorJob(basedir)[source]

Bases: femagtools.job.Job

represents a femag job that is to be run in HT Condor

prepareDescription()[source]
class femagtools.job.Job(basedir)[source]

Bases: object

represents a FEMAG job consisting of one or more tasks each to be executed by a dedicated process

add_task()[source]

adds a new task to this job

cleanup()[source]

removes all files and directories of previous run

get_results()[source]
setExitStatus(taskid, status)[source]

set exit status of task

class femagtools.job.Task(id, directory)[source]

Bases: object

represents a single execution unit that may include data files

add_file(fname, content=None)[source]

adds a file required by this task

Parameters:
  • fname – file name
  • content – list of str written to file if not None
get_results()[source]

returns result of most recent BCH file

femagtools.losscoeffs module

femagtools.losscoeffs

Fitting methods for loss coeffs

femagtools.losscoeffs.fitjordan(f, B, losses, Bo, fo)[source]
fit coeffs of
losses(f,B)=(cw*(f/fo)**alpha + ch*(f/fo)**beta)*(B/Bo)**gamma

returns (cw, alpha, ch, beta, gamma)

femagtools.losscoeffs.fitsteinmetz(f, B, losses, Bo, fo)[source]
fit coeffs of
losses(f,B)=cw*(f/fo)**alfa*(B/Bo)**beta

returns (cw, alfa, beta)

femagtools.losscoeffs.pfe_jordan(f, B, ch, fh, cw, fw, fb, fo, Bo)[source]
femagtools.losscoeffs.pfe_steinmetz(f, B, cw, fw, fb, fo, Bo)[source]

femagtools.machine module

femagtools.machine.K(d)[source]

space phasor transformation matrix (Inverse Park Transformation) T-1 * dq :param d: rotation angle

returns transformation matrix

class femagtools.machine.PmRelMachine(m, p, r1, ls)[source]

Bases: object

Abstract base class for PmRelMachines

Parameters:
  • m – number of winding phases
  • p – number of pole pairs
  • r1 – stator winding resistance (in Ohm)
beta_u(w1, u, i1)[source]

beta at given frequency, voltage and current

characteristics(T, n, u1max, nsamples=36)[source]

calculate torque speed characteristics. return dict with list values of

id, iq, n, T, ud, uq, u1, i1, beta, gamma, phi, cosphi, pmech, n_type

Keyword arguments: T – the maximum torque or the list of torque values in Nm n – the maximum speed or the list of speed values in 1/s u1max – the maximum voltage in V rms nsamples – (optional) number of speed samples

i1_torque(torque, beta)[source]

return i1 current with given torque and beta

i1_voltage(w1, u1, beta)[source]

return i1 current with given w1, u1 and beta

i1beta_characteristics(n_list, i1_list, beta_list, u1max)[source]

calculate i1-beta characteristics

id_torque(torque, iq)[source]

return d current with given torque and d-current

iq_u(w1, u, id)[source]

iq at given frequency, voltage and id current

iqd_imax_umax(i1max, w1, u1max)[source]

return d-q current at stator frequency and max voltage and max current

iqd_torque(torque)[source]

return minimum d-q-current for torque

iqd_torque_umax(torque, w1, u1max)[source]

return d-q current and torque at stator frequency and max voltage

iqd_uqd(w1, uq, ud)[source]

return iq, id current at given frequency, voltage

mtpa(i1)[source]

return iq, id, torque at maximum torque of current i1

mtpv(w1, u1)[source]

return d-q-current for voltage and frequency with maximum torque

torque_iqd(iq, id)[source]

torque at q-d-current

uqd(w1, iq, id)[source]

return uq, ud of frequency w1 and d-q current

w1_u(u, iq, id)[source]

return frequency w1 at given voltage u and id, iq current (obsolete, use w1_umax)

w1_umax(u, iq, id)[source]

return frequency w1 at given voltage u and id, iq current

Keyword arguments: u – the maximum voltage (RMS) iq, id – the d-q currents

w1max(u, iq, id)[source]

return max frequency w1 at given voltage u and d-q current (obsolete, use w1_umax)

w2_imax_umax(imax, umax)[source]

return frequency at current and voltage

class femagtools.machine.PmRelMachineLdq(m, p, psim=[], ld=[], lq=[], r1=0, beta=[], i1=[], ls=0, **kwargs)[source]

Bases: femagtools.machine.PmRelMachine

Standard set of PM machine given by i1,beta parameters: p number of pole pairs m number of phases psim flux in Vs (RMS) ld d-inductance in H lq q-inductance in H r1 stator resistance ls stator leakage inductance in H beta angle i1 vs up in degrees i1 current in A (RMS)

optional keyword args: psid D-Flux in Vs (RMS) psiq Q-Flux in Vs (RMS)

iqdmax(i1)[source]

max iq, min id for given current

iqdmin(i1)[source]

max iq, min id for given current

psi(iq, id)[source]

return psid, psiq of currents iq, id

psi0(iq, id)[source]

return psid, psiq of currents iq, id

class femagtools.machine.PmRelMachinePsidq(m, p, psid, psiq, r1, id, iq, ls=0)[source]

Bases: femagtools.machine.PmRelMachine

Standard set of PM machine parameters: p number of pole pairs m number of phases

psid d-flux (Vs Peak) psiq q-flux (Vs Peak) r1 stator resistance (Ohm) r1 stator leakage inductance (H) id q current (A, Peak) iq q current (A, Peak)

iqdmax(i1)[source]

max iq, max id for given current

iqdmin(i1)[source]

max iq, min id for given current

psi(iq, id)[source]
femagtools.machine.T(d)[source]

space phasor transformation matrix (Park Transformation) T * abc :param d: rotation angle

returns transformation matrix

femagtools.machine.betai1(iq, id)[source]

return beta and amplitude of dq currents

femagtools.machine.create(bch, r1, ls, lfe=1)[source]

create PmRelMachine from BCH

femagtools.machine.invpark(a, q, d)[source]

convert a dq vector to the abc reference frame (inverse park transformation)

Parameters:
  • a – rotation angle
  • d – value in direct axis
  • q – value in quadrature axis
femagtools.machine.iqd(beta, i1)[source]

return qd currents of beta and amplitude

femagtools.machine.mesh(x, y)[source]

return the combined vectors x and y

femagtools.magnet module

femagtools.magnet

Creating and managing magnet material

class femagtools.magnet.Magnet(mlist=[])[source]

Bases: object

find(id)[source]

find magnet by id or name

find_by_name(name)[source]

find magnet by name

femagtools.mcv module

femagtools.mcv

Reading, Creating and managing MCV/MC files

class femagtools.mcv.MagnetizingCurve(mcvpar)[source]

Bases: object

find(id)[source]

find mcv by id or name

find_by_name(name)[source]

find mcv by name

fitLossCoeffs()[source]
recalc()[source]
writefile(name, directory='.', writeproc='')[source]

find magnetic curve by name or id and write binary file returns filename if found else None

class femagtools.mcv.Mcv[source]

Bases: object

rtrimValueList(vlist)[source]

cut list at first 0

class femagtools.mcv.Reader[source]

Bases: femagtools.mcv.Mcv

getInteger(length=4)[source]
getReal()[source]
getString(length=1)[source]
get_results()[source]
readBlock(d, length=0)[source]
readData(d, length=1)[source]
readMcv(filename)[source]
class femagtools.mcv.Writer(data=None)[source]

Bases: femagtools.mcv.Mcv

getBlockLength(d)[source]
setData(data)[source]
writeBinaryFile()[source]
writeBlock(d)[source]
writeData(d)[source]
writeMcv(filename)[source]
femagtools.mcv.approx(db2, curve)[source]

return nuer, bi2, a, b approx for curve

femagtools.mcv.findNotNone(l)[source]

return lower and upper indexes of not none values in list

femagtools.model module

femagtools.model

Managing model parameters

class femagtools.model.FeaModel(parameters)[source]

Bases: femagtools.model.Model

exception femagtools.model.MCerror[source]

Bases: Exception

class femagtools.model.MachineModel(parameters)[source]

Bases: femagtools.model.Model

represents a machine model for a FE analysis

Parameters:parameters – string or dict containing the model parameters. For example:
{'lfe': 0.1,
'poles': 4,
'outer_diam': 0.13,
'bore_diam': 0.07,
'stator':{
'num_slots': 12,
'num_slots_gen': 3,
...
},
'magnet':{
    'material': 'M395',
    ..
}
}

if parameters is string it is interpreted as the model name.
get_mcvkey_magnet()[source]
is_complete()[source]

check completeness of models

magnettype()[source]

return type of magnet slot

set_magcurves(magcurves, magnetmat={})[source]

set and return real names of magnetizing curve material

Parameters:magcurves
class:’MagnetizingCurve’ including

magnetizing curve materials

Returns:set of magnetizing curve names attached to this model
set_mcvkey_magnet(mcvkey)[source]
statortype()[source]

return type of stator slot

class femagtools.model.Model(parameters)[source]

Bases: object

get(name, r=None)[source]

return value of key name

Parameters:name – key of parameter value
Returns:value of parameter identified by key
set_value(name, value, p=None)[source]

set value of parameter identified by name

Parameters:
  • name – name of parameter
  • value – value to be assigned to parameter
femagtools.model.gcd(a, b)[source]
femagtools.model.lcm(a, b)[source]

femagtools.moproblem module

femagtools.moproblem

Creating and managing multi-objective problems

class femagtools.moproblem.FemagMoProblem(decision_vars, objective_vars)[source]

Bases: femagtools.moo.problem.Problem

A multi-objective optimization problem with Femag.

objfun(x)[source]
prepare(x, model)[source]
setResult(result)[source]

femagtools.multiproc module

femagtools.engine.multiproc

Creating and managing multicore/multiprocessing jobs

authors:
  1. Tanner, N. Mauchle
class femagtools.multiproc.Engine(cmd=None, process_count=None)[source]

Bases: object

The MultiProc engine uses a pool of local calculation processes.

This is more or less a decorator for the Python multiprocessing Module

Parameters:
  • cmd – the program (executable image) to be run (femag dc is used if None)
  • process_count – number of processes (cpu_count() if None)
create_job(workdir)[source]

Create a FEMAG Job

Parameters:workdir – The workdir where the calculation files are stored
Returns:FEMAG Job
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error)
submit()[source]

Starts the FEMAG calculation(s) with the internal multiproc.run_femag() function

Returns:length of started tasks
femagtools.multiproc.run_femag(cmd, workdir, fslfile)[source]

Start the femag command as subprocess.

Internal:
Parameters:
  • cmd – The program (executable image) to be run
  • workdir – The workdir where the calculation files are stored
  • fslfile – The name of the start file (usually femag.fsl)

femagtools.ntib module

femagtools.fsl

Creating FSL Scripts

femagtools.ntib.create(speed, current, beta, r1=0, m=3)[source]

return Ntib info

femagtools.ntib.read_los(filename)[source]

return dict of losses in LOS-file

femagtools.ntib.toFloat(s, fac=1.0)[source]

femagtools.opt module

femagtools.opt

Manage multi-objective optimization with FEMAG

class femagtools.opt.Optimizer(workdir, magnetizingCurves, magnetMat)[source]

Bases: object

optimize(num_generations, opt, pmMachine, operatingConditions, engine)[source]

execute optimization

femagtools.opt.log_pop(pop, ngen)[source]

femagtools.plot module

femagtools.plot

Creating plots

femagtools.plot.airgap(airgap)[source]

creates plot of flux density in airgap

femagtools.plot.cogging(bch, title='')[source]

creates a cogging plot

femagtools.plot.felosses(losses, coeffs, title='', log=True)[source]

plot iron losses with steinmetz or jordan approximation :param losses: dict with f, B, pfe values :param coeffs: list with steinmetz (cw, alpha, beta) or

jordan (cw, alpha, ch, beta, gamma) coeffs
Parameters:
  • title – title string
  • log – log scale for x and y axes if True
femagtools.plot.force(title, pos, force)[source]

plot force vs position

femagtools.plot.i1beta_ld(i1, beta, ld)[source]

creates a surface plot of ld vs i1, beta

femagtools.plot.i1beta_lq(i1, beta, lq)[source]

creates a surface plot of ld vs i1, beta

femagtools.plot.i1beta_phasor(up, i1, beta, r1, xd, xq)[source]

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

femagtools.plot.i1beta_psid(i1, beta, psid)[source]

creates a surface plot of psid vs i1, beta

femagtools.plot.i1beta_psim(i1, beta, psim)[source]

creates a surface plot of psim vs i1, beta

femagtools.plot.i1beta_psiq(i1, beta, psiq)[source]

creates a surface plot of psiq vs i1, beta

femagtools.plot.i1beta_torque(i1, beta, torque)[source]

creates a surface plot of torque vs i1, beta

femagtools.plot.idq_ld(id, iq, ld)[source]

creates a surface plot of ld vs. id, iq

femagtools.plot.idq_lq(id, iq, lq)[source]

creates a surface plot of lq vs. id, iq

femagtools.plot.idq_psid(id, iq, psid)[source]

creates a surface plot of psid vs id, iq

femagtools.plot.idq_psim(id, iq, psim)[source]

creates a surface plot of psim vs. id, iq

femagtools.plot.idq_psiq(id, iq, psiq)[source]

creates a surface plot of psiq vs id, iq

femagtools.plot.idq_torque(id, iq, torque)[source]

creates a surface plot of torque vs id, iq

femagtools.plot.iqd_phasor(up, iqd, uqd)[source]

creates a phasor plot up: internal voltage iqd: current uqd: terminal voltage

femagtools.plot.ldlq(bch)[source]

creates the surface plots of a BCH reader object with a ld-lq identification

femagtools.plot.mcv_hbj(mcv, log=True)[source]

plot H, B, J of mcv dict

femagtools.plot.mcv_muer(mcv)[source]

plot rel. permeability vs. B of mcv dict

femagtools.plot.mtpa(pmrel, i1max, title='', projection='')[source]

create a line or surface plot with torque and mtpa curve

femagtools.plot.phasor(bch)[source]

create phasor plot from bch

femagtools.plot.pmrelsim(bch, title='')[source]

creates a plot of a PM/Rel motor simulation

femagtools.plot.psidq(bch)[source]

creates the surface plots of a BCH reader object with a psid-psiq identification

femagtools.plot.torque(pos, torque)[source]

creates plot from torque vs position

femagtools.plot.torque_fft(order, torque)[source]

plot torque harmonics

femagtools.plot.voltage(title, pos, voltage)[source]

plot voltage vs. position

femagtools.plot.voltage_fft(title, order, voltage)[source]

plot FFT harmonics of voltage

femagtools.plot.winding_current(pos, current)[source]

plot winding currents

femagtools.plot.winding_flux(pos, flux)[source]

plot flux vs position

femagtools.poc module

femagtools.poc

Manage POC files

class femagtools.poc.Poc(arg, parameters={})[source]

Bases: object

getProps()[source]
readfile(pocfile)[source]

read poc file

write(pocfilename)[source]

create a new pocfile and write the data

writefile(pocfile)[source]
femagtools.poc.curr(x, n, A, phi)[source]

return fourier sum

femagtools.tks module

femagtools.tks

Manage TKS magnetizing curve data files

class femagtools.tks.Reader(filename)[source]

Bases: object

getValues()[source]

return values as mcv dict

femagtools.tks.read(filename)[source]

read Thyssen File TKS and return mc dict

femagtools.tks.readlist(f)[source]

femagtools.tools3d module

Interface for 3D plotting functions

Module containing functions that allow to access the 3d-functions with the normal pylab syntax.

>>> from pylab import *
>>> from tools3d import *
>>> x = frange(-2,2,0.1)
>>> X, Y = meshgrid(x,x)
>>> wireframe(X, Y, X**2+Y**2)             
<mpl_toolkits.mplot3d.art3d.Line3DCollection object at 0x...>
>>> show()
femagtools.tools3d.surface(*args, **kwargs)[source]

wrapper for axes3d.Axes3D.plot_surface

allows to create surface plots with the usual pylab syntax.

Don’t forget to set cstride=1 and rstride=1. Otherwise you might get very ugly plots.

Create a surface plot.

By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the cmap argument.

The rstride and cstride kwargs set the stride used to sample the input data to generate the graph. If 1k by 1k arrays are passed in, the default values for the strides will result in a 100x100 grid being plotted. Defaults to 10. Raises a ValueError if both stride and count kwargs (see next section) are provided.

The rcount and ccount kwargs supersedes rstride and cstride for default sampling method for surface plotting. These arguments will determine at most how many evenly spaced samples will be taken from the input data to generate the graph. This is the default sampling method unless using the ‘classic’ style. Will raise ValueError if both stride and count are specified. Added in v2.0.0.

Argument Description
X, Y, Z Data values as 2D arrays
rstride Array row stride (step size)
cstride Array column stride (step size)
rcount Use at most this many rows, defaults to 50
ccount Use at most this many columns, defaults to 50
color Color of the surface patches
cmap A colormap for the surface patches.
facecolors Face colors for the individual patches
norm An instance of Normalize to map values to colors
vmin Minimum value to map
vmax Maximum value to map
shade Whether to shade the facecolors

Other arguments are passed on to Poly3DCollection

femagtools.tools3d.wireframe(*args, **kwargs)[source]

wrapper for axes3d.Axes3D.plot_wireframe

allows to create wireframe plots with the usual pylab syntax.

Plot a 3D wireframe.

The rstride and cstride kwargs set the stride used to sample the input data to generate the graph. If either is 0 the input data in not sampled along this direction producing a 3D line plot rather than a wireframe plot. The stride arguments are only used by default if in the ‘classic’ mode. They are now superseded by rcount and ccount. Will raise ValueError if both stride and count are used.

` The rcount and ccount kwargs supersedes rstride and

cstride for default sampling method for wireframe plotting. These arguments will determine at most how many evenly spaced samples will be taken from the input data to generate the graph. This is the default sampling method unless using the ‘classic’ style. Will raise ValueError if both stride and count are specified. If either is zero, then the input data is not sampled along this direction, producing a 3D line plot rather than a wireframe plot. Added in v2.0.0.

Argument Description
X, Y, Data values as 2D arrays
Z  
rstride Array row stride (step size), defaults to 1
cstride Array column stride (step size), defaults to 1
rcount Use at most this many rows, defaults to 50
ccount Use at most this many columns, defaults to 50

Keyword arguments are passed on to LineCollection.

Returns a Line3DCollection

femagtools.tpl module

femagtools.vbf module

femagtools.vbf

Manage VBF magnetizing curve data files

class femagtools.vbf.Reader(filename)[source]

Bases: object

getLossValues()[source]
femagtools.vbf.read(filename)[source]

read VBF file and return dict of content

Module contents

femagtools

Python bindings for FEMAG

femagtools.create_fsl(machine, operatingconditions={}, magnetmat=[])[source]

create FSL command list from model parameters

Parameters:
  • machine – dict with parameters
  • operatuingConditions – dict with parameters
  • magnetmat – list fo dict with parameters
femagtools.read_bchfile(filename)[source]

Read BCH/BATCH results from file filename.