HitResult¶
HitResult provides the complete chronological output stream in records
(what len(), iteration, indexing, dataframe(), and plot() all use), a
stable scheduled-sample table in samples, and exact physical event roots
in events. trajectory is a deprecated alias for records. See
Trajectory Data for the output-view
contract and examples.
HitResult
dataclass
¶
HitResult(
props: ShotProps,
records: list[TrajectoryData],
base_data: list[BaseTrajData] | None = None,
extra: bool = False,
error: RangeError | None = None,
)
Computed trajectory data of the shot.
Attributes:
| Name | Type | Description |
|---|---|---|
shot |
The parameters of the shot calculation. |
|
records |
list[TrajectoryData]
|
Exact, chronological output records produced by the integrator. Default
source for |
samples |
list[TrajectoryData]
|
Deterministic scheduled-sample table with nearby event flags annotated; its cardinality tracks the requested RANGE/TIME schedule regardless of the integrator's internal step choices, so it is the source to use when comparing results across engines or tolerances. |
events |
list[TrajectoryData]
|
Exact physical event records (ZERO, MACH, APEX, and MRT). |
trajectory |
list[TrajectoryData]
|
[DEPRECATED] Alias for |
base_data |
list[BaseTrajData] | None
|
Flat sequence of accepted-step points (dense_output engines only), for local interpolation between adjacent pairs. |
extra |
bool
|
[DEPRECATED] Whether extra_data was requested. |
error |
RangeError | None
|
RangeError, if any. |
Methods:
| Name | Description |
|---|---|
flag |
Get first TrajectoryData row with the specified flag. |
get_at |
Get TrajectoryData where key_attribute==value. |
zeros |
Get all zero crossing points. |
index_at_distance |
Deprecated. Use get_at() instead. |
get_at_distance |
Deprecated. Use get_at('distance', d) instead. |
get_at_time |
Deprecated. Use get_at('time', t) instead. |
danger_space |
Calculate the danger space for a target. |
dataframe |
Return the trajectory table as a DataFrame. |
plot |
Return a graph of the trajectory. |
Source code in py_ballisticcalc/trajectory_data.py
890 891 892 893 894 895 896 897 898 899 900 901 902 | |
events
cached
property
¶
events: list[TrajectoryData]
Return exact physical event records without output-table coalescing.
samples
cached
property
¶
samples: list[TrajectoryData]
Return the deterministic scheduled-sample table.
Physical events remain exact in :attr:events; this presentation view
annotates a scheduled sample with an event's flag only when the two
are, to floating-point precision, the same instant (see
:func:math.isclose's use below) — e.g. a RANGE sample requested at
the same distance a zero was set for, which the integrator reaches by
two different numerical paths that agree to solver residual. It never
annotates merely the nearest sample when no sample is actually
that close: with a coarse schedule (e.g. trajectory_step ==
trajectory_range, leaving only the launch and terminal samples) an
APEX or ZERO in between is not close to either endpoint, so it would
otherwise get glued onto whichever endpoint bisection happens to
prefer — misrepresenting that endpoint's own state as the event's.
Cardinality always equals the sampling schedule's, regardless of
whether any annotation occurs, so it is stable across engines and
solver tolerances even though which samples get annotated is not.
flag
¶
flag(flag: TrajFlag | int) -> TrajectoryData | None
Get first TrajectoryData row with the specified flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
TrajFlag | int
|
The flag to search for. |
required |
Returns:
| Type | Description |
|---|---|
TrajectoryData | None
|
First TrajectoryData row with the specified flag. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If flag was not requested. |
Source code in py_ballisticcalc/trajectory_data.py
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 | |
get_at
¶
get_at(
key_attribute: TrajectoryDataAttribute,
value: float | GenericDimension,
*,
epsilon: float = 1e-09,
start_from_time: float = 0.0,
) -> TrajectoryData
Get TrajectoryData where key_attribute==value.
Interpolates to create new object if necessary. Preserves the units of the original trajectory data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_attribute
|
TrajectoryDataAttribute
|
The name of the TrajectoryData attribute to key on (e.g., 'time', 'distance'). |
required |
value
|
float | GenericDimension
|
The value of the key attribute to find. If a float is provided for a dimensioned attribute, it's assumed to be a .raw_value. |
required |
epsilon
|
float
|
Allowed key value difference to match existing TrajectoryData object without interpolating. |
1e-09
|
start_from_time
|
float
|
The time to center the search from (default is 0.0). If the target value is at a local extremum then the search will only go forward in time. |
0.0
|
Returns:
| Type | Description |
|---|---|
TrajectoryData
|
TrajectoryData where key_attribute==value. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If TrajectoryData doesn't have the specified attribute. |
KeyError
|
If the key_attribute is 'flag'. |
ArithmeticError
|
If the trajectory doesn't reach the requested value, including when fewer than 2 of self.records bracket it (3 are needed for PCHIP; with exactly 2 bracketing points a linear fallback is used instead of raising). |
Notes
- Not all attributes are monotonic: Height typically goes up and then down. Velocity typically goes down, but for lofted trajectories can begin to increase. Windage can wander back and forth in complex winds. We even have (see ExtremeExamples.ipynb) backward-bending scenarios in which distance reverses!
- The only guarantee is that time is strictly increasing.
Source code in py_ballisticcalc/trajectory_data.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 | |
zeros
¶
zeros() -> list[TrajectoryData]
Get all zero crossing points.
Returns:
| Type | Description |
|---|---|
list[TrajectoryData]
|
Zero crossing points. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If extra_data was not requested. |
ArithmeticError
|
If zero crossing points are not found. |
Source code in py_ballisticcalc/trajectory_data.py
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 | |
index_at_distance
¶
Deprecated. Use get_at() instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Distance
|
Distance for which we want Trajectory Data. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Index of first trajectory row with .distance >= d; otherwise -1. |
Source code in py_ballisticcalc/trajectory_data.py
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 | |
get_at_distance
¶
get_at_distance(d: Distance) -> TrajectoryData
Deprecated. Use get_at('distance', d) instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Distance
|
Distance for which we want Trajectory Data. |
required |
Returns:
| Type | Description |
|---|---|
TrajectoryData
|
First trajectory row with .distance >= d. |
Raises:
| Type | Description |
|---|---|
ArithmeticError
|
If trajectory doesn't reach requested distance. |
Source code in py_ballisticcalc/trajectory_data.py
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
get_at_time
¶
get_at_time(t: float) -> TrajectoryData
Deprecated. Use get_at('time', t) instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time for which we want Trajectory Data. |
required |
Returns:
| Type | Description |
|---|---|
TrajectoryData
|
First trajectory row with .time >= t. |
Raises:
| Type | Description |
|---|---|
ArithmeticError
|
If trajectory doesn't reach requested time. |
Source code in py_ballisticcalc/trajectory_data.py
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | |
danger_space
¶
danger_space(
at_range: float | Distance,
target_height: float | Distance,
) -> DangerSpace
Calculate the danger space for a target.
Assumes that the trajectory hits the center of a target at any distance.
Determines how much ranging error can be tolerated if the critical region
of the target has target_height *h*. Finds how far forward and backward along the
line of sight a target can move such that the trajectory is still within *h*/2
of the original drop at_range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at_range
|
float | Distance
|
Danger space is calculated for a target centered at this sight distance. |
required |
target_height
|
float | Distance
|
Target height (h) determines danger space. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DangerSpace |
DangerSpace
|
The calculated danger space. |
Raises:
| Type | Description |
|---|---|
ArithmeticError
|
If trajectory doesn't reach requested distance. |
Source code in py_ballisticcalc/trajectory_data.py
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 | |
dataframe
¶
dataframe(formatted: bool = False) -> DataFrame
Return the trajectory table as a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formatted
|
bool
|
False for values as floats; True for strings in PreferredUnits. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The trajectory table as a DataFrame. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas or plotting dependencies are not installed. |
Source code in py_ballisticcalc/trajectory_data.py
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | |
plot
¶
plot(look_angle: Angular | None = None) -> Axes
Return a graph of the trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
look_angle
|
Angular | None
|
Look angle for the plot. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The plot Axes object. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If plotting dependencies are not installed. |
Source code in py_ballisticcalc/trajectory_data.py
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
DangerSpace
¶
Bases: NamedTuple
Stores the danger space data for distance specified.
Methods:
| Name | Description |
|---|---|
overlay |
Highlights danger-space region on plot. |
overlay
¶
overlay(ax: Axes, label: str | None = None) -> None
Highlights danger-space region on plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes to overlay on. |
required |
label
|
str | None
|
Label for the overlay. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If plotting dependencies are not installed. |
Source code in py_ballisticcalc/trajectory_data.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 | |