# Path: karta/raster/_gdal.py
# ALL = -1
# NUMPY_DTYPE = {"Byte": np.uint8,
#                "UInt16": np.uint16,
#                "Int16": np.int16,
#                "UInt32": np.uint32,
#                "Int32": np.int32,
#                "Float32": np.float32,
#                "Float64": np.float64,
#                "CInt16": np.complex64,
#                "CInt32": np.complex64,
#                "CFloat32": np.complex64,
#                "CFloat64": np.complex64}
# class GdalFileBand(object):
#     def __init__(self, band, dataset):
#     def __del__(self):
#     def getblock(self, yoff, xoff, ny, nx):
#     def setblock(self, yoff, xoff, array):
#     def __iter__(self):
#     def size(self):
#     def dtype(self):
# def SRS_from_WKT(s):
# def numpy_dtype(dt_int):
# def gdal_type(dtype):
# def read(fnm, in_memory, ibands=ALL, bandclass=CompressedBand):
# def srs_from_crs(crs):
# def write(fnm, grid, compress=None, tiled=False, **kw):


import unittest
import os.path
import numpy as np
import karta
from test_helper import TMPDATA
from karta.raster import _gdal
    def test_numpy_type_coercion(self):
        self.assertEqual(_gdal.numpy_dtype(2), np.uint16)
        self.assertEqual(_gdal.numpy_dtype(3), np.int16)
        self.assertEqual(_gdal.numpy_dtype(4), np.uint32)
        self.assertEqual(_gdal.numpy_dtype(5), np.int32)
        self.assertEqual(_gdal.numpy_dtype(6), np.float32)
        self.assertEqual(_gdal.numpy_dtype(7), np.float64)
        self.assertEqual(_gdal.numpy_dtype(8), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(9), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(10), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(11), np.complex64)
        return

    def test_write_read(self):
        # try writing a file, then read it back in and verify that it matches
        v = peaks(500)[:100,:]
        utm7 = karta.crs.ProjectedCRS("+proj=utm +zone=7 +north +datum=WGS84",
                                      "UTM 7N (WGS 84)")
        g = karta.RegularGrid([15.0, 15.0, 30.0, 30.0, 0.0, 0.0], v, crs=utm7)

        fpath = os.path.join(TMPDATA, "test.tif")
        ret = g.to_geotiff(fpath, compress=None)
        self.assertEqual(ret, g)
        gnew = karta.read_geotiff(fpath)

        self.assertTrue("+proj=utm" in gnew.crs.get_proj4())
        self.assertTrue("+zone=7" in gnew.crs.get_proj4())
        self.assertEqual(g.transform, gnew.transform)
        self.assertEqual(g.values.dtype, gnew.values.dtype)
        self.assertTrue(np.all(g[:,:] == gnew[:,:]))

# Path: karta/raster/_gdal.py
# ALL = -1
# NUMPY_DTYPE = {"Byte": np.uint8,
#                "UInt16": np.uint16,
#                "Int16": np.int16,
#                "UInt32": np.uint32,
#                "Int32": np.int32,
#                "Float32": np.float32,
#                "Float64": np.float64,
#                "CInt16": np.complex64,
#                "CInt32": np.complex64,
#                "CFloat32": np.complex64,
#                "CFloat64": np.complex64}
# class GdalFileBand(object):
#     def __init__(self, band, dataset):
#     def __del__(self):
#     def getblock(self, yoff, xoff, ny, nx):
#     def setblock(self, yoff, xoff, array):
#     def __iter__(self):
#     def size(self):
#     def dtype(self):
# def SRS_from_WKT(s):
# def numpy_dtype(dt_int):
# def gdal_type(dtype):
# def read(fnm, in_memory, ibands=ALL, bandclass=CompressedBand):
# def srs_from_crs(crs):
# def write(fnm, grid, compress=None, tiled=False, **kw):


# Path: tests/geotiff_tests.py
import unittest
import os.path
import numpy as np
import karta
from test_helper import TMPDATA
from karta.raster import _gdal

    def test_numpy_type_coercion(self):
        self.assertEqual(_gdal.numpy_dtype(2), np.uint16)
        self.assertEqual(_gdal.numpy_dtype(3), np.int16)
        self.assertEqual(_gdal.numpy_dtype(4), np.uint32)
        self.assertEqual(_gdal.numpy_dtype(5), np.int32)
        self.assertEqual(_gdal.numpy_dtype(6), np.float32)
        self.assertEqual(_gdal.numpy_dtype(7), np.float64)
        self.assertEqual(_gdal.numpy_dtype(8), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(9), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(10), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(11), np.complex64)
        return

    def test_write_read(self):
        # try writing a file, then read it back in and verify that it matches
        v = peaks(500)[:100,:]
        utm7 = karta.crs.ProjectedCRS("+proj=utm +zone=7 +north +datum=WGS84",
                                      "UTM 7N (WGS 84)")
        g = karta.RegularGrid([15.0, 15.0, 30.0, 30.0, 0.0, 0.0], v, crs=utm7)

        fpath = os.path.join(TMPDATA, "test.tif")
        ret = g.to_geotiff(fpath, compress=None)
        self.assertEqual(ret, g)
        gnew = karta.read_geotiff(fpath)

        self.assertTrue("+proj=utm" in gnew.crs.get_proj4())
        self.assertTrue("+zone=7" in gnew.crs.get_proj4())
        self.assertEqual(g.transform, gnew.transform)
        self.assertEqual(g.values.dtype, gnew.values.dtype)
        self.assertTrue(np.all(g[:,:] == gnew[:,:]))

        return