Source code for irfpy.moon.anomaly
''' Magnetic anomaly model.
Purucker's model is implemented in :class:`AnomalyModelPME`.
'''
import os
import warnings
import numpy as np
from pkg_resources import resource_filename
from irfpy.util import irfpyrc
[docs]class AnomalyModelPME:
''' Purucker's Model.
Refer to M. E. Purucker 2010 in JGR planets.
http://core2.gsfc.nasa.gov/research/purucker/moon_2010/
>>> am = AnomalyModelPME()
>>> print(am.br.shape)
(361, 361)
>>> print(am.lonlist[0:3])
[0. 1. 2.]
>>> print(am.latlist[0:3])
[90. 89.5 89. ]
>>> print(am.lonlist[130])
130.0
>>> print(am.latlist[75])
52.5
>>> print(am.br[130, 75])
0.69
>>> print(am.bt[130, 75])
-0.53
>>> print(am.bp[130, 75])
-0.49
.. todo::
Better user interface. Probably by giving longitude and
latitude, user may get a vector.
'''
def __init__(self):
''' Load a data file.
The data is obtained from
http://core2.gsfc.nasa.gov/research/purucker/moon_2010/
The corrective model with file name
``brtps_d1_170_alt30_har14tol15_dip6cpadpr_phase30_correlation.xy``
is supported here. Download it, and place it to your prefered folder
and specify by .irfpyrc, which should be [moon] section purucker_anomaly_data entry.
'''
warnings.warn("The data is based on Purucker's publication and "
"provision via the Internet. I would appreciate it. "
"Users should refer to the web page and the publication in "
"http://core2.gsfc.nasa.gov/research/purucker/moon_2010/ "
"for details of the data.")
# self.fnam = resource_filename(__name__, os.path.join('datafile',
# 'brtps_d1_170_alt30_har14tol15_dip6cpadpr_phase30_correlation.xy'))
rc = irfpyrc.Rc()
self.fnam = rc.get('moon', 'purucker_anomaly_data')
# Data is every 0.5 degrees for lat 1.0 for lon.
nlon = 361
nlat = 361
datall = np.genfromtxt(self.fnam)
self.lon = datall[:, 0].reshape([361, 361]).T
self.lat = datall[:, 1].reshape([361, 361]).T
self.br = datall[:, 2].reshape([361, 361]).T
self.bt = datall[:, 3].reshape([361, 361]).T
self.bp = datall[:, 4].reshape([361, 361]).T
self.b = datall[:, 5].reshape([361, 361]).T
self.lonlist = self.lon[:, 0].copy()
self.latlist = self.lat[0, :].copy()
import unittest
import doctest
[docs]def doctests():
return unittest.TestSuite((
doctest.DocTestSuite(),
))
if __name__ == '__main__':
unittest.main(defaultTest='doctests')