Skip to content

Commit be10b32

Browse files
authored
Merge pull request #6 from wfrierson/add_2025_coefficients
Add 2025 coefficients
2 parents 8813008 + 59e1d6f commit be10b32

19 files changed

+4939
-1082
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ rsconnect/
3333
packrat/lib*/
3434
.Rproj.user
3535
inst/docs
36+
37+
inst/extdata/coefficients

‎DESCRIPTION‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
Package: wmm
22
Type: Package
33
Title: World Magnetic Model
4-
Version: 1.1.2
4+
Version: 1.1.3
55
Authors@R: person("Will", "Frierson", email = "[email protected]",
66
role = c("aut", "cre"))
77
Maintainer: Will Frierson <[email protected]>
88
Description: Calculate magnetic field at a given location and time according to
99
the World Magnetic Model (WMM). Both the main field and secular variation
1010
components are returned. This functionality is useful for physicists and
1111
geophysicists who need orthogonal components from WMM. Currently, this package
12-
supports annualized time inputs between 2000 and 2025. If desired, users can
12+
supports annualized time inputs between 2000-01-01 to 2029-12-31. If desired, users can
1313
specify which WMM version to use, e.g., the original WMM2015 release or the
1414
recent out-of-cycle WMM2015 release. Methods used to implement WMM, including
1515
the Gauss coefficients for each release, are described in the following
16-
publications: Chulliat et al (2020) <doi:10.25923/ytk1-yx35>,
16+
publications: NOAA NCEI Geomagnetic Modeling Team and British Geological Survey (2024) <doi:10.25921/aqfd-sd83>,
17+
Chulliat et al (2020) <doi:10.25923/ytk1-yx35>,
1718
Chulliat et al (2019) <doi:10.25921/xhr3-0t19>,
1819
Chulliat et al (2015) <doi:10.7289/V5TB14V7>,
1920
Maus et al (2010) <https://www.ngdc.noaa.gov/geomag/WMM/data/WMMReports/WMM2010_Report.pdf>,
@@ -22,14 +23,15 @@ Description: Calculate magnetic field at a given location and time according to
2223
License: MIT + file LICENSE
2324
Encoding: UTF-8
2425
Depends:
25-
R (>= 2.10)
26-
RoxygenNote: 7.2.3
26+
R (>= 4.3)
27+
RoxygenNote: 7.3.2
2728
Suggests:
28-
testthat (>= 2.0.1),
29-
data.table (>= 1.12.2),
30-
knitr (>= 1.33),
31-
rmarkdown (>= 2.14),
32-
covr (>= 3.3.1)
29+
testthat (>= 3.2.3),
30+
data.table (>= 1.17.4),
31+
knitr (>= 1.50),
32+
rmarkdown (>= 2.29),
33+
covr (>= 3.6.4),
34+
devtools (>= 2.4.5)
3335
URL: https://github.com/wfrierson/wmm
3436
BugReports: https://github.com/wfrierson/wmm/issues
3537
Language: en-US

‎NEWS.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# wmm 1.1.3
2+
1. Added `inst/extdata/coefficients/` to store legacy coefficient files, though these are included in `.gitignore`.
3+
2. Added WMM2025 coefficient path to `data-raw/creatingSysData.R`.
4+
3. Added WMM2025 test values to `inst/extdata/WMMTestValues.csv`.
5+
4. Recalculated `R/sysdata.rda` to incorporate WMM2025 coefficients.
6+
5. Removed legacy roxygen syntax in `R/wmm.R`.
7+
6. In `R/functions_wmm.R`, updated roxygen labels and `wmmVersion` @param descriptions to include 'WMM2025', where appropriate.
8+
7. In `R/functions_wmm.R`, included 'WMM2000' in `wmmVersion` @param description of `.CalculateMagneticField`.
9+
8. In `R/functions_wmm.R`, updated @examples for `GetMagneticFieldWMM` to use an example from the official WMM2025 test values.
10+
9. In `R/functions_misc.R`, added date ranges for WMM2025 and WMM2000 coefficients in `.DeriveVersionInfo`.
11+
10. In `R/functions_misc.R`, included 'WMM2025' in `wmmVersion` @param description of `.CheckVersionWMM`.
12+
11. In `R/functions_misc.R`, updated URL for 'Performance Specifications WMM' in `.CheckBlackoutZone`.
13+
12. In `R/functions_coefficients.R`, included 'WMM2025' in `wmmVersion` @param description of `.CalculateGaussCoef`.
14+
13. Updated documentation in manual.
15+
14. Updated `tests/testthat.R` to work in vscode.
16+
15. Updated `vignettes/` to reference WMM2025, where appropriate.
17+
16. In `DESCRIPTION`:
18+
i. updated supported date ranges
19+
ii. included WMM2025 citation
20+
iii. updated versions within `Depends` and `Suggests`
21+
17. In `README.md`:
22+
i. updated supported date ranges
23+
ii. included WMM2025 citation
24+
18. Updated `renv.lock` to use latest package versions and R 4.3.3.
25+
126
# wmm 1.1.2
227
1. Added HTML vignette.
328
2. Added @noRd flag for internal functions.

‎R/functions_coefficients.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#'
77
#' @param t Annualized date time. E.g., 2015-02-01 = (2015 + 32/365) = 2015.088
88
#' @param t0 Annualized reference time associated with \code{t}
9-
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
9+
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020', 'WMM2025'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
1010
#'
1111
#' @return vector of Gauss coefficients, \eqn{g_{n,m}(t)} and \eqn{h_{n,m}(t)}
1212
.CalculateGaussCoef <- function(t, t0, wmmVersion = 'derived') {

‎R/functions_misc.R‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
#'
77
#' @return List of reference year and compatible WMM versions inferred from \code{time}.
88
.DeriveVersionInfo <- function(t) {
9-
output <- if(t >= 2025) {
9+
output <- if(t >= 2030) {
1010
stop('Time value not supported in current version of wmm package.')
11-
} else if(t >= 2020 & t < 2025) {
11+
} else if(t >= 2024 + 351 / 366 & t < 2030) {
12+
list(
13+
'year' = 2025,
14+
'version' = 'WMM2025'
15+
)
16+
} else if(t >= 2020 & t < 2024 + 351 / 366) {
1217
list(
1318
'year' = 2020,
1419
'version' = 'WMM2020'
@@ -23,11 +28,16 @@
2328
'year' = 2010,
2429
'version' = 'WMM2010'
2530
)
26-
} else if(t >= 2005){
31+
} else if(t >= 2005) {
2732
list(
2833
'year' = 2005,
2934
'version' = 'WMM2005'
3035
)
36+
} else if(t >= 2000) {
37+
list(
38+
'year' = 2000,
39+
'version' = 'WMM2000'
40+
)
3141
} else {
3242
stop('Time value not supported in current version of wmm package.')
3343
}
@@ -40,7 +50,7 @@
4050
#' @noRd
4151
#'
4252
#' @param t Annualized date time. E.g., 2015-02-01 = (2015 + 32/365) = 2015.088
43-
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2'.
53+
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020', 'WMM2025'.
4454
.CheckVersionWMM <- function(t, wmmVersion) {
4555
# Get what WMM versions are compatible with the input time
4656
derivedVersionInfo <- .DeriveVersionInfo(t)
@@ -75,11 +85,11 @@
7585
.CheckBlackoutZone <- function(h) {
7686
if (h < 2000) {
7787
warning(
78-
'Location is in the blackout zone around the magnetic pole as defined by the WMM military specification (https://www.ngdc.noaa.gov/geomag/WMM/data/MIL-PRF89500B.pdf). Compass accuracy is highly degraded in this region.'
88+
'Location is in the blackout zone around the magnetic pole as defined by the WMM military specification (https://www.ngdc.noaa.gov/geomag/WMM/data/MIL-PRF-89500B.pdf). Compass accuracy is highly degraded in this region.'
7989
)
8090
} else if (h < 6000) {
8191
warning(
82-
'Location is approaching the blackout zone around the magnetic pole as defined by the WMM military specification (https://www.ngdc.noaa.gov/geomag/WMM/data/MIL-PRF89500B.pdf). Compass accuracy may be degraded in this region.'
92+
'Location is approaching the blackout zone around the magnetic pole as defined by the WMM military specification (https://www.ngdc.noaa.gov/geomag/WMM/data/MIL-PRF-89500B.pdf). Compass accuracy may be degraded in this region.'
8393
)
8494
}
8595
}

‎R/functions_wmm.R‎

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#' Calculate Expected Magnetic Elements from WMM2020
1+
#' Calculate Expected Magnetic Elements from WMM2025
22
#'
33
#' Calculate the magnetic elements (i.e., horizontal intensity, total intensity, inclination, declination, and their secular variation) for given magnetic orthogonal components
44
#'
55
#' @noRd
66
#'
77
#' @param orthComps named \code{list} containing magnetic orthogonal components
88
#'
9-
#' @return Expected magnetic components from WMM2020. \code{list}
9+
#' @return Expected magnetic components from WMM2025. \code{list}
1010
#'
1111
.CalculateMagneticElements <- function(
1212
orthComps
@@ -51,9 +51,9 @@
5151
return(output)
5252
}
5353

54-
#' Calculate Expected Magnetic Field from WMM2020
54+
#' Calculate Expected Magnetic Field from WMM2025
5555
#'
56-
#' Calculate the magnetic field for a given location and time using the fitted spherical harmonic model from the 2020 World Magnetic Model.
56+
#' Calculate the magnetic field for a given location and time using the fitted spherical harmonic model from the 2025 World Magnetic Model.
5757
#'
5858
#' @noRd
5959
#'
@@ -62,9 +62,9 @@
6262
#' @param latGC GPS latitude, geocentric
6363
#' @param radius Radius of curvature of prime vertical at given geodetic latitude
6464
#' @param time Annualized date time. E.g., 2015-02-01 = (2015 + 32/365) = 2015.088
65-
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
65+
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020', 'WMM2025'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
6666
#'
67-
#' @return Expected magnetic field from WMM2020, \eqn{m_{\lambda_t,\varphi_t,h_t,t}^{WMM}}{m_wmm(lambda_t, phi_t, h_t, t)}. \code{list}
67+
#' @return Expected magnetic field from WMM2025, \eqn{m_{\lambda_t,\varphi_t,h_t,t}^{WMM}}{m_wmm(lambda_t, phi_t, h_t, t)}. \code{list}
6868
.CalculateMagneticField <- function(
6969
lon,
7070
latGD,
@@ -148,7 +148,7 @@
148148
#' @param lat GPS latitude, geodetic
149149
#' @param height GPS height in meters above ellipsoid
150150
#' @param time Annualized date time. E.g., 2015-02-01 = (2015 + 32/365) = 2015.088; optionally an object (length 1) of class 'POSIXt' or 'Date'
151-
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
151+
#' @param wmmVersion String representing WMM version to use. Must be consistent with \code{time} and one of the following: 'derived', 'WMM2000', 'WMM2005', 'WMM2010', 'WMM2015', 'WMM2015v2', 'WMM2020', 'WMM2025'. Default 'derived' value will infer the latest WMM version consistent with \code{time}.
152152
#'
153153
#' @return \code{list} of calculated main field and secular variation vector components in nT and nT/yr, resp. The magnetic element intensities (i.e., horizontal and total intensities, h & f) are in nT and the magnetic element angles (i.e., inclination and declination, i & d) are in degrees, with their secular variation in nT/yr and deg/yr, resp.: \code{x}, \code{y}, \code{z}, \code{xDot}, \code{yDot}, \code{zDot}, \code{h}, \code{f}, \code{i}, \code{d}, \code{hDot}, \code{fDot}, \code{iDot}, \code{dDot}
154154
#' @export
@@ -157,69 +157,69 @@
157157
#' GetMagneticFieldWMM(
158158
#' lon = 240,
159159
#' lat = -80,
160-
#' height = 1e5,
161-
#' time = 2022.5,
162-
#' wmmVersion = 'WMM2020'
160+
#' height = 0,
161+
#' time = 2025,
162+
#' wmmVersion = 'WMM2025'
163163
#' )
164164
#'
165165
#' ## Expected output
166-
#' # x = 5814.9658886215 nT
167-
#' # y = 14802.9663839328 nT
168-
#' # z = -49755.3119939183 nT
169-
#' # xDot = 28.0381961827 nT/yr
170-
#' # yDot = 1.3970624624 nT/yr
171-
#' # zDot = 85.6309533031 nT/yr
172-
#' # h = 15904.1391483373 nT
173-
#' # f = 52235.3588449608 nT
174-
#' # i = -72.27367 deg
175-
#' # d = 68.55389 deg
176-
#' # hDot = 11.5518244235 nT/yr
177-
#' # fDot = -78.0481471753 nT/yr
178-
#' # iDot = 0.04066726 deg/yr
179-
#' # dDot = -0.09217566 deg/yr
166+
#' # x = 6117.5 nT
167+
#' # y = 15751.9 nT
168+
#' # z = -52022.5 nT
169+
#' # xDot = 33.3 nT/yr
170+
#' # yDot = -8.6 nT/yr
171+
#' # zDot = 95.5 nT/yr
172+
#' # h = 16898.1 nT
173+
#' # f = 54698.2 nT
174+
#' # i = -72 deg
175+
#' # d = 68.78 deg
176+
#' # hDot = 4.0 nT/yr
177+
#' # fDot = -89.6 nT/yr
178+
#' # iDot = 0.03 deg/yr
179+
#' # dDot = -0.12 deg/yr
180180
#'
181181
#' ## Calculated output
182182
#' #$x
183-
#' #[1] 5814.966
183+
#' #[1] 6117.548
184184
#'
185185
#' #$y
186-
#' #[1] 14802.97
186+
#' #[1] 15751.91
187187
#'
188188
#' #$z
189-
#' #[1] -49755.31
189+
#' #[1] -52022.52
190190
#'
191191
#' #$xDot
192-
#' #[1] 28.0382
192+
#' #[1] 33.27253
193193
#'
194194
#' #$yDot
195-
#' #[1] 1.397062
195+
#' #[1] -8.646338
196196
#'
197197
#' #$zDot
198-
#' #[1] 85.63095
198+
#' #[1] 95.54722
199199
#'
200200
#' #$h
201-
#' #[1] 15904.14
201+
#' #[1] 16898.13
202202
#'
203203
#' #$f
204-
#' #[1] 52235.36
204+
#' #[1] 54698.17
205205
#'
206206
#' #$i
207-
#' #[1] -72.27367
207+
#' #[1] -72.00499
208208
#'
209209
#' #$d
210-
#' #[1] 68.55389
210+
#' #[1] 68.77539
211211
#'
212212
#' #$hDot
213-
#' #[1] 11.55182
213+
#' #[1] 3.985647
214214
#'
215215
#' #$fDot
216-
#' #[1] -78.04815
216+
#' #[1] -89.64208
217217
#'
218218
#' #$iDot
219-
#' #[1] 0.04066726
219+
#' #[1] 0.03489031
220220
#'
221221
#' #$dDot
222-
#' #[1] -0.09217566
222+
#' #[1] -0.1157767
223223
#'
224224
GetMagneticFieldWMM <- function(
225225
lon,

‎R/sysdata.rda‎

511 Bytes
Binary file not shown.

‎R/wmm.R‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#'
2424
#' @noRd
2525
#'
26-
#' @docType package
2726
#' @name wmm
2827

2928
NULL

‎README.md‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# wmm
1212
The [World Magnetic Model](https://www.ncei.noaa.gov/products/world-magnetic-model) (WMM)
1313

14-
The purpose of this package is to make accessible the magnetic field vector components from WMM. The supported date ranges for `wmm` run from 2000-01-01 to 2024-12-31. The magnetic field calculations across this time range agree with the official WMM test values to the precision provided by the authors (see the unit tests of this package for details). I will update this package for each new WMM version. For those that prefer a non-R solution, the authors of WMM provide free software to calculate magnetic field on the official website.
14+
The purpose of this package is to make accessible the magnetic field vector components from WMM. The supported date ranges for `wmm` run from 2000-01-01 to 2029-12-31. The magnetic field calculations across this time range agree with the official WMM test values to the precision provided by the authors (see the unit tests of this package for details). I will update this package for each new WMM version. For those that prefer a non-R solution, the authors of WMM provide free software to calculate magnetic field on the official website.
1515

1616
# Installation
1717

@@ -30,7 +30,7 @@ devtools::install_github('wfrierson/wmm')
3030

3131
# Usage
3232

33-
In v1.1.2, the only exported function is `GetMagneticFieldWMM`, which returns the orthogonal vector components of the main magnetic field (in nT) and secular variation field (in nT/yr) as predicted by WMM. The magnetic field elements, _h_, _f_, _i_, and _d_ (as well as their secular variation) are returned as well.
33+
In v1.1.3, the only exported function is `GetMagneticFieldWMM`, which returns the orthogonal vector components of the main magnetic field (in nT) and secular variation field (in nT/yr) as predicted by WMM. The magnetic field elements, _h_, _f_, _i_, and _d_ (as well as their secular variation) are returned as well.
3434

3535
Example usage:
3636

@@ -141,30 +141,34 @@ wmm::GetMagneticFieldWMM(
141141

142142
# Citations
143143

144-
1. Chulliat, A., W. Brown, P. Alken, C. Beggan, M. Nair, G. Cox, A. Woods,
144+
1. NOAA NCEI Geomagnetic Modeling Team, British Geological Survey,
145+
World Magnetic Model 2025, NOAA National Centers for Environmental Information,
146+
doi: 10.25921/aqfd-sd83, 2024.
147+
148+
2. Chulliat, A., W. Brown, P. Alken, C. Beggan, M. Nair, G. Cox, A. Woods,
145149
S. Macmillan, B. Meyer and M. Paniccia, The US/UK World Magnetic Model for
146150
2020-2025: Technical Report, National Centers for Environmental Information,
147151
NOAA, doi: 10.25923/ytk1-yx35, 2020.
148152

149-
2. Chulliat, A., W. Brown, P. Alken, S. Macmillan, M. Nair, C. Beggan, A. Woods,
153+
3. Chulliat, A., W. Brown, P. Alken, S. Macmillan, M. Nair, C. Beggan, A. Woods,
150154
B. Hamilton, B. Meyer and R. Redmon, 2019, Out-of-Cycle Update of the
151155
US/UK World Magnetic Model for 2015-2020: Technical Note, National
152156
Centers for Environmental Information, NOAA. doi: 10.25921/xhr3-0t19
153157

154-
3. Chulliat, A., S. Macmillan, P. Alken, C. Beggan, M. Nair, B. Hamilton, A.
158+
4. Chulliat, A., S. Macmillan, P. Alken, C. Beggan, M. Nair, B. Hamilton, A.
155159
Woods, V. Ridley, S. Maus and A. Thomson, 2015, The US/UK World
156160
Magnetic Model for 2015-2020: Technical Report, National Geophysical
157161
Data Center, NOAA. doi: 10.7289/V5TB14V7
158162

159-
4. Maus, S., S. Macmillan, S. McLean, B. Hamilton, A. Thomson,
163+
5. Maus, S., S. Macmillan, S. McLean, B. Hamilton, A. Thomson,
160164
M. Nair, and C. Rollins, 2010, The US/UK World Magnetic Model
161165
for 2010-2015, NOAA Technical Report NESDIS/NGDC.
162166

163-
5. McLean, S., S. Macmillan, S. Maus, V. Lesur, A.
167+
6. McLean, S., S. Macmillan, S. Maus, V. Lesur, A.
164168
Thomson, and D. Dater, December 2004, The
165169
US/UK World Magnetic Model for 2005-2010,
166170
NOAA Technical Report NESDIS/NGDC-1.
167171

168-
6. Macmillian, S. and J. M. Quinn, 2000.
172+
7. Macmillian, S. and J. M. Quinn, 2000.
169173
“The Derivation of the World Magnetic Model 2000,”
170174
British Geological Survey Technical Report WM/00/17R.

0 commit comments

Comments
 (0)