1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# vim:fileencoding=utf-8 |
3
|
|
|
# |
4
|
|
|
# Copyright (c) 2018 Stefan Bender |
5
|
|
|
# |
6
|
|
|
# This file is part of sciapy. |
7
|
|
|
# sciapy is free software: you can redistribute it or modify it |
8
|
|
|
# under the terms of the GNU General Public License as published by |
9
|
|
|
# the Free Software Foundation, version 2. |
10
|
|
|
# See accompanying LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html. |
11
|
1 |
|
"""AACGM 2005 geomagnetic model at 80 km |
12
|
|
|
|
13
|
|
|
""" |
14
|
1 |
|
from __future__ import absolute_import, division, print_function |
15
|
|
|
|
16
|
1 |
|
import logging |
17
|
1 |
|
from pkg_resources import resource_filename |
18
|
|
|
|
19
|
1 |
|
import numpy as np |
20
|
1 |
|
from scipy.interpolate import RectBivariateSpline |
21
|
1 |
|
import xarray as xr |
22
|
|
|
|
23
|
1 |
|
__all__ = ['gmag_aacgm2005'] |
24
|
|
|
|
25
|
|
|
|
26
|
1 |
|
def gmag_aacgm2005(lat, lon, aacgm_name="AACGM2005_80km_grid.nc"): |
27
|
|
|
"""Fixed 2005 AACGM geomagnetic coordinates at 80 km |
28
|
|
|
|
29
|
|
|
Geomagnetic coordinates according to the AACGM model but |
30
|
|
|
with fixed parameters for the 2005 epoch. |
31
|
|
|
|
32
|
|
|
Parameters |
33
|
|
|
---------- |
34
|
|
|
lat: array_like |
35
|
|
|
Geographic latitude(s) in degrees north |
36
|
|
|
lon: array_like |
37
|
|
|
Geographic longitude(s) in degrees east |
38
|
|
|
aacgm_name: str, optional |
39
|
|
|
Filename of the AACGM grid, relating geographic latitude |
40
|
|
|
and longitude to AACGM geomagnetic latitude and longitude. |
41
|
|
|
The default is the prepared grid file for 2005 and at 80 km. |
42
|
|
|
|
43
|
|
|
Returns |
44
|
|
|
------- |
45
|
|
|
aacgmlat: numpy.ndarray or float |
46
|
|
|
The AACGM 2005 geomagnetic latitude(s) |
47
|
|
|
aacgmlon: numpy.ndarray or float |
48
|
|
|
The AACGM 2005 geomagnetic longitude(s) |
49
|
|
|
""" |
50
|
1 |
|
aacgm_file = resource_filename(__name__, aacgm_name) |
51
|
1 |
|
logging.debug("aacgm_file: %s", aacgm_file) |
52
|
|
|
# Fix longitudes to +- 180 |
53
|
1 |
|
lon = (np.asarray(lon) + 180.) % 360. - 180. |
54
|
1 |
|
aacgm_ds = xr.open_dataset(aacgm_file) |
55
|
1 |
|
lats = aacgm_ds["Latitude"] |
56
|
1 |
|
lons = aacgm_ds["Longitude"] |
57
|
1 |
|
glats = aacgm_ds["Geomagnetic_latitude"] |
58
|
1 |
|
glons = aacgm_ds["Geomagnetic_longitude"] |
59
|
1 |
|
splglat = RectBivariateSpline(lats, lons, glats) |
60
|
1 |
|
splglon = RectBivariateSpline(lats, lons, glons) |
61
|
|
|
return (splglat.ev(lat, lon), splglon.ev(lat, lon)) |
62
|
|
|
|