コード例 #1
0
    def _get_coeff_filenames(self):
        """Retrieve necessary files for coefficients if needed."""
        coeff_fn = {'sea': None, 'land': None}
        if self.platform_name == "noaa-20":
            coeff_fn['land'] = retrieve("readers/limbcoef_atmsland_noaa20.txt")
            coeff_fn['sea'] = retrieve("readers/limbcoef_atmssea_noaa20.txt")
        if self.platform_name == 'npp':
            coeff_fn['land'] = retrieve("readers/limbcoef_atmsland_snpp.txt")
            coeff_fn['sea'] = retrieve("readers/limbcoef_atmssea_snpp.txt")

        return coeff_fn
コード例 #2
0
 def test_retrieve(self):
     """Test retrieving a single file."""
     import satpy
     from satpy.aux_download import find_registerable_files, retrieve
     file_registry = {}
     with satpy.config.set(config_path=[self.tmpdir], data_dir=str(self.tmpdir)), \
          mock.patch('satpy.aux_download._FILE_REGISTRY', file_registry):
         comp_file = 'composites/README.rst'
         found_files = find_registerable_files()
         assert comp_file in found_files
         assert not self.tmpdir.join(comp_file).exists()
         retrieve(comp_file)
         assert self.tmpdir.join(comp_file).exists()
コード例 #3
0
    def test_no_downloads_in_tests(self):
        """Test that tests aren't allowed to download stuff."""
        import satpy
        from satpy.aux_download import register_file, retrieve

        file_registry = {}
        with satpy.config.set(config_path=[self.tmpdir], data_dir=str(self.tmpdir),
                              download_aux=True), \
             mock.patch('satpy.aux_download._FILE_REGISTRY', file_registry):
            cache_key = 'myfile.rst'
            register_file(README_URL, cache_key)
            assert not self.tmpdir.join(cache_key).exists()
            pytest.raises(RuntimeError, retrieve, cache_key)
            # touch the file so it gets created
            open(self.tmpdir.join(cache_key), 'w').close()
            # offline downloading should still be allowed
            with satpy.config.set(download_aux=False):
                retrieve(cache_key)
コード例 #4
0
    def _get_average_elevation(self):
        if self.dem_cache_key is None:
            return

        LOG.debug("Loading CREFL averaged elevation information from: %s",
                  self.dem_cache_key)
        local_filename = retrieve(self.dem_cache_key)
        avg_elevation = self._read_var_from_hdf4_file(
            local_filename, self.dem_sds).astype(np.float64)
        if isinstance(avg_elevation, np.ma.MaskedArray):
            avg_elevation = avg_elevation.filled(np.nan)
        return avg_elevation
コード例 #5
0
    def test_offline_retrieve(self):
        """Test retrieving a single file when offline."""
        import satpy
        from satpy.aux_download import find_registerable_files, retrieve
        file_registry = {}
        with satpy.config.set(config_path=[self.tmpdir], data_dir=str(self.tmpdir), download_aux=True), \
             mock.patch('satpy.aux_download._FILE_REGISTRY', file_registry):
            comp_file = 'composites/README.rst'
            found_files = find_registerable_files()
            assert comp_file in found_files

            # the file doesn't exist, we can't download it
            assert not self.tmpdir.join(comp_file).exists()
            with satpy.config.set(download_aux=False):
                pytest.raises(RuntimeError, retrieve, comp_file)

            # allow downloading and get it
            retrieve(comp_file)
            assert self.tmpdir.join(comp_file).exists()

            # turn off downloading and make sure we get local file
            with satpy.config.set(download_aux=False):
                local_file = retrieve(comp_file)
                assert local_file
コード例 #6
0
    def _get_average_elevation(self):
        if self.dem_cache_key is None:
            return

        LOG.debug("Loading CREFL averaged elevation information from: %s",
                  self.dem_cache_key)
        local_filename = retrieve(self.dem_cache_key)
        from netCDF4 import Dataset as NCDataset
        # HDF4 file, NetCDF library needs to be compiled with HDF4 support
        nc = NCDataset(local_filename, "r")
        # average elevation is stored as a 16-bit signed integer but with
        # scale factor 1 and offset 0, convert it to float here
        avg_elevation = nc.variables[self.dem_sds][:].astype(np.float64)
        if isinstance(avg_elevation, np.ma.MaskedArray):
            avg_elevation = avg_elevation.filled(np.nan)
        return avg_elevation
コード例 #7
0
 def _retrieve_data_file(self):
     from satpy.aux_download import retrieve
     if os.path.isabs(self._cache_filename):
         return self._cache_filename
     return retrieve(self._cache_key)