예제 #1
0
 def run(self):
     """
     Overload of :py:meth:`luigi.Task.run`.
     """
     combined_header = manage_headers(self.demHeaderFile, self.header_paths)
     write_geotiff(combined_header, self.input_file, self.out_file,
                   self.no_data_value)
예제 #2
0
 def run(self):
     """
     Overload of :py:meth:`luigi.Task.run`.
     """
     header = manage_header(self.header_file, self.projection)
     write_geotiff(header, self.inputFile, self.output_file,
                   self.no_data_value)
예제 #3
0
    def test_to_geotiff_ifg(self):
        self.dest = os.path.join(TEMPDIR, 'tmp_gamma_ifg.tif')
        data_path = join(GAMMA_TEST_DIR,
                         '16x20_20090713-20090817_VV_4rlks_utm.unw')
        write_geotiff(self.COMBINED, data_path, self.dest, nodata=0)

        ds = gdal.Open(self.dest)
        exp_path = join(GAMMA_TEST_DIR,
                        '16x20_20090713-20090817_VV_4rlks_utm.tif')
        exp_ds = gdal.Open(exp_path)

        # compare data and geographic headers
        assert_array_almost_equal(exp_ds.ReadAsArray(), ds.ReadAsArray())
        self.compare_rasters(ds, exp_ds)

        md = ds.GetMetadata()
        self.assertEqual(len(md), 11)  # 11 metadata items
        self.assertTrue(md[ifc.MASTER_DATE] == str(date(2009, 7, 13)))
        self.assertTrue(md[ifc.SLAVE_DATE] == str(date(2009, 8, 17)))
        self.assertTrue(md[ifc.PYRATE_TIME_SPAN] == str(35 /
                                                        ifc.DAYS_PER_YEAR))
        self.assertTrue(md[ifc.MASTER_TIME]) == str(12)
        self.assertTrue(md[ifc.SLAVE_TIME]) == str(time(12))

        wavelen = float(md[ifc.PYRATE_WAVELENGTH_METRES])
        self.assertAlmostEqual(wavelen, 0.05627457792190739)
예제 #4
0
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)
예제 #5
0
    def test_to_geotiff_ifg(self):
        # tricker: needs ifg header, and DEM one for extents
        hdrs = self.HDRS.copy()
        hdrs[ifc.PYRATE_DATUM] = 'WGS84'
        hdrs[ifc.DATA_TYPE] = ifc.ORIG

        self.dest = os.path.join('tmp_roipac_ifg.tif')
        data_path = join(PREP_TEST_OBS, 'geo_060619-061002.unw')
        write_geotiff(hdrs, data_path, self.dest, nodata=0)

        ds = gdal.Open(self.dest)
        band = ds.GetRasterBand(1)
        self.assertEqual(ds.RasterCount, 1)

        exp_path = join(PREP_TEST_TIF, 'geo_060619-061002.tif')
        exp_ds = gdal.Open(exp_path)
        exp_band = exp_ds.GetRasterBand(1)

        # compare data and geographic headers
        assert_array_almost_equal(exp_band.ReadAsArray(), band.ReadAsArray())
        self.compare_rasters(ds, exp_ds)

        md = ds.GetMetadata()
        date1 = date(2006, 6, 19)
        date2 = date(2006, 10, 2)
        diff = (date2 - date1).days
        self.assertTrue(md[ifc.MASTER_DATE] == str(date1))
        self.assertTrue(md[ifc.SLAVE_DATE] == str(date2))
        self.assertTrue(md[ifc.PYRATE_TIME_SPAN] == str(diff /
                                                        ifc.DAYS_PER_YEAR))

        wavelen = float(md[ifc.PYRATE_WAVELENGTH_METRES])
        self.assertAlmostEqual(wavelen, 0.0562356424)
예제 #6
0
def _gamma_multiprocessing(unw_path, params):
    """
    Multiprocessing wrapper for GAMMA full-res geotiff conversion
    """
    dem_hdr_path = params[cf.DEM_HEADER_FILE]
    slc_dir = params[cf.SLC_DIR]
    header_paths = get_header_paths(unw_path, slc_dir=slc_dir)
    combined_headers = gamma.manage_headers(dem_hdr_path, header_paths)
    dest = output_tiff_filename(unw_path, params[cf.OUT_DIR])

    if os.path.basename(unw_path).split('.')[1] == (
            params[cf.APS_INCIDENCE_EXT] or params[cf.APS_ELEVATION_EXT]):
        # TODO: implement incidence class here
        combined_headers['FILE_TYPE'] = 'Incidence'

    # Create full-res geotiff if not already on disk
    if not os.path.exists(dest):
        write_geotiff(combined_headers,
                      unw_path,
                      dest,
                      nodata=params[cf.NO_DATA_VALUE])
    else:
        log.info("Full-res geotiff already exists")

    return dest
예제 #7
0
def gamma_multiprocessing(unw_path, params):
    """
    Gamma multiprocessing wrapper for geotif conversion.

    :param unw_path: Wnwrapped interferogram path
    :param params: Parameters dictionary corresponding to config file
    
    :return xxxx
    """
    dem_hdr_path = params[cf.DEM_HEADER_FILE]
    slc_dir = params[cf.SLC_DIR]
    mkdir_p(params[cf.OUT_DIR])
    header_paths = gamma_task.get_header_paths(unw_path, slc_dir=slc_dir)
    combined_headers = gamma.manage_headers(dem_hdr_path, header_paths)

    dest = output_tiff_filename(unw_path, params[cf.OUT_DIR])
    if os.path.basename(unw_path).split('.')[1] == \
            (params[cf.APS_INCIDENCE_EXT] or params[cf.APS_ELEVATION_EXT]):
        # TODO: implement incidence class here
        combined_headers['FILE_TYPE'] = 'Incidence'

    write_geotiff(combined_headers,
                  unw_path,
                  dest,
                  nodata=params[cf.NO_DATA_VALUE])
    return dest
예제 #8
0
    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())
예제 #9
0
    def test_to_geotiff_dem(self):
        hdr_path = join(GAMMA_TEST_DIR, 'dem16x20raw.dem.par')
        hdr = gamma.parse_dem_header(hdr_path)
        data_path = join(GAMMA_TEST_DIR, 'dem16x20raw.dem')
        self.dest = os.path.join(TEMPDIR, "tmp_gamma_dem.tif")

        write_geotiff(hdr, data_path, self.dest, nodata=0)
        exp_path = join(GAMMA_TEST_DIR, 'dem16x20_subset_from_gamma.tif')
        exp_ds = gdal.Open(exp_path)
        ds = gdal.Open(self.dest)

        # compare data and geographic headers
        # HACK: round  expected to nearest integer
        assert_array_almost_equal(np.rint(exp_ds.ReadAsArray()),
                                  ds.ReadAsArray())
        self.compare_rasters(exp_ds, ds)
        md = ds.GetMetadata()
        self.assertTrue(md['AREA_OR_POINT'] == 'Area')
예제 #10
0
    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)