def test_apex2geo_invalid_lat(): A = Apex(date=2000, refh=300) with pytest.raises(ValueError): A.apex2geo(91, 0, 0, 1e-2) with pytest.raises(ValueError): A.apex2geo(-91, 0, 0, 1e-2) A.apex2geo(90, 0, 0, 1e-2) A.apex2geo(-90, 0, 0, 1e-2) assert_allclose(A.apex2geo(90+1e-5, 0, 0, 1e-2), A.apex2geo(90, 0, 0, 1e-2), rtol=0, atol=1e-8)
def test_apex2geo_invalid_lat(): apex_out = Apex(date=2000, refh=300) with pytest.raises(ValueError): apex_out.apex2geo(91, 0, 0, 1e-2) with pytest.raises(ValueError): apex_out.apex2geo(-91, 0, 0, 1e-2) apex_out.apex2geo(90, 0, 0, 1e-2) apex_out.apex2geo(-90, 0, 0, 1e-2) assert_allclose(apex_out.apex2geo(90 + 1e-5, 0, 0, 1e-2), apex_out.apex2geo(90, 0, 0, 1e-2), rtol=0, atol=1e-8)
def test_apex2geo(): A = Apex(date=2000, refh=300) lat, lon, error = A.apex2geo(60, 15, 100, precision=1e-2) assert_allclose((lat, lon, error), A.qd2geo(*A.apex2qd(60, 15, 100), height=100, precision=1e-2)) assert type(lat) != np.ndarray assert type(lon) != np.ndarray assert type(error) != np.ndarray
def test_apex2geo(): apex_out = Apex(date=2000, refh=300) lat, lon, error = apex_out.apex2geo(60, 15, 100, precision=1e-2) assert_allclose((lat, lon, error), apex_out.qd2geo(*apex_out.apex2qd(60, 15, 100), height=100, precision=1e-2)) assert type(lat) != np.ndarray assert type(lon) != np.ndarray assert type(error) != np.ndarray
def test_basevectors_apex_scalar_apex(): A = Apex(date=2000, refh=300) f1, f2, f3, g1, g2, g3, d1, d2, d3, e1, e2, e3 = A.basevectors_apex(60, 15, 100, coords='apex', precision=1e-2) glat, glon, _ = A.apex2geo(60, 15, 100, precision=1e-2) _, _, _, _, f1_, f2_, _, d1_, d2_, d3_, _, e1_, e2_, e3_ = A._geo2apexall(glat, glon, 100) assert_allclose(f1, f1_) assert_allclose(f2, f2_) assert_allclose(d1, d1_) assert_allclose(d2, d2_) assert_allclose(d3, d3_) assert_allclose(e1, e1_) assert_allclose(e2, e2_) assert_allclose(e3, e3_)
def test_convert_mlt2geo(): datetime = dt.datetime(2000, 3, 9, 14, 25, 58) apex_out = Apex(date=2000, refh=300) assert_allclose( apex_out.convert(60, 15, 'mlt', 'geo', height=100, datetime=datetime, precision=1e-2, ssheight=2e5), apex_out.apex2geo(60, apex_out.mlt2mlon(15, datetime, ssheight=2e5), 100, precision=1e-2)[:-1])
def test_basevectors_apex_scalar_apex(): A = Apex(date=2000, refh=300) (f1, f2, f3, g1, g2, g3, d1, d2, d3, e1, e2, e3) = A.basevectors_apex(60, 15, 100, coords='apex', precision=1e-2) glat, glon, _ = A.apex2geo(60, 15, 100, precision=1e-2) (_, _, _, _, f1_, f2_, _, d1_, d2_, d3_, _, e1_, e2_, e3_) = A._geo2apexall(glat, glon, 100) assert_allclose(f1, f1_) assert_allclose(f2, f2_) assert_allclose(d1, d1_) assert_allclose(d2, d2_) assert_allclose(d3, d3_) assert_allclose(e1, e1_) assert_allclose(e2, e2_) assert_allclose(e3, e3_)
East, North = qd_north[0], qd_north[1] Gridproj = CS.CSprojection((lon_centre, lat_centre), [East, North]) node_grid = CS.CSgrid(Gridproj, 3700, 2200, 50., 50.) Evalproj = CS.CSprojection((lon_centre - 0.23, lat_centre + 0.23), [East, North]) eval_grid = CS.CSgrid(Evalproj, 3300, 1800, 50., 50.) node_lons, node_lats = node_grid.lon.flatten(), node_grid.lat.flatten() lat, lon = eval_grid.lat.flatten(), eval_grid.lon.flatten() min_lon = min(node_lons) - 5 max_lon = max(node_lons) + 5 min_lat = min(node_lats) - 5 # max_lat= max(node_lats) max_lat = 90 mlat = np.linspace(49, 81, 50) merid_glat, merid_glon, err = A.apex2geo(alat=mlat, alon=105, height=110) Date = pd.Timestamp('2016-02-08T02:10') Date1 = Date - pd.Timedelta(value=60, unit='m') Date2 = Date + pd.Timedelta(value=60, unit='m') Sat = Sat_Store.select(key='main', where='Date_UTC>=Date1 & Date_UTC<=Date2 \ & glon>= min_lon & glon<=max_lon & glat>=min_lat & glat<=max_lat' ) """Regularisiation""" depth = 500 λ1 = 1e-23 λ2 = λ1 * 1e2 poles = SECS(node_lons, node_lats, lon, lat,
def test_basevectors_qd_scalar_apex(): A = Apex(date=2000, refh=300) glat, glon, _ = A.apex2geo(60, 15, 100, precision=1e-2) assert_allclose(A.basevectors_qd(60, 15, 100, coords='apex', precision=1e-2), A._basevec(glat, glon, 100))
def test_apex2geo_vectorization(): A = Apex(date=2000, refh=300) assert A.apex2geo([60, 60], 15, 100)[0].shape == (2,) assert A.apex2geo(60, [15, 15], 100)[0].shape == (2,) assert A.apex2geo(60, 15, [100, 100])[0].shape == (2,)
def test_convert_mlt2geo(): datetime = dt.datetime(2000, 3, 9, 14, 25, 58) A = Apex(date=2000, refh=300) assert_allclose(A.convert(60, 15, 'mlt', 'geo', height=100, datetime=datetime, precision=1e-2, ssheight=2e5), A.apex2geo(60, A.mlt2mlon(15, datetime, ssheight=2e5), 100, precision=1e-2)[:-1])
def test_convert_apex2geo(): A = Apex(date=2000, refh=300) assert_allclose(A.convert(60, 15, 'apex', 'geo', height=100, precision=1e-2), A.apex2geo(60, 15, 100, precision=1e-2)[:-1])
class Field(object): def __init__(self, *args, **kwargs): if len(args) == 1: self.read_config(args[0]) else: self.apex_year = kwargs['apex_year'] self.field_coords = np.array(kwargs['field_coords']) self.field_values = np.array(kwargs['field_values']) # initialize Apex object self.apex = Apex(date=self.apex_year) self.map_velocity_field(self.field_coords, self.field_values) self.convert_to_ECEF() self.create_interpolators() def read_config(self, config_file): config = configparser.ConfigParser() config.read(config_file) self.apex_year = config.getint('FIELD', 'apex_year') self.field_coords = np.array(eval(config.get('FIELD', 'field_coords'))) self.field_values = np.array(eval(config.get('FIELD', 'field_values'))) def map_velocity_field(self, coords, field): # coords - array (N,3) of geodetic lat, lon, alt # field - array (N,3) of geodetic E, N, U components of the velocity field at each position # define output altitudes altitude = np.arange(50., 1000., 50.) # create array in proper shape to be applied to every input coordinate self.altitude = np.repeat(altitude, coords.shape[-1]) # map to diffent altitudes manually - the current expected input/output arrays of apexpy.map_to_height makes this function difficult to use for this purpose alat, alon = self.apex.geo2apex(coords[0], coords[1], coords[2]) # find positions at each altitude self.latitude, self.longitude, __ = self.apex.apex2geo( np.tile(alat, len(altitude)), np.tile(alon, len(altitude)), self.altitude) # map field to each altitude f = np.array([ self.apex.map_V_to_height(alat, alon, coords[2], a, field.T).T for a in altitude ]) self.field = f.reshape(-1, f.shape[-1]) def convert_to_ECEF(self): self.X, self.Y, self.Z = pm.geodetic2ecef(self.latitude, self.longitude, self.altitude * 1000.) self.Vx, self.Vy, self.Vz = pm.enu2uvw(self.field[:, 0], self.field[:, 1], self.field[:, 2], self.latitude, self.longitude) def create_interpolators(self): self.interpVx = interpolate.LinearNDInterpolator( np.array([self.X, self.Y, self.Z]).T, self.Vx) self.interpVy = interpolate.LinearNDInterpolator( np.array([self.X, self.Y, self.Z]).T, self.Vy) self.interpVz = interpolate.LinearNDInterpolator( np.array([self.X, self.Y, self.Z]).T, self.Vz) def plot_ionosphere(self): fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111, projection='3d') for x, y, z, vx, vy, vz in zip(self.X, self.Y, self.Z, self.Vx, self.Vy, self.Vz): ax.quiver(x, y, z, vx, vy, vz, length=0.4 * np.sqrt(vx**2 + vy**2 + vz**2), color='green') plt.show()
def test_apex2geo_vectorization(): apex_out = Apex(date=2000, refh=300) assert apex_out.apex2geo([60, 60], 15, 100)[0].shape == (2, ) assert apex_out.apex2geo(60, [15, 15], 100)[0].shape == (2, ) assert apex_out.apex2geo(60, 15, [100, 100])[0].shape == (2, )
def test_convert_apex2geo(): apex_out = Apex(date=2000, refh=300) assert_allclose( apex_out.convert(60, 15, 'apex', 'geo', height=100, precision=1e-2), apex_out.apex2geo(60, 15, 100, precision=1e-2)[:-1])
def test_basevectors_qd_scalar_apex(): apex_out = Apex(date=2000, refh=300) glat, glon, _ = apex_out.apex2geo(60, 15, 100, precision=1e-2) assert_allclose( apex_out.basevectors_qd(60, 15, 100, coords='apex', precision=1e-2), apex_out._basevec(glat, glon, 100))