Skip to main content

Python Antenna Simulation Module (nec2++) object-oriented interface

Project description

Python NEC2++ Module

This module wraps the C++ API for antenna simulation of nec2++. It is easier to work with, and more powerful than the C-style API wrapper. Works with Python 2.7 and 3+.

Usage

Here is an example that plots a radiation pattern.

from PyNEC import *
import numpy as np

#creation of a nec context
context=nec_context()

#get the associated geometry
geo = context.get_geometry()

#add wires to the geometry
geo.wire(0, 36, 0, 0, 0, -0.042, 0.008, 0.017, 0.001, 1.0, 1.0)
context.geometry_complete(0)

context.gn_card(-1, 0, 0, 0, 0, 0, 0, 0)

#add a "ex" card to specify an excitation
context.ex_card(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)

#add a "fr" card to specify the frequency 
context.fr_card(0, 2, 2400.0e6, 100.0e6)

#add a "rp" card to specify radiation pattern sampling parameters and to cause program execution
context.rp_card(0, 91, 1, 0, 5, 0, 0, 0.0, 45.0, 4.0, 2.0, 1.0, 0.0)

#get the radiation_pattern
rp = context.get_radiation_pattern(0)

# Gains are in decibels
gains_db = rp.get_gain()
gains = 10.0**(gains_db / 10.0)
thetas = rp.get_theta_angles() * 3.1415 / 180.0
phis = rp.get_phi_angles() * 3.1415 / 180.0


# Plot stuff
import matplotlib.pyplot as plt

ax = plt.subplot(111, polar=True)
ax.plot(thetas, gains[:,0], color='r', linewidth=3)
ax.grid(True)

ax.set_title("Gain at an elevation of 45 degrees", va='bottom')
plt.savefig('RadiationPattern.png')
plt.show()

Manual Build & install

Requirements

  • Swig
  • For Windows: C/C++ compilers.
  • Git bash (for running build.sh script)
  • uv (recommended) or pip + setuptools + numpy + wheel

Note: Download and extract swigwin.zip and add the path to swig.exe to environment.

Then do following:

    $ git clone --recursive https://github.com/tmolteno/python-necpp.git
    $ cd python-necpp
    $ cd PyNEC
    $ ./build.sh
    $ uv build               # Modern, fast build
    $ uv pip install .       # Or: pip install .

Note: 'sudo' is not required in windows.

Install from PyPI

$ sudo pip install pynec

Note: 'sudo' is not required in windows.

Testing

Requirements

  • python package: matplotlib

    $ python example/test_rp.py

The example directory contains the following additional examples (that are inspired by excercises from a course on antennas):

  • logperiodic_opt.py is an example on how to combine PyNECPP with scipy.optimize to use a genetic algorithm to optimize an antenna for multiple frequency bands at the same time (which I thin is not possible in 4nec2). The resulting gains and VSWR are plotted over the frequency range of interest. This requires scipy >= 0.15.0 due to the usage of scipy.optimize.differential_evolution.
  • monopole_realistic_ground_plane.py plots the vertical gain pattern of a monopole antenna. Its dimensions are optimized with a local search, and the path through the search space is visualized with a heat map.
  • dipole.py does a very simple optimization of a dipole, and plots the VSWR over a given frequency range for different system impedances to file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynec-1.8.2.tar.gz (222.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pynec-1.8.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-1.8.2-cp313-cp313-macosx_11_0_arm64.whl (289.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-1.8.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-1.8.2-cp312-cp312-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-1.8.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-1.8.2-cp311-cp311-macosx_11_0_arm64.whl (289.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pynec-1.8.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-1.8.2-cp310-cp310-macosx_11_0_arm64.whl (289.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pynec-1.8.2.tar.gz.

File metadata

  • Download URL: pynec-1.8.2.tar.gz
  • Upload date:
  • Size: 222.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynec-1.8.2.tar.gz
Algorithm Hash digest
SHA256 6c124d7476140595369d0844ecfea2d0efa76e7bcc57f54e63ee364aa73b2085
MD5 57f379652f26886f40a79497c2bd9074
BLAKE2b-256 dfa5771be75b8eb7290e795a7c460430cc1722d06f92ca39aa7b74db6bdf7c8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2.tar.gz:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b915fc1dd4f2ec096930a5fe10b6d7ebf09ee3a95bb7b58eec1ab9522ad73aa6
MD5 738be2a6e654c7d539511ff5622701b4
BLAKE2b-256 91125732f959f50973c97b415ee780b71e8b0886a5f27df8a67335a94c0aa79f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ff0881b96811ed7a7491d3b9c780cd1fbf0684cdf33f6915f5ad6980f05d9db
MD5 e63158d35fb57aaeb05062954a357ec5
BLAKE2b-256 84969101455d1faf671c546673b71c0ea103908610a26e88f2d62f853be791cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4279100b8367400ce02fc025f7f97ad4859ec09171b7a38d0027fdedf94ce299
MD5 d59f32ab663b46081c92feb458b7fcaf
BLAKE2b-256 34dfe76756ae9db30345367d1031688defce57b08da9b43b156ba46082e0a94c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f71096399b186826b9d430646a778b51a760db70d120ad99eefe9e286776aa9
MD5 caf4ff4211229936417c582b9e329a6f
BLAKE2b-256 aa1471d00f3f858ad0bdf9b38ac88e43f07469508edc45ee4b3c1d97c8e1787c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7bc85d57216269f1b7307e3bc5c016c5ef3bbaf79fe811056011d00bbbfe493c
MD5 a2b1c5826adf3ed7ca0953a4b654b24b
BLAKE2b-256 36d0a0c5d1019695095feb5163413c8d7d56960f977d2e676510551e56ac519e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e43a1462321be6925580023968e9e748032c87434b4e27900744a69930cc612d
MD5 aac36943529bc2f7c738237cc5a395e7
BLAKE2b-256 43351ce66ec2f52d9c3efe7c9f34b7a2524abcc64ded987e781473f861167647

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a29c834bb7b13ccc6c01110901c414c14710f94ad61b3e8f9bdeabd3304a09f0
MD5 cbcfe3415d70260e9a6562315bb06771
BLAKE2b-256 faa368e46e8de183613451b8a55308a996c68462c62076a6f1d8f1c65f0ab226

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-1.8.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.8.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 646cb8829a96d944b65ada4463a400dd013bc9e08390e9e600e48e68c31c1d9e
MD5 18525e95a7a2cde6c6e01d27733e68f3
BLAKE2b-256 742f9b520dbc750858b01a4a73aea73040a52d22ccd3987ad01b40163c83462e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.8.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page