Skip to content

Commit be03727

Browse files
committed
Test fix
1 parent 7b228a5 commit be03727

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

py_ballisticcalc/engines/scipy_engine.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def event_max_drop(t: float, s: Any) -> np.floating: # Stop when y crosses down
728728
def event_min_velocity(t: float, s: Any) -> np.floating: # Stop when velocity < _cMinimumVelocity
729729
v = np.linalg.norm(s[3:6])
730730
return v - _cMinimumVelocity
731-
#TODO: Either don't add this event, or always return 0 if _cMinimumVelocity<=0.
731+
#TODO: If _cMinimumVelocity<=0 then: either don't add this event, or always return 0.
732732
traj_events: List[SciPyEvent] = [event_max_range, event_max_drop, event_min_velocity]
733733

734734
slant_sine = math.sin(props.look_angle_rad)
@@ -781,14 +781,14 @@ def make_row(t: float, state: np.ndarray, flag: Union[TrajFlag, int]) -> Traject
781781
"""Helper function to create a TrajectoryData row."""
782782
position = Vector(*state[0:3])
783783
velocity = Vector(*state[3:6])
784-
density_ratio, mach = props.get_density_and_mach_for_altitude(position[1])
784+
_, mach = props.get_density_and_mach_for_altitude(position[1])
785785
return TrajectoryData.from_props(props, t, position, velocity, mach, flag)
786786

787787
if sol.t[-1] == 0:
788788
# If the last time is 0, we only have the initial state
789789
ranges.append(make_row(sol.t[0], sol.y[:, 0], TrajFlag.RANGE))
790790
else:
791-
# List of distances at which we want to record the trajectory data
791+
# List of distances at which we want to record the trajectory data, based on range_step
792792
desired_xs = np.arange(0, range_limit_ft + range_step_ft, range_step_ft)
793793
# Get x and t arrays from the solution
794794
x_vals = sol.y[0]
@@ -838,7 +838,7 @@ def x_minus_target(t): # Function for root finding: x(t) - x_target
838838
states_at_x.append(sol.y[:, -1]) # Last state at the end of integration
839839

840840
states_at_x_arr_t: np.ndarray[Any, np.dtype[np.float64]] = np.array(states_at_x,
841-
dtype=np.float64).T # shape: (state_dim, num_points)
841+
dtype=np.float64).T # shape: (state_dim, num_points)
842842
for i in range(states_at_x_arr_t.shape[1]):
843843
ranges.append(make_row(t_at_x[i], states_at_x_arr_t[:, i], TrajFlag.RANGE))
844844
ranges.sort(key=lambda t: t.time) # Sort by time
@@ -849,6 +849,7 @@ def x_minus_target(t): # Function for root finding: x(t) - x_target
849849
while ranges[next_record].time - time_of_last_record > time_step + self.SEPARATE_ROW_TIME_DELTA:
850850
time_of_last_record += time_step
851851
ranges.append(make_row(time_of_last_record, sol.sol(time_of_last_record), TrajFlag.RANGE))
852+
time_of_last_record = ranges[next_record].time
852853
ranges.sort(key=lambda t: t.time) # Sort by time
853854

854855
# region Find TrajectoryData points requested by filter_flags

py_ballisticcalc/trajectory_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ def get_key_val(td: "BaseTrajData", path: str) -> float:
255255
top, component = path.split('.', 1)
256256
obj = getattr(td, top)
257257
return getattr(obj, component)
258-
else:
259-
return getattr(td, path)
258+
return getattr(td, path)
260259

261260
# independent variable values
262261
x0 = get_key_val(p0, key_attribute)
@@ -299,6 +298,7 @@ def _interp_scalar(y0, y1, y2):
299298
'y': 'height',
300299
'z': 'windage',
301300
}
301+
# pylint: disable=too-many-instance-attributes,protected-access
302302
class TrajectoryData(NamedTuple):
303303
"""Data for one point in ballistic trajectory."""
304304

tests/test_trajectory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_no_rows_closer_than_merge_threshold(self, loaded_engine_instance):
250250
calc = Calculator(engine=loaded_engine_instance)
251251
shot = self._mk_shot(2800.0)
252252
# Request multiple flags and dense-ish sampling to provoke close-by events
253-
res = calc.fire(shot, trajectory_range=Distance.Yard(1000), trajectory_step=Distance.Yard(50),
253+
res = calc.fire(shot, trajectory_range=Distance.Yard(500), trajectory_step=Distance.Yard(50),
254254
time_step=0.001, flags=TrajFlag.ALL, raise_range_error=False)
255255
dt_thresh = BaseIntegrationEngine.SEPARATE_ROW_TIME_DELTA
256256
times = [td.time for td in res.trajectory]

0 commit comments

Comments
 (0)