@@ -51,6 +51,7 @@ def build(self, destination: str):
5151 nb = self .build_motor (nb )
5252 nb = self .build_rocket (nb )
5353 nb = self .build_flight (nb )
54+ nb = self .build_compare_results (nb )
5455 self .save_notebook (nb , destination )
5556 logger .info (
5657 "[NOTEBOOK BUILDER] Notebook successfully built! You can find it at: %s" ,
@@ -107,7 +108,7 @@ def build_environment(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
107108 # add a code cell
108109 text = "tomorrow = datetime.date.today() + datetime.timedelta(days=1)\n "
109110 text += "env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))\n "
110- text += "env.set_atmospheric_model(type='Forecast', file='GFS')"
111+ text += "# env.set_atmospheric_model(type='Forecast', file='GFS')"
111112 nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
112113
113114 # add a code cell
@@ -459,6 +460,201 @@ def build_flight(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
459460 logger .info ("[NOTEBOOK BUILDER] Flight section created." )
460461 return nb
461462
463+ def build_compare_results (self , nb : nbf .v4 .new_notebook ) -> nbf .v4 .new_notebook :
464+ # pylint: disable=line-too-long
465+ # add a markdown cell
466+ text = "## Compare Results\n "
467+ text += "We will now compare the results of the simulation with the "
468+ text += "parameters used to create it. Let's go!\n "
469+ nb ["cells" ].append (nbf .v4 .new_markdown_cell (text ))
470+
471+ # add a code cell
472+ text = "### OpenRocket vs RocketPy Parameters\n "
473+ time_to_apogee = self .parameters ["stored_results" ]["time_to_apogee" ]
474+ # time to apogee
475+ text += f"time_to_apogee_ork = { time_to_apogee } \n "
476+ text += "time_to_apogee_rpy = flight.apogee_time\n "
477+ text += r'print(f"Time to apogee (OpenRocket): {time_to_apogee_ork:.3f} s")'
478+ text += "\n "
479+ text += r'print(f"Time to apogee (RocketPy): {time_to_apogee_rpy:.3f} s")'
480+ text += "\n "
481+ text += "apogee_difference = time_to_apogee_rpy - time_to_apogee_ork"
482+ text += "\n "
483+ text += "error = abs((apogee_difference)/time_to_apogee_rpy)*100"
484+ text += "\n "
485+ text += r'print(f"Time to apogee difference: {error:.3f} %")'
486+ text += "\n \n "
487+
488+ # Flight time
489+ flight_time_ork = self .parameters ["stored_results" ]["flight_time" ]
490+ text += f"flight_time_ork = { flight_time_ork } \n "
491+ text += "flight_time_rpy = flight.t_final\n "
492+ text += r'print(f"Flight time (OpenRocket): {flight_time_ork:.3f} s")'
493+ text += "\n "
494+ text += r'print(f"Flight time (RocketPy): {flight_time_rpy:.3f} s")'
495+ text += "\n "
496+ text += "flight_time_difference = flight_time_rpy - flight_time_ork\n "
497+ text += (
498+ "error_flight_time = abs((flight_time_difference)/flight_time_rpy)*100\n "
499+ )
500+ text += r'print(f"Flight time difference: {error_flight_time:.3f} %")'
501+ text += "\n \n "
502+
503+ # Ground hit velocity
504+ ground_hit_velocity_ork = self .parameters ["stored_results" ][
505+ "ground_hit_velocity"
506+ ]
507+ text += f"ground_hit_velocity_ork = { ground_hit_velocity_ork } \n "
508+ text += "ground_hit_velocity_rpy = flight.impact_velocity\n "
509+ text += r'print(f"Ground hit velocity (OpenRocket): {ground_hit_velocity_ork:.3f} m/s")'
510+ text += "\n "
511+ text += r'print(f"Ground hit velocity (RocketPy): {ground_hit_velocity_rpy:.3f} m/s")'
512+ text += "\n "
513+ text += "ground_hit_velocity_difference = ground_hit_velocity_rpy - ground_hit_velocity_ork\n "
514+ text += "error_ground_hit_velocity = abs((ground_hit_velocity_difference)/ground_hit_velocity_rpy)*100\n "
515+ text += r'print(f"Ground hit velocity difference: {error_ground_hit_velocity:.3f} %")'
516+ text += "\n \n "
517+
518+ # Launch rod velocity
519+ launch_rod_velocity_ork = self .parameters ["stored_results" ][
520+ "launch_rod_velocity"
521+ ]
522+ text += f"launch_rod_velocity_ork = { launch_rod_velocity_ork } \n "
523+ text += "launch_rod_velocity_rpy = flight.out_of_rail_velocity\n "
524+ text += r'print(f"Launch rod velocity (OpenRocket): {launch_rod_velocity_ork:.3f} m/s")'
525+ text += "\n "
526+ text += r'print(f"Launch rod velocity (RocketPy): {launch_rod_velocity_rpy:.3f} m/s")'
527+ text += "\n "
528+ text += "launch_rod_velocity_difference = launch_rod_velocity_rpy - launch_rod_velocity_ork\n "
529+ text += "error_launch_rod_velocity = abs((launch_rod_velocity_difference)/launch_rod_velocity_rpy)*100\n "
530+ text += r'print(f"Launch rod velocity difference: {error_launch_rod_velocity:.3f} %")'
531+ text += "\n \n "
532+
533+ # Max acceleration
534+ max_acceleration_ork = self .parameters ["stored_results" ]["max_acceleration" ]
535+ text += f"max_acceleration_ork = { max_acceleration_ork } \n "
536+ text += "max_acceleration_rpy = flight.max_acceleration\n "
537+ text += (
538+ r'print(f"Max acceleration (OpenRocket): {max_acceleration_ork:.3f} m/s²")'
539+ )
540+ text += "\n "
541+ text += (
542+ r'print(f"Max acceleration (RocketPy): {max_acceleration_rpy:.3f} m/s²")'
543+ )
544+ text += "\n "
545+ text += "max_acceleration_difference = max_acceleration_rpy - max_acceleration_ork\n "
546+ text += "error_max_acceleration = abs((max_acceleration_difference)/max_acceleration_rpy)*100\n "
547+ text += (
548+ r'print(f"Max acceleration difference: {error_max_acceleration:.3f} %")'
549+ )
550+ text += "\n \n "
551+
552+ # Max altitude
553+ max_altitude_ork = self .parameters ["stored_results" ]["max_altitude" ]
554+ text += f"max_altitude_ork = { max_altitude_ork } \n "
555+ text += "max_altitude_rpy = flight.apogee - flight.env.elevation\n "
556+ text += r'print(f"Max altitude (OpenRocket): {max_altitude_ork:.3f} m")'
557+ text += "\n "
558+ text += r'print(f"Max altitude (RocketPy): {max_altitude_rpy:.3f} m")'
559+ text += "\n "
560+ text += "max_altitude_difference = max_altitude_rpy - max_altitude_ork\n "
561+ text += (
562+ "error_max_altitude = abs((max_altitude_difference)/max_altitude_rpy)*100\n "
563+ )
564+ text += r'print(f"Max altitude difference: {error_max_altitude:.3f} %")'
565+ text += "\n \n "
566+
567+ # Max Mach
568+ max_mach_ork = self .parameters ["stored_results" ]["max_mach" ]
569+ text += f"max_mach_ork = { max_mach_ork } \n "
570+ text += "max_mach_rpy = flight.max_mach_number \n "
571+ text += r'print(f"Max Mach (OpenRocket): {max_mach_ork:.3f}")'
572+ text += "\n "
573+ text += r'print(f"Max Mach (RocketPy): {max_mach_rpy:.3f}")'
574+ text += "\n "
575+ text += "max_mach_difference = max_mach_rpy - max_mach_ork\n "
576+ text += "error_max_mach = abs((max_mach_difference)/max_mach_rpy)*100\n "
577+ text += r'print(f"Max Mach difference: {error_max_mach:.3f} %")'
578+ text += "\n \n "
579+
580+ # Max velocity
581+ max_velocity_ork = self .parameters ["stored_results" ]["max_velocity" ]
582+ text += f"max_velocity_ork = { max_velocity_ork } \n "
583+ text += "max_velocity_rpy = flight.max_speed\n "
584+ text += r'print(f"Max velocity (OpenRocket): {max_velocity_ork:.3f} m/s")'
585+ text += "\n "
586+ text += r'print(f"Max velocity (RocketPy): {max_velocity_rpy:.3f} m/s")'
587+ text += "\n "
588+ text += "max_velocity_difference = max_velocity_rpy - max_velocity_ork\n "
589+ text += (
590+ "error_max_velocity = abs((max_velocity_difference)/max_velocity_rpy)*100\n "
591+ )
592+ text += r'print(f"Max velocity difference: {error_max_velocity:.3f} %")'
593+ text += "\n \n "
594+
595+ # Max thrust
596+ max_thrust_ork = self .parameters ["stored_results" ]["max_thrust" ]
597+ text += f"max_thrust_ork = { max_thrust_ork } \n "
598+ text += "max_thrust_rpy = flight.rocket.motor.thrust.max\n "
599+ text += r'print(f"Max thrust (OpenRocket): {max_thrust_ork:.3f} N")'
600+ text += "\n "
601+ text += r'print(f"Max thrust (RocketPy): {max_thrust_rpy:.3f} N")'
602+ text += "\n "
603+ text += "max_thrust_difference = max_thrust_rpy - max_thrust_ork\n "
604+ text += "error_max_thrust = abs((max_thrust_difference)/max_thrust_rpy)*100\n "
605+ text += r'print(f"Max thrust difference: {error_max_thrust:.3f} %")'
606+ text += "\n \n "
607+
608+ # # Burnout stability margin
609+ burnout_stability_margin_ork = self .parameters ["stored_results" ][
610+ "burnout_stability_margin"
611+ ]
612+ text += f"burnout_stability_margin_ork = { burnout_stability_margin_ork } \n "
613+ text += "burnout_stability_margin_rpy = flight.stability_margin(flight.rocket.motor.burn_out_time)\n "
614+ text += r'print(f"Burnout stability margin (OpenRocket): {burnout_stability_margin_ork:.3f}")'
615+ text += "\n "
616+ text += r'print(f"Burnout stability margin (RocketPy): {burnout_stability_margin_rpy:.3f}")'
617+ text += "\n "
618+ text += "burnout_stability_margin_difference = burnout_stability_margin_rpy - burnout_stability_margin_ork\n "
619+ text += "error_burnout_stability_margin = abs((burnout_stability_margin_difference)/burnout_stability_margin_rpy)*100\n "
620+ text += r'print(f"Burnout stability margin difference: {error_burnout_stability_margin:.3f} %")'
621+ text += "\n \n "
622+
623+ # # Max stability margin
624+ max_stability_margin_ork = self .parameters ["stored_results" ][
625+ "max_stability_margin"
626+ ]
627+ text += f"max_stability_margin_ork = { max_stability_margin_ork } \n "
628+ text += "max_stability_margin_rpy = flight.max_stability_margin\n "
629+ text += r'print(f"Max stability margin (OpenRocket): {max_stability_margin_ork:.3f}")'
630+ text += "\n "
631+ text += r'print(f"Max stability margin (RocketPy): {max_stability_margin_rpy:.3f}")'
632+ text += "\n "
633+ text += "max_stability_margin_difference = max_stability_margin_rpy - max_stability_margin_ork\n "
634+ text += "error_max_stability_margin = abs((max_stability_margin_difference)/max_stability_margin_rpy)*100\n "
635+ text += r'print(f"Max stability margin difference: {error_max_stability_margin:.3f} %")'
636+ text += "\n \n "
637+
638+ # Min stability margin
639+ min_stability_margin_ork = self .parameters ["stored_results" ][
640+ "min_stability_margin"
641+ ]
642+ text += f"min_stability_margin_ork = { min_stability_margin_ork } \n "
643+ text += "min_stability_margin_rpy = flight.min_stability_margin\n "
644+ text += r'print(f"Min stability margin (OpenRocket): {min_stability_margin_ork:.3f}")'
645+ text += "\n "
646+ text += r'print(f"Min stability margin (RocketPy): {min_stability_margin_rpy:.3f}")'
647+ text += "\n "
648+ text += "min_stability_margin_difference = min_stability_margin_rpy - min_stability_margin_ork\n "
649+ text += "error_min_stability_margin = abs((min_stability_margin_difference)/min_stability_margin_rpy)*100\n "
650+ text += r'print(f"Min stability margin difference: {error_min_stability_margin:.3f} %")'
651+ text += "\n \n "
652+
653+ nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
654+
655+ logger .info ("[NOTEBOOK BUILDER] Compare Results section created." )
656+ return nb
657+
462658 def save_notebook (self , nb : nbf .v4 .new_notebook , destination : str ) -> None :
463659 """Writes the .ipynb file to the destination folder. Also applies black
464660 formatting to the file to improve readability."""
0 commit comments