def galactic_Sun_north_directions( recv_time, user_longlatdist=geographic_position): user_longlatdist = np.array(user_longlatdist)#46.07983746062874, 26.232615661106784, 659.5100082775696 with load.open(hipparcos.URL) as f: df = hipparcos.load_dataframe(f) planets = load('de421.bsp') earth = planets['earth'] user_position = earth + Topos('{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) #user_longlatdist user_longlatdist[0],user_longlatdist[1] terrestrial_time = format_time(recv_time) ts = load.timescale() t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2], terrestrial_time[3], terrestrial_time[4], terrestrial_time[5]) sun = planets['sun'] astrometric_sun = user_position.at(t).observe(sun) alt_sun, az_sun, distance_sun = astrometric_sun.apparent().altaz()#astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() print('Location: ', '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) print('Sun (alt/az): ',alt_sun, az_sun) sun_position = pm.aer2ecef( az_sun.degrees, alt_sun.degrees, distance_sun.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) # Északi Galaktikus Pólus (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0) coma_berenices = Star(ra_hours=(12, 51, 25.2), dec_degrees=(27, 7, 48.0)) astrometric_berenice = user_position.at(t).observe(coma_berenices) alt_b, az_b, distance_b = astrometric_berenice.apparent().altaz() print('Coma Berenice (alt/az): ',alt_b, az_b) berenice_position = pm.aer2ecef( az_b.degrees, alt_b.degrees, distance_b.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) stars_pos=[sun_position, berenice_position] return stars_pos
def get_star_position( recv_time, star_name, star_name2, user_longlatdist=geographic_position): # if not star_name: # star_name = 57632 #Denebola # if not star_name2: # star_name2 = 109074 #Sadalmelik user_longlatdist = np.array(user_longlatdist)#46.07983746062874, 26.232615661106784, 659.5100082775696 with load.open(hipparcos.URL) as f: df = hipparcos.load_dataframe(f) planets = load('de421.bsp') earth = planets['earth'] user_position = earth + Topos('{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) #user_longlatdist user_longlatdist[0],user_longlatdist[1] terrestrial_time = format_time(recv_time) ts = load.timescale() t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2], terrestrial_time[3], terrestrial_time[4], terrestrial_time[5]) denebola = Star.from_dataframe(df.loc[star_name]) astrometric_denebola = user_position.at(t).observe(denebola) alt_d, az_d, distance_d = astrometric_denebola.apparent().altaz()#astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() print('Location: ', '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) print('S1 (alt/az): ',alt_d, az_d) star_pos_d = pm.aer2ecef( az_d.degrees,alt_d.degrees, distance_d.m,user_longlatdist[0],user_longlatdist[1],user_longlatdist[2]) sadalmelik = Star.from_dataframe(df.loc[star_name2]) astrometric_sadalmelik = user_position.at(t).observe(sadalmelik) alt_s, az_s, distance_s = astrometric_sadalmelik.apparent().altaz() print('S2 (alt/az): ',alt_s, az_s) star_pos_s = pm.aer2ecef( az_s.degrees,alt_s.degrees, distance_s.m,user_longlatdist[0],user_longlatdist[1],user_longlatdist[2]) stars_pos=[star_pos_d,star_pos_s] return stars_pos
def test_aer_ecef(): xyz = pm.aer2ecef(*aer0, *lla0) assert xyz == approx(axyz0) assert pm.aer2ecef(*raer0, *rlla0, deg=False) == approx(axyz0) with pytest.raises(ValueError): pm.aer2ecef(aer0[0], aer0[1], -1, *lla0) assert pm.ecef2aer(*xyz, *lla0) == approx(aer0) assert pm.ecef2aer(*xyz, *rlla0, deg=False) == approx(raer0)
def test_aer2ecef(aer, lla, xyz): x, y, z = pm.aer2ecef(*aer, *lla) assert x == approx(xyz[0]) assert y == approx(xyz[1]) assert z == approx(xyz[2]) raer = (radians(aer[0]), radians(aer[1]), aer[2]) rlla = (radians(lla[0]), radians(lla[1]), lla[2]) assert pm.aer2ecef(*raer, *rlla, deg=False) == approx(xyz) with pytest.raises(ValueError): pm.aer2ecef(aer[0], aer[1], -1, *lla)
def test_ned(): xyz = pm.aer2ecef(*aer0, *lla0) enu = pm.aer2enu(*aer0) ned = (enu[1], enu[0], -enu[2]) lla = pm.aer2geodetic(*aer0, *lla0) assert pm.aer2ned(*aer0) == approx(ned0) with pytest.raises(ValueError): pm.aer2ned(aer0[0], aer0[1], -1) assert pm.enu2aer(*enu) == approx(aer0) assert pm.enu2aer(*enu, deg=False) == approx(raer0) assert pm.ned2aer(*ned) == approx(aer0) assert pm.ecef2ned(*xyz, *lla0) == approx(ned) assert pm.ned2ecef(*ned, *lla0) == approx(xyz) # %% assert pm.ecef2enuv(vx, vy, vz, *lla0[:2]) == approx((ve, vn, vu)) assert pm.ecef2nedv(vx, vy, vz, *lla0[:2]) == approx((vn, ve, -vu)) # %% enu3 = pm.geodetic2enu(*lla, *lla0) ned3 = (enu3[1], enu3[0], -enu3[2]) assert pm.geodetic2ned(*lla, *lla0) == approx(ned3) assert pm.enu2geodetic(*enu3, *lla0) == approx(lla) assert pm.ned2geodetic(*ned3, *lla0) == approx(lla)
def test_ecef_ned(): enu = pm.aer2enu(*aer0) ned = (enu[1], enu[0], -enu[2]) xyz = pm.aer2ecef(*aer0, *lla0) n, e, d = pm.ecef2ned(*xyz, *lla0) assert n == approx(ned[0]) assert e == approx(ned[1]) assert d == approx(ned[2]) assert pm.ned2ecef(*ned, *lla0) == approx(xyz)
def test_aer_enu(): xyz = pm.aer2ecef(*aer0, *lla0) enu = pm.aer2enu(*aer0) assert enu == approx(enu0) assert pm.aer2enu(*raer0, deg=False) == approx(enu0) with pytest.raises(ValueError): pm.aer2enu(aer0[0], aer0[1], -1) assert pm.enu2ecef(*enu, *lla0) == approx(xyz) assert pm.enu2ecef(*enu, *rlla0, deg=False) == approx(xyz) assert pm.ecef2enu(*xyz, *lla0) == approx(enu) assert pm.ecef2enu(*xyz, *rlla0, deg=False) == approx(enu)
def projectisrhist(isrlla,beamazel,optlla,optazel,heightkm): """ intended to project ISR beam at a single height into optical data. output: az,el,slantrange in degrees,meters """ isrlla = asarray(isrlla); optlla=asarray(optlla) assert isrlla.size == optlla.size == 3 x,y,z = aer2ecef(beamazel[0],beamazel[1],heightkm*1e3,isrlla[0],isrlla[1],isrlla[2]) try: az,el,srng = ecef2aer(x,y,z,optlla[0],optlla[1],optlla[2]) except IndexError: az,el,srng = ecef2aer(x,y,z,optlla['lat'],optlla['lon'],optlla['alt_km']) return {'az':az,'el':el,'srng':srng}
def pixelmask(data: xarray.Dataset, method: str = None) -> xarray.Dataset: """ Use list because image may not be square returns mask of chosen pixels """ if method is None or method == "rect": # outermost edge of image (trivial) mask = np.zeros(data["az"].shape, dtype=bool) mask[:, 0] = True mask[0, :] = True mask[:, -1] = True mask[-1, :] = True elif method == "perimeter": # perimeter for arbitrary shapes e.g all-sky cameras if ndi is None: raise ImportError("pip install scipy") mask = ndi.distance_transform_cdt(~np.isnan(data["az"]), "taxicab") == 1 elif method.lower() == "mzslice": """ Assuming the imagers are all-sky, we arbitrarily discard pixels of low elevation as distortion is high low to horizon. """ MIN_EL = 5 # degrees, arbitrary if data.srpts is None: return ValueError("must include slant range points") mask = np.zeros(data["az"].shape, dtype=bool) mask[data["el"] >= MIN_EL] = True data["fovmask"] = (("y", "x"), mask) data.attrs["x2mz"], data.attrs["y2mz"], data.attrs["z2mz"] = pm.aer2ecef( data.attrs["Baz"], data.attrs["Bel"], data.srpts, data.attrs["lat"], data.attrs["lon"], data.attrs["alt_m"] ) return data else: raise ValueError(f"unknown mask {method}") # %% sanity check if ~mask.any(): raise ValueError("no FOV overlap found") data["fovmask"] = (("y", "x"), mask) return data
def projectisrhist(isrlla, beamazel, optlla, optazel, heightkm): """ intended to project ISR beam at a single height into optical data. output: az,el,slantrange in degrees,meters """ isrlla = asarray(isrlla) optlla = asarray(optlla) assert isrlla.size == optlla.size == 3 x, y, z = aer2ecef(beamazel[0], beamazel[1], heightkm * 1e3, isrlla[0], isrlla[1], isrlla[2]) try: az, el, srng = ecef2aer(x, y, z, optlla[0], optlla[1], optlla[2]) except IndexError: az, el, srng = ecef2aer(x, y, z, optlla["lat"], optlla["lon"], optlla["alt_km"]) return {"az": az, "el": el, "srng": srng}
def test_ecefenu(): assert_allclose(pm.aer2ecef(taz, tel, tsrange, tlat, tlon, talt), (a2x, a2y, a2z), rtol=0.01, err_msg='aer2ecef: {}'.format( pm.aer2ecef(taz, tel, tsrange, tlat, tlon, talt))) assert_allclose(pm.aer2enu(taz, tel, tsrange), (a2e, a2n, a2u), rtol=0.01, err_msg='aer2enu: ' + str(pm.aer2enu(taz, tel, tsrange))) assert_allclose(pm.aer2ned(taz, tel, tsrange), (a2n, a2e, -a2u), rtol=0.01, err_msg='aer2ned: ' + str(pm.aer2ned(taz, tel, tsrange))) assert_allclose(pm.ecef2enu(tx, ty, tz, tlat, tlon, talt), (e2e, e2n, e2u), rtol=0.01, err_msg='ecef2enu: {}'.format( pm.ecef2enu(tx, ty, tz, tlat, tlon, talt))) assert_allclose(pm.ecef2enuv(vx, vy, vz, tlat, tlon), (ve, vn, vu)) assert_allclose(pm.ecef2ned(tx, ty, tz, tlat, tlon, talt), (e2n, e2e, -e2u), rtol=0.01, err_msg='ecef2ned: {}'.format( pm.ecef2enu(tx, ty, tz, tlat, tlon, talt))) assert_allclose(pm.ecef2nedv(vx, vy, vz, tlat, tlon), (vn, ve, -vu)) assert_allclose(pm.aer2geodetic(taz, tel, tsrange, tlat, tlon, talt), (a2la, a2lo, a2a), rtol=0.01, err_msg='aer2geodetic {}'.format( pm.aer2geodetic(taz, tel, tsrange, tlat, tlon, talt))) assert_allclose(pm.ecef2aer(tx, ty, tz, tlat, tlon, talt), (ec2az, ec2el, ec2rn), rtol=0.01, err_msg='ecef2aer {}'.format( pm.ecef2aer(a2x, a2y, a2z, tlat, tlon, talt))) #%% assert_allclose(pm.enu2aer(te, tn, tu), (e2az, e2el, e2rn), rtol=0.01, err_msg='enu2aer: ' + str(pm.enu2aer(te, tn, tu))) assert_allclose(pm.ned2aer(tn, te, -tu), (e2az, e2el, e2rn), rtol=0.01, err_msg='enu2aer: ' + str(pm.enu2aer(te, tn, tu))) assert_allclose(pm.enu2geodetic(te, tn, tu, tlat, tlon, talt), (lat2, lon2, alt2), rtol=0.01, err_msg='enu2geodetic: ' + str(pm.enu2geodetic(te, tn, tu, tlat, tlon, talt))) assert_allclose(pm.ned2geodetic(tn, te, -tu, tlat, tlon, talt), (lat2, lon2, alt2), rtol=0.01, err_msg='enu2geodetic: ' + str(pm.enu2geodetic(te, tn, tu, tlat, tlon, talt))) assert_allclose(pm.enu2ecef(te, tn, tu, tlat, tlon, talt), (e2x, e2y, e2z), rtol=0.01, err_msg='enu2ecef: ' + str(pm.enu2ecef(te, tn, tu, tlat, tlon, talt))) assert_allclose( pm.ned2ecef(tn, te, -tu, tlat, tlon, talt), (e2x, e2y, e2z), rtol=0.01, err_msg='ned2ecef: ' + str(pm.ned2ecef(tn, te, -tu, tlat, tlon, talt)))
def map_target(tx, rx, az, el, rf): """ Find the scatter location given tx location, rx, location, total rf distance, and target angle-of-arrival. Parameters ---------- tx : float np.array [latitude, longitude, altitude] of tx array in degrees and kilometers rx : float np.array [latitude, longitude, altitude] of rx array in degrees and kilometers az : float angle-of-arrival azimuth in degrees el : float angle-of-arrival elevation in degrees rf : float np.array total rf path distance rf = c * tau Returns ------- sx : float np.array [latitude, longitude, altitude] of scatter in degrees and kilometers r : float bistatic slant range in kilometers """ # Setup givens in correct units rf = rf * 1.0e3 * 1.5 - 230e3 # Assumed rf propagation correction in km az = np.where(az < 0, np.deg2rad(az + 367.0), np.deg2rad(az + 7.0)) el = np.deg2rad(np.abs(el)) sx = np.zeros((3, len(rf))) uv = np.zeros((3, len(rf))) us = np.zeros((3, len(rf))) # Determine the slant range, r bx1, by1, bz1 = pm.geodetic2ecef(rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) ur = np.array([bx1, by1, bz1]) / np.linalg.norm([bx1, by1, bz1]) bx2, by2, bz2 = pm.geodetic2ecef(tx[0], tx[1], tx[2], ell=pm.Ellipsoid("wgs84"), deg=True) ut = np.array([bx2, by2, bz2]) / np.linalg.norm([bx2, by2, bz2]) bx = bx2 - bx1 by = by2 - by1 bz = bz2 - bz1 b = np.linalg.norm([bx, by, bz]) ub = np.array([bx, by, bz]) / b dr = np.ones(1000) dtheta = np.ones(1000) dr[0] = 1e6 dtheta[0] = 1e6 r2 = np.copy(rf) theta2 = np.ones(len(az)) * np.pi cnt = 0 while np.max(dtheta[cnt]) >= 0.002 and dr[cnt] >= 1500: ua = np.array([np.sin(az) * np.cos(el), np.cos(az) * np.cos(el), np.sin(el)]) theta = np.arccos(ua[0, :] * ub[0] + ua[1, :] * ub[1] + ua[2, :] * ub[2]) r = (rf ** 2 - b ** 2) / (2 * (rf - b * np.cos(theta))) # Correct elevation using geocentric angle gamma and first order ranges, find scatter lat, long, alt for i in range(len(rf)): bx3, by3, bz3 = pm.aer2ecef(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) us[:, i] = np.array([bx3, by3, bz3]) / np.linalg.norm([bx3, by3, bz3]) el[i] -= np.arccos(ur[0] * us[0, i] + ur[1] * us[1, i] + ur[2] * us[2, i]) sx[:, i] = pm.aer2geodetic(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) dr[cnt + 1] = np.max(np.abs(r - r2)) dtheta[cnt + 1] = np.max(np.abs(theta - theta2)) cnt += 1 r2 = r theta2 = theta # Find the bistatic bisector velocity unit vector uv = (us + ua) / 2.0 uv = uv / np.linalg.norm(uv) # Set units to degrees and kilometers sx[2, :] /= 1.0e3 r /= 1.0e3 return sx[2, :], r, dr[0:cnt], dtheta[0:cnt]
def galactic_Sun_north_center_SD_directions( measurement_date, recv_time, user_longlatdist=geographic_position, prints=False): user_longlatdist = np.array(user_longlatdist) with load.open(hipparcos.URL) as f: df = hipparcos.load_dataframe(f) planets = load('de421.bsp') earth = planets['earth'] user_position = earth + Topos( '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1]) ) #user_longlatdist user_longlatdist[0],user_longlatdist[1] terrestrial_time = format_time_auto(measurement_date, recv_time) ts = load.timescale() t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2], terrestrial_time[3], terrestrial_time[4], terrestrial_time[5]) sun = planets['sun'] astrometric_sun = user_position.at(t).observe(sun) alt_sun, az_sun, distance_sun = astrometric_sun.apparent().altaz( ) #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() sun_position = pm.aer2ecef(az_sun.degrees, alt_sun.degrees, distance_sun.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) # Északi Galaktikus Pólus (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0) coma_berenices = Star(ra_hours=(12, 51, 25.2), dec_degrees=(27, 7, 48.0)) astrometric_berenice = user_position.at(t).observe(coma_berenices) alt_b, az_b, distance_b = astrometric_berenice.apparent().altaz() berenice_position = pm.aer2ecef(az_b.degrees, alt_b.degrees, distance_b.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) # Galaktikus Center (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0) 17h 45.6m −28.94° galactic_center = Star(ra_hours=(17, 45, 36.0), dec_degrees=(-28, 56, 24.0)) astrometric_center = user_position.at(t).observe(galactic_center) alt_c, az_c, distance_c = astrometric_center.apparent().altaz() center_position = pm.aer2ecef(az_c.degrees, alt_c.degrees, distance_c.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) nunki = Star.from_dataframe(df.loc[92855]) astrometric_nunki = user_position.at(t).observe(nunki) alt_n, az_n, distance_n = astrometric_nunki.apparent().altaz( ) #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() star_pos_n = pm.aer2ecef(az_n.degrees, alt_n.degrees, distance_n.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) capella = Star.from_dataframe(df.loc[24608]) astrometric_capella = user_position.at(t).observe(capella) alt_ca, az_ca, distance_ca = astrometric_capella.apparent().altaz( ) #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() star_pos_ca = pm.aer2ecef(az_ca.degrees, alt_ca.degrees, distance_ca.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) denebola = Star.from_dataframe(df.loc[57632]) astrometric_denebola = user_position.at(t).observe(denebola) alt_d, az_d, distance_d = astrometric_denebola.apparent().altaz( ) #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz() star_pos_d = pm.aer2ecef(az_d.degrees, alt_d.degrees, distance_d.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) sadalmelik = Star.from_dataframe(df.loc[109074]) astrometric_sadalmelik = user_position.at(t).observe(sadalmelik) alt_s, az_s, distance_s = astrometric_sadalmelik.apparent().altaz() star_pos_s = pm.aer2ecef(az_s.degrees, alt_s.degrees, distance_s.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2]) if prints: print('Time: ', terrestrial_time) print('Location: ', '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) print('Sun (alt/az): ', alt_sun, az_sun) print('Coma Berenice (alt/az): ', alt_b, az_b) print('Galactic Center (alt/az): ', alt_c, az_c) print('Nunki (alt/az): ', alt_n, az_n) print('Capella (alt/az): ', alt_ca, az_ca) print('Denebola (alt/az): ', alt_d, az_d) print('Sadalmelik (alt/az): ', alt_s, az_s) stars_pos = [ sun_position, berenice_position, center_position, star_pos_n, star_pos_ca, star_pos_d, star_pos_s ] return stars_pos
def map_target(tx, rx, az, el, rf): """ Find the scatter location given tx location, rx, location, total rf distance, and target angle-of-arrival. Parameters ---------- tx : float np.array [latitude, longitude, altitude] of tx array in degrees and kilometers rx : float np.array [latitude, longitude, altitude] of rx array in degrees and kilometers az : float angle-of-arrival azimuth in degrees el : float angle-of-arrival elevation in degrees rf : float np.array total rf path distance rf = c * tau Returns ------- sx : float np.array [latitude, longitude, altitude] of scatter in degrees and kilometers r : float bistatic slant range in kilometers """ # Setup givens in correct units rf = rf * 1.0e3 * 1.5 - 230e3 az = np.where(az < 0, np.deg2rad(az + 367.0), np.deg2rad(az + 7.0)) el = np.deg2rad(np.abs(el)) sx = np.zeros((3, len(rf))) uv = np.zeros((3, len(rf))) us = np.zeros((3, len(rf))) # Determine the slant range, r bx1, by1, bz1 = pm.geodetic2ecef(rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) ur = np.array([bx1, by1, bz1]) / np.linalg.norm([bx1, by1, bz1]) bx2, by2, bz2 = pm.geodetic2ecef(tx[0], tx[1], tx[2], ell=pm.Ellipsoid("wgs84"), deg=True) ut = np.array([bx2, by2, bz2]) / np.linalg.norm([bx2, by2, bz2]) bx = bx2 - bx1 by = by2 - by1 bz = bz2 - bz1 b = np.linalg.norm([bx, by, bz]) ub = np.array([bx, by, bz]) / b ua = np.array( [np.sin(az) * np.cos(el), np.cos(az) * np.cos(el), np.sin(el)]) theta = np.arccos(ua[0, :] * ub[0] + ua[1, :] * ub[1] + ua[2, :] * ub[2]) r = (rf**2 - b**2) / (2 * (rf - b * np.cos(theta))) # Correct elevation using geocentric angle gamma and first order ranges, find scatter lat, long, alt for i in range(len(rf)): bx3, by3, bz3 = pm.aer2ecef(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) us[:, i] = np.array([bx3, by3, bz3]) / np.linalg.norm([bx3, by3, bz3]) #el[i] -= np.arccos(ut[0]*us[0, i] + ut[1]*us[1, i] + ut[2]*us[2, i]) el[i] -= np.arccos(ur[0] * us[0, i] + ur[1] * us[1, i] + ur[2] * us[2, i]) sx[:, i] = pm.aer2geodetic(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) # Second order slant range, r ua = np.array( [np.sin(az) * np.cos(el), np.cos(az) * np.cos(el), np.sin(el)]) theta = np.arccos(ua[0, :] * ub[0] + ua[1, :] * ub[1] + ua[2, :] * ub[2]) r = (rf**2 - b**2) / (2 * (rf - b * np.cos(theta))) for i in range(len(rf)): sx[:, i] = pm.aer2geodetic(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) # Find the bistatic bisector velocity unit vector uv = (us + ua) / 2.0 uv = uv / np.linalg.norm(uv) # Set units to degrees and kilometers sx[2, :] /= 1.0e3 r /= 1.0e3 # d = rf/2 - 200e3 # r1 = np.sqrt((6378.1370e3 * np.cos(np.deg2rad(52.1579))) ** 2 + (6356.7523e3 * np.sin(np.deg2rad(52.1579))) ** 2) # pre_alt = np.sqrt(r1 ** 2 + (d) ** 2 - 2 * r1 * (d) * np.cos(np.pi/2 + el)) # el -= np.arccos(((d) ** 2 - (r1 ** 2) - (pre_alt ** 2)) / (-2 * r1 * pre_alt)) # Find lat, long, alt of target # sx = np.zeros((3, len(rf))) # for i in range(len(rf)): # sx[:, i] = pm.aer2geodetic(np.rad2deg(az[i]), np.rad2deg(el[i]), np.abs(r[i]), # rx[0], rx[1], rx[2], ell=pm.Ellipsoid("wgs84"), deg=True) #return sx, r, uv vaz, vel, _ = pm.ecef2aer(uv[0, :] + bx3, uv[1, :] + by3, uv[2, :] + bz3, sx[0, :], sx[1, :], sx[2, :], ell=pm.Ellipsoid("wgs84"), deg=True) return sx[2, :], r, vaz, vel
def test_geodetic(self): if pyproj: ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84') lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84') xyz1 = pm.geodetic2ecef(*lla0) assert_allclose(pm.geodetic2ecef(*rlla0, deg=False), xyz1, err_msg='geodetic2ecef: rad') assert_allclose(xyz1, xyz0, err_msg='geodetic2ecef: deg') assert_allclose(pm.ecef2geodetic(*xyz1), lla0, err_msg='ecef2geodetic: deg') assert_allclose(pm.ecef2geodetic(*xyz1, deg=False), rlla0, err_msg='ecef2geodetic: rad') if pyproj: assert_allclose( pyproj.transform(lla, ecef, lla0[1], lla0[0], lla0[2]), xyz1) assert_allclose(pyproj.transform(ecef, lla, *xyz1), (lla0[1], lla0[0], lla0[2])) lla2 = pm.aer2geodetic(*aer0, *lla0) rlla2 = pm.aer2geodetic(*raer0, *rlla0, deg=False) assert_allclose(lla2, lla1, err_msg='aer2geodetic: deg') assert_allclose(rlla2, rlla1, err_msg='aer2geodetic:rad') assert_allclose(pm.geodetic2aer(*lla2, *lla0), aer0, err_msg='geodetic2aer: deg') assert_allclose(pm.geodetic2aer(*rlla2, *rlla0, deg=False), raer0, err_msg='geodetic2aer: rad') # %% aer-ecef xyz2 = pm.aer2ecef(*aer0, *lla0) assert_allclose(pm.aer2ecef(*raer0, *rlla0, deg=False), axyz0, err_msg='aer2ecef:rad') assert_allclose(xyz2, axyz0, err_msg='aer2ecef: deg') assert_allclose(pm.ecef2aer(*xyz2, *lla0), aer0, err_msg='ecef2aer:deg') assert_allclose(pm.ecef2aer(*xyz2, *rlla0, deg=False), raer0, err_msg='ecef2aer:rad') # %% aer-enu enu1 = pm.aer2enu(*aer0) ned1 = (enu1[1], enu1[0], -enu1[2]) assert_allclose(enu1, enu0, err_msg='aer2enu: deg') assert_allclose(pm.aer2enu(*raer0, deg=False), enu0, err_msg='aer2enu: rad') assert_allclose(pm.aer2ned(*aer0), ned0, err_msg='aer2ned') assert_allclose(pm.enu2aer(*enu1), aer0, err_msg='enu2aer: deg') assert_allclose(pm.enu2aer(*enu1, deg=False), raer0, err_msg='enu2aer: rad') assert_allclose(pm.ned2aer(*ned1), aer0, err_msg='ned2aer') # %% enu-ecef assert_allclose(pm.enu2ecef(*enu1, *lla0), xyz2, err_msg='enu2ecef: deg') assert_allclose(pm.enu2ecef(*enu1, *rlla0, deg=False), xyz2, err_msg='enu2ecef: rad') assert_allclose(pm.ecef2enu(*xyz2, *lla0), enu1, err_msg='ecef2enu:deg') assert_allclose(pm.ecef2enu(*xyz2, *rlla0, deg=False), enu1, err_msg='ecef2enu:rad') assert_allclose(pm.ecef2ned(*xyz2, *lla0), ned1, err_msg='ecef2ned') assert_allclose(pm.ned2ecef(*ned1, *lla0), xyz2, err_msg='ned2ecef') # %% assert_allclose(pm.ecef2enuv(vx, vy, vz, *lla0[:2]), (ve, vn, vu)) assert_allclose(pm.ecef2nedv(vx, vy, vz, *lla0[:2]), (vn, ve, -vu)) # %% enu3 = pm.geodetic2enu(*lla2, *lla0) ned3 = (enu3[1], enu3[0], -enu3[2]) assert_allclose(pm.geodetic2ned(*lla2, *lla0), ned3, err_msg='geodetic2ned: deg') assert_allclose(pm.enu2geodetic(*enu3, *lla0), lla2, err_msg='enu2geodetic') assert_allclose(pm.ned2geodetic(*ned3, *lla0), lla2, err_msg='ned2geodetic')
def test_geodetic(self): if pyproj: ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84') lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84') x1, y1, z1 = pm.geodetic2ecef(tlat, tlon, talt) assert_allclose( pm.geodetic2ecef(radians(tlat), radians(tlon), talt, deg=False), (x1, y1, z1)) assert_allclose((x1, y1, z1), (x0, y0, z0), err_msg='geodetic2ecef') assert_allclose(pm.ecef2geodetic(x1, y1, z1), (tlat, tlon, talt), err_msg='ecef2geodetic') if pyproj: assert_allclose(pyproj.transform(lla, ecef, tlon, tlat, talt), (x1, y1, z1)) assert_allclose(pyproj.transform(ecef, lla, x1, y1, z1), (tlon, tlat, talt)) lat2, lon2, alt2 = pm.aer2geodetic(taz, tel, tsrange, tlat, tlon, talt) assert_allclose((lat2, lon2, alt2), (lat1, lon1, alt1), err_msg='aer2geodetic') assert_allclose(pm.geodetic2aer(lat2, lon2, alt2, tlat, tlon, talt), (taz, tel, tsrange), err_msg='geodetic2aer') x2, y2, z2 = pm.aer2ecef(taz, tel, tsrange, tlat, tlon, talt) assert_allclose( pm.aer2ecef(radians(taz), radians(tel), tsrange, radians(tlat), radians(tlon), talt, deg=False), (a2x, a2y, a2z)) assert_allclose((x2, y2, z2), (a2x, a2y, a2z), err_msg='aer2ecef') assert_allclose(pm.ecef2aer(x2, y2, z2, tlat, tlon, talt), (taz, tel, tsrange), err_msg='ecef2aer') e1, n1, u1 = pm.aer2enu(taz, tel, tsrange) assert_allclose((e1, n1, u1), (e0, n0, u0), err_msg='aer2enu') assert_allclose(pm.aer2ned(taz, tel, tsrange), (n0, e0, -u0), err_msg='aer2ned') assert_allclose(pm.enu2aer(e1, n1, u1), (taz, tel, tsrange), err_msg='enu2aer') assert_allclose(pm.ned2aer(n1, e1, -u1), (taz, tel, tsrange), err_msg='ned2aer') assert_allclose(pm.enu2ecef(e1, n1, u1, tlat, tlon, talt), (x2, y2, z2), err_msg='enu2ecef') assert_allclose(pm.ecef2enu(x2, y2, z2, tlat, tlon, talt), (e1, n1, u1), err_msg='ecef2enu') assert_allclose(pm.ecef2ned(x2, y2, z2, tlat, tlon, talt), (n1, e1, -u1), err_msg='ecef2ned') assert_allclose(pm.ned2ecef(n1, e1, -u1, tlat, tlon, talt), (x2, y2, z2), err_msg='ned2ecef') # %% assert_allclose(pm.ecef2enuv(vx, vy, vz, tlat, tlon), (ve, vn, vu)) assert_allclose(pm.ecef2nedv(vx, vy, vz, tlat, tlon), (vn, ve, -vu)) #%% e3, n3, u3 = pm.geodetic2enu(lat2, lon2, alt2, tlat, tlon, talt) assert_allclose(pm.geodetic2ned(lat2, lon2, alt2, tlat, tlon, talt), (n3, e3, -u3)) assert_allclose(pm.enu2geodetic(e3, n3, u3, tlat, tlon, talt), (lat2, lon2, alt2), err_msg='enu2geodetic') assert_allclose(pm.ned2geodetic(n3, e3, -u3, tlat, tlon, talt), (lat2, lon2, alt2), err_msg='ned2geodetic')
def toecef(self,ranges): assert isinstance(self.Baz,float), 'please specify [cam]Bincl, [cam]Bdecl for each camera in .ini file' assert isinstance(self.lat,float), 'please specify [cam]latitude, [cam]longitude' self.x2mz, self.y2mz, self.z2mz = aer2ecef(self.Baz,self.Bel,ranges, self.lat,self.lon,self.alt_m)