Skip to content

Sight

Sight dataclass

Sight(
    focal_plane: SightFocalPlane = "FFP",
    scale_factor: Optional[Union[float, Distance]] = None,
    h_click_size: Optional[Union[float, Angular]] = None,
    v_click_size: Optional[Union[float, Angular]] = None,
)

Sight configuration for ballistic calculations and adjustments.

This class represents the optical sight system mounted on a weapon, including the focal plane type, magnification properties, and click adjustment sizes. It provides methods for calculating sight adjustments based on target distance and magnification settings.

Attributes:

Name Type Description
focal_plane SightFocalPlane

Type of focal plane ('FFP' for First Focal Plane, 'SFP' for Second Focal Plane, 'LWIR' for Long Wave Infrared).

scale_factor Distance

Distance representing the scale factor for sight calculations.

h_click_size Angular

Angular size of horizontal click adjustments.

v_click_size Angular

Angular size of vertical click adjustments.

Example
sight = Sight(
    focal_plane='FFP',
    scale_factor=Unit.Meter(100),
    h_click_size=Unit.Mil(0.2),
    v_click_size=Unit.Mil(0.2)
)

Parameters:

Name Type Description Default
focal_plane SightFocalPlane

Type of focal plane ('FFP', 'SFP', or 'LWIR'). Defaults to 'FFP' (First Focal Plane).

'FFP'
scale_factor Optional[Union[float, Distance]]

Distance used for sight scale calculations. Required for SFP sights. If None, defaults to 1 unit.

None
h_click_size Optional[Union[float, Angular]]

Angular size of horizontal click adjustments. Must be positive value.

None
v_click_size Optional[Union[float, Angular]]

Angular size of vertical click adjustments. Must be positive value.

None

Raises:

Type Description
ValueError

If focal_plane is not supported or scale_factor missing for SFP.

TypeError

If click sizes are not Angular type or not positive.

Example
# Default FFP sight
sight = Sight()

# SFP sight with required scale factor
sight = Sight(
    focal_plane='SFP',
    scale_factor=Unit.Yard(100),
    h_click_size=Unit.MOA(0.25),
    v_click_size=Unit.MOA(0.25)
)

Methods:

Name Description
get_adjustment

Calculate sight adjustment for target distance and magnification.

get_trajectory_adjustment

Calculate sight adjustment from trajectory data point.

Source code in py_ballisticcalc/munition.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def __init__(self,
             focal_plane: SightFocalPlane = 'FFP',
             scale_factor: Optional[Union[float, Distance]] = None,
             h_click_size: Optional[Union[float, Angular]] = None,
             v_click_size: Optional[Union[float, Angular]] = None):
    """Initialize a Sight instance with given parameters.

    Args:
        focal_plane: Type of focal plane ('FFP', 'SFP', or 'LWIR').
                    Defaults to 'FFP' (First Focal Plane).
        scale_factor: Distance used for sight scale calculations.
                     Required for SFP sights. If None, defaults to 1 unit.
        h_click_size: Angular size of horizontal click adjustments.
                     Must be positive value.
        v_click_size: Angular size of vertical click adjustments.
                     Must be positive value.

    Raises:
        ValueError: If focal_plane is not supported or scale_factor missing for SFP.
        TypeError: If click sizes are not Angular type or not positive.

    Example:
        ```python
        # Default FFP sight
        sight = Sight()

        # SFP sight with required scale factor
        sight = Sight(
            focal_plane='SFP',
            scale_factor=Unit.Yard(100),
            h_click_size=Unit.MOA(0.25),
            v_click_size=Unit.MOA(0.25)
        )
        ```
    """
    if focal_plane not in get_args(SightFocalPlane):
        raise ValueError("Wrong focal plane")

    if not scale_factor and focal_plane == 'SFP':
        raise ValueError('Scale_factor required for SFP sights')

    if (not isinstance(h_click_size, (Angular, float, int))
        or not isinstance(v_click_size, (Angular, float, int))
    ):
        raise TypeError("Angle expected for 'h_click_size' and 'v_click_size'")

    self.focal_plane = focal_plane
    self.scale_factor = PreferredUnits.distance(scale_factor or 1)
    self.h_click_size = PreferredUnits.adjustment(h_click_size)
    self.v_click_size = PreferredUnits.adjustment(v_click_size)
    if self.h_click_size.raw_value <= 0 or self.v_click_size.raw_value <= 0:
        raise TypeError("'h_click_size' and 'v_click_size' must be positive")

Functions

get_adjustment
get_adjustment(
    target_distance: Distance,
    drop_adj: Angular,
    windage_adj: Angular,
    magnification: float,
) -> SightClicks

Calculate sight adjustment for target distance and magnification.

This method computes the required sight adjustments (in clicks) based on the ballistic solution for a given target distance and current magnification. The calculation method varies depending on the focal plane type.

Parameters:

Name Type Description Default
target_distance Distance

Distance to the target.

required
drop_adj Angular

Required vertical angular adjustment for drop compensation.

required
windage_adj Angular

Required horizontal angular adjustment for windage.

required
magnification float

Current magnification setting of the sight.

required

Returns:

Type Description
SightClicks

SightClicks with vertical and horizontal click adjustments needed.

Raises:

Type Description
AttributeError

If focal_plane is not one of the supported types.

Note
  • SFP sights: Adjustments scaled by target distance and magnification
  • FFP sights: Direct conversion using click sizes
  • LWIR sights: Adjustments scaled by magnification only
Example
clicks = sight.get_adjustment(
    target_distance=Unit.Meter(500),
    drop_adj=Unit.Mil(2.5),
    windage_adj=Unit.Mil(0.8),
    magnification=12.0
)
print(f"Adjust: {clicks.vertical} up, {clicks.horizontal} right")
Source code in py_ballisticcalc/munition.py
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
243
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
def get_adjustment(self, target_distance: Distance,
                   drop_adj: Angular, windage_adj: Angular,
                   magnification: float) -> SightClicks:
    """Calculate sight adjustment for target distance and magnification.

    This method computes the required sight adjustments (in clicks) based on
    the ballistic solution for a given target distance and current magnification.
    The calculation method varies depending on the focal plane type.

    Args:
        target_distance: Distance to the target.
        drop_adj: Required vertical angular adjustment for drop compensation.
        windage_adj: Required horizontal angular adjustment for windage.
        magnification: Current magnification setting of the sight.

    Returns:
        SightClicks with vertical and horizontal click adjustments needed.

    Raises:
        AttributeError: If focal_plane is not one of the supported types.

    Note:
        - SFP sights: Adjustments scaled by target distance and magnification
        - FFP sights: Direct conversion using click sizes
        - LWIR sights: Adjustments scaled by magnification only

    Example:
        ```python
        clicks = sight.get_adjustment(
            target_distance=Unit.Meter(500),
            drop_adj=Unit.Mil(2.5),
            windage_adj=Unit.Mil(0.8),
            magnification=12.0
        )
        print(f"Adjust: {clicks.vertical} up, {clicks.horizontal} right")
        ```
    """
    if magnification <= 0:
        raise ValueError("magnification must be positive")
    if self.focal_plane == 'SFP':
        steps = self._adjust_sfp_reticle_steps(target_distance, magnification)
        return SightClicks(
            drop_adj.raw_value / steps.vertical.raw_value,
            windage_adj.raw_value / steps.horizontal.raw_value
        )
    if self.focal_plane == 'FFP':
        return SightClicks(
            drop_adj.raw_value / self.v_click_size.raw_value,
            windage_adj.raw_value / self.h_click_size.raw_value
        )
    if self.focal_plane == 'LWIR':
        return SightClicks(  # adjust clicks to magnification
            drop_adj.raw_value / (self.v_click_size.raw_value / magnification),
            windage_adj.raw_value / (self.h_click_size.raw_value / magnification)
        )
    raise AttributeError("Wrong focal_plane")
get_trajectory_adjustment
get_trajectory_adjustment(
    trajectory_point: TrajectoryData, magnification: float
) -> SightClicks

Calculate sight adjustment from trajectory data point.

This convenience method extracts the necessary adjustment values from a TrajectoryData instance and calculates the required sight clicks.

Parameters:

Name Type Description Default
trajectory_point TrajectoryData

TrajectoryData instance containing ballistic solution.

required
magnification float

Current magnification setting of the sight.

required

Returns:

Type Description
SightClicks

SightClicks with vertical and horizontal click adjustments needed.

Example
# Assuming trajectory_result is from Calculator.fire()
for point in trajectory_result:
    clicks = sight.get_trajectory_adjustment(point, magnification=10.0)
    print(f"At {point.distance}: {clicks.vertical} clicks up")
Source code in py_ballisticcalc/munition.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
def get_trajectory_adjustment(self, trajectory_point: 'TrajectoryData', magnification: float) -> SightClicks:
    """Calculate sight adjustment from trajectory data point.

    This convenience method extracts the necessary adjustment values from a
    TrajectoryData instance and calculates the required sight clicks.

    Args:
        trajectory_point: TrajectoryData instance containing ballistic solution.
        magnification: Current magnification setting of the sight.

    Returns:
        SightClicks with vertical and horizontal click adjustments needed.

    Example:
        ```python
        # Assuming trajectory_result is from Calculator.fire()
        for point in trajectory_result:
            clicks = sight.get_trajectory_adjustment(point, magnification=10.0)
            print(f"At {point.distance}: {clicks.vertical} clicks up")
        ```
    """
    return self.get_adjustment(trajectory_point.distance,
                               trajectory_point.drop_adj,
                               trajectory_point.windage_adj,
                               magnification)

SightClicks

Bases: NamedTuple

Sight click adjustments as numeric values.

This named tuple represents the number of clicks needed for vertical and horizontal sight adjustments, typically used for turret adjustments.

Attributes:

Name Type Description
vertical float

Number of vertical clicks for adjustment.

horizontal float

Number of horizontal clicks for adjustment.

Example
clicks = SightClicks(vertical=5.0, horizontal=2.5)

SightReticleStep

Bases: NamedTuple

Reticle step adjustments for sight calculations.

This named tuple lists the angular step size of adjustments (clicks) available on a particular sight.

Attributes:

Name Type Description
vertical Angular

Vertical angular adjustment step.

horizontal Angular

Horizontal angular adjustment step.

Example
step = SightReticleStep(
    vertical=Angular.Mil(0.2),
    horizontal=Angular.Mil(0.2)
)