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. Requires Python 3.9+.

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

$ 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-2.2.6.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

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

pynec-2.2.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

pynec-2.2.6-cp314-cp314-macosx_11_0_arm64.whl (289.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pynec-2.2.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

pynec-2.2.6-cp313-cp313-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.2.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

pynec-2.2.6-cp312-cp312-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.2.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

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

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pynec-2.2.6.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pynec-2.2.6.tar.gz
Algorithm Hash digest
SHA256 bc78682ae51119fbd5a798a4e1fcc50008503bba18330e7b1f5f9a8879b220c4
MD5 62a0f31cee8cf3360fb711ff10a2fc0a
BLAKE2b-256 2356f5ce78bed5ea099f1a313abcf6e7918a3040faae467bdce7aad556e3a6a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6.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-2.2.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7904245e657b50db71c51f6507e182040afb22d3ff4ee045446e3b685cff7eb2
MD5 ef74de33a17548dae27c7bd4315ea2b0
BLAKE2b-256 777ee884b79ba8ac02f576f1100196c6a596602895657d23db1c02c6afcced8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-cp314-cp314-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-2.2.6-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a7ac2189e429e57c6e958953e29feced2fea51d2378036b0b3ae4889aad2987
MD5 c7e704387502707af0f05415eae39eba
BLAKE2b-256 6b1a8eb0e309629d5ebacf5fb2a041569a50c0bf26edda10d6219dba7b786c42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-cp314-cp314-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-2.2.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f309646ddefa639c8f4e7608d5a77eac1e0952fad89d52ed9a2430b606dc57d9
MD5 1020baad52ad773eacf02543a2557593
BLAKE2b-256 3af2cd3890748fff258112d172cc095b4cb750c37886b08b141983a30dc36fa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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-2.2.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2b41252bfb7c17f409bec027d8d4318fa3848e7d90a15743510077f60d6a633
MD5 4ca38a5a06265050313518fa1ef26d6b
BLAKE2b-256 98cd7f6d53fb04fd80f0e16d25a9271249c8875b6a5d967762e1a93d6a538f76

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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-2.2.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6922ff115a815785324984e4e27a444b26c57c609cf0ba5b650c04719045146
MD5 08399f84f5da101e2a45a0aafa5de63b
BLAKE2b-256 b8f9909424325d20e6a8ec4a1322b3e4a3589f400e294e01936d112b85b0cf94

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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-2.2.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 850623cafb7ac30b76b72374857638346628f6aae1dd0183ff4b59ed23c36df5
MD5 7c9c50010fc0b9596247a15a4a7e6978
BLAKE2b-256 641096d76f02a55f4389fd628b8101a85389a458215b1483727535bf03b92d2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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-2.2.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab54e53c547a55de2fa2a7b7a27f72fc95da0673ac7734e30d680e3dc80d7e6d
MD5 acf118c656b5dea9b0e2f1429c97ea49
BLAKE2b-256 975701fbd59fccd24879c9ff30d41b14bbfb071c6801a9f34950ffc6c7af7c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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-2.2.6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8808935e801c24ea99c0aea0257a9656eb253c77c45b042120a8f208b571d70d
MD5 cece768400a1129420c5efd8f98bb019
BLAKE2b-256 418a80c488a8566c22e7b43e1900bca639a006cd4044ff53f84bda0fb4929a73

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.6-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.

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