def test_resample_n_1d_s(self): slat = np.array([30, 33, 36, 39], dtype=np.float64) slon = np.array([40, 43, 46, 49], dtype=np.float64) tlat = np.array([40, 37, 34, 31], dtype=np.float64) tlon = np.array([50, 47, 44, 41], dtype=np.float64) sdata = np.array([1, 2, 3, 4], dtype=np.float64) #radius 150 km(about the distance between (30,40) and(31,41)) r = 150000. g = pytaf.resample_n(slat, slon, tlat, tlon, sdata, r) h = np.array([4, 3, 2, 1]) try: np.testing.assert_array_equal(g, h) res = True except AssertionError as err: res = False print(err) self.assertTrue(res)
def regrid_MODIS_2_MAIA(source_lat, source_lon, target_lat, target_lon, source_data): ''' Objective: take source geolocation and source data, and regrid it to a target geolocation using nearest nieghbor. Arguments: source_lat, source_lon {2D narrays} -- lat/lon of data to be regridded target_lat, target_lon {2D narrays} -- lat/lon of refrence grid source_data {2D narray} -- data that will be regridded Returns: target_data {2D narray} -- returns regridded source data, such that it matches up with the target lat/lon ''' #radius in meters to search around pixel for a neighbor max_radius = 5556. target_data = pytaf.resample_n(source_lat, source_lon, target_lat,\ target_lon, source_data, max_radius) return target_data
def test_resample_n_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)) r = 5555 g = pytaf.resample_n(slat, slon, tlat, tlon, sdata, r) h = np.array([[-0., -333., -666., -999.], [-1332., -1665., -1998., -2331.], [-999, -2997., -3330., -3663.]]) try: np.testing.assert_array_equal(g, h) res = True except AssertionError as err: res = False print(err) self.assertTrue(res)
print(a) print('Test high-level nearest neighbor resample(1D lat/lon).') # radius 150 km r = 150000. a= np.array([30,33,36,39],dtype=np.float64) b= np.array([40,43,46,49],dtype=np.float64) d= np.array([40,37,34,31],dtype=np.float64) e= np.array([50,47,44,41],dtype=np.float64) f=np.array([1,2,3,4],dtype=np.float64) print('Source value(f) before testing') #should be [1 2 3 4] print(f) g = pytaf.resample_n(a, b, d, e, f, r) print('Source value after resampling') #should be [4 3 2 1] print(g) print('Test high-level nearest neighbor resample(2D lat/lon).') a= np.array([30,33,36,39],dtype=np.float64).reshape((2,2)) b= np.array([40,43,46,49],dtype=np.float64).reshape((2,2)) d= np.array([40,37,34,31],dtype=np.float64).reshape((2,2)) e= np.array([50,47,44,41],dtype=np.float64).reshape((2,2)) f=np.array([1,2,3,4],dtype=np.float64).reshape((2,2)) print('Source value(f) before testing') #should be [1 2] [3 4] print(f) g = pytaf.resample_n(a, b, d, e, f, r) print('Source value after resampling')
# Read source lat/lon. Shape: {23040, 2092} ds_lat = f['/Geolocation/Latitude'] slat = ds_lat[:, :].astype(np.float64) ds_lon = f['/Geolocation/Longitude'] slon = ds_lon[:, :].astype(np.float64) f.close() with h5py.File(file_name2, 'r') as f2: # Read target lat/lon. {40620, 1354} ds_tlat = f2['/Geolocation/Latitude'] tlat = ds_tlat[:, :].astype(np.float64) ds_tlon = f2['/Geolocation/Longitude'] tlon = ds_tlon[:, :].astype(np.float64) ds_tmisr = f2['/Source/Data_Fields/MISR_Radiance'] tmisr = ds_tmisr[0, 0, :, :].astype(np.float64) f2.close() lat_orig = tlat.copy() lon_orig = tlon.copy() trg_data = pytaf.resample_n(slat, slon, tlat, tlon, misr_data, 5556) print(trg_data[0, 0:10]) # Open file for writing. f3 = h5py.File('misr2modis.h5', 'w') dset = f3.create_dataset('/Target/Data_Fields/MISR_Radiance', data=trg_data) dset2 = f3.create_dataset('/Source/Data_Fields/MISR_Radiance', data=tmisr) dset3 = f3.create_dataset('/Geolocation/Latitude', data=lat_orig) dset4 = f3.create_dataset('/Geolocation/Longitude', data=lon_orig) f3.close()
print('Source pixel count value after low-level summary interpolation') print(c1) f = np.arange(12, dtype=np.float64).reshape((3,4)) print('Testing block index build') print('Index ID value before testing') pytaf.find_nn_block_index(d, e, 3, a, b, c, f, 3, 10000.0) print('Index ID value after testing') print(c) # radius 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')