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-2.2.1.tar.gz (225.1 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.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (289.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: pynec-2.2.1.tar.gz
  • Upload date:
  • Size: 225.1 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.1.tar.gz
Algorithm Hash digest
SHA256 4126d5647a7fd691ce151fef23236e4d9df9f9ec32f6e5101a02815d2c066fff
MD5 cec08fbf8b9e558c3ec7c275c6a676b7
BLAKE2b-256 e99f9374c31d1c809628da9b3991cb5e139dd4233eaa30b93f4fd511ad169c8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 20e7d996143fd2484e5153504a864bfd5188ff8e2843547e35ea73b18a90e8b5
MD5 e7bfc77562aa036bd4d1ba998a004dea
BLAKE2b-256 062a03fbe2061c6b129a2dd8116c43a5d8c99ff95bcb1f90016aa7267bc85705

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 583b43d1bc596a2707153e4739bc04f80fa0c91accba1f6803531f8ae1a941d7
MD5 204814a5bcbab1c915cb6eecd514f44d
BLAKE2b-256 e5c50d4e6aa9c06154a157fb24f1e76142ca44d377f7ff8e74a4a00ee7780604

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 59eb348221c4a2e7c73b8ceed283df302da88ee4a571fa4ae6c52513a0cdd652
MD5 007aadbc0f0f1b2b9968727572082691
BLAKE2b-256 493ae71284954d4ca4e990fe6bac958f48d514f0cc5a9156efe42760741ef840

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a81bf56eb93b4da3cf3f559d4ebf044c61a82526d0bf9a356bcc90e6485508d2
MD5 6bb9b523357895fc2233b14b9eabae3c
BLAKE2b-256 6d9c8039fa95ede2779617c228bf2391f915b1de4f4942a9ec867072f1fc0079

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0bb32a42563b63156528dcec59b86f886ab77ad77a9897e793295b633110d745
MD5 662fc586d2a327e3c00db155c6ded6e5
BLAKE2b-256 2d704e04e4c347b9aea0cdd7c91a1073e404fd0d196b6f7ce85e4d4a4bf016e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd8130d168bd902951b254c8e09c07addcbb52ccaca0f76896ab19ec198107e9
MD5 aed1f29c98825fb635bf4b08200be5f0
BLAKE2b-256 72db053a8758058401d880cde9b6bd0dad027105d5e5069af560444c6e0b1b4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 92b69ce663fe00f8bd6579d99e0ce61e7d6655c7202e526d70ed03cb5ba0a18e
MD5 5d7fb12ea3d549cff8a3b2286c3a3e39
BLAKE2b-256 c7828a6c4514e5b1f0ab06122128a8b1222a4b181b7304296e3ec6142a483063

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f38b08a4cac9b97bb29ab6a340e9c0e28a15946163b2f13e8762f1c52ea73b7
MD5 f24b3e63bfd6509611d846b9475a6f52
BLAKE2b-256 7a14473c41ecec87c211c6b73d15a9baa91e5fd2ec768d3ec245ee92a460ae56

See more details on using hashes here.

Provenance

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