def roipac_prepifg(base_ifg_paths, params): """ Prepare ROI_PAC interferograms which combines both conversion to geotiff and multilooking/cropping operations. :param list base_ifg_paths: List of unwrapped interferograms :param dict params: Parameters dictionary corresponding to config file """ log.info("Preparing ROI_PAC format interferograms") parallel = params[cf.PARALLEL] if parallel: log.info("Parallel prepifg is not implemented for ROI_PAC") log.info("Running prepifg in serial") xlooks, ylooks, crop = cf.transform_params(params) rsc_file = os.path.join(params[cf.DEM_HEADER_FILE]) if rsc_file is not None: projection = roipac.parse_header(rsc_file)[ifc.PYRATE_DATUM] else: raise roipac.RoipacException('No DEM resource/header file is ' 'provided') dest_base_ifgs = [os.path.join(params[cf.OUT_DIR], os.path.basename(q).split('.')[0] + '_' + os.path.basename(q).split('.')[1] + '.tif') for q in base_ifg_paths] for b, d in zip(base_ifg_paths, dest_base_ifgs): header_file = "%s.%s" % (b, ROI_PAC_HEADER_FILE_EXT) header = roipac.manage_header(header_file, projection) write_geotiff(header, b, d, nodata=params[cf.NO_DATA_VALUE]) prepifg.prepare_ifgs( dest_base_ifgs, crop_opt=crop, xlooks=xlooks, ylooks=ylooks)
def test_parse_full_roipac_header(self): # Ensures "long style" original header can be parsed correctly hdrs = roipac.parse_header(FULL_HEADER_PATH) # check DATE/ DATE12 fields are parsed correctly date0 = date(2006, 6, 19) # from "DATE 060619" header date2 = date(2006, 8, 28) # from DATE12 060619-060828 self.assertEqual(hdrs[ifc.MASTER_DATE], date0) self.assertEqual(hdrs[ifc.SLAVE_DATE], date2)
def test_parse_short_roipac_header(self): hdrs = roipac.parse_header(SHORT_HEADER_PATH) self.assertEqual(hdrs[ifc.PYRATE_NCOLS], 47) self.assertEqual(hdrs[ifc.PYRATE_NROWS], 72) self.assertAlmostEqual(hdrs[ifc.PYRATE_LONG], 150.910) self.assertEqual(hdrs[ifc.PYRATE_X_STEP], 0.000833333) self.assertEqual(hdrs[ifc.PYRATE_LAT], -34.170000000) self.assertEqual(hdrs[ifc.PYRATE_Y_STEP], -0.000833333) self.assertEqual(hdrs[ifc.PYRATE_WAVELENGTH_METRES], 0.0562356424)
def test_parse_short_header_has_timespan(self): # Ensures TIME_SPAN_YEAR field is added during parsing hdrs = roipac.parse_header(SHORT_HEADER_PATH) self.assertIn(roipac.TIME_SPAN_YEAR, hdrs.keys()) # check time span calc master = date(2006, 6, 19) slave = date(2006, 10, 2) diff = (slave - master).days / ifc.DAYS_PER_YEAR self.assertEqual(diff, hdrs[roipac.TIME_SPAN_YEAR])
def test_to_geotiff_dem(self): hdr = roipac.parse_header(SML_TEST_DEM_HDR) self.dest = os.path.join(TEMPDIR, "tmp_roipac_dem.tif") write_geotiff(hdr, SML_TEST_DEM_ROIPAC, self.dest, nodata=0) exp_path = join(SML_TEST_DEM_DIR, 'roipac_test_trimmed.tif') exp_ds = gdal.Open(exp_path) ds = gdal.Open(self.dest) # compare data and geographic headers assert_array_almost_equal(exp_ds.ReadAsArray(), ds.ReadAsArray()) self.compare_rasters(ds, exp_ds) self.assertIsNotNone(ds.GetMetadata())
def requires(self): if self.resourceHeader is not None: header = parse_header(self.resourceHeader) if ifc.PYRATE_DATUM not in header: raise Exception('Error: header/resource file does not ' 'include DATUM and -p option not given') projection = header[ifc.PYRATE_DATUM] else: if self.projection: projection = self.projection else: raise Exception('Error: no header/resource file given ' 'and -p option not specified') ifg_files = self.ifg_list(tif=False) tasks = [ ConvertFileToGeotiff(inputFile=path, projection=projection) for path in ifg_files ] return tasks
def test_xylast(self): # Test the X_LAST and Y_LAST header elements are calculated hdrs = roipac.parse_header(FULL_HEADER_PATH) self.assertAlmostEqual(hdrs[roipac.X_LAST], 151.8519444445) self.assertAlmostEqual(hdrs[roipac.Y_LAST], -34.625)
def test_read_full_roipac_header2(self): # Tests header from cropped original dataset is parsed correctly hdrs = roipac.parse_header(FULL_HEADER_PATH) self.assertTrue(len(hdrs) is not None)
def setUpClass(cls): hdr_path = join(PREP_TEST_OBS, 'geo_060619-061002.unw.rsc') cls.HDRS = roipac.parse_header(hdr_path)