Newer
Older
Convert between different components and coordinate systems used by
the geomagnetic community.
Hal Simpson
committed
We use three coordinate systems.
Geo: Based on Geographic North. X, Y, Z
Hal Simpson
committed
X is north, Y is east
Hal Simpson
committed
Obs: Based on the observatories orientaion. H, E, Z [d]
Mag: Based on Magnetic North. H, D, Z [E]
d0: Declination baseline in radians
import numpy
Hal Simpson
committed
M2R = numpy.pi / 180 / 60 # Minutes to Radians
R2M = 180.0 / numpy.pi * 60 # Radians to Minutes
Hal Simpson
committed
# ###
# get geographic coordinates from....
# ###
def get_geo_from_obs(h, e, d0=0):
"""gets the geographical components given the observatory components.
Parameters
__________
h: array_like
Hal Simpson
committed
the h component from the observatory
e: array_like
Hal Simpson
committed
the e component from the observatory
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
tuple of array_like
[0]: x component as a float
[1]: y component as a float
"""
mag_h, mag_d = get_mag_from_obs(h, e, d0)
return get_geo_from_mag(mag_h, mag_d)
def get_geo_from_mag(h, d):
"""gets the geographical components given the magnetic components
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
Returns
_______
tuple of array_like
geo_x: x component as a float
geo_y: y component as a float
"""
geo_x = get_geo_x_from_mag(h, d)
geo_y = get_geo_y_from_mag(h, d)
return (geo_x, geo_y)
# inividual get geo from calls
Hal Simpson
committed
def get_geo_x_from_mag(h, d):
"""gets the geographical x component given magnetic north components
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
Returns
_______
array_like
Hal Simpson
committed
x component
"""
return numpy.multiply(h, numpy.cos(d))
Hal Simpson
committed
def get_geo_y_from_mag(h, d):
"""gets the geographical y component given magnetic north components
Hal Simpson
committed
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
Returns
_______
array_like
Hal Simpson
committed
y component
Hal Simpson
committed
"""
return numpy.multiply(h, numpy.sin(d))
Hal Simpson
committed
# ###
# get magnetic north coordinates from....
# ###
def get_mag_from_obs(h, e, d0=0):
"""gets the magnetic north components given the observatory components.
Parameters
__________
h: array_like
Hal Simpson
committed
the h component from the observatory
e: array_like
Hal Simpson
committed
the e component from the observatory
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
tuple of array_like
[0]: total h component as a float
[1]: total d declination as a float
"""
mag_h = get_mag_h_from_obs(h, e)
mag_d = get_mag_d_from_obs(h, e, d0)
return (mag_h, mag_d)
def get_mag_from_geo(x, y):
"""gets the magnetic north components given the geographic components.
Hal Simpson
committed
Parameters
__________
x: array_like
Hal Simpson
committed
the geographic x component
y: array_like
Hal Simpson
committed
the geographic y component
Returns
_______
tuple of array_like
[0]: total h component as a float
[1]: total d declination as a float
"""
mag_h = get_mag_h_from_geo(x, y)
mag_d = get_mag_d_from_geo(x, y)
return (mag_h, mag_d)
def get_mag_d_from_obs(h, e, d0=0):
"""gets the magnetic d component given the observatory components.
Hal Simpson
committed
Hal Simpson
committed
Parameters
Hal Simpson
committed
__________
h: array_like
Hal Simpson
committed
the h component from the observatory
e: array_like
Hal Simpson
committed
the e component from the observatory
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
array_like
Hal Simpson
committed
the total magnetic declination
return numpy.add(d0, get_obs_d_from_obs(h, e))
Hal Simpson
committed
def get_mag_d_from_geo(x, y):
"""gets the magnetic d component given the geographic components.
Parameters
__________
x: array_like
Hal Simpson
committed
the geographic x component
y: array_like
Hal Simpson
committed
the geographic y component
Returns
_______
array_like
Hal Simpson
committed
the total magnetic declination
"""
return numpy.arctan2(y, x)
def get_mag_h_from_obs(h, e):
"""gets the magnetic h component given the observatory components.
Parameters
__________
h: array_like
Hal Simpson
committed
the h component from the observatory
e: array_like
Hal Simpson
committed
the e component from the observatory
Returns
_______
array_like
Hal Simpson
committed
the total magnetic h component
"""
return numpy.hypot(h, e)
def get_mag_h_from_geo(x, y):
"""gets the magnetic h component given the geographic components.
Parameters
__________
x: array_like
Hal Simpson
committed
the geographic x component
y: array_like
Hal Simpson
committed
the geographic y component
Returns
_______
array_like
Hal Simpson
committed
the total magnetic h component
"""
return numpy.hypot(x, y)
# ###
# get observatory coordinates from....
# ###
def get_obs_from_geo(x, y, d0=0):
"""gets the observatory components given the geographic components.
Parameters
__________
x: array_like
Hal Simpson
committed
the geographic x component
y: array_like
Hal Simpson
committed
the geographic y component
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
tuple of array_like
[0]: observatory h component
[1]: observatory e component
[2]: observatory d declination
"""
mag_h, mag_d = get_mag_from_geo(x, y)
return get_obs_from_mag(mag_h, mag_d, d0)
def get_obs_from_mag(h, d, d0=0):
"""gets the observatory components given the magnetic north components.
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
tuple of array_like
[0]: observatory h component
[1]: observatory e component
[2]: observatory d declination
"""
obs_h = get_obs_h_from_mag(h, d, d0)
obs_e = get_obs_e_from_mag(h, d, d0)
Hal Simpson
committed
return (obs_h, obs_e)
Hal Simpson
committed
# inividual get obs from calls
def get_obs_d_from_obs(h, e):
"""gets the observatory d declination given the observatory components.
Parameters
__________
h: array_like
Hal Simpson
committed
the h component from the observatory
e: array_like
Hal Simpson
committed
the e component from the observatory
Returns
_______
array_like
Hal Simpson
committed
the observatory d declination
"""
return numpy.arctan2(e, h)
Hal Simpson
committed
def get_obs_d_from_mag_d(d, d0=0):
Hal Simpson
committed
"""gets the observatory d declination given the magnetic north
declination.
Parameters
__________
d: array_like
Hal Simpson
committed
the total declination d to magnetic north
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
array_like
Hal Simpson
committed
the observatory d declination
"""
return numpy.subtract(d, d0)
Hal Simpson
committed
def get_obs_e_from_mag(h, d, d0=0):
"""gets the observatory e component given the magnetic components.
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
array_like
Hal Simpson
committed
the observatory e component
"""
Hal Simpson
committed
obs_d = get_obs_d_from_mag_d(d, d0)
return numpy.multiply(h, numpy.sin(obs_d))
Hal Simpson
committed
def get_obs_e_from_obs(h, d):
"""gets the observatory e component given the observatory components.
Parameters
__________
h: array_like
Hal Simpson
committed
the observatory h component.
d: array_like
Hal Simpson
committed
the observatory d declination.
Returns
_______
array_like
Hal Simpson
committed
the observatory e component
"""
return numpy.multiply(h, numpy.tan(d))
Hal Simpson
committed
def get_obs_h_from_mag(h, d, d0=0):
"""gets the observatory h component given the magnetic north components
Parameters
__________
h: array_like
Hal Simpson
committed
the total h component in the magnetic north direction.
d: array_like
Hal Simpson
committed
the total d declination for the magnetic north direction.
d0: float
the declination baseline angle in radians
Hal Simpson
committed
Returns
_______
array_like
Hal Simpson
committed
the observatory h component
"""
Hal Simpson
committed
obs_d = get_obs_d_from_mag_d(d, d0)
return numpy.multiply(h, numpy.cos(obs_d))
Hal Simpson
committed
def get_radians_from_minutes(m):
"""gets the radian value given the decimal value
Parameters
__________
d: array_like
the decimal value to be converted
"""
return numpy.multiply(m, M2R)
Hal Simpson
committed
def get_minutes_from_radians(r):
"""gets the decimal value given the radian value
Parameters
__________
r: float
the radian value to be converted
"""
return numpy.multiply(r, R2M)