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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: pynec-2.2.5.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.5.tar.gz
Algorithm Hash digest
SHA256 041e3342898d90f704fff303c9d94477eb1a9fb186a242f06d14a127fcb011b4
MD5 5b0da7fb8227a391e32d51a54f3ce69a
BLAKE2b-256 fd4fe25b00dea898b4b45c5eb10d8548188fa70395c66a6ee2917183c20ff5b8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d1472a37e33e50aa758bc16be71329138e6c702646d9dd7a2ed8273b03fe686
MD5 f6df5c44a06c5b372ee42185e6aadb00
BLAKE2b-256 b5d8540ca742d199dae6bf2cc7eb8fad786b5dad72d25ebb8135edf7fbd9833f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0312f65c50dcdfd94bf5239786d6be500ad9f462e57514fc5b455385a9939999
MD5 fccfd9124d939c30fea81186077bf74b
BLAKE2b-256 a8b37bbbaa993f6b2ae6f9b95ff606a26e7d1210dc535ff3d8fdcb3aa62a72df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 413655e1f337d90c21d0b632e86f9641ea7bf09c31a12b80cdf227d368454517
MD5 1a3e76a9e58b52c0b8a1dcb10f4e4d9f
BLAKE2b-256 c5e42c307eecd90e306de5acff782bc8885f04ced5ae3ad8bc9c68ebfc052e6d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c653860561b65a7c28b28f6d3384cdde36d7f465245c97ab00723b6f0b102943
MD5 fb012f0c246b651a6add24c05d732fe5
BLAKE2b-256 32e185cc163351b326dfb4f6d9135105b06bcdac86f0ffb6c714452935fe97f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce4822cad98dcee93b117723be33df3ea1ec654f948a9e3eae90f5f09392b0cb
MD5 b619e0c546544b9842642a6c8580fbbc
BLAKE2b-256 1b9903106890d3b69ef7e84c9c405e3b27e235054dbbe7da6e52f7c556744ae8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5abd3ecf9dfa500c534dfe6c4de61b1551b793f81fb2a5763fefa1c8dea384f3
MD5 90111fb39579e6130c127fb8e5397b62
BLAKE2b-256 da97fff969de859c6e74537a0e00a6e00c7ee5afbe41ca122ec642ac36ce250d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4809ea68ec9e197702185dbbf687f74d3cd67ab08b912e230053d1bdaaa4b733
MD5 977239262047bd14171296fc6fef88a1
BLAKE2b-256 d107553e69ad8bed6801d8d6d434af45e2c7308d1a0908abb67747ab3830771a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91e4751d71472508f0f5588d476dae745eb4df5fef97ff31d392ce712ac74440
MD5 83a7915999fb5447139c0fbec2560ea7
BLAKE2b-256 f2b9a143c6dc9c7b8d0828668badf15eebc78393736f6a3900ab8618c103c1cf

See more details on using hashes here.

Provenance

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