def test_resample_s_2d_to_1d(self): slat = np.arange(12, dtype=np.float64).reshape((3, 4)) slon = np.arange(12, dtype=np.float64).reshape((3, 4)) sdata = slat * -333 tlat = np.arange(12, dtype=np.float64) tlon = np.arange(12, dtype=np.float64) tsd1 = np.arange(12, dtype=np.float64) npix1 = np.arange(12, dtype=np.int32) g = pytaf.resample_s(slat, slon, tlat, tlon, sdata, self.r, tsd1, npix1) h = np.array([ 0., -999., -999., -999., -999., -999., -999., -999., -999., -999., -999., -999. ]) j = np.zeros(12) j[0] = 1 try: np.testing.assert_almost_equal(g, h) np.testing.assert_almost_equal(tsd1, h) np.testing.assert_almost_equal(npix1, j) res = True except AssertionError as err: res = False print(err) self.assertTrue(res)
def test_resample_s_1d_s(self): slat = np.array([30.5, 31.5, 32.5, 33.5, 36.5, 37.5, 38.5, 39.5], dtype=np.float64) slon = np.array([40.5, 41.5, 42.5, 43.5, 46.5, 47.5, 48.5, 49.5], dtype=np.float64) tlat = np.array([39, 37, 33, 31], dtype=np.float64) tlon = np.array([49, 47, 43, 41], dtype=np.float64) sdata = np.array([1, 3, 5, 7, 9, 11, 13, 15], dtype=np.float64) sd = np.arange(4, dtype=np.float64) pc = np.arange(4, dtype=np.int32) g = pytaf.resample_s(slat, slon, tlat, tlon, sdata, self.r, sd, pc) h = np.array([14, 10, 6, 2], dtype=np.float64) pc1 = np.array([2, 2, 2, 2], dtype=np.float64) sd1 = np.array([1, 1, 1, 1], dtype=np.float64) try: np.testing.assert_array_equal(g, h) np.testing.assert_array_equal(sd1, sd) np.testing.assert_array_equal(pc1, pc) res = True except AssertionError as err: res = False print(err) self.assertTrue(res)
def test_resample_s_1d_to_2d(self): slat = np.arange(12, dtype=np.float64) slon = np.arange(12, dtype=np.float64) sdata = slat * -333 tlat = np.arange(12, dtype=np.float64).reshape((3, 4)) tlon = np.arange(12, dtype=np.float64).reshape((3, 4)) g = pytaf.resample_s(slat, slon, tlat, tlon, sdata, self.r, self.tsd, self.npix) h = np.array([[0., -999., -999., -999.], [-999., -999., -999., -999.], [-999., -999., -999., -999.]]) try: np.testing.assert_almost_equal(g, h) res = True except AssertionError as err: res = False print(err) self.assertTrue(res)
r = 100000. print('Test summary resample(1D lat/lon).') a1 = np.array([30.5,31.5,32.5,33.5,36.5,37.5,38.5,39.5],dtype=np.float64) b1 = np.array([40.5,41.5,42.5,43.5,46.5,47.5,48.5,49.5],dtype=np.float64) d1 = np.array([39,37,33,31],dtype=np.float64) e1 = np.array([49,47,43,41],dtype=np.float64) f=np.array([1,3,5,7,9,11,13,15],dtype=np.float64) sd = np.arange(4, dtype=np.float64) pc = np.arange(4, dtype=np.int32) print('Source value(f) before testing') #should be [1 3 5 7 9 11 13 15] print(f) g1 = pytaf.resample_s(a1, b1, d1, e1, f, r,sd,pc) print('Source value(f) after testing') #should be [14 10 6 2] print(g1) print('Source SD value after summary interpolation') #should be [1 1 1 1] print(sd) print('Source pixel count value after summary interpolation') #should be [2 2 2 2] print(pc) print('Test summary resample(2D lat/lon).') a1 = np.array([30.5,31.5,32.5,33.5,36.5,37.5,38.5,39.5],dtype=np.float64).reshape(4,2) b1 = np.array([40.5,41.5,42.5,43.5,46.5,47.5,48.5,49.5],dtype=np.float64).reshape(4,2) d1 = np.array([39,37,33,31],dtype=np.float64).reshape(2,2) e1 = np.array([49,47,43,41],dtype=np.float64).reshape(2,2)
lon = h5f['MISR/HRGeolocation/GeoLongitude'][:] # Convert 3-D MISR grids to 2-D. src_var = np.vstack(var).astype(np.float64) print(src_var.shape) src_lat = np.vstack(lat).astype(np.float64) src_lon = np.vstack(lon).astype(np.float64) # Call resample using summary interpolation. sd = np.zeros(src_var.shape, dtype=src_var.dtype) npix = np.zeros(src_var.shape, dtype=np.int32) # Make copies of target lat/lon because resample will modify them. tlat = target_lat.copy() tlon = target_lon.copy() trg_data = pytaf.resample_s(src_lat, src_lon, target_lat, target_lon, src_var, max_radius, sd, npix) print(trg_data.shape) print(trg_data.size) print(trg_data) # Write data for plotting. f3 = h5py.File('misr2ceres.h5', 'w') dset = f3.create_dataset('/Target/Data_Fields/MISR_AN_Red_Radiance', data=trg_data) dset3 = f3.create_dataset('/Geolocation/Latitude', data=tlat) dset4 = f3.create_dataset('/Geolocation/Longitude', data=tlon) f3.close() print("--- %s seconds ---" % (time.time() - start_time))
r = 5555 print('Test high-level nearest neighbor resample.') print('Source value(e) before testing') g = pytaf.resample_n(a, b, d, e, f, r) print('Source value after resampling') print(g) sd = np.arange(12, dtype=np.float64).reshape((3,4)) pc = np.arange(12, dtype=np.int32).reshape((3,4)) print('Test summary resample.') print('Source value(f) before testing') print(f) g1 = pytaf.resample_s(a, b, d, e, f, r,sd,pc) print('Source value(f) after testing') print(g1) print('Source SD value after summary interpolation') print(sd) print('Source pixel count value after summary interpolation') print(pc) # Test 1D lat/lon in target. k = np.arange(12,dtype=np.float64) l = np.arange(12,dtype=np.float64) # Test 1D var for target lat and 2D var for target lon. #print('Test dimension mismatch.') #m0 = pytaf.resample_n(a, b, k, e, f, r)