Exemplo n.º 1
0
    def download(self):
        """
        Download a specific set of Gipps to the given folder.
        First, attempt to download the most recent git archive containing the .EEF files as well as the
        url to download the LUTs. Then, the latter will be downloaded separately.
        :return:
        """
        import shutil
        from Common import FileSystem
        self.out_path = os.path.join(self.fpath, self.gipp_folder_name)
        FileSystem.download_file(self.url, self.gipp_archive, self.log_level)
        FileSystem.unzip(self.gipp_archive, self.temp_folder)
        gipp_maja_git = os.path.join(self.temp_folder, "maja-gipp-master")
        # TODO Remove second WATV for Venus-Natif
        platform_folder = FileSystem.find_single(path=gipp_maja_git,
                                                 pattern="^" +
                                                 self.gipp_folder_name + "$")
        if not platform_folder:
            self.__clean_up()
            raise OSError("Cannot find any gipp folder for platform %s" %
                          self.gipp_folder_name)
        readme = FileSystem.find_single(path=platform_folder,
                                        pattern="readme*")
        if not readme:
            self.__clean_up()
            raise OSError("Cannot find download-file for LUT-Download in %s" %
                          platform_folder)
        lut_url = FileSystem.find_in_file(readme, self.zenodo_reg)
        if not lut_url:
            self.__clean_up()
            raise OSError("Cannot find url to download LUTs")
        FileSystem.download_file(lut_url, self.lut_archive, self.log_level)
        FileSystem.unzip(self.lut_archive, platform_folder)
        lut_folder = FileSystem.find_single(path=platform_folder,
                                            pattern="LUTs")
        if not lut_folder:
            self.__clean_up()
            raise OSError("Cannot find 'LUTs' folder in %s" % self.temp_folder)
        for f in os.listdir(lut_folder):
            shutil.move(os.path.join(lut_folder, f), platform_folder)

        if os.path.isdir(self.out_path):
            FileSystem.remove_directory(self.out_path)
        shutil.move(platform_folder, self.out_path)
        self.__clean_up()
        FileSystem.remove_directory(lut_folder)
        # Sanity check:
        if not self.check_completeness():
            raise ValueError(
                "GIPP download failed. Please delete gipp/ folder and try again."
            )
Exemplo n.º 2
0
    def prepare_mnt(self):
        """
        Prepare the eudem files.

        :return: Path to the full resolution DEM file.gsw
        :rtype: str
        """
        # Find/Download EuDEM archives:
        eudem_files = self.get_raw_data()
        # Unzip the downloaded/found EuDEM zip files:
        unzipped = []
        for arch in eudem_files:
            basename = os.path.splitext(os.path.basename(arch))[0]
            FileSystem.unzip(arch, self.wdir)
            fn_unzipped = FileSystem.find_single(pattern=basename + ".TIF$",
                                                 path=self.wdir)
            unzipped.append(fn_unzipped)
        # Fusion of all EuDEM files
        ds_cropped = []
        for fn in unzipped:
            ds = ImageTools.gdal_warp(fn,
                                      of="GTiff",
                                      ot="Int16",
                                      r="cubic",
                                      te=self.site.te_str,
                                      t_srs=self.site.epsg_str,
                                      tr=self.site.tr_str,
                                      multi=True)
            ds.array[ds.array < self.lowest_allowed_height] = -32767
            ds_cropped.append(ds)
        eudem_full_res = os.path.join(self.wdir,
                                      "eudem_%sm.tif" % int(self.site.res_x))
        ImageTools.gdal_merge(*ds_cropped,
                              dst=eudem_full_res,
                              n=-32767,
                              a_nodata=0,
                              q=True)
        return eudem_full_res
Exemplo n.º 3
0
    def prepare_mnt(self):
        """
        Prepare the srtm files.

        :return: Path to the full resolution DEM file.gsw
        :rtype: str
        """
        # Find/Download SRTM archives:
        srtm_archives = self.get_raw_data()
        # Unzip the downloaded/found srtm zip files:
        unzipped = []
        for arch in srtm_archives:
            basename = os.path.splitext(os.path.basename(arch))[0]
            FileSystem.unzip(arch, self.wdir)
            fn_unzipped = FileSystem.find_single(pattern=basename + ".tif",
                                                 path=self.wdir)
            unzipped.append(fn_unzipped)
        # Fusion of all SRTM files
        concat = ImageTools.gdal_buildvrt(*unzipped, vrtnodata=-32768)
        # Set nodata to 0
        nodata = ImageTools.gdal_warp(concat,
                                      srcnodata=-32768,
                                      dstnodata=0,
                                      multi=True)
        # Combine to image of fixed extent
        srtm_full_res = os.path.join(self.wdir,
                                     "srtm_%sm.tif" % int(self.site.res_x))
        ImageTools.gdal_warp(nodata,
                             dst=srtm_full_res,
                             r="cubic",
                             te=self.site.te_str,
                             t_srs=self.site.epsg_str,
                             tr=self.site.tr_str,
                             dstnodata=0,
                             srcnodata=0,
                             multi=True)
        return srtm_full_res