Skip to content

Ammo

A base class for creating Weapon.

Attributes:

Name Type Description
dm DragModel

DragModel for projectile

mv Velocity

Muzzle Velocity

powder_temp Temperature

Baseline temperature that produces the given mv

temp_modifier float

Change in velocity w temperature: % per 15°C. Can be computed with .calc_powder_sens(). Only applies if: Settings.use_powder_sensitivity = True

use_powder_sensitivity bool

Flag to allow to adjust muzzle velocity to the powder sensitivity

Parameters:

Name Type Description Default
dm DragModel

drag model

required
mv Union[float, Velocity]

muzzle velocity at given powder temperature

required
powder_temp Optional[Union[float, Temperature]]

powder temperature

None
temp_modifier float

Change in velocity w temperature: % per 15°C. Can be computed with .calc_powder_sens(). Only applies if: Ammo.use_powder_sensitivity = True

0
use_powder_sensitivity bool

should adjust muzzle velocity using powder sensitivity

False
Example

This is how you can create a weapon

from py_ballisticcalc import Ammo, Unit, DragModel

ammo = Ammo(
    dm=DragModel(
        bc=0.381,
        drag_table=TableG7,
        weight=Unit.Grain(300),
        length=Unit.Inch(1.7),
        diameter=Unit.Inch(0.338),
    ),
    mv=Unit.MPS(815),
    powder_temp=Unit.Celsius(15),
    temp_modifier=0.123,
    use_powder_sensitivity=True,
)
Source code in py_ballisticcalc\munition.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def __init__(self,
             dm: DragModel,
             mv: Union[float, Velocity],
             powder_temp: Optional[Union[float, Temperature]] = None,
             temp_modifier: float = 0,
             use_powder_sensitivity: bool = False):
    """
    Create a new ammo instance with given parameters

    Args:
        dm: drag model
        mv: muzzle velocity at given powder temperature
        powder_temp: powder temperature
        temp_modifier: Change in velocity w temperature: % per 15°C.
            Can be computed with .calc_powder_sens().  Only applies if:
            Ammo.use_powder_sensitivity = True
        use_powder_sensitivity: should adjust muzzle velocity using powder sensitivity

    Example:
        This is how you can create a weapon

        ```python
        from py_ballisticcalc import Ammo, Unit, DragModel

        ammo = Ammo(
            dm=DragModel(
                bc=0.381,
                drag_table=TableG7,
                weight=Unit.Grain(300),
                length=Unit.Inch(1.7),
                diameter=Unit.Inch(0.338),
            ),
            mv=Unit.MPS(815),
            powder_temp=Unit.Celsius(15),
            temp_modifier=0.123,
            use_powder_sensitivity=True,
        )
        ```
    """
    self.dm = dm
    self.mv = PreferredUnits.velocity(mv or 0)
    self.powder_temp = PreferredUnits.temperature(powder_temp or Temperature.Celsius(15))
    self.temp_modifier = temp_modifier or 0
    self.use_powder_sensitivity = use_powder_sensitivity

dm instance-attribute

dm: DragModel = dm

mv instance-attribute

mv: Velocity = velocity(mv or 0)

powder_temp instance-attribute

powder_temp: Temperature = temperature(powder_temp or Celsius(15))

temp_modifier instance-attribute

temp_modifier: float = temp_modifier or 0

use_powder_sensitivity class-attribute instance-attribute

use_powder_sensitivity: bool = use_powder_sensitivity

calc_powder_sens

calc_powder_sens(other_velocity: Union[float, Velocity], other_temperature: Union[float, Temperature]) -> float

Calculates velocity correction by temperature change; assigns to self.temp_modifier

Parameters:

Name Type Description Default
other_velocity Union[float, Velocity]

other velocity at other_temperature

required
other_temperature Union[float, Temperature]

other temperature

required

Returns:

Type Description
float

temperature modifier in terms %v_delta/15°C

Example
powder_sensitivity = ammo.calc_powder_sens(
    Unit.MPS(830),
    Unit.Celsius(200)
)
Source code in py_ballisticcalc\munition.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def calc_powder_sens(self, other_velocity: Union[float, Velocity],
                     other_temperature: Union[float, Temperature]) -> float:
    """Calculates velocity correction by temperature change; assigns to self.temp_modifier

    Args:
        other_velocity: other velocity at other_temperature
        other_temperature: other temperature

    Returns:
        temperature modifier in terms %v_delta/15°C

    Example:
        ```python
        powder_sensitivity = ammo.calc_powder_sens(
            Unit.MPS(830),
            Unit.Celsius(200)
        )
        ```
    """
    v0 = self.mv >> Velocity.MPS
    t0 = self.powder_temp >> Temperature.Celsius
    v1 = PreferredUnits.velocity(other_velocity) >> Velocity.MPS
    t1 = PreferredUnits.temperature(other_temperature) >> Temperature.Celsius

    v_delta = math.fabs(v0 - v1)
    t_delta = math.fabs(t0 - t1)
    v_lower = v1 if v1 < v0 else v0

    if v_delta == 0 or t_delta == 0:
        raise ValueError(
            "Temperature modifier error, other velocity"
            " and temperature can't be same as default"
        )
    self.temp_modifier = v_delta / t_delta * (15 / v_lower)  # * 100
    return self.temp_modifier

get_velocity_for_temp

get_velocity_for_temp(current_temp: Union[float, Temperature]) -> Velocity

Calculates muzzle velocity at temperature, based on temp_modifier.

Parameters:

Name Type Description Default
current_temp Union[float, Temperature]

Temperature of cartridge powder

required

Returns:

Type Description
Velocity

Muzzle velocity corrected to current_temp

Example
muzzle_velocity = ammo.get_velocity_for_temp(
    Unit.Celsius(200)
)
Source code in py_ballisticcalc\munition.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
def get_velocity_for_temp(self, current_temp: Union[float, Temperature]) -> Velocity:
    """Calculates muzzle velocity at temperature, based on temp_modifier.

    Args:
        current_temp: Temperature of cartridge powder

    Returns:
        Muzzle velocity corrected to current_temp

    Example:
        ```python
        muzzle_velocity = ammo.get_velocity_for_temp(
            Unit.Celsius(200)
        )
        ```
    """
    if not self.use_powder_sensitivity:
        return self.mv
    try:
        v0 = self.mv >> Velocity.MPS
        t0 = self.powder_temp >> Temperature.Celsius
        t1 = PreferredUnits.temperature(current_temp) >> Temperature.Celsius
        t_delta = t1 - t0
        muzzle_velocity = self.temp_modifier / (15 / v0) * t_delta + v0
    except ZeroDivisionError:
        muzzle_velocity = 0
    return Velocity.MPS(muzzle_velocity)