py-ballisticcalc


Namepy-ballisticcalc JSON
Version 2.0.4 PyPI version JSON
download
home_pageNone
SummaryLGPL library for small arms ballistic calculations (Python 3)
upload_time2024-08-17 12:26:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseGNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
keywords py_ballisticcalc ballistics cython ballistic calculator python python3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BallisticCalculator
LGPL library for small arms ballistic calculations based on point-mass (3 DoF) plus spin drift.

### Table of contents
* **[Installation](#installation)**
  * [Latest stable](#latest-stable-release-from-pypi)

  [//]: # (    * [From sources]&#40;#installing-from-sources&#41;)
  [//]: # (  * [Clone and build]&#40;#clone-and-build&#41;)

* **[Usage](#usage)**
  * [Simple example](#simple-zero)
  * [Plot trajectory](#plot-trajectory-with-danger-space)
  * [Range card](#plot-trajectory-with-danger-space)
  * [Complex example](#complex-example)
  * [Jupyter notebook](Example.ipynb)
  * [Units of measure](#units-and-preferences)

  [//]: # (  * [An example of calculations]&#40;#an-example-of-calculations&#41;)
  [//]: # (  * [Output example]&#40;#example-of-the-formatted-output&#41;)
* **[Concepts](#concepts)**
* **[Older versions]()**
  * [v1.1.x](https://github.com/o-murphy/py_ballisticcalc/tree/v1.1.4)
  * [v1.0.x](https://github.com/o-murphy/py_ballisticcalc/tree/v1.0.12)
* **[Contributors](#contributors)**
* **[About project](#about-project)**

# Installation

[//]: # (```python setup.py build_ext --inplace```)

[//]: # (## Latest stable release from pypi)
```shell
pip install py-ballisticcalc

# Using precompiled backend (improves performance)
pip install py-ballisticcalc[exts]

# Using matplotlib and pandas uses additional dependencies
pip install py-ballisticcalc[charts]
```

# Usage
**See [Example.ipynb](Example.ipynb) for detailed illustrations of all features and usage.**

```python
# Uncomment pyximport to compile instead of running pure python
#import pyximport; pyximport.install(language_level=3)

from py_ballisticcalc import *
```

## Simple Zero
```python
# Establish 100-yard zero for a standard .308, G7 bc=0.22, muzzle velocity 2600fps
zero = Shot(weapon=Weapon(sight_height=2), ammo=Ammo(DragModel(0.22, TableG7), mv=Velocity.FPS(2600)))
calc = Calculator()
zero_distance = Distance.Yard(100)
zero_elevation = calc.set_weapon_zero(zero, zero_distance)
print(f'Barrel elevation for {zero_distance} zero: {zero_elevation << PreferredUnits.adjustment}')
```

    Barrel elevation for 100.0yd zero: 1.33mil

## Plot Trajectory with Danger Space
```python
# Plot trajectory out to 500 yards
shot_result = calc.fire(zero, trajectory_range=500, extra_data=True)
ax = shot_result.plot()
# Find danger space for a half-meter tall target at 300 yards
danger_space = shot_result.danger_space(Distance.Yard(300), Distance.Meter(.5))
print(danger_space)
danger_space.overlay(ax)  # Highlight danger space on the plot
plt.show()
```

    Danger space at 300.0yd for 19.7inch tall target ranges from 217.1yd to 355.7yd
![plot](doc/output_2_1.png)


## Print Range Card
```python
# Range card for this zero with 5mph cross-wind from left to right
zero.winds = [Wind(Velocity.MPH(5), Angular.OClock(3))]
range_card = calc.fire(zero, trajectory_range=1000)
range_card.dataframe().to_clipboard()
range_card.dataframe(True)[['distance', 'velocity', 'mach', 'time', 'target_drop', 'drop_adj', 'windage', 'windage_adj']].set_index('distance')
```

| distance | velocity | mach | time | target_drop | drop_adj | windage | windage_adj |
| -------- | -------- | ---- | ---- | ----------- | -------- | ------- | ----------- |
| 0.0 yd | 2600.0 ft/s | 2.33 mach | 0.000 s | -2.0 inch | 0.00 mil | -0.0 inch | 0.00 mil |
| 100.0 yd | 2398.1 ft/s | 2.15 mach | 0.120 s | -0.0 inch | -0.00 mil | 0.4 inch | 0.12 mil |
| 200.0 yd | 2205.5 ft/s | 1.98 mach | 0.251 s | -4.1 inch | -0.57 mil | 1.7 inch | 0.25 mil |
| 300.0 yd | 2022.3 ft/s | 1.81 mach | 0.393 s | -15.3 inch | -1.44 mil | 4.1 inch | 0.39 mil |
| 400.0 yd | 1847.5 ft/s | 1.65 mach | 0.548 s | -35.0 inch | -2.48 mil | 7.6 inch | 0.54 mil |
| 500.0 yd | 1680.1 ft/s | 1.50 mach | 0.718 s | -65.0 inch | -3.68 mil | 12.4 inch | 0.70 mil |
| 600.0 yd | 1519.5 ft/s | 1.36 mach | 0.906 s | -107.3 inch | -5.06 mil | 18.8 inch | 0.89 mil |
| 700.0 yd | 1366.0 ft/s | 1.22 mach | 1.114 s | -164.8 inch | -6.66 mil | 27.0 inch | 1.09 mil |
| 800.0 yd | 1221.3 ft/s | 1.09 mach | 1.347 s | -240.9 inch | -8.52 mil | 37.3 inch | 1.32 mil |
| 900.0 yd | 1093.2 ft/s | 0.98 mach | 1.607 s | -340.5 inch | -10.71 mil | 50.0 inch | 1.57 mil |
| 1000.0 yd | 1029.8 ft/s | 0.92 mach | 1.891 s | -469.0 inch | -13.27 mil | 64.8 inch | 1.83 mil |

## Complex Example

Here we define a standard .50BMG, enable powder temperature sensitivity, and zero for a distance of 500 meters, in a 5°C atmosphere at altitude 1000ft ASL.

```python
dm = DragModel(0.62, TableG1, 661, 0.51, 2.3)
ammo=Ammo(dm, Velocity.MPS(850), Temperature.Celsius(15))
ammo.calc_powder_sens(Velocity.MPS(820), Temperature.Celsius(0))
weapon = Weapon(sight_height=Distance.Centimeter(9), twist=15)
atmo = Atmo(altitude=Distance.Foot(1000), temperature=Unit.Celsius(5), humidity=.5)
zero = Shot(weapon=weapon, ammo=ammo, atmo=atmo)
zero_distance = Distance.Meter(500)
calc = Calculator()
zero_elevation = calc.set_weapon_zero(zero, zero_distance)
print(f'Barrel elevation for {zero_distance} zero: {zero_elevation << PreferredUnits.adjustment}')
print(f'Muzzle velocity at zero temperature {atmo.temperature} is {ammo.get_velocity_for_temp(atmo.temperature) << Velocity.MPS}')
```

    Barrel elevation for 500.0m zero: 4.69mil
    Muzzle velocity at zero temperature 5.0°C is 830.0m/s

## Units and Preferences
In version 2.x.x we changed concepts of settings, there are 2 ways to set preferences

#### 1.1. To change library default units directly from code use `PreferredUnits` object

```python
from py_ballisticcalc import PreferredUnits

# Change default library units
PreferredUnits.velocity = Velocity.MPS
PreferredUnits.adjustment = Angular.Mil
PreferredUnits.temperature = Temperature.Celsius
PreferredUnits.distance = Distance.Meter
PreferredUnits.sight_height = Distance.Centimeter
PreferredUnits.drop = Distance.Centimeter

print(f'PreferredUnits: {str(PreferredUnits)}')
print(f'Default distance unit: {PreferredUnits.distance.name}')

# Can create value in default unit with either float or another unit of same type
print(f'\tInstantiated from float (5): {PreferredUnits.distance(5)}')
print(f'\tInstantiated from Distance.Line(200): {PreferredUnits.distance(Distance.Line(200))}')
```

#### 1.2. To change solver global setting use global flags setters

```python
from py_ballisticcalc import *

# enable powder sensitivity calculation
set_global_use_powder_sensitivity(True)
# enable powder sensitivity calculation
set_global_max_calc_step_size(Unit.Meter(1))

# get that values
enabled = get_global_use_powder_sensitivity()
step = get_global_max_calc_step_size()

# reset global flags to defaults
reset_globals()
```

#### 2. Use new method to set preferred units/settings globally for the venv or the user
Create `.pybc.toml` or `pybc.toml` file in your project root directory _(where venv was placed)_.
Or place this file in user's home directory. _(The file in project root have priority.)_
You can use `basicConfig()` function to load your custom `.toml` file

The references of `.pybc.toml` settings file you can [**get there**](https://github.com/o-murphy/py-ballisticcalc/blob/master/.pybc.toml)
and [**there**](https://github.com/o-murphy/py-ballisticcalc/tree/master/assets)

```toml
# Config template for py_ballisticcalc

title = "standard py_ballisticcalc config template"
version = "2.0.0b4"

[pybc.preferred_units]
angular = 'Degree'
distance = 'Yard'
velocity = 'FPS'
# ... other there

[pybc.calculator]
max_calc_step_size = { value = 0.5, units = "Foot" }
use_powder_sensitivity = false
# ...
```

```python
from py_ballisticcalc import basicConfig

basicConfig("path/to/your_config.toml")
```

#### Available manipulations with units
```python
from py_ballisticcalc.unit import *

# Ways to define value in units
# 1. old syntax
unit_in_meter = Distance(100, Distance.Meter)
# 2. short syntax by Unit type class
unit_in_meter = Distance.Meter(100)
# 3. by Unit enum class
unit_in_meter = Unit.Meter(100)
print(f'100 meters: {unit_in_meter}')
# >>> 100 meters: 100.0m

# Convert unit
# 1. by .convert()
unit_in_yards = unit_in_meter.convert(Distance.Yard)
# 2. using shift syntax
unit_in_yards = unit_in_meter << Distance.Yard  # '<<=' operator also supports
print(f'100 meters in {unit_in_yards.units.key}: {unit_in_yards}')
# >>> 100 meters in yard: 109.4yd

# Get value in specified units (as float)
# 1. by .get_in()
value_in_km = unit_in_yards.get_in(Distance.Kilometer)
# 2. by shift syntax
value_in_km = unit_in_yards >> Distance.Kilometer  # '>>=' operator also supports
print(f'100 meters, value in km: {value_in_km}  (value type is {type(value_in_km)})')
# >>> 100 meters, value in km: 0.1  (value type is <class 'float'>)

# Getting unit raw value (a float)
rvalue = Distance.Meter(100).raw_value
rvalue = float(Distance.Meter(100))
print(f'100 meters in raw value: {rvalue}  (raw type is {type(rvalue)})')
# >>> 100 meters in raw value: 3937.0078740157483  (raw type is <class 'float'>)

# Comparison operators supported: < > <= >= == !=
print(f'Comparison: {unit_in_meter} == {Distance.Centimeter(100)}: {unit_in_meter == Distance.Centimeter(100)}')
# >>> False, compare two units by raw value
print(f'Comparison: {unit_in_meter} > .1*{unit_in_meter}: {unit_in_meter > .1*unit_in_meter.raw_value}')
# >>> True, compare unit with float by raw value
```

# Concepts

## Look angle
*Look angle* is the elevation of the sight line (a.k.a., _Line of Sight_, or _LoS_) relative to the horizon.  For flat fire at angles close to horizontal this does not make a significant difference.  When the look angle is significantly above or below the horizon the trajectory will be different because:

1. Gravity is not orthogonal to the velocity
2. Air density changes with altitude, so the drag effects will vary across an arcing trajectory.

The shooter typically cares about the line of sight (LoS): Sight adjustments (_drop_ in the following figure) are made relative to LoS, and ranging errors – and hence [danger space](#danger-space) – follow the line of sight, not the horizon.

The following diagram shows how _look distance_ and _drop_ relate by _look angle_ to the underlying (distance _x_, height _y_) trajectory data.
![Look-angle trigonometry](doc/BallisticTrig.png)

## Danger Space
Danger space is a practical measure of sensitivity to ranging error.  It is defined for a target of height *h* and distance *d*, and it indicates how far forward and backward along the line of sight the target can move such that the trajectory will still hit somewhere (vertically) on the target.

![Danger Space](doc/DangerSpace.png)

# About project

The library provides trajectory calculation for ballistic projectiles including air rifles, bows, firearms, artillery, and so on.

The 3DoF model that is used in this calculator is rooted in public C code of [JBM's calculator](https://jbmballistics.com/ballistics/calculators/calculators.shtml), ported to C#, optimized, fixed and extended with elements described in Litz's _Applied Ballistics_ book and from the friendly project of Alexandre Trofimov and then ported to Go.

This Python3 implementation has been expanded to support multiple ballistic coefficients and custom drag functions, such as those derived from Doppler radar data.

**[The online version of Go documentation is located here](https://godoc.org/github.com/gehtsoft-usa/go_ballisticcalc)**.

**[C# version of the package is located here](https://github.com/gehtsoft-usa/BallisticCalculator1), and [the online version of C# API documentation is located here](https://gehtsoft-usa.github.io/BallisticCalculator/web-content.html)**.

## Contributors
**This project exists thanks to all the people who contribute.**

<a href="https://github.com/o-murphy/py_ballisticcalc/graphs/contributors"><img height=32 src="https://contrib.rocks/image?repo=o-murphy/py_ballisticcalc" /></a>

Special thanks to:
- **[David Bookstaber](https://github.com/dbookstaber)** - Ballistics Expert\
*For help understanding and improving the functionality*
- **[Nikolay Gekht](https://github.com/nikolaygekht)** \
*For the sources code on C# and GO-lang from which this project firstly was forked*

[//]: # (## Sister projects)

[//]: # ()
[//]: # (* **Py-BalCalc** - GUI App for [py_ballisticcalc]&#40;https://github.com/o-murphy/py_ballisticcalc&#41; solver library and profiles editor)

[//]: # (* **eBallistica** - Kivy based mobile App for ballistic calculations)

[//]: # ()
[//]: # (* <img align="center" height=32 src="https://github.com/JAremko/ArcherBC2/blob/main/resources/skins/sol-dark/icons/icon-frame.png?raw=true" /> [ArcherBC2]&#40;https://github.com/JAremko/ArcherBC2&#41; and [ArcherBC2 mobile]&#40;https://github.com/ApodemusSylvaticus/archerBC2_mobile&#41; - Ballistic profile editors)

[//]: # (  - *See also [a7p_transfer_example]&#40;https://github.com/JAremko/a7p_transfer_example&#41; or [a7p]&#40;https://github.com/o-murphy/a7p&#41; repo to get info about the ballistic profile format*)

## RISK NOTICE

The library performs very limited simulation of a complex physical process and so it performs a lot of approximations. Therefore, the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior or characteristics of projectiles. While these results may be used for educational purpose, they must NOT be considered as reliable for the areas where incorrect calculation may cause making a wrong decision, financial harm, or can put a human life at risk.

THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "py-ballisticcalc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "py_ballisticcalc, ballistics, Cython, ballistic calculator, python, python3",
    "author": null,
    "author_email": "o-murphy <thehelixpg@gmail.com>, dbookstaber <bookstaber@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/93/f9/8ba1c9afc7e5a96c5ad9f1140386d3800a2acb1d6e3b5c142a058322cedc/py_ballisticcalc-2.0.4.tar.gz",
    "platform": null,
    "description": "# BallisticCalculator\nLGPL library for small arms ballistic calculations based on point-mass (3 DoF) plus spin drift.\n\n### Table of contents\n* **[Installation](#installation)**\n  * [Latest stable](#latest-stable-release-from-pypi)\n\n  [//]: # (    * [From sources]&#40;#installing-from-sources&#41;)\n  [//]: # (  * [Clone and build]&#40;#clone-and-build&#41;)\n\n* **[Usage](#usage)**\n  * [Simple example](#simple-zero)\n  * [Plot trajectory](#plot-trajectory-with-danger-space)\n  * [Range card](#plot-trajectory-with-danger-space)\n  * [Complex example](#complex-example)\n  * [Jupyter notebook](Example.ipynb)\n  * [Units of measure](#units-and-preferences)\n\n  [//]: # (  * [An example of calculations]&#40;#an-example-of-calculations&#41;)\n  [//]: # (  * [Output example]&#40;#example-of-the-formatted-output&#41;)\n* **[Concepts](#concepts)**\n* **[Older versions]()**\n  * [v1.1.x](https://github.com/o-murphy/py_ballisticcalc/tree/v1.1.4)\n  * [v1.0.x](https://github.com/o-murphy/py_ballisticcalc/tree/v1.0.12)\n* **[Contributors](#contributors)**\n* **[About project](#about-project)**\n\n# Installation\n\n[//]: # (```python setup.py build_ext --inplace```)\n\n[//]: # (## Latest stable release from pypi)\n```shell\npip install py-ballisticcalc\n\n# Using precompiled backend (improves performance)\npip install py-ballisticcalc[exts]\n\n# Using matplotlib and pandas uses additional dependencies\npip install py-ballisticcalc[charts]\n```\n\n# Usage\n**See [Example.ipynb](Example.ipynb) for detailed illustrations of all features and usage.**\n\n```python\n# Uncomment pyximport to compile instead of running pure python\n#import pyximport; pyximport.install(language_level=3)\n\nfrom py_ballisticcalc import *\n```\n\n## Simple Zero\n```python\n# Establish 100-yard zero for a standard .308, G7 bc=0.22, muzzle velocity 2600fps\nzero = Shot(weapon=Weapon(sight_height=2), ammo=Ammo(DragModel(0.22, TableG7), mv=Velocity.FPS(2600)))\ncalc = Calculator()\nzero_distance = Distance.Yard(100)\nzero_elevation = calc.set_weapon_zero(zero, zero_distance)\nprint(f'Barrel elevation for {zero_distance} zero: {zero_elevation << PreferredUnits.adjustment}')\n```\n\n    Barrel elevation for 100.0yd zero: 1.33mil\n\n## Plot Trajectory with Danger Space\n```python\n# Plot trajectory out to 500 yards\nshot_result = calc.fire(zero, trajectory_range=500, extra_data=True)\nax = shot_result.plot()\n# Find danger space for a half-meter tall target at 300 yards\ndanger_space = shot_result.danger_space(Distance.Yard(300), Distance.Meter(.5))\nprint(danger_space)\ndanger_space.overlay(ax)  # Highlight danger space on the plot\nplt.show()\n```\n\n    Danger space at 300.0yd for 19.7inch tall target ranges from 217.1yd to 355.7yd\n![plot](doc/output_2_1.png)\n\n\n## Print Range Card\n```python\n# Range card for this zero with 5mph cross-wind from left to right\nzero.winds = [Wind(Velocity.MPH(5), Angular.OClock(3))]\nrange_card = calc.fire(zero, trajectory_range=1000)\nrange_card.dataframe().to_clipboard()\nrange_card.dataframe(True)[['distance', 'velocity', 'mach', 'time', 'target_drop', 'drop_adj', 'windage', 'windage_adj']].set_index('distance')\n```\n\n| distance | velocity | mach | time | target_drop | drop_adj | windage | windage_adj |\n| -------- | -------- | ---- | ---- | ----------- | -------- | ------- | ----------- |\n| 0.0 yd | 2600.0 ft/s | 2.33 mach | 0.000 s | -2.0 inch | 0.00 mil | -0.0 inch | 0.00 mil |\n| 100.0 yd | 2398.1 ft/s | 2.15 mach | 0.120 s | -0.0 inch | -0.00 mil | 0.4 inch | 0.12 mil |\n| 200.0 yd | 2205.5 ft/s | 1.98 mach | 0.251 s | -4.1 inch | -0.57 mil | 1.7 inch | 0.25 mil |\n| 300.0 yd | 2022.3 ft/s | 1.81 mach | 0.393 s | -15.3 inch | -1.44 mil | 4.1 inch | 0.39 mil |\n| 400.0 yd | 1847.5 ft/s | 1.65 mach | 0.548 s | -35.0 inch | -2.48 mil | 7.6 inch | 0.54 mil |\n| 500.0 yd | 1680.1 ft/s | 1.50 mach | 0.718 s | -65.0 inch | -3.68 mil | 12.4 inch | 0.70 mil |\n| 600.0 yd | 1519.5 ft/s | 1.36 mach | 0.906 s | -107.3 inch | -5.06 mil | 18.8 inch | 0.89 mil |\n| 700.0 yd | 1366.0 ft/s | 1.22 mach | 1.114 s | -164.8 inch | -6.66 mil | 27.0 inch | 1.09 mil |\n| 800.0 yd | 1221.3 ft/s | 1.09 mach | 1.347 s | -240.9 inch | -8.52 mil | 37.3 inch | 1.32 mil |\n| 900.0 yd | 1093.2 ft/s | 0.98 mach | 1.607 s | -340.5 inch | -10.71 mil | 50.0 inch | 1.57 mil |\n| 1000.0 yd | 1029.8 ft/s | 0.92 mach | 1.891 s | -469.0 inch | -13.27 mil | 64.8 inch | 1.83 mil |\n\n## Complex Example\n\nHere we define a standard .50BMG, enable powder temperature sensitivity, and zero for a distance of 500 meters, in a 5\u00b0C atmosphere at altitude 1000ft ASL.\n\n```python\ndm = DragModel(0.62, TableG1, 661, 0.51, 2.3)\nammo=Ammo(dm, Velocity.MPS(850), Temperature.Celsius(15))\nammo.calc_powder_sens(Velocity.MPS(820), Temperature.Celsius(0))\nweapon = Weapon(sight_height=Distance.Centimeter(9), twist=15)\natmo = Atmo(altitude=Distance.Foot(1000), temperature=Unit.Celsius(5), humidity=.5)\nzero = Shot(weapon=weapon, ammo=ammo, atmo=atmo)\nzero_distance = Distance.Meter(500)\ncalc = Calculator()\nzero_elevation = calc.set_weapon_zero(zero, zero_distance)\nprint(f'Barrel elevation for {zero_distance} zero: {zero_elevation << PreferredUnits.adjustment}')\nprint(f'Muzzle velocity at zero temperature {atmo.temperature} is {ammo.get_velocity_for_temp(atmo.temperature) << Velocity.MPS}')\n```\n\n    Barrel elevation for 500.0m zero: 4.69mil\n    Muzzle velocity at zero temperature 5.0\u00b0C is 830.0m/s\n\n## Units and Preferences\nIn version 2.x.x we changed concepts of settings, there are 2 ways to set preferences\n\n#### 1.1. To change library default units directly from code use `PreferredUnits` object\n\n```python\nfrom py_ballisticcalc import PreferredUnits\n\n# Change default library units\nPreferredUnits.velocity = Velocity.MPS\nPreferredUnits.adjustment = Angular.Mil\nPreferredUnits.temperature = Temperature.Celsius\nPreferredUnits.distance = Distance.Meter\nPreferredUnits.sight_height = Distance.Centimeter\nPreferredUnits.drop = Distance.Centimeter\n\nprint(f'PreferredUnits: {str(PreferredUnits)}')\nprint(f'Default distance unit: {PreferredUnits.distance.name}')\n\n# Can create value in default unit with either float or another unit of same type\nprint(f'\\tInstantiated from float (5): {PreferredUnits.distance(5)}')\nprint(f'\\tInstantiated from Distance.Line(200): {PreferredUnits.distance(Distance.Line(200))}')\n```\n\n#### 1.2. To change solver global setting use global flags setters\n\n```python\nfrom py_ballisticcalc import *\n\n# enable powder sensitivity calculation\nset_global_use_powder_sensitivity(True)\n# enable powder sensitivity calculation\nset_global_max_calc_step_size(Unit.Meter(1))\n\n# get that values\nenabled = get_global_use_powder_sensitivity()\nstep = get_global_max_calc_step_size()\n\n# reset global flags to defaults\nreset_globals()\n```\n\n#### 2. Use new method to set preferred units/settings globally for the venv or the user\nCreate `.pybc.toml` or `pybc.toml` file in your project root directory _(where venv was placed)_.\nOr place this file in user's home directory. _(The file in project root have priority.)_\nYou can use `basicConfig()` function to load your custom `.toml` file\n\nThe references of `.pybc.toml` settings file you can [**get there**](https://github.com/o-murphy/py-ballisticcalc/blob/master/.pybc.toml)\nand [**there**](https://github.com/o-murphy/py-ballisticcalc/tree/master/assets)\n\n```toml\n# Config template for py_ballisticcalc\n\ntitle = \"standard py_ballisticcalc config template\"\nversion = \"2.0.0b4\"\n\n[pybc.preferred_units]\nangular = 'Degree'\ndistance = 'Yard'\nvelocity = 'FPS'\n# ... other there\n\n[pybc.calculator]\nmax_calc_step_size = { value = 0.5, units = \"Foot\" }\nuse_powder_sensitivity = false\n# ...\n```\n\n```python\nfrom py_ballisticcalc import basicConfig\n\nbasicConfig(\"path/to/your_config.toml\")\n```\n\n#### Available manipulations with units\n```python\nfrom py_ballisticcalc.unit import *\n\n# Ways to define value in units\n# 1. old syntax\nunit_in_meter = Distance(100, Distance.Meter)\n# 2. short syntax by Unit type class\nunit_in_meter = Distance.Meter(100)\n# 3. by Unit enum class\nunit_in_meter = Unit.Meter(100)\nprint(f'100 meters: {unit_in_meter}')\n# >>> 100 meters: 100.0m\n\n# Convert unit\n# 1. by .convert()\nunit_in_yards = unit_in_meter.convert(Distance.Yard)\n# 2. using shift syntax\nunit_in_yards = unit_in_meter << Distance.Yard  # '<<=' operator also supports\nprint(f'100 meters in {unit_in_yards.units.key}: {unit_in_yards}')\n# >>> 100 meters in yard: 109.4yd\n\n# Get value in specified units (as float)\n# 1. by .get_in()\nvalue_in_km = unit_in_yards.get_in(Distance.Kilometer)\n# 2. by shift syntax\nvalue_in_km = unit_in_yards >> Distance.Kilometer  # '>>=' operator also supports\nprint(f'100 meters, value in km: {value_in_km}  (value type is {type(value_in_km)})')\n# >>> 100 meters, value in km: 0.1  (value type is <class 'float'>)\n\n# Getting unit raw value (a float)\nrvalue = Distance.Meter(100).raw_value\nrvalue = float(Distance.Meter(100))\nprint(f'100 meters in raw value: {rvalue}  (raw type is {type(rvalue)})')\n# >>> 100 meters in raw value: 3937.0078740157483  (raw type is <class 'float'>)\n\n# Comparison operators supported: < > <= >= == !=\nprint(f'Comparison: {unit_in_meter} == {Distance.Centimeter(100)}: {unit_in_meter == Distance.Centimeter(100)}')\n# >>> False, compare two units by raw value\nprint(f'Comparison: {unit_in_meter} > .1*{unit_in_meter}: {unit_in_meter > .1*unit_in_meter.raw_value}')\n# >>> True, compare unit with float by raw value\n```\n\n# Concepts\n\n## Look angle\n*Look angle* is the elevation of the sight line (a.k.a., _Line of Sight_, or _LoS_) relative to the horizon.  For flat fire at angles close to horizontal this does not make a significant difference.  When the look angle is significantly above or below the horizon the trajectory will be different because:\n\n1. Gravity is not orthogonal to the velocity\n2. Air density changes with altitude, so the drag effects will vary across an arcing trajectory.\n\nThe shooter typically cares about the line of sight (LoS): Sight adjustments (_drop_ in the following figure) are made relative to LoS, and ranging errors \u2013 and hence [danger space](#danger-space) \u2013 follow the line of sight, not the horizon.\n\nThe following diagram shows how _look distance_ and _drop_ relate by _look angle_ to the underlying (distance _x_, height _y_) trajectory data.\n![Look-angle trigonometry](doc/BallisticTrig.png)\n\n## Danger Space\nDanger space is a practical measure of sensitivity to ranging error.  It is defined for a target of height *h* and distance *d*, and it indicates how far forward and backward along the line of sight the target can move such that the trajectory will still hit somewhere (vertically) on the target.\n\n![Danger Space](doc/DangerSpace.png)\n\n# About project\n\nThe library provides trajectory calculation for ballistic projectiles including air rifles, bows, firearms, artillery, and so on.\n\nThe 3DoF model that is used in this calculator is rooted in public C code of [JBM's calculator](https://jbmballistics.com/ballistics/calculators/calculators.shtml), ported to C#, optimized, fixed and extended with elements described in Litz's _Applied Ballistics_ book and from the friendly project of Alexandre Trofimov and then ported to Go.\n\nThis Python3 implementation has been expanded to support multiple ballistic coefficients and custom drag functions, such as those derived from Doppler radar data.\n\n**[The online version of Go documentation is located here](https://godoc.org/github.com/gehtsoft-usa/go_ballisticcalc)**.\n\n**[C# version of the package is located here](https://github.com/gehtsoft-usa/BallisticCalculator1), and [the online version of C# API documentation is located here](https://gehtsoft-usa.github.io/BallisticCalculator/web-content.html)**.\n\n## Contributors\n**This project exists thanks to all the people who contribute.**\n\n<a href=\"https://github.com/o-murphy/py_ballisticcalc/graphs/contributors\"><img height=32 src=\"https://contrib.rocks/image?repo=o-murphy/py_ballisticcalc\" /></a>\n\nSpecial thanks to:\n- **[David Bookstaber](https://github.com/dbookstaber)** - Ballistics Expert\\\n*For help understanding and improving the functionality*\n- **[Nikolay Gekht](https://github.com/nikolaygekht)** \\\n*For the sources code on C# and GO-lang from which this project firstly was forked*\n\n[//]: # (## Sister projects)\n\n[//]: # ()\n[//]: # (* **Py-BalCalc** - GUI App for [py_ballisticcalc]&#40;https://github.com/o-murphy/py_ballisticcalc&#41; solver library and profiles editor)\n\n[//]: # (* **eBallistica** - Kivy based mobile App for ballistic calculations)\n\n[//]: # ()\n[//]: # (* <img align=\"center\" height=32 src=\"https://github.com/JAremko/ArcherBC2/blob/main/resources/skins/sol-dark/icons/icon-frame.png?raw=true\" /> [ArcherBC2]&#40;https://github.com/JAremko/ArcherBC2&#41; and [ArcherBC2 mobile]&#40;https://github.com/ApodemusSylvaticus/archerBC2_mobile&#41; - Ballistic profile editors)\n\n[//]: # (  - *See also [a7p_transfer_example]&#40;https://github.com/JAremko/a7p_transfer_example&#41; or [a7p]&#40;https://github.com/o-murphy/a7p&#41; repo to get info about the ballistic profile format*)\n\n## RISK NOTICE\n\nThe library performs very limited simulation of a complex physical process and so it performs a lot of approximations. Therefore, the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior or characteristics of projectiles. While these results may be used for educational purpose, they must NOT be considered as reliable for the areas where incorrect calculation may cause making a wrong decision, financial harm, or can put a human life at risk.\n\nTHE CODE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.\n",
    "bugtrack_url": null,
    "license": "GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.   This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.  0. Additional Definitions.  As used herein, \"this License\" refers to version 3 of the GNU Lesser General Public License, and the \"GNU GPL\" refers to version 3 of the GNU General Public License.  \"The Library\" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.  An \"Application\" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.  A \"Combined Work\" is a work produced by combining or linking an Application with the Library.  The particular version of the Library with which the Combined Work was made is also called the \"Linked Version\".  The \"Minimal Corresponding Source\" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.  The \"Corresponding Application Code\" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.  1. Exception to Section 3 of the GNU GPL.  You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.  2. Conveying Modified Versions.  If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:  a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or  b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.  3. Object Code Incorporating Material from Library Header Files.  The object code form of an Application may incorporate material from a header file that is part of the Library.  You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:  a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.  b) Accompany the object code with a copy of the GNU GPL and this license document.  4. Combined Works.  You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:  a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.  b) Accompany the Combined Work with a copy of the GNU GPL and this license document.  c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.  d) Do one of the following:  0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.  1) Use a suitable shared library mechanism for linking with the Library.  A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.  e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)  5. Combined Libraries.  You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:  a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.  b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.  6. Revised Versions of the GNU Lesser General Public License.  The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.  Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License \"or any later version\" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.  If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ",
    "summary": "LGPL library for small arms ballistic calculations (Python 3)",
    "version": "2.0.4",
    "project_urls": {
        "Bug Reports": "https://github.com/o-murphy/py_ballisticcalc/issues",
        "Homepage": "https://github.com/o-murphy/py_ballisticcalc",
        "Source": "https://github.com/o-murphy/py_ballisticcalc"
    },
    "split_keywords": [
        "py_ballisticcalc",
        " ballistics",
        " cython",
        " ballistic calculator",
        " python",
        " python3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "290d2b8aa155b05164c3ef1bdec193b7a9d5a48af2bee4982c45b7eade42b63b",
                "md5": "d32257f1f0a7ac8fced73d7903ed1824",
                "sha256": "6033249732386bd2377834b594111587b554b1d4865fd45efdf16a591294ebbb"
            },
            "downloads": -1,
            "filename": "py_ballisticcalc-2.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d32257f1f0a7ac8fced73d7903ed1824",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 46048,
            "upload_time": "2024-08-17T12:25:54",
            "upload_time_iso_8601": "2024-08-17T12:25:54.574443Z",
            "url": "https://files.pythonhosted.org/packages/29/0d/2b8aa155b05164c3ef1bdec193b7a9d5a48af2bee4982c45b7eade42b63b/py_ballisticcalc-2.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93f98ba1c9afc7e5a96c5ad9f1140386d3800a2acb1d6e3b5c142a058322cedc",
                "md5": "7a3b3f3cf601e3cf196b2c849f378ec7",
                "sha256": "9eaa5bf5f754065692af0b1be835384c7b16a0651570e9969029606b35d58ce1"
            },
            "downloads": -1,
            "filename": "py_ballisticcalc-2.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7a3b3f3cf601e3cf196b2c849f378ec7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 257548,
            "upload_time": "2024-08-17T12:26:06",
            "upload_time_iso_8601": "2024-08-17T12:26:06.665449Z",
            "url": "https://files.pythonhosted.org/packages/93/f9/8ba1c9afc7e5a96c5ad9f1140386d3800a2acb1d6e3b5c142a058322cedc/py_ballisticcalc-2.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-17 12:26:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "o-murphy",
    "github_project": "py_ballisticcalc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "py-ballisticcalc"
}
        
Elapsed time: 0.31889s