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.1.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.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (289.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-1.8.1-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.1-cp312-cp312-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: pynec-1.8.1.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.1.tar.gz
Algorithm Hash digest
SHA256 16b447f144cd217cc38f4f70f81792c3ea4c0da45e0a8ee85b7f759784512160
MD5 3cd4f010f59e234ba34368d5bb229484
BLAKE2b-256 ce60794e57982234106fae62ccd69461e022e76c4b058fc87a152a787fa6c66c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6955f0c224a714c5cfb8239891e6d7e7e61c52fb7aa73597b786757fc777fd72
MD5 22ae430c4d855bee84e61f2b51e587ea
BLAKE2b-256 2e5396dbf8fdff3c4a26971ed55e4ae0dd6bc36f5f840d2c99a32489a8147327

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54286a956b0956bebe3d04be2cfb7e0fff2d5d8b454a6a7a37bbd21c67d442e2
MD5 c69b72576262c47b7f7c9e779f879c7f
BLAKE2b-256 0a00d0f7714acbc1cc199ab8dc4582617159b69d52d45cc4756312e4892e811d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 288a5d19574a8c89cc39f2ac68caf2f553c4b34611bb59a8efe825f8f5c17c41
MD5 067ac3140fe722611c209b3dc120e891
BLAKE2b-256 994c215976c90223bd9de2d603359f587b8a1e362f3c87b2ae205594fb9ecfe1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89025744c7afe67db00e9ec25b0ab119359c0406eda5d27b307ca48504fcb51f
MD5 765f8308e21e55f2879c87460f6c4d75
BLAKE2b-256 e7a07d80e268efdb319ef733562ca51e61f55f15f735d19db26f7b2b963842aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6967a5fc0c43c8c3e6722d0a9588c1cb6a0b90f2a234ad3c09c402d732ee3bea
MD5 86f1393ed1e2b9690fddf3037d13f485
BLAKE2b-256 6c8ad5cafa6df2d9a2032c4d3fa9fad838cea90015005b39814bcefead003078

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad4df1820400043febe246a1796ae6e07203cedc88f8feb692a27cf24598843f
MD5 4a6c5e98d9cd36f9154074bb6d4de7fe
BLAKE2b-256 f6635fa3b670d281213c6dc743fd765bbfeec5c7530a1c7f7cc8f24125830544

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 94bb7634d7cc49f2ca3c8dc728179b6699ce94dc5e534fce18fa3ca92b069b8e
MD5 496450a767ab47ab9d4518c9f1c43f10
BLAKE2b-256 15fe6caa718442e6240f41e9ba1886d50bff7fb85d7c0cea4fd59b5e89685980

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-1.8.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31d8f1aed4d63f9bf057e7eed095f06e1e644e1e4a4626b9f549aebf82dfd12b
MD5 39a0641d9c453169924e780d40343e3f
BLAKE2b-256 c13e16af9f9f01e21634f3ac79f3c48a0a9c600ea52caef64f92afd90d4e879b

See more details on using hashes here.

Provenance

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