5050vector components with respect to the inertial frame.
5151
5252As this :ref:`MagneticFieldWMM` model is specific to Earth, there are
53- no parameters to set of tune. Rather, the ``WMM .COF`` WMM coefficient
53+ no parameters to set of tune. Rather, the ``WMM2025 .COF`` WMM coefficient
5454file is set via the ``configureWMMFile()`` method and loaded on reset.
5555
5656The default planet's position vector is assumed to be the inertial
127127
128128import matplotlib .pyplot as plt
129129import numpy as np
130+
130131# The path to the location of Basilisk
131132# Used to get the location of supporting data.
132133from Basilisk import __path__
138139# import simulation related support
139140from Basilisk .simulation import spacecraft
140141from Basilisk .simulation import magneticFieldWMM
142+
141143# general support file with common unit test functions
142144# import general simulation support files
143- from Basilisk .utilities import (SimulationBaseClass , macros , orbitalMotion ,
144- simIncludeGravBody , unitTestSupport )
145+ from Basilisk .utilities import (
146+ SimulationBaseClass ,
147+ macros ,
148+ orbitalMotion ,
149+ simIncludeGravBody ,
150+ unitTestSupport ,
151+ )
145152from Basilisk .utilities .supportDataTools .dataFetcher import get_path , DataFile
146153
147- #attempt to import vizard
154+ # attempt to import vizard
148155from Basilisk .utilities import vizSupport
149156
150157
@@ -158,7 +165,6 @@ def run(show_plots, orbitCase):
158165
159166 """
160167
161-
162168 # Create simulation variable names
163169 simTaskName = "simTask"
164170 simProcessName = "simProcess"
@@ -172,7 +178,7 @@ def run(show_plots, orbitCase):
172178 dynProcess = scSim .CreateNewProcess (simProcessName )
173179
174180 # create the dynamics task and specify the integration update time
175- simulationTimeStep = macros .sec2nano (60. )
181+ simulationTimeStep = macros .sec2nano (60.0 )
176182 dynProcess .addTask (scSim .CreateNewTask (simTaskName , simulationTimeStep ))
177183
178184 #
@@ -189,7 +195,7 @@ def run(show_plots, orbitCase):
189195 # setup Gravity Body
190196 gravFactory = simIncludeGravBody .gravBodyFactory ()
191197 planet = gravFactory .createEarth ()
192- planet .isCentralBody = True # ensure this is the central gravitational body
198+ planet .isCentralBody = True # ensure this is the central gravitational body
193199 mu = planet .mu
194200 req = planet .radEquator
195201
@@ -203,15 +209,19 @@ def run(show_plots, orbitCase):
203209 magModule .ModelTag = "WMM"
204210
205211 # set the minReach and maxReach values if on an elliptic orbit
206- if orbitCase == ' elliptical' :
207- magModule .envMinReach = 10000 * 1000.
208- magModule .envMaxReach = 20000 * 1000.
212+ if orbitCase == " elliptical" :
213+ magModule .envMinReach = 10000 * 1000.0
214+ magModule .envMaxReach = 20000 * 1000.0
209215
210216 # set epoch date/time message
211- epochMsg = unitTestSupport .timeStringToGregorianUTCMsg ('2019 June 27, 10:23:0.0 (UTC)' )
217+ epochMsg = unitTestSupport .timeStringToGregorianUTCMsg (
218+ "2019 June 27, 10:23:0.0 (UTC)"
219+ )
212220
213221 # add spacecraft to the magnetic field module so it can read the sc position messages
214- magModule .addSpacecraftToModel (scObject .scStateOutMsg ) # this command can be repeated if multiple
222+ magModule .addSpacecraftToModel (
223+ scObject .scStateOutMsg
224+ ) # this command can be repeated if multiple
215225
216226 # add the magnetic field module to the simulation task stack
217227 scSim .AddModelToTask (simTaskName , magModule )
@@ -221,12 +231,12 @@ def run(show_plots, orbitCase):
221231 #
222232 # setup the orbit using classical orbit elements
223233 oe = orbitalMotion .ClassicElements ()
224- rPeriapses = req * 1.1 # meters
225- if orbitCase == ' circular' :
234+ rPeriapses = req * 1.1 # meters
235+ if orbitCase == " circular" :
226236 oe .a = rPeriapses
227237 oe .e = 0.0000
228- elif orbitCase == ' elliptical' :
229- rApoapses = req * 3.5
238+ elif orbitCase == " elliptical" :
239+ rApoapses = req * 3.5
230240 oe .a = (rPeriapses + rApoapses ) / 2.0
231241 oe .e = 1.0 - rPeriapses / oe .a
232242 else :
@@ -249,8 +259,8 @@ def run(show_plots, orbitCase):
249259
250260 # set the simulation time
251261 n = np .sqrt (mu / oe .a / oe .a / oe .a )
252- P = 2. * np .pi / n
253- simulationTime = macros .sec2nano (1. * P )
262+ P = 2.0 * np .pi / n
263+ simulationTime = macros .sec2nano (1.0 * P )
254264
255265 # connect messages
256266 magModule .epochInMsg .subscribeTo (epochMsg )
@@ -259,17 +269,22 @@ def run(show_plots, orbitCase):
259269 # Setup data logging before the simulation is initialized
260270 #
261271 numDataPoints = 100
262- samplingTime = unitTestSupport .samplingTime (simulationTime , simulationTimeStep , numDataPoints )
272+ samplingTime = unitTestSupport .samplingTime (
273+ simulationTime , simulationTimeStep , numDataPoints
274+ )
263275 dataLog = scObject .scStateOutMsg .recorder (samplingTime )
264276 magLog = magModule .envOutMsgs [0 ].recorder (samplingTime )
265277 scSim .AddModelToTask (simTaskName , dataLog )
266278 scSim .AddModelToTask (simTaskName , magLog )
267279
268280 # if this scenario is to interface with the BSK Viz, uncomment the following line
269281 if vizSupport .vizFound :
270- viz = vizSupport .enableUnityVisualization (scSim , simTaskName , scObject ,
271- # saveFile=fileName,
272- )
282+ viz = vizSupport .enableUnityVisualization (
283+ scSim ,
284+ simTaskName ,
285+ scObject ,
286+ # saveFile=fileName,
287+ )
273288 viz .epochInMsg .subscribeTo (epochMsg )
274289
275290 viz .settings .show24hrClock = 1
@@ -301,41 +316,56 @@ def run(show_plots, orbitCase):
301316 plt .figure (1 )
302317 fig = plt .gcf ()
303318 ax = fig .gca ()
304- ax .ticklabel_format (useOffset = False , style = 'sci' )
305- ax .get_yaxis ().set_major_formatter (plt .FuncFormatter (lambda x , loc : "{:,}" .format (int (x ))))
319+ ax .ticklabel_format (useOffset = False , style = "sci" )
320+ ax .get_yaxis ().set_major_formatter (
321+ plt .FuncFormatter (lambda x , loc : "{:,}" .format (int (x )))
322+ )
306323 rData = []
307324 for idx in range (0 , len (posData )):
308325 rMag = np .linalg .norm (posData [idx ])
309- rData .append (rMag / 1000. )
310- plt .plot (timeAxis / P , rData , color = '#aa0000' )
311- if orbitCase == 'elliptical' :
312- plt .plot (timeAxis / P , [magModule .envMinReach / 1000. ]* len (rData ), color = '#007700' , dashes = [5 , 5 , 5 , 5 ])
313- plt .plot (timeAxis / P , [magModule .envMaxReach / 1000. ] * len (rData ),
314- color = '#007700' , dashes = [5 , 5 , 5 , 5 ])
315-
316- plt .xlabel ('Time [orbits]' )
317- plt .ylabel ('Radius [km]' )
318- plt .ylim (min (rData )* 0.9 , max (rData )* 1.1 )
326+ rData .append (rMag / 1000.0 )
327+ plt .plot (timeAxis / P , rData , color = "#aa0000" )
328+ if orbitCase == "elliptical" :
329+ plt .plot (
330+ timeAxis / P ,
331+ [magModule .envMinReach / 1000.0 ] * len (rData ),
332+ color = "#007700" ,
333+ dashes = [5 , 5 , 5 , 5 ],
334+ )
335+ plt .plot (
336+ timeAxis / P ,
337+ [magModule .envMaxReach / 1000.0 ] * len (rData ),
338+ color = "#007700" ,
339+ dashes = [5 , 5 , 5 , 5 ],
340+ )
341+
342+ plt .xlabel ("Time [orbits]" )
343+ plt .ylabel ("Radius [km]" )
344+ plt .ylim (min (rData ) * 0.9 , max (rData ) * 1.1 )
319345 figureList = {}
320346 pltName = fileName + "1" + orbitCase
321347 figureList [pltName ] = plt .figure (1 )
322348
323349 plt .figure (2 )
324350 fig = plt .gcf ()
325351 ax = fig .gca ()
326- ax .ticklabel_format (useOffset = False , style = 'sci' )
327- ax .get_yaxis ().set_major_formatter (plt .FuncFormatter (lambda x , loc : "{:,}" .format (int (x ))))
352+ ax .ticklabel_format (useOffset = False , style = "sci" )
353+ ax .get_yaxis ().set_major_formatter (
354+ plt .FuncFormatter (lambda x , loc : "{:,}" .format (int (x )))
355+ )
328356 for idx in range (3 ):
329- plt .plot (timeAxis / P , magData [:, idx ] * 1e9 ,
330- color = unitTestSupport .getLineColor (idx , 3 ),
331- label = r'$B\_N_{' + str (idx ) + '}$' )
332- plt .legend (loc = 'lower right' )
333- plt .xlabel ('Time [orbits]' )
334- plt .ylabel ('Magnetic Field [nT]' )
357+ plt .plot (
358+ timeAxis / P ,
359+ magData [:, idx ] * 1e9 ,
360+ color = unitTestSupport .getLineColor (idx , 3 ),
361+ label = r"$B\_N_{" + str (idx ) + "}$" ,
362+ )
363+ plt .legend (loc = "lower right" )
364+ plt .xlabel ("Time [orbits]" )
365+ plt .ylabel ("Magnetic Field [nT]" )
335366 pltName = fileName + "2" + orbitCase
336367 figureList [pltName ] = plt .figure (2 )
337368
338-
339369 if show_plots :
340370 plt .show ()
341371
@@ -345,13 +375,12 @@ def run(show_plots, orbitCase):
345375 return figureList
346376
347377
348-
349378#
350379# This statement below ensures that the unit test scrip can be run as a
351380# stand-along python script
352381#
353382if __name__ == "__main__" :
354383 run (
355- True , # show_plots
356- ' elliptical' , # orbit Case (circular, elliptical)
384+ True , # show_plots
385+ " elliptical" , # orbit Case (circular, elliptical)
357386 )
0 commit comments