Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmrynk committed Nov 11, 2023
1 parent e8c8cd5 commit 875ecd9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/data/remote_sensing_data_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_response(self, bounding_box):
format='image/tiff',
size=(image_size, image_size),
bgcolor='#000000').read()

return response

def get_image(self, coordinates):
Expand Down
2 changes: 2 additions & 0 deletions src/data/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def remote_sensing_data_downloader_no_clip_border(_mocked_wms):
wms_layer='wms_layer',
epsg_code=25832,
clip_border=False)

return remote_sensing_data_downloader


Expand All @@ -35,4 +36,5 @@ def remote_sensing_data_downloader_clip_border(_mocked_wms):
wms_layer='wms_layer',
epsg_code=25832,
clip_border=True)

return remote_sensing_data_downloader
12 changes: 9 additions & 3 deletions src/data/tests/data/tests_data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
fill_value=np.array([102, 51, 0]),
dtype=np.uint8)

image_top = np.concatenate((image_top_left, image_top_right), axis=1)
image_bottom = np.concatenate((image_bottom_left, image_bottom_right), axis=1)
expected = np.concatenate((image_top, image_bottom), axis=0)
image_top = np.concatenate((image_top_left,
image_top_right),
axis=1)
image_bottom = np.concatenate((image_bottom_left,
image_bottom_right),
axis=1)
expected = np.concatenate((image_top,
image_bottom),
axis=0)

Image.fromarray(expected).save('data_test_get_image.tiff')
6 changes: 5 additions & 1 deletion src/preprocessing/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def get_image(self,
:rtype: np.ndarray[np.float32]
"""
image_nir = image_nir[..., 0]
image = np.concatenate((image_rgb, image_nir[..., np.newaxis]), axis=-1)

image = np.concatenate((image_rgb,
image_nir[..., np.newaxis]),
axis=-1)

image = self.normalize_image(image)
return image
3 changes: 1 addition & 2 deletions src/preprocessing/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ def preprocessor():
:returns: preprocessor
:rtype: Preprocessor
"""
preprocessor = Preprocessor()
return preprocessor
return Preprocessor()
60 changes: 45 additions & 15 deletions src/preprocessing/tests/data/tests_data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
fill_value=np.array([153, 102, 51, 0]),
dtype=np.uint8)

image_top = np.concatenate((image_top_left, image_top_right), axis=1)
image_bottom = np.concatenate((image_bottom_left, image_bottom_right), axis=1)
test_input = np.concatenate((image_top, image_bottom), axis=0)
image_top = np.concatenate((image_top_left,
image_top_right),
axis=1)
image_bottom = np.concatenate((image_bottom_left,
image_bottom_right),
axis=1)
test_input = np.concatenate((image_top,
image_bottom),
axis=0)

image_normalized_top_left = np.full(shape=(640, 640, 4),
fill_value=np.array([0., .2, .4, .6]),
Expand All @@ -32,9 +38,15 @@
fill_value=np.array([.6, .4, .2, 0.]),
dtype=np.float32)

image_normalized_top = np.concatenate((image_normalized_top_left, image_normalized_top_right), axis=1)
image_normalized_bottom = np.concatenate((image_normalized_bottom_left, image_normalized_bottom_right), axis=1)
expected = np.concatenate((image_normalized_top, image_normalized_bottom), axis=0)
image_normalized_top = np.concatenate((image_normalized_top_left,
image_normalized_top_right),
axis=1)
image_normalized_bottom = np.concatenate((image_normalized_bottom_left,
image_normalized_bottom_right),
axis=1)
expected = np.concatenate((image_normalized_top,
image_normalized_bottom),
axis=0)

np.save('data_test_normalize_image_test_input', test_input)
np.save('data_test_normalize_image_expected', expected)
Expand All @@ -54,9 +66,15 @@
fill_value=np.array([102, 51, 0]),
dtype=np.uint8)

image_rgb_top = np.concatenate((image_rgb_top_left, image_rgb_top_right), axis=1)
image_rgb_bottom = np.concatenate((image_rgb_bottom_left, image_rgb_bottom_right), axis=1)
test_input_rgb = np.concatenate((image_rgb_top, image_rgb_bottom), axis=0)
image_rgb_top = np.concatenate((image_rgb_top_left,
image_rgb_top_right),
axis=1)
image_rgb_bottom = np.concatenate((image_rgb_bottom_left,
image_rgb_bottom_right),
axis=1)
test_input_rgb = np.concatenate((image_rgb_top,
image_rgb_bottom),
axis=0)

image_nir_top_left = np.full(shape=(640, 640, 3),
fill_value=0,
Expand All @@ -71,9 +89,15 @@
fill_value=255,
dtype=np.uint8)

image_nir_top = np.concatenate((image_nir_top_left, image_nir_top_right), axis=1)
image_nir_bottom = np.concatenate((image_nir_bottom_left, image_nir_bottom_right), axis=1)
test_input_nir = np.concatenate((image_nir_top, image_nir_bottom), axis=0)
image_nir_top = np.concatenate((image_nir_top_left,
image_nir_top_right),
axis=1)
image_nir_bottom = np.concatenate((image_nir_bottom_left,
image_nir_bottom_right),
axis=1)
test_input_nir = np.concatenate((image_nir_top,
image_nir_bottom),
axis=0)

image_top_left = np.full(shape=(640, 640, 4),
fill_value=np.array([0., .2, .4, 0.]),
Expand All @@ -88,9 +112,15 @@
fill_value=np.array([.4, .2, 0., 1.]),
dtype=np.float32)

image_top = np.concatenate((image_top_left, image_top_right), axis=1)
image_bottom = np.concatenate((image_bottom_left, image_bottom_right), axis=1)
expected = np.concatenate((image_top, image_bottom), axis=0)
image_top = np.concatenate((image_top_left,
image_top_right),
axis=1)
image_bottom = np.concatenate((image_bottom_left,
image_bottom_right),
axis=1)
expected = np.concatenate((image_top,
image_bottom),
axis=0)

np.save('data_test_get_image_test_input_rgb', test_input_rgb)
np.save('data_test_get_image_test_input_nir', test_input_nir)
Expand Down
2 changes: 2 additions & 0 deletions src/preprocessing/tests/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_normalize_image():
"""
test_input = np.load(DATA_DIR_PATH / 'data_test_normalize_image_test_input.npy')
image_normalized = Preprocessor.normalize_image(image=test_input)

expected = np.load(DATA_DIR_PATH / 'data_test_normalize_image_expected.npy')

assert image_normalized.dtype == expected.dtype
Expand All @@ -47,6 +48,7 @@ def test_get_image(preprocessor):
test_input_nir = np.load(DATA_DIR_PATH / 'data_test_get_image_test_input_nir.npy')
image = preprocessor.get_image(image_rgb=test_input_rgb,
image_nir=test_input_nir)

expected = np.load(DATA_DIR_PATH / 'data_test_get_image_expected.npy')

assert image.dtype == expected.dtype
Expand Down

0 comments on commit 875ecd9

Please sign in to comment.