def navigate(timecodes, satellite): orb = Orbital(satellite) first_time = timecode(timecodes[0]) first_time = datetime(first_time.year, first_time.month, first_time.day) hrpttimes = [timecode(x) - first_time for x in timecodes] hrpttimes = np.array([x.seconds + x.microseconds / 1000000.0 for x in hrpttimes]) scan_points = np.arange(2048) if satellite == "noaa 16": scan_angle = 55.25 else: scan_angle = 55.37 scans_nb = len(hrpttimes) avhrr_inst = np.vstack(((scan_points / 1023.5 - 1) * np.deg2rad(-scan_angle), np.zeros((len(scan_points),)))).T avhrr_inst = np.tile(avhrr_inst, [scans_nb, 1]) offset = hrpttimes times = (np.tile(scan_points * 0.000025, [scans_nb, 1]) + np.expand_dims(offset, 1)) sgeom = ScanGeometry(avhrr_inst, times.ravel()) s_times = sgeom.times(first_time) rpy = (0, 0, 0) pixels_pos = compute_pixels((orb.tle._line1, orb.tle._line2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) return pos_time
def navigate(timecodes, satellite): orb = Orbital(satellite) first_time = timecode(timecodes[0]) first_time = datetime(first_time.year, first_time.month, first_time.day) hrpttimes = [timecode(x) - first_time for x in timecodes] hrpttimes = np.array( [x.seconds + x.microseconds / 1000000.0 for x in hrpttimes]) scan_points = np.arange(2048) if satellite == "noaa 16": scan_angle = 55.25 else: scan_angle = 55.37 scans_nb = len(hrpttimes) avhrr_inst = np.vstack( ((scan_points / 1023.5 - 1) * np.deg2rad(-scan_angle), np.zeros((len(scan_points), )))).T avhrr_inst = np.tile(avhrr_inst, [scans_nb, 1]) offset = hrpttimes times = (np.tile(scan_points * 0.000025, [scans_nb, 1]) + np.expand_dims(offset, 1)) sgeom = ScanGeometry(avhrr_inst, times.ravel()) s_times = sgeom.times(first_time) rpy = (0, 0, 0) pixels_pos = compute_pixels((orb.tle._line1, orb.tle._line2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) return pos_time
def test_scan_geometry(self): """Test the ScanGeometry object. """ scans_nb = 1 xy = np.vstack((np.deg2rad(np.array([10, 0, -10])), np.array([0, 0, 0]))) xy = np.tile(xy[:, np.newaxis, :], [1, np.int(scans_nb), 1]) times = np.tile([-0.1, 0, 0.1], [np.int(scans_nb), 1]) instrument = ScanGeometry(xy, times) self.assertTrue( np.allclose(np.rad2deg(instrument.fovs[0]), np.array([[10, 0, -10]]))) # Test vectors pos = np.rollaxis(np.tile(np.array([0, 0, 7000]), [3, 1, 1]), 2) vel = np.rollaxis(np.tile(np.array([1, 0, 0]), [3, 1, 1]), 2) pos = np.stack([np.array([0, 0, 7000])] * 3, 1)[:, np.newaxis, :] vel = np.stack([np.array([1, 0, 0])] * 3, 1)[:, np.newaxis, :] vec = instrument.vectors(pos, vel) self.assertTrue(np.allclose(np.array([[0, 0, -1]]), vec[:, 0, 1])) # minus sin because we use trigonometrical direction of angles self.assertTrue( np.allclose( np.array( [[0, -np.sin(np.deg2rad(10)), -np.cos(np.deg2rad(10))]]), vec[:, 0, 0])) self.assertTrue( np.allclose( np.array( [[0, -np.sin(np.deg2rad(-10)), -np.cos(np.deg2rad(-10))]]), vec[:, 0, 2])) # Test times start_of_scan = np.datetime64(datetime(2014, 1, 8, 11, 30)) times = instrument.times(start_of_scan) self.assertEqual(times[0, 1], start_of_scan) self.assertEqual(times[0, 0], start_of_scan - np.timedelta64(100, 'ms')) self.assertEqual(times[0, 2], start_of_scan + np.timedelta64(100, 'ms'))
def test_scan_geometry(self): """Test the ScanGeometry object. """ scans_nb = 1 xy = np.vstack((np.deg2rad(np.array([10, 0, -10])), np.array([0, 0, 0]))) xy = np.tile(xy[:, np.newaxis, :], [1, np.int(scans_nb), 1]) times = np.tile([-0.1, 0, 0.1], [np.int(scans_nb), 1]) instrument = ScanGeometry(xy, times) self.assertTrue(np.allclose(np.rad2deg(instrument.fovs[0]), np.array([[10, 0, -10]]))) # Test vectors pos = np.rollaxis(np.tile(np.array([0, 0, 7000]), [3, 1, 1]), 2) vel = np.rollaxis(np.tile(np.array([1, 0, 0]), [3, 1, 1]), 2) pos = np.stack([np.array([0, 0, 7000])] * 3, 1)[:, np.newaxis, :] vel = np.stack([np.array([1, 0, 0])] * 3, 1)[:, np.newaxis, :] vec = instrument.vectors(pos, vel) self.assertTrue(np.allclose(np.array([[0, 0, -1]]), vec[:, 0, 1])) # minus sin because we use trigonometrical direction of angles self.assertTrue(np.allclose(np.array([[0, -np.sin(np.deg2rad(10)), -np.cos(np.deg2rad(10))]]), vec[:, 0, 0])) self.assertTrue(np.allclose(np.array([[0, -np.sin(np.deg2rad(-10)), -np.cos(np.deg2rad(-10))]]), vec[:, 0, 2])) # Test times start_of_scan = np.datetime64(datetime(2014, 1, 8, 11, 30)) times = instrument.times(start_of_scan) self.assertEquals(times[0, 1], start_of_scan) self.assertEquals(times[0, 0], start_of_scan - np.timedelta64(100, 'ms')) self.assertEquals(times[0, 2], start_of_scan + np.timedelta64(100, 'ms'))
def test_scan_geometry(self): """Test the ScanGeometry object. """ instrument = ScanGeometry( np.deg2rad(np.array([[10, 0], [0, 0], [-10, 0]])), np.array([-0.1, 0, 0.1])) self.assertTrue( np.allclose(np.rad2deg(instrument.fovs[:, 0]), np.array([10, 0, -10]))) # Test vectors pos = np.array([[0, 0, 7000]]).T vel = np.array([[1, 0, 0]]).T vec = instrument.vectors(pos, vel) self.assertTrue(np.allclose(np.array([[0, 0, -1]]), vec[:, 1])) # minus sin because we use trigonometrical direction of angles self.assertTrue( np.allclose( np.array( [[0, -np.sin(np.deg2rad(10)), -np.cos(np.deg2rad(10))]]), vec[:, 0])) self.assertTrue( np.allclose( np.array( [[0, -np.sin(np.deg2rad(-10)), -np.cos(np.deg2rad(-10))]]), vec[:, 2])) # Test times start_of_scan = datetime(2014, 1, 8, 11, 30) times = instrument.times(start_of_scan) self.assertEqual(times[1], start_of_scan) self.assertEqual(times[0], start_of_scan - timedelta(seconds=0.1)) self.assertEqual(times[2], start_of_scan + timedelta(seconds=0.1))
def test_scan_geometry(self): """Test the ScanGeometry object. """ instrument = ScanGeometry(np.deg2rad(np.array([[10, 0], [0, 0], [-10, 0]])), np.array([-0.1, 0, 0.1])) self.assertTrue(np.allclose(np.rad2deg(instrument.fovs[:, 0]), np.array([10, 0, -10]))) # Test vectors pos = np.array([[0, 0, 7000]]).T vel = np.array([[1, 0, 0]]).T vec = instrument.vectors(pos, vel) self.assertTrue(np.allclose(np.array([[0, 0, -1]]), vec[:, 1])) # minus sin because we use trigonometrical direction of angles self.assertTrue(np.allclose(np.array([[0, -np.sin(np.deg2rad(10)), -np.cos(np.deg2rad(10))]]), vec[:, 0])) self.assertTrue(np.allclose(np.array([[0, -np.sin(np.deg2rad(-10)), -np.cos(np.deg2rad(-10))]]), vec[:, 2])) # Test times start_of_scan = datetime(2014, 1, 8, 11, 30) times = instrument.times(start_of_scan) self.assertEquals(times[1], start_of_scan) self.assertEquals(times[0], start_of_scan - timedelta(seconds=0.1)) self.assertEquals(times[2], start_of_scan + timedelta(seconds=0.1))
np.zeros((len(scan_points), )))).transpose() avhrr = np.tile(avhrr, [scanline_nb, 1]) # building the corresponding times array offset = np.arange(scanline_nb) * 0.1666667 times = (np.tile(scan_points * 0.000025 + 0.0025415, [scanline_nb, 1]) + np.expand_dims(offset, 1)) # build the scan geometry object sgeom = ScanGeometry(avhrr, times.ravel()) # roll, pitch, yaw in radians rpy = (0, 0, 0) # print the lonlats for the pixel positions s_times = sgeom.times(t) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) print(pos_time) # Plot the result m = Basemap(projection='stere', llcrnrlat=24, urcrnrlat=70, llcrnrlon=-25, urcrnrlon=120, lat_ts=58, lat_0=58, lon_0=14, resolution='l')
np.zeros((len(scan_points),)))).transpose() avhrr = np.tile(avhrr, [scanline_nb, 1]) # building the corresponding times array offset = np.arange(scanline_nb) * 0.1666667 times = (np.tile(scan_points * 0.000025 + 0.0025415, [scanline_nb, 1]) + np.expand_dims(offset, 1)) # build the scan geometry object sgeom = ScanGeometry(avhrr, times.ravel()) # roll, pitch, yaw in radians rpy = (0, 0, 0) # print the lonlats for the pixel positions s_times = sgeom.times(t) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) print pos_time # Plot the result from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt m = Basemap(projection='stere', llcrnrlat=24, urcrnrlat=70, llcrnrlon=-25, urcrnrlon=120, lat_ts=58, lat_0=58, lon_0=14, resolution='l') # convert and plot the predicted pixels in red x, y = m(pos_time[0], pos_time[1])