def get_incidence_angle(date_pair, params): # incidence angle exists in unw header files, not in dem SLC_DIR = params[cf.SLC_DIR] if params[cf.SLC_DIR] else \ params[cf.OBS_DIR] header_path = glob2.glob( os.path.join(SLC_DIR, '**/*%s*slc.par' % date_pair[0]))[0] header = gamma.parse_epoch_header(header_path) incidence_angle = header[ifc.INCIDENCE_ANGLE] return incidence_angle
def setUpClass(cls): # create common combined header obj so the headers are only read once # tricker: needs both ifg headers, and DEM one for the extents filenames = ['r20090713_VV.slc.par', 'r20090817_VV.slc.par'] hdr_paths = [join(GAMMA_TEST_DIR, f) for f in filenames] hdrs = [gamma.parse_epoch_header(p) for p in hdr_paths] dem_hdr_path = join(GAMMA_TEST_DIR, 'dem16x20raw.dem.par') cls.DEM_HDR = gamma.parse_dem_header(dem_hdr_path) cls.COMBINED = gamma.combine_headers(*hdrs, dem_hdr=cls.DEM_HDR)
def test_parse_gamma_epoch_header(self): # minimal required headers are: # date: 2009 7 13 # radar_frequency: 5.3310040e+09 Hz path = join(GAMMA_TEST_DIR, 'r20090713_VV.slc.par') hdrs = gamma.parse_epoch_header(path) exp_date = date(2009, 7, 13) self.assertEqual(hdrs[ifc.MASTER_DATE], exp_date) exp_wavelen = LIGHTSPEED / 5.3310040e+09 self.assertEqual(hdrs[ifc.PYRATE_WAVELENGTH_METRES], exp_wavelen) incidence_angle = 22.9671 self.assertEqual(hdrs[ifc.PYRATE_INCIDENCE_DEGREES], incidence_angle)
def test_combine_headers(self): filenames = ['r20090713_VV.slc.par', 'r20090817_VV.slc.par'] paths = [join(GAMMA_TEST_DIR, p) for p in filenames] hdr0, hdr1 = [gamma.parse_epoch_header(p) for p in paths] chdr = gamma.combine_headers(hdr0, hdr1, self.dh) exp_timespan = (18 + 17) / ifc.DAYS_PER_YEAR self.assertEqual(chdr[ifc.PYRATE_TIME_SPAN], exp_timespan) exp_date = date(2009, 7, 13) self.assertEqual(chdr[ifc.MASTER_DATE], exp_date) exp_date2 = date(2009, 8, 17) self.assertEqual(chdr[ifc.SLAVE_DATE], exp_date2) exp_wavelen = LIGHTSPEED / 5.3310040e+09 self.assertEqual(chdr[ifc.PYRATE_WAVELENGTH_METRES], exp_wavelen)
def test_unw_contains_same_data_as_numpy_array(self): from datetime import time temp_unw = tempfile.mktemp(suffix='.unw') temp_tif = tempfile.mktemp(suffix='.tif') # setup some header files for use in write_geotif dem_header_file = common.SML_TEST_DEM_HDR_GAMMA dem_header = gamma.parse_dem_header(dem_header_file) header = gamma.parse_epoch_header( os.path.join(common.SML_TEST_GAMMA, '20060828_slc.par')) header.update(dem_header) # insert some dummy data so we are the dem in write_geotiff is not # not activated and ifg write_geotiff operation works header[ifc.PYRATE_TIME_SPAN] = 0 header[ifc.SLAVE_DATE] = 0 header[ifc.DATA_UNITS] = 'degrees' header[ifc.DATA_TYPE] = ifc.ORIG header[ifc.SLAVE_TIME] = time(10) # now create aritrary data data = np.random.rand(dem_header[ifc.PYRATE_NROWS], dem_header[ifc.PYRATE_NCOLS]) # convert numpy array to .unw shared.write_unw_from_data_or_geotiff(geotif_or_data=data, dest_unw=temp_unw, ifg_proc=1) # convert the .unw to geotif shared.write_geotiff(header=header, data_path=temp_unw, dest=temp_tif, nodata=np.nan) # now compare geotiff with original numpy array ds = gdal.Open(temp_tif, gdal.GA_ReadOnly) data_lv_theta = ds.ReadAsArray() ds = None np.testing.assert_array_almost_equal(data, data_lv_theta) os.remove(temp_tif) os.remove(temp_unw)