{"id":21921713,"url":"https://github.com/westphae/geomag","last_synced_at":"2026-05-09T22:27:52.768Z","repository":{"id":144203760,"uuid":"183132090","full_name":"westphae/geomag","owner":"westphae","description":"Golang implementation of the NOAA World Magnetic Model","archived":false,"fork":false,"pushed_at":"2020-01-11T21:26:17.000Z","size":5242,"stargazers_count":20,"open_issues_count":5,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T08:24:19.947Z","etag":null,"topics":["egm","geomagnetic","geomagnetism","go","golang","golang-application","golang-library","golang-package","legendre-polynomials","legendre-series","magnetic-field","magnetic-fields","magnetic-north","noaa","stratux","world-magnetic-model"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/westphae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-24T02:31:16.000Z","updated_at":"2025-01-26T06:09:34.000Z","dependencies_parsed_at":"2023-06-19T06:05:41.435Z","dependency_job_id":null,"html_url":"https://github.com/westphae/geomag","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westphae%2Fgeomag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westphae%2Fgeomag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westphae%2Fgeomag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westphae%2Fgeomag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/westphae","download_url":"https://codeload.github.com/westphae/geomag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249708442,"owners_count":21313940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["egm","geomagnetic","geomagnetism","go","golang","golang-application","golang-library","golang-package","legendre-polynomials","legendre-series","magnetic-field","magnetic-fields","magnetic-north","noaa","stratux","world-magnetic-model"],"created_at":"2024-11-28T20:26:14.048Z","updated_at":"2026-05-09T22:27:52.759Z","avatar_url":"https://github.com/westphae.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# geomag\ngeomag is an implementation in Go of the NOAA World Magnetic Model.\n\nThe World Magnetic Model home is at https://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml.\n\nThe coefficients for 2025-2029 can be downloaded at https://www.ncei.noaa.gov/products/world-magnetic-model\n\n## Install\n\nRequires Go 1.22 or newer. The current WMM coefficients (WMM2025) are embedded\nin the package, so there is no separate data file to download.\n\nTo install the `wmm_point` command-line tool:\n\n```sh\ngo install github.com/westphae/geomag/cmd/wmm_point@latest\n```\n\nThe binary lands in `$(go env GOBIN)` (or `$(go env GOPATH)/bin` if `GOBIN` is\nunset) — make sure that directory is on your `PATH`. Pin to a specific release\nby replacing `@latest` with `@v1.2025.0`, etc.\n\nTo use the library in your own Go project:\n\n```sh\ngo get github.com/westphae/geomag@latest\n```\n\nthen `import \"github.com/westphae/geomag/pkg/wmm\"` and/or\n`\"github.com/westphae/geomag/pkg/egm96\"`. See the per-package examples\nbelow.\n\n## Commands\ngeomag provides three command line programs, modeled after the command line programs in the official NOAA software.\n\n`wmm_point` calculates magnetic field values for a single location and time:\n```\n\u003e wmm_point N30 W88.51 0.01 2019.5\n\nResults For\n\nLatitude:       30.00N\nLongitude:      88.51W\nAltitude:        0.010 kilometers above mean sea level\nDate:           2019.5\n\n       Main Field             Secular Change\n       F    =  46944.3 nT ± 152.0 nT  -118.8 nT/yr\n       H    =  24074.6 nT ± 133.0 nT    -6.8 nT/yr\n       X    =  24060.2 nT ± 138.0 nT    -8.0 nT/yr\n       Y    =   -831.0 nT ±  89.0 nT   -36.3 nT/yr\n       Z    =  40301.2 nT ± 165.0 nT  -134.3 nT/yr\n       Decl =     -1º 59' ± 19'         -5.2'/yr\n       Incl =     59º  9' ± 13'         -4.6'/yr\n\n       Grid Variation =  -1º 59'\n```\n\n`wmm_file` batch-processes a coordinate file (one record per line) into a\nmatching output file. Input format mirrors NOAA's `wmm_file` reference:\n\n```\n\u003e cat coords.txt\n2025.5 E K100  70.3 30.8\n2026.5 E M1042 70.3 30.8\n2027.5 E F30000 70.3 30.8\n\u003e wmm_file f coords.txt out.txt\n\u003e head -2 out.txt\nDate Coord-System Altitude Latitude Longitude D_deg D_min I_deg I_min H_nT X_nT Y_nT Z_nT F_nT dD_min dI_min dH_nT dX_nT dY_nT dZ_nT dF_nT\n2025.5 E K100 70.3 30.8    16d 48m    79d 13m    9827.3   9407.8   2840.6  51603.9  52531.3    15.0       1.4        -11.5    -23.4     37.7     51.1     48.1\n```\n\nEach input line is `\u003cdate\u003e \u003ccoord-system\u003e \u003caltitude\u003e \u003clat\u003e \u003clng\u003e` where\n`\u003ccoord-system\u003e` is `E` (height above WGS84 ellipsoid) or `M` (height\nabove mean sea level), and `\u003caltitude\u003e` is a single-character unit prefix\n(`K`=km, `M`=meters, `F`=feet) followed by a signed decimal magnitude.\nAdd `e` (or `--Errors`) between the `f` and the input filename to append\nseven uncertainty columns.\n\n`wmm_grid` generates a 4-D grid of magnetic field values over latitude,\nlongitude, altitude, and time, evaluating one chosen output element at\neach grid point:\n\n```\n\u003e wmm_grid --lat=-80,80,40 --lng=0,0,0 --alt=0,0,0 --date=2026,2026,0 --element=F --errors\n-80 0 0 2026 46061.398... 138\n-40 0 0 2026 23369.279... 138\n0 0 0 2026 31813.131... 138\n40 0 0 2026 45193.628... 138\n80 0 0 2026 55208.584... 138\n```\n\nEach axis flag takes a comma-separated `START,END,STEP` triple. Setting\nSTART=END collapses the axis (e.g. `--alt=0,0,0` for sea level only,\n`--date=2026,2026,0` for a single instant). `--element` accepts D, I, F,\nH, X, Y, Z, dD, dI, dF, dH, dX, dY, dZ. `--errors` adds an uncertainty\ncolumn (only for the static-field elements). Output goes to stdout\nunless you pass `--output=PATH`.\n\n## Packages\nTwo packages are provided by this library:\n\n### egm96\nPackage egm96 provides a representation of the 1996 Earth Gravitational Model (EGM96),\na geopotential model of the Earth.\n\nEGM96 is the geoid reference model component of the World Geodetic System (WGS84).\nIt consists of n=m=360 spherical harmonic coefficients as published by the\nNational Geospatial-Intelligence Agency (NGA).  The NGA also publishes a raster grid\nof the calculated heights which can be interpolated to approximate the geoid height\nat any location.\n\nIn effect, this model provides the height of sea level above the WGS84 reference ellipsoid.\nIt is used, for example, in GPS navigation to provide the height above sea level.\n\nThis package is based on the NGA-provided 15'x15' resolution grid encoding\nthe heights of the geopotential surface at each lat/long, and interpolates between grid\npoints using a bilinear interpolation.\n\nusage:\n```\nimport \"github.com/westphae/geomag/pkg/egm96\"\n\n// Calculate height above MSL for a point at a\n// latitude of 12.25 South, longitude of 82.75 East, and\n// altitude of 1000m above the WGS84 ellipsoid (i.e. GPS altitude)\nh, err := egm96.NewLocationGeodetic(-12.25, 82.75, 1000).HeightAboveMSL()\n```\n\n### wmm\nPackage wmm provides a representation of the 2025 World Magnetic Model (WMM),\na mathematical model of the magnetic field produced by the Earth's core and\nits variation over time.\n\nWMM is the magnetic model component of the World Geodetic System (WGS84).\nIt consists of n=m=12 spherical harmonic coefficients as published by the\nNational Geospatial-Intelligence Agency (NGA).\n\nThis model evaluates all magnetic field components and their rates of change\nfor any location on the Earth's surface.  These field components include the\nX, Y, and Z values and the declination D and inclination I.\nThe Declination is used, for example, in correcting a Magnetic Heading to a\nTrue Heading.\n\nusage:\n```\nimport \"github.com/westphae/geomag/pkg/egm96\"\nimport \"github.com/westphae/geomag/pkg/wmm\"\n\ntt := wmm.DecimalYear(2019.5)\nloc := egm96.NewLocationGeodetic(-12.25, 82.75, 1000)\n\nmag, _ := wmm.CalculateWMMMagneticField(loc, tt.ToTime())\nfmt.Printf(\"Declination at your location: %2.2f\\n\", mag.D())\n```\n\n## Validation\nThe library code is fully tested.\nIn particular, all test values provided with the official NOAA WMM are tested here,\nas well as the detailed example in the WMM technical paper.\nPlease submit an issue on github if you notice any other issues.\n\n## Updating Coefficients\nCoefficients are currently updated through the WMM2025 model. To bump to a\nnewer release, drop the new `WMM.COF` into `pkg/wmm/embedded/` (replacing the\nexisting one) and rebuild — the file is embedded at compile time via\n`//go:embed`. Add the historical version to `pkg/wmm/testdata/` if you want\nto keep its tests alongside the new ones.\n\n## License Info\nThis software is based on the NOAA World Magnetic Model.\nThe source code in this project is not based on the source code provided by NOAA, but on the\nequations provided in the World Magnetic Model reference paper.\n\nThe WMM source code is not subject to copyright protection: https://www.ngdc.noaa.gov/geomag/WMM/license.shtml\n\nThe WMM source code is in the public domain and not licensed or under copyright. The information and software may be used freely by the public. As required by 17 U.S.C. 403, third parties producing copyrighted works consisting predominantly of the material produced by U.S. government agencies must provide notice with such work(s) identifying the U.S. Government material incorporated and stating that such material is not subject to copyright protection.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestphae%2Fgeomag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwestphae%2Fgeomag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestphae%2Fgeomag/lists"}