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.4.tar.gz (226.3 kB 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.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.2.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.2.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (289.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pynec-2.2.4-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

pynec-2.2.4-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-2.2.4.tar.gz.

File metadata

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

File hashes

Hashes for pynec-2.2.4.tar.gz
Algorithm Hash digest
SHA256 03707aa8b610e72a3cec213bdc4585b4019ad542a1c5a41230b5f3b74a23342f
MD5 1b0da7f5bab8369c3fc1d43b7bc5e9e3
BLAKE2b-256 cdeb1716b834fd5365e93c9c685e38625e9ff4190b27583ca3fc98420171e7e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e28b607cf46a14288de9816d5a5244d2c2f5eb2e9ee1f670a16175fdbc5cd2af
MD5 a4c2c58eeb95cefde383b3411c823a17
BLAKE2b-256 68d5231a5328dbccd8781f424d9ea432f61398deffcbbc14bd69ea31d8fa8124

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d5c0ce752ad0b76c288db30500a4f452505a78860ad29d1762e4d0168bc92bb
MD5 7dc6adecd3a727752fcb04ae3899c6b5
BLAKE2b-256 b351fed7adb225ae5ab9158aad354a00840fe5e11b9a214f9b4aef93ee679837

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b71e23a93c44abafc8c5499f958b966cd65b10e363b4a9cd5a97011aadac8a1
MD5 a8103716fae341511420fcc384104540
BLAKE2b-256 f53c78d2e397e6d285581ed8985171f1ed298a3180d22e25b473dabbc71256bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be0f46ae1478fa030ba0f1451543d38f07f49c58fab39289a4d70a05c3b6d721
MD5 35dcac11739a37f81d5b70ffee499c89
BLAKE2b-256 486b7ce2fc2d0576c1a57ad333b9d32284b3a976b9f9c55c67cf55e1690a6fa1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 af13c24d480f05c7b27048360a4b6bf4c44b31c729b4a79f752cb7a59748aa91
MD5 d4ccf97ae5252393ddfae1653c60c2de
BLAKE2b-256 b3a55c9a44516a457facf1a5677b4654197814f2e4b8c841c2d85eafcd7a70ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2f2b68e73b98af64540888572aca8cbfe3e6524f2623a1de5eda92406100dac9
MD5 9038911697b25c03c87367c9ca6b6833
BLAKE2b-256 9e3ac3f1eb1fb001ba1ddba71a6dac3762c8627634a97515914664925655948a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 403817f533e029c9f47153b72d9252a097dc6d9f99ba2222ee682ff6a2f79775
MD5 e649faac9c56ef92421623e36bf31823
BLAKE2b-256 033ae52afbe173bece32c399bacb5cae05a47f15e099f78dd197b8fb5b33bb51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 988c51316b2b29859b058917f87624682a7998b2a3f9c50e1033dda0ee6e2fcd
MD5 826d0afb6073b2d107a6cee5103d57c1
BLAKE2b-256 28de834d6d0650620f7560ae02824f7072019ed5220b8b1b4858581d640b7d20

See more details on using hashes here.

Provenance

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