1
1
from os .path import join
2
-
2
+ from datetime import date
3
3
import numpy as np
4
4
from geoalchemy2 .shape import to_shape
5
5
from geoalchemy2 .types import Raster
14
14
15
15
16
16
class TestRaster (TableTestBase ):
17
- '''
17
+ """
18
18
Test uploading a raster
19
- '''
19
+ """
20
20
21
21
# Class to use to upload the data
22
22
UploaderClass = UploadRaster
23
23
24
24
# Positional arguments to pass to the uploader class
25
- args = [join ('be_gm1_0328' ,'w001001x.adf' )]
25
+ args = [join ('be_gm1_0328' , 'w001001x.adf' )]
26
26
27
27
# Keyword args to pass to the uploader class
28
- kwargs = {'type' :'dem' , 'epsg' :26912 , 'description' :'test' }
28
+ kwargs = {'type' : 'dem' , 'epsg' : 26912 , 'description' : 'test' }
29
29
30
30
# Always define this using a table class from data.py and is used for ORM
31
31
TableClass = ImageData
32
32
33
33
# First filter to be applied is count_attribute == data_name
34
34
count_attribute = 'type'
35
35
36
-
37
36
# Define params which is a dictionary of test names and their args
38
37
params = {
39
- 'test_count' : [dict (data_name = 'dem' , expected_count = 1 )],
40
- 'test_value' : [dict (data_name = 'dem' , attribute_to_check = 'description' , filter_attribute = 'id' , filter_value = 1 , expected = 'test' )],
41
- 'test_unique_count' : [dict (data_name = 'dem' , attribute_to_count = 'id' , expected_count = 1 )]
42
- }
38
+ 'test_count' : [dict (data_name = 'dem' , expected_count = 1 )],
39
+ 'test_value' : [dict (data_name = 'dem' , attribute_to_check = 'description' ,
40
+ filter_attribute = 'id' , filter_value = 1 ,
41
+ expected = 'test' )],
42
+ 'test_unique_count' : [dict (data_name = 'dem' , attribute_to_count = 'id' ,
43
+ expected_count = 1 )]
44
+ }
45
+
43
46
44
47
class TestTiledRaster (DBSetup ):
45
- '''
48
+ """
46
49
A class to test common operations and features of tiled raster in the DB
47
- '''
50
+ """
48
51
49
52
def setup_class (self ):
50
- '''
53
+ """
51
54
Setup the database one time for testing
52
- '''
55
+ """
53
56
super ().setup_class ()
54
57
# Positional arguments to pass to the uploader class
55
- args = [join (self .data_dir , 'uavsar' ,'uavsar_utm.amp1.real.tif' )]
58
+ args = [join (self .data_dir , 'uavsar' , 'uavsar_utm.amp1.real.tif' )]
56
59
57
60
# Keyword args to pass to the uploader class
58
- kwargs = {'type' :'insar' , 'epsg' :26912 , 'description' :'test' , 'tiled' :True }
61
+ kwargs = {'type' : 'insar' , 'epsg' : 26912 , 'description' : 'test' , 'tiled' : True }
59
62
# Upload two rasters (next two each other)
60
63
u = UploadRaster (* args , ** kwargs )
61
64
u .submit (self .session )
62
65
63
66
def test_tiled_raster_count (self ):
64
- '''
67
+ """
65
68
Test two rasters uploaded
66
- '''
69
+ """
67
70
records = self .session .query (ImageData .id ).all ()
68
71
assert len (records ) == 4
69
72
70
73
def test_tiled_raster_size (self ):
71
- '''
74
+ """
72
75
Tiled raster should be 500x500 in most cases (can be smaller to fit domains)
73
- '''
76
+ """
74
77
rasters = self .session .query (func .ST_AsTiff (ImageData .raster )).all ()
75
78
datasets = raster_to_rasterio (self .session , rasters )
76
79
@@ -79,9 +82,9 @@ def test_tiled_raster_size(self):
79
82
assert d .height <= 500
80
83
81
84
def test_raster_point_retrieval (self ):
82
- '''
85
+ """
83
86
Test we can retrieve coordinates of a point from the database
84
- '''
87
+ """
85
88
86
89
# Get the first pixel as a point
87
90
records = self .session .query (ST_PixelAsPoint (ImageData .raster , 1 , 1 )).limit (1 ).all ()
@@ -93,19 +96,27 @@ def test_raster_point_retrieval(self):
93
96
np .testing .assert_almost_equal (received .y , expected .y , 6 )
94
97
95
98
def test_raster_union (self ):
96
- '''
99
+ """
97
100
Test we can retrieve coordinates of a point from the database
98
- '''
101
+ """
99
102
100
103
# Get the first pixel as a point
101
104
rasters = self .session .query (func .ST_AsTiff (func .ST_Union (ImageData .raster , type_ = Raster ))).all ()
102
105
assert len (rasters ) == 1
103
106
104
107
def test_raster_union2 (self ):
105
- '''
108
+ """
106
109
Test we can retrieve coordinates of a point from the database
107
- '''
110
+ """
108
111
109
112
# Get the first pixel as a point
110
- merged = self .session .query (func .ST_Union (ImageData .raster , type_ = Raster )).filter (ImageData .id .in_ ([1 , 2 ])).all ()
113
+ merged = self .session .query (func .ST_Union (ImageData .raster , type_ = Raster )).filter (
114
+ ImageData .id .in_ ([1 , 2 ])).all ()
111
115
assert len (merged ) == 1
116
+
117
+ def test_date_accessed (self ):
118
+ """
119
+ Tests that the date accessed is auto assigned on upload
120
+ """
121
+ result = self .session .query (ImageData .date_accessed ).limit (1 ).all ()
122
+ assert type (result [0 ][0 ]) is date
0 commit comments