示例#1
0
def main():
    lon, lat = np.meshgrid(np.arange(-180, 180 + 10, 10),
                           np.arange(-90, 90 + 10, 10))

    mag = wmm.wmm(lat, lon, 0, 2015)

    plt.plotwmm(mag)

    show()
示例#2
0
def test_wmm2015():
    mag = wmm.wmm(65, 85, alt_km=0, yeardec=2012.52868852459)

    assert mag.north.item() == approx(9215.692665)
    assert mag.east.item() == approx(2516.0058789)
    assert mag.down.item() == approx(59708.529371)
    assert mag.total.item() == approx(60467.906831)

    assert mag.incl.item() == approx(80.910090)
    assert mag.decl.item() == approx(15.27036)
示例#3
0
    def wmmMagneticField(self):
        """
        In Tesla, in the geocentrical frame of reference.
        """
        mag = wmm.wmm(self.i, self.u, self.r / 1000 - 6371.0088, 2019)
        mag_orbital = 1e-9 * np.array(
            [[-mag.down.values[0][0]], [mag.north.values[0][0]],
             [mag.east.values[0][0]]])  #in the orbital frame

        return np.dot(self.A_yx(), mag_orbital)  # in the intertial frame
示例#4
0
def test_wmm2015():
    dt = datetime.datetime(2012, 7, 12, 12)

    mag = wmm.wmm(65, 85, 0, datetime2yeardec(dt))

    assert mag.north.item() == approx(9215.692665)
    assert mag.east.item() == approx(2516.0058789)
    assert mag.down.item() == approx(59708.529371)
    assert mag.total.item() == approx(60467.906831)

    assert mag.incl.item() == approx(80.910090)
    assert mag.decl.item() == approx(15.27036)
示例#5
0
def lookup_u_mag_enu(lon, lat, alt=0.0, year=2020):
    """Return the unit vector of the magnetic field in a local ENU
    frame.

    Args:
        lon   longitude of measurement (rad)
        lat   planetodetic/geodetic latitude of measurement (rad)
        alt   altitude above geoid (m; defaults to 0)
        year  decimal year of measurement (default is 2020)

    Returns:
        A unit vector in an ENU frame.
    """

    # WMM takes degrees and km
    mag = wmm2015.wmm(lat * 180 / np.pi, lon * 180 / np.pi, alt / 1000.0, year)

    # Get vector in north/east/down coordinates.
    enu = np.array([mag.east.item(), mag.north.item(), -mag.down.item()])
    return enu / spl.norm(enu)
示例#6
0
#!/usr/bin/env python
import numpy as np
from matplotlib.pyplot import show
import argparse

import wmm2015 as wmm
import wmm2015.plots as plt

p = argparse.ArgumentParser()
p.add_argument("yeardec", help="decimal year e.g. 2015.62", type=float)
p.add_argument("alt_km",
               help="altitude (km) default: 0.",
               type=float,
               default=0.0)
P = p.parse_args()

lon, lat = np.meshgrid(np.arange(-180, 180 + 10, 10),
                       np.arange(-90, 90 + 10, 10))

mag = wmm.wmm(lat, lon, P.alt_km, P.yeardec)

plt.plotwmm(mag)

show()
示例#7
0
motionCtrlAddress = liblo.Address("127.0.0.1", 8000)

gps = MirrorGPS.getGPSinfo()
print(gps)
date = gps[0]
time = gps[1]
suntime = Time(date + " " + time)
lon = float(gps[2]) / 100
lat = float(gps[4]) / 100
print("lon: %f" % lon)
print("lat: %f" % lat)
print("suntime: %s" % suntime)
sunPos = get_sun(suntime)
print("sunra: %s" % sunPos.ra)
magDecl = wmm.wmm(lat, lon, 0, 2019)
print("magDecl: %s" % (magDecl.decl.item(), ))

location = EarthLocation.from_geodetic(lat=lat, lon=lon, height=0)
altaz = sunPos.transform_to(AltAz(obstime=suntime, location=location))
sunalt = 90 - altaz.alt.deg
sunaz = altaz.az.deg
print(sunalt, sunaz)

if (argHeading == None):
    import berryIMU
    orientation = berryIMU.getValues()
    print("pitch: %s , roll: %s , heading: %s" % orientation)
    heading = orientation[2] - magDecl.decl.item()
    print("corrected heading %f" % heading)
else: