Skip to content

Commit 7c7cd7b

Browse files
committed
Merge pull request #1264 from AVSLab/feature/new-wmm-coef
Update WMM coef. file to 2025 version
1 parent f2cfaaf commit 7c7cd7b

File tree

9 files changed

+266
-232
lines changed

9 files changed

+266
-232
lines changed

docs/source/Support/bskReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Version |release|
3636
- Fixed range of grammatical typos in the Basilisk documentation
3737
- Ensure the HTML documentation figures from the example scenario look more consistent
3838
- Avoid a memory leak when saving off figures in the CI Unit tests to build the online documentation
39+
- Updated the World Magnetic Model (WMM) Coefficients file to the 2025 version.
3940

4041

4142
Version 2.9.0 (Jan. 28 2026)

examples/scenarioMagneticFieldWMM.py

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
vector components with respect to the inertial frame.
5151
5252
As 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
5454
file is set via the ``configureWMMFile()`` method and loaded on reset.
5555
5656
The default planet's position vector is assumed to be the inertial
@@ -127,6 +127,7 @@
127127

128128
import matplotlib.pyplot as plt
129129
import numpy as np
130+
130131
# The path to the location of Basilisk
131132
# Used to get the location of supporting data.
132133
from Basilisk import __path__
@@ -138,13 +139,19 @@
138139
# import simulation related support
139140
from Basilisk.simulation import spacecraft
140141
from 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+
)
145152
from Basilisk.utilities.supportDataTools.dataFetcher import get_path, DataFile
146153

147-
#attempt to import vizard
154+
# attempt to import vizard
148155
from 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
#
353382
if __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

Comments
 (0)