Exemplo n.º 1
0
def test_igrf11():

    mag = igrf12.igrf(time, 65, 85, 0, model=11)

    assert mag.north.item() == approx(9301.523160)
    assert mag.east.item() == approx(2563.450424)
    assert mag.down.item() == approx(59666.132881)
    assert mag.total.item() == approx(60441.186489)

    assert mag.incl.item() == approx(80.814513)
    assert mag.decl.item() == approx(15.407924)
Exemplo n.º 2
0
def test_igrf12():

    mag = igrf12.igrf(time, 65, 85, 0, model=12)

    assert mag.north.item() == approx(9295.100256)
    assert mag.east.item() == approx(2560.199706)
    assert mag.down.item() == approx(59670.251893)
    assert mag.total.item() == approx(60444.126863)

    assert mag.incl.item() == approx(80.821738)
    assert mag.decl.item() == approx(15.399442)
def merge_custom_iss(file_name):
	#TODO: Create custom equation to mimic altitude 
    altitude = 330 

    df = pd.read_csv(file_name)
    for i,row in df.iterrows():
    	latitude = df.iloc[i][1]
    	longitude = df.iloc[i][2]
    	mag = igrf12.igrf('2010-07-12', glat=latitude, glon=longitude, alt_km=altitude)
    	df.at[i, 'mag_x'] = mag.north.values[0] / 100000
    	df.at[i, 'mag_y'] = mag.east.values[0] / 100000
    	df.at[i, 'mag_z'] = mag.down.values[0] / 100000

    new_file_name = "{}_merged.csv".format(file_name.split('.')[0])
    df.to_csv(new_file_name, index=False)
    return True
def generate_m_data():
    '''
        
    1) Pull random datapoint from https://natronics.github.io/ISS-photo-locations/
    2) Create igrf model at lat and lon specified by #1 and at alt_km = between 330-435km (https://en.wikipedia.org/wiki/International_Space_Station)
    3) Convert igrf north, east, down -> x,y,z (nT to gauss)

    According to http://geomag.nrcan.gc.ca/mag_fld/comp-en.php: 
    X is positive northward
    Y is positive eastward
    Z is positive downward

    4) Return expected (x,y,z) + random noise 

    '''

    # TODO: Instead of random selection from a single csv, could use the entire dataset.
    lines = open('data/ISS001.csv').read().splitlines()
    line = random.choice(lines)

    columns = line.split(',')
    latitude = float(columns[1])
    longitude = float(columns[2])

    altitude = random.randint(330, 435)

    #TODO: Instead of the 2010 model, could use the 2015 model.
    mag = igrf12.igrf('2010-07-12',
                      glat=latitude,
                      glon=longitude,
                      alt_km=altitude)

    #Convert nT to Gauss
    x = mag.north.values[0] / 100000
    y = mag.east.values[0] / 100000
    z = mag.down.values[0] / 100000

    #Add random noise
    x = x + random.uniform(-0.01, 0.01)
    y = y + random.uniform(-0.01, 0.01)
    z = z + random.uniform(-0.01, 0.01)

    return [x, y, z]
Exemplo n.º 5
0
def declination_tables(query):
    lats = np.arange(query.min_lat, query.max_lat + query.res, query.res)
    lons = np.arange(query.min_lon, query.max_lon + query.res, query.res)

    num_lat = lats.size
    num_lon = lons.size

    intensity = np.empty((num_lat, num_lon))
    inclination = np.empty((num_lat, num_lon))
    declination = np.empty((num_lat, num_lon))

    for i, lat in enumerate(lats):
        for j, lon in enumerate(lons):
            mag = igrf12.igrf(date, glat=lat, glon=lon, alt_km=0., isv=0, itype=1)
            intensity[i][j] = mag.total / 1e5
            inclination[i][j] = mag.incl
            declination[i][j] = mag.decl

    return Result(query=query, lats=lats, lons=lons,
        declination=declination, inclination=inclination, intensity=intensity)
Exemplo n.º 6
0
def add_mag(df):
    '''

	Calculates the magnetic field using the IGRF-12 coefficients. 

	Feel free to change altitude 

	'''
    altitude = 330

    for i, row in df.iterrows():
        latitude = df.iloc[i][1]
        longitude = df.iloc[i][2]
        mag = igrf12.igrf('2010-07-12',
                          glat=latitude,
                          glon=longitude,
                          alt_km=altitude)
        df.at[i, 'mag_x'] = mag.north.values[0] / 100000 - 0.2
        df.at[i, 'mag_y'] = mag.east.values[0] / 100000
        df.at[i, 'mag_z'] = mag.down.values[0] / 100000

    return True
Exemplo n.º 7
0
    SAMPLING_MIN_LON = -180
    SAMPLING_MAX_LON = 180

    lats = np.arange(SAMPLING_MIN_LAT, SAMPLING_MAX_LAT+SAMPLING_RES, SAMPLING_RES)
    lons = np.arange(SAMPLING_MIN_LON, SAMPLING_MAX_LON+SAMPLING_RES, SAMPLING_RES)

    NUM_LAT = lats.size
    NUM_LON = lons.size

    intensity_table = np.empty((NUM_LAT, NUM_LON))
    inclination_table = np.empty((NUM_LAT, NUM_LON))
    declination_table = np.empty((NUM_LAT, NUM_LON))

    for i,lat in enumerate(lats):
        for j,lon in enumerate(lons):
            mag = igrf.igrf(date, glat=lat, glon=lon, alt_km=0., isv=0, itype=1)
            intensity_table[i][j] = mag.total/1e5
            inclination_table[i][j] = mag.incl
            declination_table[i][j] = mag.decl

    with open("tables.cpp", 'w') as f:
        f.write('''// this is an auto-generated file from the IGRF tables. Do not edit
// To re-generate run generate/generate.py

#include "AP_Declination.h"

''')

        f.write('''const float AP_Declination::SAMPLING_RES = %u;
const float AP_Declination::SAMPLING_MIN_LAT = %u;
const float AP_Declination::SAMPLING_MAX_LAT = %u;
Exemplo n.º 8
0
                     SAMPLING_RES)
    lons = np.arange(SAMPLING_MIN_LON, SAMPLING_MAX_LON + SAMPLING_RES,
                     SAMPLING_RES)

    NUM_LAT = lats.size
    NUM_LON = lons.size

    intensity_table = np.empty((NUM_LAT, NUM_LON))
    inclination_table = np.empty((NUM_LAT, NUM_LON))
    declination_table = np.empty((NUM_LAT, NUM_LON))

    for i, lat in enumerate(lats):
        for j, lon in enumerate(lons):
            mag = igrf.igrf(date,
                            glat=lat,
                            glon=lon,
                            alt_km=0.,
                            isv=0,
                            itype=1)
            intensity_table[i][j] = mag.total / 1e5
            inclination_table[i][j] = mag.incl
            declination_table[i][j] = mag.decl

    with open("tables.cpp", 'w') as f:
        f.write(
            '''// this is an auto-generated file from the IGRF tables. Do not edit
// To re-generate run generate/generate.py

#include "AP_Declination.h"

''')