Browse Source

initial import tests dir

tags/v0.7.4
ocourtin 3 months ago
parent
commit
02607c4f62
24 changed files with 306 additions and 0 deletions
  1. +0
    -0
      tests/__init__.py
  2. BIN
      tests/fixtures/images/18/69105/105093.jpg
  3. BIN
      tests/fixtures/images/18/69108/105091.jpg
  4. BIN
      tests/fixtures/images/18/69108/105092.jpg
  5. BIN
      tests/fixtures/labels/18/69105/105093.png
  6. BIN
      tests/fixtures/labels/18/69108/105091.png
  7. BIN
      tests/fixtures/labels/18/69108/105092.png
  8. BIN
      tests/fixtures/osm/18/69105/105093.png
  9. BIN
      tests/fixtures/osm/18/69108/105091.png
  10. BIN
      tests/fixtures/osm/18/69108/105092.png
  11. +175
    -0
      tests/fixtures/parking/features.geojson
  12. BIN
      tests/fixtures/parking/images/18/69623/104946.webp
  13. BIN
      tests/fixtures/parking/images/18/70761/104120.webp
  14. BIN
      tests/fixtures/parking/images/18/70762/104119.webp
  15. BIN
      tests/fixtures/parking/images/18/70763/104119.webp
  16. BIN
      tests/fixtures/parking/labels/18/69623/104946.png
  17. BIN
      tests/fixtures/parking/labels/18/70761/104120.png
  18. BIN
      tests/fixtures/parking/labels/18/70762/104119.png
  19. BIN
      tests/fixtures/parking/labels/18/70763/104119.png
  20. +4
    -0
      tests/fixtures/parking/tiles.csv
  21. +3
    -0
      tests/fixtures/tiles.csv
  22. +47
    -0
      tests/loaders/test_semseg.py
  23. +28
    -0
      tests/test_tiles.py
  24. +49
    -0
      tests/tools/test_rasterize.py

+ 0
- 0
tests/__init__.py View File


BIN
tests/fixtures/images/18/69105/105093.jpg View File

Before After
Width: 512  |  Height: 512  |  Size: 47KB

BIN
tests/fixtures/images/18/69108/105091.jpg View File

Before After
Width: 512  |  Height: 512  |  Size: 38KB

BIN
tests/fixtures/images/18/69108/105092.jpg View File

Before After
Width: 512  |  Height: 512  |  Size: 41KB

BIN
tests/fixtures/labels/18/69105/105093.png View File

Before After
Width: 512  |  Height: 512  |  Size: 129B

BIN
tests/fixtures/labels/18/69108/105091.png View File

Before After
Width: 512  |  Height: 512  |  Size: 129B

BIN
tests/fixtures/labels/18/69108/105092.png View File

Before After
Width: 512  |  Height: 512  |  Size: 129B

BIN
tests/fixtures/osm/18/69105/105093.png View File

Before After
Width: 512  |  Height: 512  |  Size: 142B

BIN
tests/fixtures/osm/18/69108/105091.png View File

Before After
Width: 512  |  Height: 512  |  Size: 142B

BIN
tests/fixtures/osm/18/69108/105092.png View File

Before After
Width: 512  |  Height: 512  |  Size: 142B

+ 175
- 0
tests/fixtures/parking/features.geojson View File

@@ -0,0 +1,175 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-82.8224934,
34.6787452
],
[
-82.8216356,
34.6787385
],
[
-82.8215841,
34.6778632
],
[
-82.8218244,
34.6775386
],
[
-82.8220047,
34.6773692
],
[
-82.8234209,
34.6773974
],
[
-82.8234818,
34.6774475
],
[
-82.8235839,
34.6775315
],
[
-82.8236513,
34.6781899
],
[
-82.8230346,
34.6784279
],
[
-82.8226999,
34.6785903
],
[
-82.8224934,
34.6787452
]
]
]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-106.5503557,
35.1168049
],
[
-106.5503088,
35.1167621
],
[
-106.5501478,
35.1167522
],
[
-106.5500325,
35.1167511
],
[
-106.5500271,
35.1168959
],
[
-106.5500285,
35.1170813
],
[
-106.5500244,
35.1171098
],
[
-106.5499386,
35.117112
],
[
-106.5499476,
35.117322
],
[
-106.5500982,
35.1173248
],
[
-106.5502135,
35.1174938
],
[
-106.5502377,
35.1175256
],
[
-106.5502699,
35.117541
],
[
-106.5504858,
35.1175453
],
[
-106.5506865,
35.117536
],
[
-106.5506741,
35.1172861
],
[
-106.5506729,
35.1171422
],
[
-106.550573,
35.1171366
],
[
-106.5505423,
35.1170818
],
[
-106.5505412,
35.1170446
],
[
-106.5502641,
35.1170428
],
[
-106.55023,
35.1169657
],
[
-106.5502289,
35.1168654
],
[
-106.5503061,
35.1168412
],
[
-106.5503557,
35.1168049
]
]
]
},
"properties": {}
}
]
}

BIN
tests/fixtures/parking/images/18/69623/104946.webp View File

Before After

BIN
tests/fixtures/parking/images/18/70761/104120.webp View File

Before After

BIN
tests/fixtures/parking/images/18/70762/104119.webp View File

Before After

BIN
tests/fixtures/parking/images/18/70763/104119.webp View File

Before After

BIN
tests/fixtures/parking/labels/18/69623/104946.png View File

Before After
Width: 512  |  Height: 512  |  Size: 129B

BIN
tests/fixtures/parking/labels/18/70761/104120.png View File

Before After
Width: 512  |  Height: 512  |  Size: 604B

BIN
tests/fixtures/parking/labels/18/70762/104119.png View File

Before After
Width: 512  |  Height: 512  |  Size: 491B

BIN
tests/fixtures/parking/labels/18/70763/104119.png View File

Before After
Width: 512  |  Height: 512  |  Size: 190B

+ 4
- 0
tests/fixtures/parking/tiles.csv View File

@@ -0,0 +1,4 @@
70762,104119,18
69623,104946,18
70763,104119,18
70761,104120,18

+ 3
- 0
tests/fixtures/tiles.csv View File

@@ -0,0 +1,3 @@
69623,104945,18
69622,104945,18
69623,104946,18

+ 47
- 0
tests/loaders/test_semseg.py View File

@@ -0,0 +1,47 @@
import unittest

import torch
import mercantile

from neat_eo.loaders.semseg import SemSeg


class TestSemSeg(unittest.TestCase):
def test_len(self):
path = "tests/fixtures"
config = {
"channels": [{"name": "images", "bands": [1, 2, 3]}],
"classes": [{"title": "Building", "color": "deeppink"}],
"model": {"ts": (512, 512)},
"train": {"pretrained": True, "da": {"name": "RGB", "p": 1.0}},
}

# mode train
dataset = SemSeg(config, (512, 512), path, mode="train")
self.assertEqual(len(dataset), 3)

# mode predict
dataset = SemSeg(config, (512, 512), path, mode="predict")
self.assertEqual(len(dataset), 3)

def test_getitem(self):
path = "tests/fixtures"
config = {
"channels": [{"name": "images", "bands": [1, 2, 3]}],
"classes": [{"title": "Building", "color": "deeppink"}],
"model": {"ts": (512, 512)},
"train": {"pretrained": True, "da": {"name": "RGB", "p": 1.0}},
}

# mode train
dataset = SemSeg(config, (512, 512), path, mode="train")
image, mask, tile, weight = dataset[0]

assert tile == mercantile.Tile(69105, 105093, 18)
self.assertEqual(image.shape, torch.Size([3, 512, 512]))

# mode predict
dataset = SemSeg(config, (512, 512), path, mode="predict")
images, tiles = dataset[0]

self.assertEqual(type(images), torch.Tensor)

+ 28
- 0
tests/test_tiles.py View File

@@ -0,0 +1,28 @@
import unittest

import mercantile

from neat_eo.tiles import tiles_from_dir, tiles_from_csv


class TestSlippyMapTiles(unittest.TestCase):
def test_slippy_map_directory(self):
root = "tests/fixtures/images"
tiles = [(tile, path) for tile, path in tiles_from_dir(root, xyz_path=True)]
tiles.sort()

self.assertEqual(len(tiles), 3)

tile, path = tiles[0]
self.assertEqual(type(tile), mercantile.Tile)
self.assertEqual(path, "tests/fixtures/images/18/69105/105093.jpg")


class TestReadTiles(unittest.TestCase):
def test_read_tiles(self):
filename = "tests/fixtures/tiles.csv"
tiles = [tile for tile in tiles_from_csv(filename)]
tiles.sort()

self.assertEqual(len(tiles), 3)
self.assertEqual(tiles[1], mercantile.Tile(69623, 104945, 18))

+ 49
- 0
tests/tools/test_rasterize.py View File

@@ -0,0 +1,49 @@
import json
import unittest

import numpy as np
import mercantile

from PIL import Image

from neat_eo.geojson import geojson_tile_burn


def get_parking():
with open("tests/fixtures/parking/features.geojson") as f:
parking_fc = json.load(f)

assert len(parking_fc["features"]) == 2
return parking_fc


class TestBurn(unittest.TestCase):
def test_burn_with_feature(self):
parking_fc = get_parking()

# The tile below has a parking lot in our fixtures.
tile = mercantile.Tile(70762, 104119, 18)

rasterized = geojson_tile_burn(tile, parking_fc["features"], 4326, (512, 512))
rasterized = Image.fromarray(rasterized, mode="P")

# rasterized.save('rasterized.png')

self.assertEqual(rasterized.size, (512, 512))

# Tile has a parking feature in our fixtures, thus sum should be non-zero.
self.assertNotEqual(np.sum(rasterized), 0)

def test_burn_without_feature(self):
parking_fc = get_parking()

# This tile does not have a parking lot in our fixtures.
tile = mercantile.Tile(69623, 104946, 18)

rasterized = geojson_tile_burn(tile, parking_fc["features"], 4326, (512, 512))
rasterized = Image.fromarray(rasterized, mode="P")

self.assertEqual(rasterized.size, (512, 512))

# Tile does not have a parking feature in our fixture, the sum of pixels is zero.
self.assertEqual(np.sum(rasterized), 0)

Loading…
Cancel
Save