Skip to content

Commit 09f9169

Browse files
authored
[skip ci] Notebooks improvements (#1331)
1 parent d280579 commit 09f9169

File tree

4 files changed

+54
-51
lines changed

4 files changed

+54
-51
lines changed

examples/python/AoA vs CAS.ipynb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,23 @@
131131
"source": [
132132
"# Confirm that JSBSim is installed. If not and running on Google Colab\n",
133133
"# then install JSBSim into the Google Colab instance.\n",
134+
"\n",
135+
"import os\n",
136+
"\n",
134137
"try:\n",
135138
" import jsbsim\n",
136139
" print('JSBSim is installed')\n",
140+
" # Relative path to the directory where the flight model is stored\n",
141+
" # Note - Aircraft directory needs to be writeable in order to modify the cg\n",
142+
" PATH_TO_JSBSIM_FILES=\"../..\"\n",
143+
" print(f'Current working directory: {os.getcwd()}')\n",
137144
"except ImportError:\n",
138145
" import sys\n",
139146
" if 'google.colab' in sys.modules:\n",
140147
" print('Installing JSBSim...')\n",
141-
" !git clone https://github.com/JSBSim-Team/jsbsim.git\n",
142148
" !pip install jsbsim\n",
143-
" %cd jsbsim/examples/python\n",
144-
"print('Current working directory:')\n",
145-
"!pwd"
149+
" # Use the standard aircraft supplied by the JSBSim Python package\n",
150+
" PATH_TO_JSBSIM_FILES=None"
146151
]
147152
},
148153
{
@@ -155,18 +160,14 @@
155160
"import jsbsim\n",
156161
"import xml.etree.ElementTree as ET\n",
157162
"import matplotlib.pyplot as plt\n",
158-
"import os\n",
159163
"\n",
160164
"# Global variables that must be modified to match your particular need\n",
161165
"# The aircraft name\n",
162166
"# Note - It should match the exact spelling of the model file\n",
163167
"AIRCRAFT_NAME=\"global5000\"\n",
164-
"# Relative path to the directory where the flight model is stored\n",
165-
"# Note - Aircraft directory needs to be writeable in order to modify the cg\n",
166-
"PATH_TO_JSBSIM_FILES=\"../..\"\n",
167168
"\n",
168169
"# Avoid flooding the console with log messages\n",
169-
"jsbsim.FGJSBBase().debug_lvl = 0\n"
170+
"jsbsim.FGJSBBase().debug_lvl = 0"
170171
]
171172
},
172173
{
@@ -211,7 +212,7 @@
211212
"\n",
212213
"# Instantiate the FDMExec object and load the aircraft\n",
213214
"fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES)\n",
214-
"fdm.load_model(f'{AIRCRAFT_NAME}')\n",
215+
"fdm.load_model(AIRCRAFT_NAME)\n",
215216
"\n",
216217
"ac_xml_tree = ET.parse(os.path.join(fdm.get_root_dir(), f'aircraft/{AIRCRAFT_NAME}/{AIRCRAFT_NAME}.xml'))\n",
217218
"ac_xml_root = ac_xml_tree.getroot()\n",
@@ -290,7 +291,7 @@
290291
"dElev_deg = [d * 180 / 3.14159 for d in dElev_rad]\n",
291292
"\n",
292293
"# Plot AoA vs KCAS\n",
293-
"ax1.plot(speed, alpha, \n",
294+
"ax1.plot(speed, alpha,\n",
294295
" label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n",
295296
" marker='o', linestyle='-', color='blue')\n",
296297
"\n",
@@ -300,7 +301,7 @@
300301
"ax1.legend(loc='upper right')\n",
301302
"\n",
302303
"# Plot elevator deflection vs KCAS\n",
303-
"ax2.plot(speed, dElev_deg, \n",
304+
"ax2.plot(speed, dElev_deg,\n",
304305
" label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n",
305306
" marker='o', linestyle='-', color='red')\n",
306307
"\n",
@@ -310,7 +311,7 @@
310311
"ax2.legend(loc=\"upper right\")\n",
311312
"\n",
312313
"# Plot normalized elevator deflection vs KCAS\n",
313-
"ax3.plot(speed, dElev_norm, \n",
314+
"ax3.plot(speed, dElev_norm,\n",
314315
" label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n",
315316
" marker='o', linestyle='-', color='green')\n",
316317
"\n",
@@ -363,10 +364,6 @@
363364
}
364365
],
365366
"source": [
366-
"%matplotlib inline\n",
367-
"# Avoid flooding the console with log messages\n",
368-
"jsbsim.FGJSBBase().debug_lvl = 0\n",
369-
"\n",
370367
"# Control whether to print results to console in addition to generating a plot\n",
371368
"print_output = False\n",
372369
"\n",
@@ -424,10 +421,10 @@
424421
"for j in range(2):\n",
425422
" fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES)\n",
426423
" fdm.load_model(f'{AIRCRAFT_NAME}')\n",
427-
" \n",
424+
"\n",
428425
" # Set engines running\n",
429426
" fdm['propulsion/set-running'] = -1\n",
430-
" \n",
427+
"\n",
431428
" # Change CoG-x in the aircraft xml\n",
432429
" xcg_ = changeCG(fdm, xs_cg[j], False)\n",
433430
"\n",
@@ -466,26 +463,26 @@
466463
" print(\"KCAS, AoA (deg)\")\n",
467464
" for result in results:\n",
468465
" print(result[0], result[1])\n",
469-
" \n",
466+
"\n",
470467
" print(\"---------\")\n",
471468
" print(\"KCAS, Elevator deflection (rad), Normalized elevator deflection (-1 to 1)\")\n",
472469
" for result_fcs in results_fcs:\n",
473470
" print(result_fcs[0], result_fcs[1], result_fcs[2])\n",
474471
"\n",
475472
" speed, alpha = zip(*results)\n",
476-
" ax1.plot(speed, alpha, \n",
473+
" ax1.plot(speed, alpha,\n",
477474
" label=\"{0} weight, {1:.0f} kft, {2:.2f} % CoG\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n",
478475
" marker='o', linestyle='-')\n",
479476
"\n",
480477
" speed, dElev_rad, dElev_norm = zip(*results_fcs)\n",
481478
" # Convert elevator deflection from radians to degrees\n",
482479
" dElev_deg = [d * 180 / 3.14159 for d in dElev_rad]\n",
483480
"\n",
484-
" ax2.plot(speed, dElev_deg, \n",
481+
" ax2.plot(speed, dElev_deg,\n",
485482
" label=\"{0} weight {1:.0f} kft {2:.2f} % cg\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n",
486483
" marker='o', linestyle='-')\n",
487-
" \n",
488-
" ax3.plot(speed, dElev_norm, \n",
484+
"\n",
485+
" ax3.plot(speed, dElev_norm,\n",
489486
" label=\"{0} weight {1:.0f} kft {2:.2f} % cg\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n",
490487
" marker='o', linestyle='-')\n",
491488
"\n",

examples/python/Rudder Kick.ipynb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@
2222
"source": [
2323
"# Confirm that JSBSim is installed. If not and running on Google Colab\n",
2424
"# then install JSBSim into the Google Colab instance.\n",
25+
"\n",
26+
"import os\n",
27+
"\n",
2528
"try:\n",
2629
" import jsbsim\n",
2730
" print('JSBSim is installed')\n",
31+
" # Relative path to the directory where the flight model is stored\n",
32+
" # Note - Aircraft directory needs to be writeable in order to modify the cg\n",
33+
" PATH_TO_JSBSIM_FILES=\"../..\"\n",
34+
" print(f'Current working directory: {os.getcwd()}')\n",
2835
"except ImportError:\n",
2936
" import sys\n",
3037
" if 'google.colab' in sys.modules:\n",
3138
" print('Installing JSBSim...')\n",
32-
" !git clone https://github.com/JSBSim-Team/jsbsim.git\n",
3339
" !pip install jsbsim\n",
34-
" %cd jsbsim/examples/python\n",
35-
"print('Current working directory:')\n",
36-
"!pwd"
40+
" # Use the standard aircraft supplied by the JSBSim Python package\n",
41+
" PATH_TO_JSBSIM_FILES=None"
3742
]
3843
},
3944
{
@@ -1499,9 +1504,6 @@
14991504
"# The aircraft name\n",
15001505
"# Note - It should match the exact spelling of the model file\n",
15011506
"AIRCRAFT_NAME=\"737\"\n",
1502-
"# Path to JSBSim files, location of the folders \"aircraft\", \"engines\" and \"systems\"\n",
1503-
"PATH_TO_JSBSIM_FILES=\"../..\"\n",
1504-
"\n",
15051507
"\n",
15061508
"# --- JSBSim Initialization ---\n",
15071509
"# These lines initialize the flight dynamics model.\n",
@@ -1561,12 +1563,12 @@
15611563
"fdm['ic/beta-deg'] = 0 #sideslip angle (deg)\n",
15621564
"\n",
15631565
"# Initialize the aircraft with initial conditions\n",
1564-
"fdm.run_ic() \n",
1566+
"fdm.run_ic()\n",
15651567
"\n",
15661568
"# Attempt to trim the aircraft.\n",
15671569
"try:\n",
15681570
" # 1 means straight flight by using all changeable control variables.\n",
1569-
" fdm['simulation/do_simple_trim'] = 1 \n",
1571+
" fdm['simulation/do_simple_trim'] = 1\n",
15701572
"\n",
15711573
"except jsbsim.TrimFailureError:\n",
15721574
" print(\"Trim failed, continuing rudder kick in an untrimmed state.\")\n",

examples/python/Thrust Vectoring Analysis.ipynb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@
2424
"source": [
2525
"# Confirm that JSBSim is installed. If not and running on Google Colab\n",
2626
"# then install JSBSim into the Google Colab instance.\n",
27+
"\n",
28+
"import os\n",
29+
"\n",
2730
"try:\n",
2831
" import jsbsim\n",
2932
" print('JSBSim is installed')\n",
33+
" # Relative path to the directory where the flight model is stored\n",
34+
" # Note - Aircraft directory needs to be writeable in order to modify the cg\n",
35+
" PATH_TO_JSBSIM_FILES=\"../..\"\n",
36+
" print(f'Current working directory: {os.getcwd()}')\n",
3037
"except ImportError:\n",
3138
" import sys\n",
3239
" if 'google.colab' in sys.modules:\n",
3340
" print('Installing JSBSim...')\n",
34-
" !git clone https://github.com/JSBSim-Team/jsbsim.git\n",
3541
" !pip install jsbsim\n",
36-
" %cd jsbsim/examples/python\n",
37-
"print('Current working directory:')\n",
38-
"!pwd"
42+
" # Use the standard aircraft supplied by the JSBSim Python package\n",
43+
" PATH_TO_JSBSIM_FILES=None"
3944
]
4045
},
4146
{
@@ -3516,9 +3521,6 @@
35163521
"# The aircraft name\n",
35173522
"# Note - It should match the exact spelling of the model file\n",
35183523
"AIRCRAFT_NAME=\"737\"\n",
3519-
"# Path to JSBSim files, location of the folders \"aircraft\", \"engines\" and \"systems\"\n",
3520-
"PATH_TO_JSBSIM_FILES=\"../..\"\n",
3521-
"\n",
35223524
"\n",
35233525
"# --- JSBSim Initialization ---\n",
35243526
"# These lines initialize the flight dynamics model.\n",
@@ -3562,16 +3564,16 @@
35623564
" # This line initializes the flight dynamics model.\n",
35633565
"\n",
35643566
" # Initial conditions\n",
3565-
" fdm['ic/h-sl-ft'] = altitude # altitude above sea level (ft) \n",
3567+
" fdm['ic/h-sl-ft'] = altitude # altitude above sea level (ft)\n",
35663568
" # Check the speed and set the value according to if the speed is mach or kts\n",
35673569
" if speed < 1.0:\n",
35683570
" fdm['ic/mach'] = speed # mach number of speed\n",
35693571
" else:\n",
35703572
" fdm['ic/vc-kts'] = speed # calibrated airspeed (kts)\n",
35713573
" fdm['ic/gamma-deg'] = flight_path_angle # flight path angle (deg)\n",
3572-
" \n",
3574+
"\n",
35733575
" # Initialize the aircraft with initial conditions\n",
3574-
" fdm.run_ic() \n",
3576+
" fdm.run_ic()\n",
35753577
"\n",
35763578
"\n",
35773579
" # --- Simulation running ---\n",

examples/python/Trim Envelope.ipynb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@
2121
"source": [
2222
"# Confirm that JSBSim is installed. If not and running on Google Colab\n",
2323
"# then install JSBSim into the Google Colab instance.\n",
24+
"\n",
25+
"import os\n",
26+
"\n",
2427
"try:\n",
2528
" import jsbsim\n",
2629
" print('JSBSim is installed')\n",
30+
" # Relative path to the directory where the flight model is stored\n",
31+
" # Note - Aircraft directory needs to be writeable in order to modify the cg\n",
32+
" PATH_TO_JSBSIM_FILES=\"../..\"\n",
33+
" print(f'Current working directory: {os.getcwd()}')\n",
2734
"except ImportError:\n",
2835
" import sys\n",
2936
" if 'google.colab' in sys.modules:\n",
3037
" print('Installing JSBSim...')\n",
31-
" !git clone https://github.com/JSBSim-Team/jsbsim.git\n",
3238
" !pip install jsbsim\n",
33-
" %cd jsbsim/examples/python\n",
34-
"print('Current working directory:')\n",
35-
"!pwd"
39+
" # Use the standard aircraft supplied by the JSBSim Python package\n",
40+
" PATH_TO_JSBSIM_FILES=None"
3641
]
3742
},
3843
{
@@ -64,9 +69,6 @@
6469
"# The aircraft name\n",
6570
"# Note - It should match the exact spelling of the model file\n",
6671
"AIRCRAFT_NAME=\"737\"\n",
67-
"# Path to JSBSim files, location of the folders \"aircraft\", \"engines\" and \"systems\"\n",
68-
"PATH_TO_JSBSIM_FILES=\"../..\"\n",
69-
"\n",
7072
"\n",
7173
"# --- JSBSim Initialization ---\n",
7274
"# These lines initialize the flight dynamics model.\n",
@@ -146,7 +148,7 @@
146148
"for title, ax, data in graph_data:\n",
147149
" # Scatter plot with airspeed on x-axis, gamma on y-axis and either thrust setting or\n",
148150
" # AoA indicated via color map\n",
149-
" scatter = ax.scatter(speed, gamma, c=data, cmap='viridis') \n",
151+
" scatter = ax.scatter(speed, gamma, c=data, cmap='viridis')\n",
150152
" cb = fig.colorbar(scatter, ax=ax) # Add a colorbar to the plot.\n",
151153
" cb.set_label(title)\n",
152154
"\n",

0 commit comments

Comments
 (0)