Ejemplo n.º 1
0
    def test_reproject_gcps_on_repro_gcps(self):
        n1 = Nansat(self.test_file_stere,
                    log_level=40,
                    mapper=self.default_mapper)
        n2 = Nansat(self.test_file_gcps,
                    log_level=40,
                    mapper=self.default_mapper)
        n2.reproject_gcps()
        n1.reproject(n2)
        tmpfilename = os.path.join(self.tmp_data_path,
                                   'nansat_reproject_gcps_on_repro_gcps.png')
        n1.write_figure(tmpfilename, 2, clim='hist')

        self.assertEqual(n1.shape(), n2.shape())
        self.assertEqual(type(n1[1]), np.ndarray)
Ejemplo n.º 2
0
 def test_export_option(self):
     n = Nansat(self.test_file_arctic, mapper=self.default_mapper)
     tmpfilename = os.path.join(self.tmp_data_path,
                                'nansat_export_option.nc')
     # Test with band numbers
     n.export(tmpfilename, options='WRITE_LONLAT=YES')
     n.export(tmpfilename + '2', options=['WRITE_LONLAT=NO'])
     nn = Nansat(tmpfilename, mapper=self.default_mapper)
     nn2 = Nansat(tmpfilename + '2', mapper=self.default_mapper)
     self.assertTrue(nn.has_band('lon'))
     self.assertTrue(nn.has_band('lat'))
     self.assertTrue(nn.has_band('Bristol'))
     self.assertFalse(nn2.has_band('lon'))
     self.assertFalse(nn2.has_band('lat'))
     self.assertTrue(nn2.has_band('Bristol'))
Ejemplo n.º 3
0
    def test_reproject_and_export_band(self):
        n1 = Nansat(self.test_file_gcps,
                    log_level=40,
                    mapper=self.default_mapper)
        n2 = Nansat(self.test_file_stere,
                    log_level=40,
                    mapper=self.default_mapper)
        n1.reproject(n2)
        tmpfilename = os.path.join(self.tmp_data_path,
                                   'nansat_reproject_export_band.nc')
        n1.export(tmpfilename, bands=[1])

        n = Nansat(tmpfilename, mapper=self.default_mapper)
        self.assertTrue(os.path.exists(tmpfilename))
        self.assertEqual(n.vrt.dataset.RasterCount, 1)
Ejemplo n.º 4
0
 def setUp(self):
     ''' Load test data '''
     testDir = os.getenv('ICE_DRIFT_TEST_DATA_DIR')
     if testDir is None:
         sys.exit('ICE_DRIFT_TEST_DATA_DIR is not defined')
     testFiles = sorted(glob.glob(os.path.join(testDir, 'S1A_*tif')))
     if len(testFiles) < 2:
         sys.exit('Not enough test files in %s' % testDir)
     self.n1 = Nansat(testFiles[0])
     self.n2 = Nansat(testFiles[1])
     self.img1 = self.n1['sigma0_HV']
     self.img2 = self.n2['sigma0_HV']
     self.imgMin = 0.001
     self.imgMax = 0.013
     self.nFeatures = 10000
Ejemplo n.º 5
0
    def test_get_metadata_wrong_key(self):
        n1 = Nansat(self.test_file_stere,
                    log_level=40,
                    mapper=self.default_mapper)

        with self.assertRaises(ValueError):
            n1.get_metadata('some_crap')
Ejemplo n.º 6
0
    def test_get_metadata_key(self):
        n1 = Nansat(self.test_file_stere,
                    log_level=40,
                    mapper=self.default_mapper)
        m = n1.get_metadata('filename')

        self.assertEqual(type(m), str)
Ejemplo n.º 7
0
    def test_write_figure_logo(self):
        n1 = Nansat(self.test_file_stere, log_level=40, mapper=self.default_mapper)
        tmpfilename = os.path.join(self.tmp_data_path, 'nansat_write_figure_logo.png')
        n1.write_figure(tmpfilename, 3, clim='hist',
                        logoFileName=self.test_file_gcps)

        self.assertTrue(os.path.exists(tmpfilename))
Ejemplo n.º 8
0
    def test_get_auto_ticks_vector(self):
        n = Nansat(self.test_file_gcps)
        lon, lat = n.get_geolocation_grids()
        f = Figure(lon)
        lonTicks = f._get_auto_ticks([28, 29, 30, 100], lon)

        self.assertEqual(len(lonTicks), 3)
Ejemplo n.º 9
0
    def test_write_geotiffimage(self):
        n1 = Nansat(self.test_file_stere, logLevel=40)
        tmpfilename = os.path.join(ntd.tmp_data_path,
                                   'nansat_write_geotiffimage.tif')
        n1.write_geotiffimage(tmpfilename)

        self.assertTrue(os.path.exists(tmpfilename))
Ejemplo n.º 10
0
    def test_get_GDALRasterBand(self):
        n = Nansat(self.test_file_gcps, logLevel=40)
        b = n.get_GDALRasterBand(1)
        arr = b.ReadAsArray()

        self.assertEqual(type(b), gdal.Band)
        self.assertEqual(type(arr), np.ndarray)
Ejemplo n.º 11
0
 def test_get_invalid_mask_all_valid(self):
     n = Nansat(self.testFiles[0])
     img = n[1]
     mask = np.zeros((np.array(img.shape) / 20).astype(int))
     n.watermask = MagicMock(return_value=[None, mask])
     mask = get_invalid_mask(img, n, 20)
     self.assertEqual(np.where(mask)[0].size, 0)
Ejemplo n.º 12
0
 def test_example2(self):
     n = Nansat(self.tmp_ncfile)
     res = n.export2thredds(self.filename_exported,
                            {'x_wind_10m': {
                                'description': 'example'
                            }})
     self.assertEqual(res, None)
Ejemplo n.º 13
0
 def test_export_add_geoloc(self, mock_add_geolocation):
     n = Nansat(self.test_file_arctic, mapper=self.default_mapper)
     with warnings.catch_warnings(record=True) as recorded_warnings:
         n.export(self.tmp_filename, addGeoloc=True)
         self.assertEqual(recorded_warnings[0].category,
                          NansatFutureWarning)
     self.assertTrue(mock_add_geolocation.called)
    def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
        ''' Create VRT '''

        ##############
        # Get time
        ##############
        if fileName[0:len(keywordBase)] != keywordBase:
            raise AttributeError("Wrong mapper")

        timestr = fileName[len(keywordBase)+1::]
        time = datetime.strptime(timestr, '%Y%m%d%H%M')

        ######################################################
        # Find windFileName corresponding to a Nansat-readable
        # file in your local (or remote) file archive
        ######################################################
        windFileName = localFolder + <.......>

        ######################################################
        # Open file with any other Nansat mapper
        ######################################################
        w = Nansat(windFileName)
        VRT.__init__(self, vrtDataset=w.vrt.dataset)

        return
Ejemplo n.º 15
0
    def test_from_domain_nansat(self):
        n1 = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
        n2 = Nansat.from_domain(n1, n1[1])

        self.assertEqual(type(n2), Nansat)
        self.assertEqual(len(n2.bands()), 1)
        self.assertEqual(type(n2[1]), np.ndarray)
Ejemplo n.º 16
0
 def test_crop_interactive(self, mock_digitize_points):
     mock_digitize_points.return_value = [np.array([[10, 20], [10, 30]])]
     n = Nansat(self.test_file_arctic,
                log_level=40,
                mapper=self.default_mapper)
     n.crop_interactive()
     self.assertEqual(n.shape(), (20, 10))
Ejemplo n.º 17
0
    def test_open_gcps(self):
        n = Nansat(self.test_file_gcps, logLevel=40)

        self.assertEqual(type(n), Nansat)
        self.assertEqual(n.vrt.dataset.GetProjection(), '')
        self.assertTrue(
            (n.vrt.dataset.GetGCPProjection().startswith('GEOGCS["WGS 84",')))
Ejemplo n.º 18
0
    def test_resize_by_height(self):
        n = Nansat(self.test_file_gcps,
                   log_level=40,
                   mapper=self.default_mapper)
        n.resize(height=500, resample_alg=1)

        self.assertEqual(type(n[1]), np.ndarray)
Ejemplo n.º 19
0
    def test_write_figure_legend(self):
        n1 = Nansat(self.test_file_stere, logLevel=40)
        tmpfilename = os.path.join(ntd.tmp_data_path,
                                   'nansat_write_figure_legend.png')
        n1.write_figure(tmpfilename, 3, clim='hist', legend=True)

        self.assertTrue(os.path.exists(tmpfilename))
Ejemplo n.º 20
0
    def test_resize_complex_alg4(self):
        n = Nansat(self.test_file_complex,
                   log_level=40,
                   mapper=self.default_mapper)
        n.resize(0.5, resample_alg=4)

        self.assertTrue(np.any(n[1].imag != 0))
Ejemplo n.º 21
0
    def test_crop_complex(self):
        n1 = Nansat(self.test_file_complex, logLevel=40)
        ext = n1.crop(10, 20, 50, 60)

        self.assertEqual(n1.shape(), (60, 50))
        self.assertEqual(ext, (10, 20, 50, 60))
        self.assertEqual(type(n1[1]), np.ndarray)
Ejemplo n.º 22
0
    def test_list_bands_true(self):
        n = Nansat(self.test_file_gcps,
                   log_level=40,
                   mapper=self.default_mapper)
        lb = n.list_bands(True)

        self.assertEqual(lb, None)
Ejemplo n.º 23
0
    def test_get_GDALRasterBand_if_bandID_is_given(self):
        n = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
        b = n.get_GDALRasterBand(bandID=1)
        arr = b.ReadAsArray()

        self.assertEqual(type(b), gdal.Band)
        self.assertEqual(type(arr), np.ndarray)
Ejemplo n.º 24
0
    def test_list_bands_false(self):
        n = Nansat(self.test_file_gcps,
                   log_level=40,
                   mapper=self.default_mapper)
        lb = n.list_bands(False)

        self.assertEqual(type(lb), str)
Ejemplo n.º 25
0
    def test_get_time_coverage_start_end(self):
        n = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
        n.set_metadata('time_coverage_start', '2016-01-20')
        n.set_metadata('time_coverage_end', '2016-01-21')

        self.assertEqual(type(n.time_coverage_start), datetime.datetime)
        self.assertEqual(type(n.time_coverage_end), datetime.datetime)
Ejemplo n.º 26
0
 def test_watermask_fail_if_mod44path_not_exist(self):
     """ Nansat.watermask should raise an IOError"""
     n1 = Nansat(self.test_file_gcps,
                 log_level=40,
                 mapper=self.default_mapper)
     del os.environ['MOD44WPATH']
     self.assertRaises(IOError, n1.watermask)
Ejemplo n.º 27
0
 def test_extend(self):
     n = Nansat(self.test_file_arctic, log_level=40, mapper=self.default_mapper)
     nshape1 = n.shape()
     n.extend(left=10, right=20, top=30, bottom=40)
     be = n[1]
     self.assertEqual(n.shape(), (nshape1[0]+70, nshape1[1]+30))
     self.assertIsInstance(be, np.ndarray)
Ejemplo n.º 28
0
    def test_crop_no_gcps_arctic(self):
        n1 = Nansat(self.test_file_arctic, log_level=40, mapper=self.default_mapper)
        ext = n1.crop(10, 20, 50, 60)

        self.assertEqual(n1.shape(), (60, 50))
        self.assertEqual(ext, (10, 20, 50, 60))
        self.assertEqual(type(n1[1]), np.ndarray)
Ejemplo n.º 29
0
    def test_crop_lonlat(self):
        n1 = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
        ext = n1.crop_lonlat([28, 29], [70.5, 71])

        self.assertEqual(n1.shape(), (111, 110))
        self.assertEqual(ext, (31, 89, 110, 111))
        self.assertEqual(type(n1[1]), np.ndarray)
Ejemplo n.º 30
0
 def test_digitize_points(self, mock_PointBrowser):
     """ shall create PointBrowser and call PointBrowser.get_points() """
     value = 'points'
     mock_PointBrowser().get_points.return_value = value
     n = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
     points = n.digitize_points(1)
     self.assertTrue(mock_PointBrowser.called_once())
     self.assertEqual(points, value)