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 StartMaja.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-develop")
        # 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 get_raw_data(self):
        """
        Get the DEM raw-data from a given directory. If not existing, an attempt will be made to download
        it automatically.

        :return: A list of filenames containing the raw DEM data.
        :rtype: list of str
        """

        filenames = []
        for code in self.srtm_codes:
            current_url = srtm_url % code
            filename = os.path.basename(current_url)
            output_path = os.path.join(self.raw_dem, filename)
            if not os.path.isfile(output_path):
                # Download file:
                FileSystem.download_file(current_url, output_path, log_level=logging.INFO)
            filenames.append(output_path)
        return filenames