コード例 #1
0
class TestAGoodle(unittest.TestCase):
    def setUp(self):
        path = os.path.dirname(__file__)
        self.tifpath = os.path.join(path, 'data', 'raster.tif')
        self.ag = AGoodle(self.tifpath)

    def test_bbox_to_grid_coords(self):
        e = self.ag.ri
        rx = e.right - e.left
        ry = e.top - e.bottom
        bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
        coords, new_bbox = self.ag.bbox_to_grid_coords(bbox)
        assert 0 < coords[0] < coords[2] < self.ag.ri.ny
        assert 0 < coords[1] < coords[3] < self.ag.ri.nx

        for o, n in zip(bbox, new_bbox):
            assert abs(o - n) < 20, (o, n)


    def test_object_initialization(self):
        self.ag = AGoodle(self.tifpath)
        self.assert_(isinstance(self.ag, AGoodle))

    def test_read_array_bbox(self):
        e = self.ag.ri
        rx = e.right - e.left
        ry = e.top - e.bottom
        bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
        a = self.ag.read_array_bbox(bbox)
        assert hasattr(a, 'agoodle')

        # and with full extent
        a = self.ag.read_array_bbox()
        assert hasattr(a, 'agoodle')
コード例 #2
0
class TestAGoodle(unittest.TestCase):
    def setUp(self):
        path = os.path.dirname(__file__)
        self.tifpath = os.path.join(path, 'data', 'raster.tif')
        self.ag = AGoodle(self.tifpath)

    def test_bbox_to_grid_coords(self):
        e = self.ag.ri
        rx = e.right - e.left
        ry = e.top - e.bottom
        bbox = (e.left + rx / 2.1, e.bottom + ry / 2.1, e.right - rx / 2.1,
                e.top - ry / 2.1)
        coords, new_bbox = self.ag.bbox_to_grid_coords(bbox)
        assert 0 < coords[0] < coords[2] < self.ag.ri.ny
        assert 0 < coords[1] < coords[3] < self.ag.ri.nx

        for o, n in zip(bbox, new_bbox):
            assert abs(o - n) < 20, (o, n)

    def test_object_initialization(self):
        self.ag = AGoodle(self.tifpath)
        self.assert_(isinstance(self.ag, AGoodle))

    def test_read_array_bbox(self):
        e = self.ag.ri
        rx = e.right - e.left
        ry = e.top - e.bottom
        bbox = (e.left + rx / 2.1, e.bottom + ry / 2.1, e.right - rx / 2.1,
                e.top - ry / 2.1)
        a = self.ag.read_array_bbox(bbox)
        assert hasattr(a, 'agoodle')

        # and with full extent
        a = self.ag.read_array_bbox()
        assert hasattr(a, 'agoodle')
コード例 #3
0
 def setUp(self):
     path = os.path.dirname(__file__)
     self.tifpath = os.path.join(path, 'data', 'z.tif')
     self.ag = AGoodle(self.tifpath)
     extent = self.ag.ri.extent
     #rx, ry = e.right - e.left, e.top - e.bottom
     #bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
     self.a = self.ag.read_array_bbox(extent)
コード例 #4
0
 def setUp(self):
     path = os.path.dirname(__file__)
     self.tifpath = os.path.join(path, 'data', 'z.tif')
     self.ag = AGoodle(self.tifpath)
     extent = self.ag.ri.extent
     #rx, ry = e.right - e.left, e.top - e.bottom
     #bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
     self.a = self.ag.read_array_bbox(extent)
コード例 #5
0
def summarize_raster(filename,wkt):
    g = AGoodle(filename)
    srs = osr.SpatialReference()
    srs.ImportFromWkt(g.raster.GetProjection())
    pts, bbox = points_from_wkt(wkt, srs, srs)
    
    arr = g.read_array_bbox(bbox)
    # not working right, blows up in agoodle
    #arr.mask_with_poly(pts, copy=False)
    cell_area = abs(g.raster_info.xsize * g.raster_info.ysize)
    result = {}
    result['sum'] = str(arr.sum())
    result['max'] = str(arr.max())
    result['min'] = str(arr.min())
    result['mean'] = str(arr.mean())
    result['data_type'] = str(arr.dtype)
    result['area'] = str(len(arr) * cell_area)
    return result
コード例 #6
0
class TestGoodlearray(unittest.TestCase):
    def setUp(self):
        path = os.path.dirname(__file__)
        self.tifpath = os.path.join(path, 'data', 'z.tif')
        self.ag = AGoodle(self.tifpath)
        extent = self.ag.ri.extent
        #rx, ry = e.right - e.left, e.top - e.bottom
        #bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
        self.a = self.ag.read_array_bbox(extent)

    def test_mask_with_poly(self):
        a = self.a
        bbox = a.extent
        xcoords = np.linspace(bbox[0], bbox[2], 6)
        ycoords = list(np.linspace(bbox[1], bbox[3], 6))
        ycoords = ycoords[3:] + ycoords[:3]
        verts = zip(xcoords, ycoords)
        verts.append(verts[0])
        verts = np.array(verts)

        b = a.mask_with_poly(verts, copy=True, mask_value=0)
        assert b.sum() < a.sum()
        assert b.shape == a.shape

    def test_rw(self):
        self.a.to_raster('test_ost.tif')
        assert os.path.exists('test_ost.tif')

    def test_rw2index(self):
        a = self.a
        bbox = a.extent
        ix, iy = a.rw2index(bbox[0], bbox[1])
        assert ix == 0
        assert iy == a.shape[0] - 1, (iy, a.shape[0])
        ix, iy = a.rw2index(bbox[2], bbox[3])
        assert iy == 0
        assert ix == a.shape[1] - 1, (ix, a.shape[1])

    def tearDown(self):
        try:
            os.unlink('test_ost.tif')
        except:
            pass
コード例 #7
0
class TestGoodlearray(unittest.TestCase):
    def setUp(self):
        path = os.path.dirname(__file__)
        self.tifpath = os.path.join(path, 'data', 'z.tif')
        self.ag = AGoodle(self.tifpath)
        extent = self.ag.ri.extent
        #rx, ry = e.right - e.left, e.top - e.bottom
        #bbox = (e.left + rx/2.1, e.bottom + ry/2.1, e.right - rx/2.1, e.top - ry/2.1)
        self.a = self.ag.read_array_bbox(extent)

    def test_mask_with_poly(self):
        a = self.a
        bbox = a.extent
        xcoords = np.linspace(bbox[0], bbox[2], 6)
        ycoords = list(np.linspace(bbox[1], bbox[3], 6))
        ycoords = ycoords[3:] + ycoords[:3]
        verts = zip(xcoords, ycoords)
        verts.append(verts[0])
        verts = np.array(verts)

        b = a.mask_with_poly(verts, copy=True, mask_value=0)
        assert b.sum() < a.sum()
        assert b.shape == a.shape


    def test_rw(self):
        self.a.to_raster('test_ost.tif')
        assert os.path.exists('test_ost.tif')


    def test_rw2index(self):
        a = self.a
        bbox = a.extent
        ix, iy = a.rw2index(bbox[0], bbox[1])
        assert ix == 0 
        assert iy == a.shape[0] - 1, (iy, a.shape[0])
        ix, iy = a.rw2index(bbox[2], bbox[3])
        assert iy == 0 
        assert ix == a.shape[1] - 1, (ix, a.shape[1])

    def tearDown(self):
        try: os.unlink('test_ost.tif')
        except: pass
コード例 #8
0
             results = {}
             try:
                 surface_stats = summarize_raster(SURFACE,wkt)
                 results['surface'] = surface_stats
             except Exception, e:
                 results['error'] = str(e)
             # TODO - other rasters..
             mime = 'text/plain'
             response = json.dumps(results)
         else:
             response = '{"error":"wgs84_wkt param was empty!"}'
     else:
         response = '{"error":"nematodes without data are not sexy!"}'
 elif (path_info == '/meta'):
     mime = 'text/plain'
     g = AGoodle(SURFACE)
     meta = {}
     meta['extent'] = g.raster_info.extent
     meta['nx'] = g.raster_info.nx
     meta['ny'] = g.raster_info.ny
     meta['xsize'] = g.raster_info.xsize
     meta['ysize'] = g.raster_info.ysize
     response = json.dumps(meta)
     
 # root of app requested
 elif (path_info == '/'):
     mime = 'text/html'
     response = FileWrapper(open('index.html','rb'))
 elif (path_info == '/favicon.ico'):
     response = 'favicons are silly'
 else:
コード例 #9
0
 def setUp(self):
     path = os.path.dirname(__file__)
     self.tifpath = os.path.join(path, 'data', 'z.tif')
     self.ag = AGoodle(self.tifpath)
コード例 #10
0
 def test_object_initialization(self):
     self.ag = AGoodle(self.tifpath)
     self.assert_(isinstance(self.ag, AGoodle))
コード例 #11
0
import os.path as op
import numpy as np
from agoodle import AGoodle
import matplotlib
matplotlib.use('Agg')
import pylab

path = op.join(op.dirname(__file__), "..", "agoodle", "tests", "data", "z.tif")
g = AGoodle(path)
e = g.raster_info
rx = e.right - e.left
ry = e.top - e.bottom

# take a subset.
bbox = (e.left + rx/2.1, e.bottom + ry/2.1,
        e.right - rx/2.1, e.top - ry/2.1)
assert bbox[2] > bbox[0] and bbox[1] < bbox[3]

a = g.read_array_bbox(bbox)
assert hasattr(a, 'agoodle')

# save to a new tif.
a.to_raster('z.tif')

bbox = a.extent

# use rw2index to convert to array indexes.
ix, iy = a.rw2index(bbox[0], bbox[1])
assert ix == 0
ix, iy = a.rw2index(bbox[2], bbox[3])
assert ix == a.shape[1] - 1, (ix, a.shape[1])
コード例 #12
0
 def test_object_initialization(self):
     self.ag = AGoodle(self.tifpath)
     self.assert_(isinstance(self.ag, AGoodle))
コード例 #13
0
 def setUp(self):
     path = os.path.dirname(__file__)
     self.tifpath = os.path.join(path, 'data', 'raster.tif')
     self.ag = AGoodle(self.tifpath)