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
Hal Simpson
committed
Notes: We use numpy functions instead of standard python arithmetic funtions
for 2 reasons. 1) so that either array's can be passed in, or individual
values. 2) Because they are more flexible/robust then the standard python
functions.
import numpy
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))
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
def get_deltaf(fv, fs):
"""gets the deltaf value given the scalar F and computed F values.
Parameters
----------
fv: array_like
the F vector computed from the observatory instruments
fs: array_like
the measured F value
"""
return numpy.subtract(fv, fs)
def get_computed_f_using_squares(x, y, z):
"""gets the computed f value
Parameters
----------
x: array_like
the x component from the observatory
y: array_like
the y component from the observatory
z: array_like
the z component from the observatory
Notes
-----
This works for geographic coordinates, or observatory coordinates.
ie x, y, z or h, e, z
We're using variables x,y,z to represent generic cartisian coordinates.
"""
x2 = numpy.square(x)
y2 = numpy.square(y)
z2 = numpy.square(z)
fv = numpy.add(x2, y2)
fv = numpy.add(fv, z2)
return numpy.sqrt(fv)
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)