Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fitting a simulation to a flight

hpr fit moves a simulation’s drag, impulse, wind and mass until it passes through a log’s heights, and gives most of them a 90% interval.

This page is for a flyer who has flown a rocket and wants to know what the flight says about the simulation of it. Seeing how far the two lie apart, with nothing fitted, is Comparing a flight with its simulation. The method and its tests are on the least-squares fit’s page.

The tests run the command on one public logged flight, NDRT’s 2020 flight, and on the invented log below. The project’s automated checks (CI) fetch that flight’s log from RocketPy’s public data on Linux, and fail there without it. CI’s macOS and Windows jobs, and a machine of your own that hasn’t fetched the log, skip the public flight. That flight shows that the command runs on a real log, not that its answer is right. Its fitted drag scale lies below 0.8, outside the range the intervals were tested over, and prints marked so.

Run it

Give the log, then the design, its motor and the launch, as hpr sim takes them (the command line). A log that is a plain table needs --mapping, the file that says which column is which (Reading a flight log). This example’s log is invented. It is the repository’s Level 1 guide rocket flown in a 6 m/s (13 mph) wind. Its heights are read 4% low and rounded to a foot (how it is made). The fit is told the day’s wind. It also solves for a barometer’s scale (the method), but is told that it is 1 give or take 0.14%, one standard deviation. That is far less than 4%. See where the error goes:

$ hpr fit validation/fixtures/logs/compare/level-1-flown.csv validation/fixtures/ork/guides/level-1.ork --mapping validation/fixtures/logs/compare/level-1.mapping.json --wind 6
level-1-flown.csv, its simulation fitted to it
  flown: level-1.ork, [H170M-10]
  on the launch day: a wind entered of 6.0 m/s from 0°, the same at every height; the 1976 standard atmosphere's air
  each simulated height is read as a barometer on the pad would read it, as the log's is

Read from the log
  liftoff  10.10 s, within 0.89 s
           measured, from the logger's barometric altitude
  apogee   1015.6 m (3332 ft), within 76.9 m (253 ft), at 21.65 s, within 0.93 s
           measured, from the logger's barometric altitude
  heights  51 of 51 quarter-second bins from 1 s before liftoff to apogee
           measured, from the logger's barometric altitude
  drift    none: the log holds no latitude and longitude

Fitted by least squares
                         fitted      90% interval      told before the log
  drag scale             1.036       0.981 to 1.086 *  1.000 ± 0.109
  impulse scale          0.955       0.921 to 0.990    1.000 ± 0.033
  burn time scale        1.035       none              1.000 ± 0.055
  wind toward the east   0.0 m/s     none              0.0 ± 3.9 m/s
                         (0 ft/s)                      (0 ± 13 ft/s)
  wind toward the north  -6.4 m/s    none              -6.0 ± 3.9 m/s
                         (-21 ft/s)                    (-20 ± 13 ft/s)
  structure mass scale   1.003       0.985 to 1.022    1.000 ± 0.011
  * This interval fails its test: the caveat below.
  The burn time scale states no interval: not asked of the fit.
  The wind states no interval: a log of height alone can't tell the wind.
  So the fit is told a wind of at least 5.16 m/s (16.9 ft/s), the wind its intervals were sized in.
  Caveat. The drag scale's 90% interval fails its test. On 1,000 synthetic flights flown with a
  model unlike the fit's own, 79 truths lay below the interval, where a 90% interval leaves 50. So
  its lower end can read too high: take the fitted drag scale as reading high, and a flight
  predicted with it as reading low. Recorded, not fixed:
  https://github.com/nrdptel/fusionspace-eridanus/issues/1108

The fitted flight
  heights' residual  0.8 m (3 ft) RMS, 0.2% of the heights' spread
  apogee             1014.4 m (3328 ft), top Mach 0.80; as stated, 1058.3 m (3472 ft)
  simulations flown  52

How far to trust it. Fitted: the simulation's drag, impulse, wind and mass moved until it passes
through the log, on the inputs you gave. A scale is the factor that best fits this one flight, not
the rocket's drag at every speed, and the simulation's own errors go into the scales with nothing to
say so. The 90% intervals were tested on synthetic flights only: no real flight has checked them.
Don't size a flight to a waiver or a field's ceiling from a fitted scale alone; the altimeter's own
reading is the one to log, and the RSO decides.
More: https://hpr.fusionspace.co/fitting-a-flight.html
warning: drag: issue #67: a cone-like nose's or shoulder's pressure drag reads high from Mach 0.8 (about twice a measured cone's at Mach 0.85, still +15% at 1.5). So the apogee, top speed and drift read low, and the flutter margin and largest dynamic pressure look better than they are. This flight reaches Mach 0.80 at 1.8 s
warning: drag: issue #68: base drag reads high from Mach 0.8 to 1.2 (0.225 against a measured 0.156 at Mach 0.9). So the apogee, top speed and drift read low, and the flutter margin and largest dynamic pressure look better than they are. This flight reaches Mach 0.80 at 1.8 s
warning: drag: issue #18: skin friction is taken as fully turbulent; on a smooth surface a laminar run near the nose lowers it, by 3.6% on RocketPy's Calisto at Mach 0.3. If this surface is that smooth, the apogee, top speed and drift read low, and the flutter margin and largest dynamic pressure look better than they are
warning: stability: issue #172: the static margin read up to 0.1108 calibers above OpenRocket's on four private designs, cause unknown; this flight's may read high by as much
warning: stability: issue #1290: on one of two wind-tunnel models, the center of pressure sat 0.11 to 0.92 calibers aft of the tunnel's at Mach 0.6 and 0.8, as the report's curve reads; fitted over −3° to 4°, about 0.08 at 0.8. So from Mach 0.6 the flight margin may read high. This flight reaches Mach 0.80 at 1.8 s
warning: stability: issue #1198: the center of pressure sat 0.67 to 1.35 calibers aft of a wind tunnel's on two models at Mach 0.9, so past Mach 0.8 the flight margin may read high. This flight reaches Mach 0.80 at 1.8 s
help: issues: https://github.com/nrdptel/fusionspace-eridanus/issues/<number>
note: the file's 1 recovery device flies as OpenRocket flies it. Each opens fully at its event, with the file's drag coefficient or OpenRocket's own. Once one opens, the rocket descends as a point under the open devices' drag alone
note: the log was read in the units your mapping or layout states, so the fit holds only if those are right
note: a log's main altitude, or a column you mapped, is taken as a barometer's: give --height-reads height-climbed for a GPS receiver's
note: the fit flies the climb with nothing open: a flight whose parachute opened before apogee was slowed by it, and the fit puts that into the drag scale

The fitted flight passes through the log: its heights miss by 0.8 m (3 ft) RMS. It got there with an impulse scale of 0.955 and a drag scale of 1.036. Neither is what happened. The motor gave its whole impulse and the logger read low. A close fit shows that some set of scales explains the log. It doesn’t show that those scales are the cause.

The line that starts “So the fit is told a wind of at least” prints on every log of height alone (why).

Read the result

A scale is a factor on what the design or the motor’s file states. A scale of 1 leaves it as stated, and 1.05 is 5% more.

Read from the log lists what the fit took from the log. It fits the heights from a second before the liftoff to the apogee, in quarter-second bins, each bin holding the median of its samples. A log with latitude and longitude adds its drift. Under each is where it came from: the sensor, and whether it was measured or derived, as hpr analyze reads it.

Fitted by least squares has a row for each parameter:

  • The drag scale multiplies the rocket’s drag with no lift, at every speed.
  • The impulse scale multiplies the motor’s total impulse, and the burn time scale its burn time. The burn time’s scale is moved so that a longer or shorter burn doesn’t lean on the other scales. Its interval was never tested, so it states none: “not asked of the fit”.
  • The wind is one constant wind, toward the east and toward the north. The example’s wind blows from 0°, the north, so it is −6 m/s (−20 ft/s) toward the north. A log of height alone can’t tell a wind. There it has no interval, and its fitted value mostly repeats what the fit was told (the wind on a log of height alone).
  • The structure mass scale multiplies the mass of the rocket without its motors.

The 90% interval is sized so that, over many flights, the true value lies inside 9 times in 10 (how well it holds). It holds over a set of flights, not on each one. Each printed end is rounded outward, so the interval never claims less than it holds.

Told before the log is what the fit started from: the stated value, give or take one standard deviation. Those ranges are the ones the intervals were sized with, so the command has no option to change them. Compare each fitted value with it. A scale that lands several of those deviations away is a sign that the design, the motor or the log isn’t the flight’s. In the example the impulse scale sits more than one deviation low. In this invented log that comes from the heights read 4% low, not from the motor.

The fitted flight gives the heights’ residual, the fitted flight’s apogee beside the apogee as stated, and how many simulations the fit flew. Both apogees are the climb’s as the fit flies it, with no recovery device opening.

The notes at the end say what the fit took on trust. They name the units your mapping states and the kind of height it took the log’s for. They also say that nothing opened on the way up. One note is hpr sim’s own, on how the file’s recovery devices fly: the flight the warnings come from is flown whole.

The wind on a log of height alone

A wind from any direction lowers a flight’s top, and heights alone can’t tell how much of a low flight is wind. The intervals were sized on fits told a wind of 5.16 m/s (16.9 ft/s) (the method), and no test covers a fit told less. So on a log with no latitude and longitude the fit is told a wind of at least that. A slower wind you give is raised to it along its own direction, and calm air to that toward the east. A stronger wind stands as given, as the example’s 6 m/s (13 mph) does. A line under the table states the floor. A log with a track is told the wind you give, with no floor.

The fit’s last digits can differ from one computer to another. The outputs on this page were written on macOS. The tests hold them exactly there. On Linux and Windows they check only the wording: any number counts as a number, a run of spaces counts as one, and the warnings aren’t compared.

The wind on a log with a track

A log with latitude and longitude lets the fit state the wind’s interval. A rocket turns into the wind under thrust and flies upwind, and the air then carries it back. So its drift doesn’t grow steadily with the wind, and a track can be fitted fairly well by two winds: the flight’s, and another far from it. A search from the wind you give can settle at the wrong one. The 54 mm (2.1 in) design’s own flight in a wind of 9 m/s (20 mph) toward the east, fitted from calm air, once came out as a wind the other way, with a narrow interval (issue #1646 has the numbers).

So after its first search the fit scans the wind. It flies the flight in calm air and in winds every 1.5 m/s (4.9 ft/s) up to 12 m/s (39 ft/s), in 12 directions, and searches again from the three lowest of that scan’s lows (points no higher than their neighbors) away from its first answer. The answer that fits the log best stands. One found from the scan counts only within 12 m/s (27 mph), and the search from the wind you give counts wherever it ends (the method). A test fits that design’s flights in winds of 2 m/s (4.5 mph), 4, 6 and 9 m/s (20 mph) from calm air, one of them off a 3 m (9.8 ft) rail and one told a wrong wind of 3 m/s (6.7 mph). Each interval holds the wind the flight was flown in (fit_finds_the_wind_a_track_was_flown_in_from_calm_air).

The scan found the wind on each of that test’s flights, but it doesn’t rule out a wrong answer, and no test counts how often one remains. It can miss a second answer between its points. It was tried on one design’s flights and on the synthetic flights. It also ran on the two real logs with a track that the report of fits of real logs fits, but no real flight has its wind measured apart from its log to check the fitted one against. If the fitted wind differs from the field’s by more than its interval, distrust the other scales too. The scan adds 97 flights of the simulation to a fit of a log with a track, and each search from it more.

A second answer past 12 m/s (27 mph). A search from the scan that ends past that speed isn’t taken. That speed is more than the 20 mph (8.9 m/s) the NAR’s high-power safety code allows, and beyond it lie lows the scan never saw. But a flight can be flown in such a wind, and then the answer left out is the flight’s. So the fit says when a search ended past the scan’s reach and fits the log better than the fitted wind. A caveat prints under the table, and --json gives it as wind_past_scan. On a simulated flight of that design in a wind of 12.5 m/s (28 mph) toward the east, fitted from calm air, it reads:

Caveat. The wind has a second answer, which the fit didn't take. A search ended at a wind of 12.2 m/s (27.3 mph) from 270°, past the 12 m/s (26.8 mph) the fit's scan of the wind reaches. It fits the log better than the fitted wind: a misfit (χ²) of 15.3 against 127.8. Past the scan's reach the fit can't tell the flight's wind from a wrong one, so the fitted wind stands. If the day's wind was near the second answer, fit again with that wind given. If you have no record of the day's wind, take the fitted wind, and the scales fitted with it, as unsettled. On the command line: `--wind 12.2 --wind-from 270`.

A wind toward the east blows from the west, which is 270° clockwise from north. The misfit, χ², is the sum the fit makes as small as it can: each height’s and each track point’s miss over its noise, squared, plus a term for the ranges the fit is told (the method). The lower of two fits the log better. A fit given --weather or --launch-time prints the caveat without its last line of options, as --wind can’t be given beside either. To fit again there, give --wind and --wind-from in place of that option. The refit then flies without that option’s air.

The fitted wind on that flight blew more than 4 m/s (9 mph) the other way, and its interval missed the flight’s wind. Fitted again with those two options, the fit ends within 0.5 m/s (1.6 ft/s) of the flight’s wind and says no second answer (fit_says_the_second_answer_it_leaves_past_the_wind_scans_reach, which also holds the block above to a run). Its interval can still miss by a little, as the fitted wind reads slow (issue #1651).

The caveat doesn’t say which answer is the flight’s. On the fit report’s slice of synthetic flights, 2 of the 195 fits of a track print it (the_slice_says_a_second_answer_twice_and_both_are_wrong). Both times the second answer is the wrong one: it lies more than 3 m/s (9.8 ft/s) from the report’s true wind. The fitted wind is within 1 m/s (3.3 ft/s) of that true wind. The slice can’t show a second answer that is right, as none of its fits of a track has a true wind past the scan’s reach; the flight in 12.5 m/s (28 mph) above does. So where the caveat prints, check it against the wind on the field that day. If that was near the second answer, fit again from it. If it was near the fitted wind, the fitted wind stands. With no record of the day’s wind, take the fitted wind and the scales as unsettled. The caveat isn’t counted over all the synthetic flights yet (issue #1652).

The mark on a value outside the tested range

The intervals were tested on synthetic flights whose true values were drawn from fixed ranges:

  • the drag scale, from 0.8 to 1.2;
  • the impulse scale, from 0.94 to 1.06;
  • the burn time scale, from 0.9 to 1.1;
  • the structure’s mass, within 2% of the weighed one;
  • the wind, up to 8.9 m/s (29 ft/s).

A fitted value outside its range prints with a †, and a line under the table names the range. No test covers the fit’s intervals out there, that parameter’s or another’s. The mark is a limit on what was tested. It doesn’t say the fit is wrong, and a fit with no mark isn’t shown right by it.

The caveat

The drag scale’s interval is marked with a *, and a caveat under the table says why. On 1,000 synthetic flights flown with a model unlike the fit’s own, 79 true values, the message’s “truths”, lay below the interval, where a 90% interval leaves 50. So the fitted drag can read high, and a flight predicted with it reads low: the side that flatters a field’s ceiling (which miss flatters). I’ve recorded that gap and not widened the interval to hide it (issue #1108). The caveat prints with the intervals until the interval passes its test.

The warnings

After the result come the warnings hpr sim gives for the same flight, one for each known issue the fitted flight meets. Drag that reads high past Mach 0.8 is one (the accuracy note on every result). They matter more here. Where the simulation’s drag is known to read wrong, the drag scale takes that error in.

The launch day

Without weather options the fit flies the 1976 standard atmosphere. Give the launch day’s air and wind with the options hpr sim takes: --wind and --wind-from, --temperature, --pressure, a --weather file, or --launch-time for Open-Meteo’s archive at the site (Launch-day weather). The air is flown as given. The wind, averaged over the climb, becomes what the fit is told before the log. On a log of height alone a wind slower than 5.16 m/s (16.9 ft/s) is raised to that (why):

hpr fit flight.pf2 rocket.ork --motor CTI-J350 --wind 4 --wind-from 270 --temperature 28

A log’s main altitude is taken as a barometer’s, and the simulated height is read the same way in that air. If the height is a GPS receiver’s, give --height-reads height-climbed.

When it refuses

The command stops with its reason, and prints no numbers, when:

  • the log has no apogee the reader will state, or its climb can’t be read (when a log has nothing to fit);
  • the flight comes apart in the air, as a stage that separates does. The fit doesn’t follow the parts;
  • no flight of the design passes through the log. The best fit’s residual is more than a tenth of the heights’ spread, the cut the method’s page gives. Check the design, its motor and --height-reads, and look at the two with hpr compare.

A fit that isn’t refused can still be of the wrong rocket. In a test, a 54 mm (2.1 in) design passes the Level 1 rocket’s log to under 2 m (7 ft) RMS. Its drag scale comes out above 1.4 and its impulse scale below 0.8. Both print marked as outside their tested ranges, and nothing else flags it.

From Python

FlightLog.fit runs the same fit and gives the same numbers as a dict (Python). This example fits the same log as the command above did. The site is at sea level, in standard air with the same 6 m/s (13 mph) wind, and the rail is 1.5 m (4.9 ft). recovery=True reads the file’s parachute, so the warnings are the whole flight’s. It prints each parameter with its interval or the reason it has none, the caveat’s counts, and how many known issues the fitted flight meets:

from fusionspace import hpr

folder = "validation/fixtures/logs/compare"
log = hpr.FlightLog.read(f"{folder}/level-1-flown.csv", mapping=f"{folder}/level-1.mapping.json")
rocket = hpr.Rocket.from_file("validation/fixtures/ork/guides/level-1.ork", recovery=True)
site = hpr.Environment(0.0, 0.0, 0.0, wind_speed_m_s=6.0)
fitted = log.fit(rocket, site, rail_length_m=1.5)
for row in fitted["parameters"]:
    interval = row["interval_90"]
    said = f"{interval['low']:.3f} to {interval['high']:.3f}" if interval else row["no_interval"]
    print(f"{row['parameter']}: {row['value']:.3f}, {said}")
drag = fitted["parameters"][0]
print(f"{drag['caveat']['below']} of {drag['caveat']['flights']} truths lay below the drag's")
print(len(fitted["issue_warnings"]), "known issues met")
drag_scale: 1.036, 0.981 to 1.085
impulse_scale: 0.955, 0.922 to 0.990
burn_time_scale: 1.035, not_asked
wind_east_m_s: 0.014, height_alone
wind_north_m_s: -6.375, height_alone
mass_scale: 1.003, 0.985 to 1.021
79 of 1000 truths lay below the drag's
6 known issues met

not_asked is the burn time’s scale, whose interval was never tested, and height_alone is the wind on a log with no latitude and longitude. The example rounds each end of an interval to the nearest thousandth, where the command rounds it outward. The last line counts the warnings: issue_warnings holds each one’s issue number, message and url. The environment’s wind, averaged over the climb, is what the fit is told before the log. The same floor holds on a log of height alone. Each parameter’s stated holds that mean and its standard deviation. tested_range holds the range the intervals were tested over, and outside_tested_range says whether the value lies outside it. readings holds what was read from the log, with each source and provenance. wind_past_scan is None, or the second answer past the scan as a dict with its message. fitted["text"] is the whole result as lines to print, in SI units.

What it leaves out

  • Everything after apogee, and the accelerometer. The fit reads heights, and a track if the log has one.
  • A parachute that opened before apogee. The fit flies the climb with nothing open, so an early ejection’s drag goes into the drag scale. A note says so.
  • A wind that changes with height. The fitted wind is one constant wind.
  • A second answer for the wind that the scan misses between its points, on a log with a track. One past 12 m/s (27 mph) is said only where a search from the scan ended there (the scan).
  • A logger that reads far low or high. The fit is told a barometer’s scale is 1 give or take 0.14%, and the example’s 4% error shows up in the other scales.
  • A flight that separates in the air, which is refused.
  • A check on a real flight’s fitted values against something measured apart from the log, such as a weighed mass or a static test’s impulse. I have no such flight yet (the register’s row on the fit; the issue that asks for one).
  • The Bayesian option, which is in the Rust library only. More of its intervals fail their tests.

Don’t size a flight to a waiver or a field’s ceiling from a fitted scale alone. The altimeter’s own reading is the one to log, and the RSO decides.

FusionSpace HPRVersion 0.1.0Issued 2026-11-27In preparationAbout HPR Sim