Skip to content

Commit

Permalink
Changed default atmosphere to use 0% humidity (vs. 78% previously).
Browse files Browse the repository at this point in the history
Changed trajectory tests based on this default.
Added twist tests.
Fixed sign on spin drift.
Switched default units for pressure, temperature, and energy from metric to standard (matching all the others).
Optional argument to format DataFrame values as strings with units.
  • Loading branch information
dbookstaber committed Jan 25, 2024
1 parent 604795a commit d8fe2a2
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 62 deletions.
273 changes: 243 additions & 30 deletions Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"angular = degree\n",
"distance = yard\n",
"velocity = fps\n",
"pressure = hp\n",
"temperature = celsius\n",
"pressure = inhg\n",
"temperature = fahrenheit\n",
"diameter = inch\n",
"length = inch\n",
"weight = grain\n",
"adjustment = mil\n",
"drop = inch\n",
"energy = joule\n",
"energy = foot * pound\n",
"ogw = pound\n",
"sight_height = inch\n",
"target_height = inch\n",
Expand All @@ -42,7 +42,7 @@
"from matplotlib import pyplot as plt\n",
"from py_ballisticcalc import Velocity, Distance, Angular\n",
"from py_ballisticcalc import DragModel, TableG7\n",
"from py_ballisticcalc import Ammo\n",
"from py_ballisticcalc import Ammo, Wind\n",
"from py_ballisticcalc import Weapon, Shot, Calculator\n",
"from py_ballisticcalc import Settings as Set\n",
"\n",
Expand Down Expand Up @@ -166,44 +166,257 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"shot_result.dataframe.to_clipboard()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('0.00 s', '0.000 yd', '2600.0 ft/s', '2.33 mach', '-4.0 inch', '0.00 mil', '0.0 inch', '0.00 mil', '0.1224 °', '3419 J', '744.098 lb', 8)\n",
"('0.12 s', '100.000 yd', '2398.1 ft/s', '2.15 mach', '1.0 inch', '0.28 mil', '-0.1 inch', '-0.02 mil', '0.0336 °', '2908 J', '583.865 lb', 8)\n",
"('0.25 s', '200.050 yd', '2205.4 ft/s', '1.98 mach', '-0.1 inch', '-0.02 mil', '-0.3 inch', '-0.04 mil', '-0.0711 °', '2460 J', '454.104 lb', 8)\n",
"('0.39 s', '300.050 yd', '2022.2 ft/s', '1.81 mach', '-8.4 inch', '-0.79 mil', '-0.7 inch', '-0.06 mil', '-0.1952 °', '2068 J', '350.104 lb', 8)\n",
"('0.55 s', '400.050 yd', '1847.5 ft/s', '1.65 mach', '-25.1 inch', '-1.78 mil', '-1.2 inch', '-0.08 mil', '-0.3433 °', '1726 J', '266.954 lb', 8)\n",
"('0.72 s', '500.000 yd', '1680.1 ft/s', '1.50 mach', '-52.1 inch', '-2.95 mil', '-2.0 inch', '-0.11 mil', '-0.5215 °', '1428 J', '200.776 lb', 8)\n",
"('0.91 s', '600.000 yd', '1519.5 ft/s', '1.36 mach', '-91.5 inch', '-4.31 mil', '-3.0 inch', '-0.14 mil', '-0.7383 °', '1168 J', '148.526 lb', 8)\n",
"('1.11 s', '700.000 yd', '1366.0 ft/s', '1.22 mach', '-145.9 inch', '-5.90 mil', '-4.4 inch', '-0.18 mil', '-1.0049 °', '944 J', '107.918 lb', 8)\n",
"('1.35 s', '800.000 yd', '1221.3 ft/s', '1.09 mach', '-219.1 inch', '-7.75 mil', '-6.2 inch', '-0.22 mil', '-1.3368 °', '754 J', '77.122 lb', 8)\n",
"('1.61 s', '900.000 yd', '1093.3 ft/s', '0.98 mach', '-315.7 inch', '-9.93 mil', '-8.6 inch', '-0.27 mil', '-1.7532 °', '604 J', '55.322 lb', 8)\n",
"('1.89 s', '1000.000 yd', '1030.1 ft/s', '0.92 mach', '-441.2 inch', '-12.48 mil', '-11.5 inch', '-0.33 mil', '-2.2479 °', '537 J', '46.272 lb', 8)\n"
]
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>time</th>\n",
" <th>distance</th>\n",
" <th>velocity</th>\n",
" <th>mach</th>\n",
" <th>drop</th>\n",
" <th>drop_adj</th>\n",
" <th>windage</th>\n",
" <th>windage_adj</th>\n",
" <th>angle</th>\n",
" <th>energy</th>\n",
" <th>ogw</th>\n",
" <th>flag</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.00 s</td>\n",
" <td>0.000 yd</td>\n",
" <td>2600.0 ft/s</td>\n",
" <td>2.33 mach</td>\n",
" <td>-4.0 inch</td>\n",
" <td>0.00 mil</td>\n",
" <td>0.0 inch</td>\n",
" <td>0.00 mil</td>\n",
" <td>0.1224 °</td>\n",
" <td>2521 ft·lb</td>\n",
" <td>744.098 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.12 s</td>\n",
" <td>100.000 yd</td>\n",
" <td>2398.1 ft/s</td>\n",
" <td>2.15 mach</td>\n",
" <td>1.0 inch</td>\n",
" <td>0.28 mil</td>\n",
" <td>0.1 inch</td>\n",
" <td>0.02 mil</td>\n",
" <td>0.0336 °</td>\n",
" <td>2145 ft·lb</td>\n",
" <td>583.865 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.25 s</td>\n",
" <td>200.050 yd</td>\n",
" <td>2205.4 ft/s</td>\n",
" <td>1.98 mach</td>\n",
" <td>-0.1 inch</td>\n",
" <td>-0.02 mil</td>\n",
" <td>0.3 inch</td>\n",
" <td>0.04 mil</td>\n",
" <td>-0.0711 °</td>\n",
" <td>1814 ft·lb</td>\n",
" <td>454.104 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.39 s</td>\n",
" <td>300.050 yd</td>\n",
" <td>2022.2 ft/s</td>\n",
" <td>1.81 mach</td>\n",
" <td>-8.4 inch</td>\n",
" <td>-0.79 mil</td>\n",
" <td>0.7 inch</td>\n",
" <td>0.06 mil</td>\n",
" <td>-0.1952 °</td>\n",
" <td>1525 ft·lb</td>\n",
" <td>350.104 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.55 s</td>\n",
" <td>400.050 yd</td>\n",
" <td>1847.5 ft/s</td>\n",
" <td>1.65 mach</td>\n",
" <td>-25.1 inch</td>\n",
" <td>-1.78 mil</td>\n",
" <td>1.2 inch</td>\n",
" <td>0.08 mil</td>\n",
" <td>-0.3433 °</td>\n",
" <td>1273 ft·lb</td>\n",
" <td>266.954 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.72 s</td>\n",
" <td>500.000 yd</td>\n",
" <td>1680.1 ft/s</td>\n",
" <td>1.50 mach</td>\n",
" <td>-52.1 inch</td>\n",
" <td>-2.95 mil</td>\n",
" <td>2.0 inch</td>\n",
" <td>0.11 mil</td>\n",
" <td>-0.5215 °</td>\n",
" <td>1053 ft·lb</td>\n",
" <td>200.776 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.91 s</td>\n",
" <td>600.000 yd</td>\n",
" <td>1519.5 ft/s</td>\n",
" <td>1.36 mach</td>\n",
" <td>-91.5 inch</td>\n",
" <td>-4.31 mil</td>\n",
" <td>3.0 inch</td>\n",
" <td>0.14 mil</td>\n",
" <td>-0.7383 °</td>\n",
" <td>861 ft·lb</td>\n",
" <td>148.526 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>1.11 s</td>\n",
" <td>700.000 yd</td>\n",
" <td>1366.0 ft/s</td>\n",
" <td>1.22 mach</td>\n",
" <td>-145.9 inch</td>\n",
" <td>-5.90 mil</td>\n",
" <td>4.4 inch</td>\n",
" <td>0.18 mil</td>\n",
" <td>-1.0049 °</td>\n",
" <td>696 ft·lb</td>\n",
" <td>107.918 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>1.35 s</td>\n",
" <td>800.000 yd</td>\n",
" <td>1221.3 ft/s</td>\n",
" <td>1.09 mach</td>\n",
" <td>-219.1 inch</td>\n",
" <td>-7.75 mil</td>\n",
" <td>6.2 inch</td>\n",
" <td>0.22 mil</td>\n",
" <td>-1.3368 °</td>\n",
" <td>556 ft·lb</td>\n",
" <td>77.122 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>1.61 s</td>\n",
" <td>900.000 yd</td>\n",
" <td>1093.3 ft/s</td>\n",
" <td>0.98 mach</td>\n",
" <td>-315.7 inch</td>\n",
" <td>-9.93 mil</td>\n",
" <td>8.6 inch</td>\n",
" <td>0.27 mil</td>\n",
" <td>-1.7532 °</td>\n",
" <td>446 ft·lb</td>\n",
" <td>55.322 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>1.89 s</td>\n",
" <td>1000.000 yd</td>\n",
" <td>1030.1 ft/s</td>\n",
" <td>0.92 mach</td>\n",
" <td>-441.2 inch</td>\n",
" <td>-12.48 mil</td>\n",
" <td>11.5 inch</td>\n",
" <td>0.33 mil</td>\n",
" <td>-2.2479 °</td>\n",
" <td>396 ft·lb</td>\n",
" <td>46.272 lb</td>\n",
" <td>8</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" time distance velocity mach drop drop_adj \\\n",
"0 0.00 s 0.000 yd 2600.0 ft/s 2.33 mach -4.0 inch 0.00 mil \n",
"1 0.12 s 100.000 yd 2398.1 ft/s 2.15 mach 1.0 inch 0.28 mil \n",
"2 0.25 s 200.050 yd 2205.4 ft/s 1.98 mach -0.1 inch -0.02 mil \n",
"3 0.39 s 300.050 yd 2022.2 ft/s 1.81 mach -8.4 inch -0.79 mil \n",
"4 0.55 s 400.050 yd 1847.5 ft/s 1.65 mach -25.1 inch -1.78 mil \n",
"5 0.72 s 500.000 yd 1680.1 ft/s 1.50 mach -52.1 inch -2.95 mil \n",
"6 0.91 s 600.000 yd 1519.5 ft/s 1.36 mach -91.5 inch -4.31 mil \n",
"7 1.11 s 700.000 yd 1366.0 ft/s 1.22 mach -145.9 inch -5.90 mil \n",
"8 1.35 s 800.000 yd 1221.3 ft/s 1.09 mach -219.1 inch -7.75 mil \n",
"9 1.61 s 900.000 yd 1093.3 ft/s 0.98 mach -315.7 inch -9.93 mil \n",
"10 1.89 s 1000.000 yd 1030.1 ft/s 0.92 mach -441.2 inch -12.48 mil \n",
"\n",
" windage windage_adj angle energy ogw flag \n",
"0 0.0 inch 0.00 mil 0.1224 ° 2521 ft·lb 744.098 lb 8 \n",
"1 0.1 inch 0.02 mil 0.0336 ° 2145 ft·lb 583.865 lb 8 \n",
"2 0.3 inch 0.04 mil -0.0711 ° 1814 ft·lb 454.104 lb 8 \n",
"3 0.7 inch 0.06 mil -0.1952 ° 1525 ft·lb 350.104 lb 8 \n",
"4 1.2 inch 0.08 mil -0.3433 ° 1273 ft·lb 266.954 lb 8 \n",
"5 2.0 inch 0.11 mil -0.5215 ° 1053 ft·lb 200.776 lb 8 \n",
"6 3.0 inch 0.14 mil -0.7383 ° 861 ft·lb 148.526 lb 8 \n",
"7 4.4 inch 0.18 mil -1.0049 ° 696 ft·lb 107.918 lb 8 \n",
"8 6.2 inch 0.22 mil -1.3368 ° 556 ft·lb 77.122 lb 8 \n",
"9 8.6 inch 0.27 mil -1.7532 ° 446 ft·lb 55.322 lb 8 \n",
"10 11.5 inch 0.33 mil -2.2479 ° 396 ft·lb 46.272 lb 8 "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now shooter prints range card for this new zero\n",
"zero.look_angle = 0\n",
"shot_result = calc.fire(zero, trajectory_range=1000)\n",
"for p in shot_result:\n",
" print(p.formatted())"
"# for p in shot_result:\n",
"# print(p.formatted())\n",
"shot_result.dataframe().to_clipboard()\n",
"shot_result.dataframe(True)"
]
},
{
Expand Down
11 changes: 5 additions & 6 deletions py_ballisticcalc/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
cA3: float = -3.07031e-06
cA4: float = 4.21329e-07
cA5: float = 3.342e-04
cStandardTemperature: float = 59.0
cStandardPressure: float = 29.92
cStandardDensity: float = 0.076474
cStandardTemperature: float = 59.0 # degrees F
cStandardPressure: float = 29.92 # InHg
cStandardDensity: float = 0.076474 # lb/ft^3

cIcaoTemperatureDeltaR: float = cIcaoStandardTemperatureR - cIcaoFreezingPointTemperatureR

Expand All @@ -35,7 +35,7 @@ class Atmo(TypedUnits): # pylint: disable=too-many-instance-attributes
altitude: [float, Distance] = field(default_factory=lambda: Set.Units.distance)
pressure: [float, Pressure] = field(default_factory=lambda: Set.Units.pressure)
temperature: [float, Temperature] = field(default_factory=lambda: Set.Units.temperature)
humidity: float = 0.78
humidity: float = 0
density: float = field(init=False)
mach: Velocity = field(init=False)
_mach1: Velocity = field(init=False)
Expand All @@ -45,11 +45,10 @@ class Atmo(TypedUnits): # pylint: disable=too-many-instance-attributes
_ta: float = field(init=False)

def __post_init__(self):

if self.humidity > 1:
self.humidity = self.humidity / 100.0
if not 0 <= self.humidity <= 1:
self.humidity = 0.78
self.humidity = 0.0
if not self.altitude:
self.altitude = Distance.Foot(0)
if not self.pressure:
Expand Down
2 changes: 2 additions & 0 deletions py_ballisticcalc/munition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Weapon(TypedUnits):
zero_elevation: [float, Angular] = field(default_factory=lambda: Set.Units.angular)

def __post_init__(self):
if not self.sight_height:
self.sight_height = 0
if not self.twist:
self.twist = 0
if not self.zero_elevation:
Expand Down
6 changes: 3 additions & 3 deletions py_ballisticcalc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Units(metaclass=Metadataclass): # pylint: disable=too-many-instance-attri
angular: Unit = Unit.DEGREE
distance: Unit = Unit.YARD
velocity: Unit = Unit.FPS
pressure: Unit = Unit.HP
temperature: Unit = Unit.CELSIUS
pressure: Unit = Unit.IN_HG
temperature: Unit = Unit.FAHRENHEIT
diameter: Unit = Unit.INCH
length: Unit = Unit.INCH
weight: Unit = Unit.GRAIN
adjustment: Unit = Unit.MIL
drop: Unit = Unit.INCH
energy: Unit = Unit.JOULE
energy: Unit = Unit.FOOT_POUND
ogw: Unit = Unit.POUND
sight_height: Unit = Unit.INCH
target_height: Unit = Unit.INCH
Expand Down
2 changes: 1 addition & 1 deletion py_ballisticcalc/trajectory_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _trajectory(self, ammo: Ammo, atmo: Atmo,

if twist != 0 and length and diameter:
stability_coefficient = calculate_stability_coefficient(shot_info.weapon.twist, ammo, atmo)
twist_coefficient = -1 if twist > 0 else 1
twist_coefficient = 1 if twist > 0 else -1

# With non-zero look_angle, rounding can suggest multiple adjacent zero-crossings
seen_zero = TrajFlag.NONE # Record when we see each zero crossing so we only register one
Expand Down
Loading

0 comments on commit d8fe2a2

Please sign in to comment.