Example #1
0
 def _check_dtype(self, dtype, gdal_dtype):
     cube = self._cube(dtype)
     with self.temp_filename(".tif") as temp_filename:
         export_geotiff(cube, temp_filename)
         dataset = gdal.Open(temp_filename, gdal.GA_ReadOnly)
         band = dataset.GetRasterBand(1)
         self.assertEqual(band.DataType, gdal_dtype)
         self.assertEqual(band.ComputeRasterMinMax(1), (20, 31))
Example #2
0
 def test_ellipsoid(self):
     cube = self._cube(GeogCS(6377000, 6360000))
     with self.temp_filename('.tif') as temp_filename:
         export_geotiff(cube, temp_filename)
         dataset = gdal.Open(temp_filename, gdal.GA_ReadOnly)
         self.assertEqual(
             dataset.GetProjection(),
             'GEOGCS["unnamed ellipse",DATUM["unknown",'
             'SPHEROID["unnamed",6377000,375.117647058816]],'
             'PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]')
Example #3
0
 def test_(self):
     data = np.arange(12).reshape(3, 4).astype(np.uint8)
     cube = Cube(data, "air_pressure_anomaly")
     coord = DimCoord([30, 40, 50], "latitude", units="degrees")
     coord.guess_bounds()
     cube.add_dim_coord(coord, 0)
     coord = DimCoord([-10, -5, 0, 5], "longitude", units="degrees")
     coord.guess_bounds()
     cube.add_dim_coord(coord, 1)
     with self.temp_filename(".tif") as temp_filename:
         export_geotiff(cube, temp_filename)
         dataset = gdal.Open(temp_filename, gdal.GA_ReadOnly)
         self.assertEqual(dataset.GetGeoTransform(), (-12.5, 5, 0, 55, 0, -10))
Example #4
0
 def test_ellipsoid(self):
     cube = self._cube(GeogCS(6377000, 6360000))
     with self.temp_filename(".tif") as temp_filename:
         export_geotiff(cube, temp_filename)
         dataset = gdal.Open(temp_filename, gdal.GA_ReadOnly)
         projection_string = dataset.GetProjection()
         # String has embedded floating point values,
         # Test with values to N decimal places, using a regular expression.
         re_pattern = (
             r'GEOGCS\["unnamed ellipse",DATUM\["unknown",'
             r'SPHEROID\["unnamed",637....,375.117[0-9]*\]\],'
             r'PRIMEM\["Greenwich",0\],UNIT\["degree",0.01745[0-9]*\]\]'
         )
         re_exp = re.compile(re_pattern)
         self.assertIsNotNone(
             re_exp.match(projection_string),
             "projection string {!r} does not match {!r}".format(projection_string, re_pattern),
         )
Example #5
0
 def test_no_ellipsoid(self):
     cube = self._cube()
     with self.temp_filename(".tif") as temp_filename:
         export_geotiff(cube, temp_filename)
         dataset = gdal.Open(temp_filename, gdal.GA_ReadOnly)
         self.assertEqual(dataset.GetProjection(), "")
Example #6
0
 def test_invalid(self):
     cube = self._cube("i1")
     with self.assertRaises(ValueError):
         with self.temp_filename(".tif") as temp_filename:
             export_geotiff(cube, temp_filename)