From 2ad9803a65d3baea226ff6c9f15232cdb7899176 Mon Sep 17 00:00:00 2001 From: nilsleh Date: Thu, 17 Feb 2022 16:39:33 +0100 Subject: [PATCH 01/11] add own plot method and data.py --- tests/data/cbf/Alberta.geojson | 8 +-- tests/data/cbf/Alberta.zip | Bin 350 -> 284 bytes tests/data/cbf/BritishColumbia.geojson | 7 -- tests/data/cbf/BritishColumbia.zip | Bin 366 -> 0 bytes tests/data/cbf/Manitoba.geojson | 7 -- tests/data/cbf/Manitoba.zip | Bin 352 -> 0 bytes tests/data/cbf/NewBrunswick.geojson | 7 -- tests/data/cbf/NewBrunswick.zip | Bin 360 -> 0 bytes .../data/cbf/NewfoundlandAndLabrador.geojson | 7 -- tests/data/cbf/NewfoundlandAndLabrador.zip | Bin 382 -> 0 bytes tests/data/cbf/NorthwestTerritories.geojson | 7 -- tests/data/cbf/NorthwestTerritories.zip | Bin 376 -> 0 bytes tests/data/cbf/NovaScotia.geojson | 7 -- tests/data/cbf/NovaScotia.zip | Bin 356 -> 0 bytes tests/data/cbf/Nunavut.geojson | 7 -- tests/data/cbf/Nunavut.zip | Bin 350 -> 0 bytes tests/data/cbf/Ontario.geojson | 7 -- tests/data/cbf/Ontario.zip | Bin 350 -> 0 bytes tests/data/cbf/PrinceEdwardIsland.geojson | 7 -- tests/data/cbf/PrinceEdwardIsland.zip | Bin 372 -> 0 bytes tests/data/cbf/Quebec.geojson | 7 -- tests/data/cbf/Quebec.zip | Bin 348 -> 0 bytes tests/data/cbf/Saskatchewan.geojson | 7 -- tests/data/cbf/Saskatchewan.zip | Bin 360 -> 0 bytes tests/data/cbf/YukonTerritory.geojson | 7 -- tests/data/cbf/YukonTerritory.zip | Bin 364 -> 0 bytes tests/data/cbf/data.py | 61 ++++++++++++++++++ tests/datasets/test_cbf.py | 8 ++- torchgeo/datasets/cbf.py | 49 ++++++++++++++ 29 files changed, 118 insertions(+), 92 deletions(-) delete mode 100644 tests/data/cbf/BritishColumbia.geojson delete mode 100644 tests/data/cbf/BritishColumbia.zip delete mode 100644 tests/data/cbf/Manitoba.geojson delete mode 100644 tests/data/cbf/Manitoba.zip delete mode 100644 tests/data/cbf/NewBrunswick.geojson delete mode 100644 tests/data/cbf/NewBrunswick.zip delete mode 100644 tests/data/cbf/NewfoundlandAndLabrador.geojson delete mode 100644 tests/data/cbf/NewfoundlandAndLabrador.zip delete mode 100644 tests/data/cbf/NorthwestTerritories.geojson delete mode 100644 tests/data/cbf/NorthwestTerritories.zip delete mode 100644 tests/data/cbf/NovaScotia.geojson delete mode 100644 tests/data/cbf/NovaScotia.zip delete mode 100644 tests/data/cbf/Nunavut.geojson delete mode 100644 tests/data/cbf/Nunavut.zip delete mode 100644 tests/data/cbf/Ontario.geojson delete mode 100644 tests/data/cbf/Ontario.zip delete mode 100644 tests/data/cbf/PrinceEdwardIsland.geojson delete mode 100644 tests/data/cbf/PrinceEdwardIsland.zip delete mode 100644 tests/data/cbf/Quebec.geojson delete mode 100644 tests/data/cbf/Quebec.zip delete mode 100644 tests/data/cbf/Saskatchewan.geojson delete mode 100644 tests/data/cbf/Saskatchewan.zip delete mode 100644 tests/data/cbf/YukonTerritory.geojson delete mode 100644 tests/data/cbf/YukonTerritory.zip create mode 100644 tests/data/cbf/data.py diff --git a/tests/data/cbf/Alberta.geojson b/tests/data/cbf/Alberta.geojson index f2654944650..4b790f19c46 100644 --- a/tests/data/cbf/Alberta.geojson +++ b/tests/data/cbf/Alberta.geojson @@ -1,7 +1 @@ -{ -"type": "FeatureCollection", -"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, -"features": [ -{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 1.0, 0.0 ], [ 0.0, 0.0 ] ] ] } } -] -} +{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}, "features": [{"type": "Feature", "properties": {}, "geometry": {"type": "Polygon", "coordinates": [[[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 0.0]]]}}]} \ No newline at end of file diff --git a/tests/data/cbf/Alberta.zip b/tests/data/cbf/Alberta.zip index fe275027152def811329aea4cf58e7c820ccc07d..cd6e828377f9d0fb742078fb4356705d15f0ae61 100644 GIT binary patch literal 284 zcmWIWW@Zs#U|`^2*x4Kya!c=v^&B8igpq-PA4ogqB&8OWB=cW4X^ z-Sss ni~-(^Od`y>C literal 350 zcmWIWW@Zs#U|`^2SQRQC{Pl&1;wm7|fRTZLpFxJfF()ats3cJ@JvBe8I6p5mgp+}} z-%l@bDiD`ea5FHnd&U6BQ_3(~@=;;Z zesee7snZ%;XWpDUx3f{2x9Lg2u}i#S#jmVF)~WI~HEvq}!1vGQrKjZ_3k;_5L|uRM z%H8%y^VLaGs@iK(Ev8-f*4z9<;q&juB`oiD@~`~*Da)>Q)A|ov56!QUU&6N1J^gs? zLg~_E~Uok9b1hFuJfE5x1XxqN3Yy%e>7j6B&DjoCe>ovb#J}RPZU1?eq6%xZYTfBub;B)YB#O_u=UXV z8u=w`E8WwN*DjPUO*WqXbU{bX)mN8vPYPyE>Z<(Ul%sPy;@jzOvnRT?+*^|{Z!cqj wHzSiAGcM0d0E2;n0q84+1&tsU&Y)n01O-|!1bDNufwVCKVJwjT4dO5W06Ro~ga7~l diff --git a/tests/data/cbf/Manitoba.geojson b/tests/data/cbf/Manitoba.geojson deleted file mode 100644 index f2654944650..00000000000 --- a/tests/data/cbf/Manitoba.geojson +++ /dev/null @@ -1,7 +0,0 @@ -{ -"type": "FeatureCollection", -"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, -"features": [ -{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 1.0, 0.0 ], [ 0.0, 0.0 ] ] ] } } -] -} diff --git a/tests/data/cbf/Manitoba.zip b/tests/data/cbf/Manitoba.zip deleted file mode 100644 index ae49962b2bbe17ed77fdb8637dace36121d9a069..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 352 zcmWIWW@Zs#U|`^2SQRQC{Pl&1;wm7|fRTYgfI)`AH!&}>BtI!pFFiFst2jR|G=!6Z zx!+GOF?tneVrd0810%~M-ho)jFr#4A?($|_`?DsNNcru7ee|7>1*TF$Y+U>Z-< z^+&JVZGSXhog}5Iy(ZOS+I4Te%}*3Q|9)J;@@^;p%CDcY>}ofy|FHGY{2KWsY%AT< zkJm1gE=@L`{&Yb{&ed0!bWaLqPU@=s;FP0tJL22vZ?h-5w%l8jFmEqofHxzP95XIo oO91`PzyS0W!-7T-3o{H@Az^^#{{U}RHjsKoAPfW2UqBoN0IV^2#Q*>R diff --git a/tests/data/cbf/NewBrunswick.geojson b/tests/data/cbf/NewBrunswick.geojson deleted file mode 100644 index f2654944650..00000000000 --- a/tests/data/cbf/NewBrunswick.geojson +++ /dev/null @@ -1,7 +0,0 @@ -{ -"type": "FeatureCollection", -"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, -"features": [ -{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 1.0, 0.0 ], [ 0.0, 0.0 ] ] ] } } -] -} diff --git a/tests/data/cbf/NewBrunswick.zip b/tests/data/cbf/NewBrunswick.zip deleted file mode 100644 index dbd1f116af57f52a5aa62464741076dcfe97181e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 360 zcmWIWW@Zs#U|`^2SQRQC{Pl&1;wm7|fRTYggh7VEFSXpMs5Gy*JTp04FFiFst2jR| zG=!6Zx!+GOF?khdVrd0810%~M-ho)jFr#4A?($|_`?DsNNcru7ee|7>1*TF$Y+ zU>Z-<^+&JVZGSXhog}5Iy(ZOS+I4Te%}*3Q|9)J;@@^;p%CDcY>}ofy|FHGY{2KWs zY%ATqN3Yy%e>7j6B&DjoCe>ovb#J}RPZU1?eq6%xZYTfBub;B) zYB#O_u=UXV8u=w`E8WwN*DjPUO*WqXbU{bX)mN8vPYPyE>Z<(Ul%sPy;@jzOvnRT? z+*^|{Z!cqjHzSiAGp<0800svG1JG9t3mQQzf_{vb2}TQd7GXT9J|CTR{Y8;WSuH+Q{$%f4}AY@UV2*2vA|#& zPt^5CuiR~aG+&)0rK-Iq)neLpZ@tY=6h8lcT*C5hC;!T?pR(*~H?9A$_0aqp`6X;C z-P4cPE|e}!HlF@;K}XKjSC@283T95~s{G)TqjNjr+v#t!C%U%WTaz$vFJpi=Ba<96 rE`Lh^Lx6z+=qrW=jUX1bP+*0G0$Kq zN3Yy%e>7j6B&DjoCe>ovb#J}RPZU1?eq6%xZYTfBub;B)YB#O_u=UXV8u=w`E8WwN z*DjPUO*WqXbU{bX)mN8vPYPyE>Z<(Ul%sPy;@jzOvnRT?+*^|{Z!cqjHzSiAGcHd{ n0KLz^0Q42Zf<_PvBM4X_L4fA{0B=?{ka9*K3mT_3*}U|$oMVB(G@hvI zk6yXk{%F2BNlI0FO{>>)v{spD29({kVkX-A?|MUq5Bp)oxn4J`&tFJEUo)pZS)K&SxDM#ma#JAJmW>0i&xwj@^-d@H4Z$>6LW?Y_@ n0D7N+0q84+1&tsUMi8(7&%;T=XN$q^EN#xIChCwtoW5x$U0Ttrp8U{ANc;+ zy!5o3V}Zdmo~Y}OUb)-;Xudj0N>zJJs>QVH-g=v#D183?xP;~1PX3i&KV{j~Zd(6g z>!JBI@=MrOx~CtnT_|0eY&`wxf{vW4uP*7H6wI8|Rr$dwN9T6Lx6|KdPjqd$wh5;h6Dox&{qr#8bK_4p}`6X4YZI5@MdKL>0|`L1R(tn#9;scsPBRF diff --git a/tests/data/cbf/Quebec.geojson b/tests/data/cbf/Quebec.geojson deleted file mode 100644 index f2654944650..00000000000 --- a/tests/data/cbf/Quebec.geojson +++ /dev/null @@ -1,7 +0,0 @@ -{ -"type": "FeatureCollection", -"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, -"features": [ -{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 1.0, 0.0 ], [ 0.0, 0.0 ] ] ] } } -] -} diff --git a/tests/data/cbf/Quebec.zip b/tests/data/cbf/Quebec.zip deleted file mode 100644 index fc6cfcdf1b40e3f68d403fdec2e0bb809b15a687..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 348 zcmWIWW@Zs#U|`^2SQRQC{Pl&1;wm7|fRTZLk3ohZurxI(HCZn`H9xC3KQA_{vb2}TQd7GXT9J|CTR{Y8;WSuH+Q{$%f4}AY@UV2*2vA|#&Pt^5C zuiR~aG+&)0rK-Iq)neLpZ@tY=6h8lcT*C5hC;!T?pR(*~H?9A$_0aqp`6X;C-P4cP zE|e}!HlF@;K}XKjSC@283T95~s{G)TqjNjr+v#t!C%U%WTaz$vFJpi=Ba<96EXla{U~+nhgZ@JQqzo?>OaKK#}OJWbbMnIhA!v z8D>j9DoomM?xs6+T4U?Xn{(%OHcIn0Jt;VLiC3)nl~u?(RoyKW!+x}?2I!Q`ZdrhjvwCmn_o1Z9r{{6Uw<=syHm0v$)+0|}Z|6%K)`8D!O z*jBoyAFo{~U7Bn>{po^^oU5-c>7EqKoYYnM!6`@QcEq>S-)2vAZMnB5VcuTG0B=Sn tIc8iwmjH$V0|U@k3=0}TEbQUH3JC|aFbMEwWdrG91i~mF{R6~d003vteSQD{ diff --git a/tests/data/cbf/YukonTerritory.geojson b/tests/data/cbf/YukonTerritory.geojson deleted file mode 100644 index f2654944650..00000000000 --- a/tests/data/cbf/YukonTerritory.geojson +++ /dev/null @@ -1,7 +0,0 @@ -{ -"type": "FeatureCollection", -"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, -"features": [ -{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 1.0, 0.0 ], [ 0.0, 0.0 ] ] ] } } -] -} diff --git a/tests/data/cbf/YukonTerritory.zip b/tests/data/cbf/YukonTerritory.zip deleted file mode 100644 index 0bffe5b35aca000850ecbf66ac8ecacced96583e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 364 zcmWIWW@Zs#U|`^2SQRQC{Pl&1;wm7|fRTYgj6sGWvNStCFC?|7D6=HLs8TOIH9xC3 zKQA7&%;T=XN$q^EN#xIChCwtoW5x$U0Ttrp8U{ANc;+y!5o3 zV}Zdmo~Y}OUb)-;Xudj0N>zJJs>QVH-g=v#D183?xP;~1PX3i&KV{j~Zd(6g>!JBI z@=MrOx~CtnT_|0eY&`wxf{vW4uP*7H6wI8|Rr$dwN9T6Lx6|KdPjqd$w3A9iM@MdKL>0$)J7$E%%#9;sc0QY~X diff --git a/tests/data/cbf/data.py b/tests/data/cbf/data.py new file mode 100644 index 00000000000..efc57827e33 --- /dev/null +++ b/tests/data/cbf/data.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import hashlib +import json +import os +import random +import shutil + +import numpy as np + +SIZE = 32 + +np.random.seed(0) +random.seed(0) + + +def create_geojson(): + geojson = { + "type": "FeatureCollection", + "crs": { + "type": "name", + "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}, + }, + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 0.0]] + ], + }, + } + ], + } + return geojson + + +if __name__ == "__main__": + filename = "Alberta.zip" + geojson = create_geojson() + + with open(filename.replace(".zip", ".geojson"), "w") as f: + json.dump(geojson, f) + + # compress single file directly with no directory + shutil.make_archive( + filename.replace(".zip", ""), + "zip", + os.getcwd(), + filename.replace(".zip", ".geojson"), + ) + + # Compute checksums + with open(filename, "rb") as f: + md5 = hashlib.md5(f.read()).hexdigest() + print(f"{filename}: {md5}") diff --git a/tests/datasets/test_cbf.py b/tests/datasets/test_cbf.py index 3189270b2c3..c5434813fd4 100644 --- a/tests/datasets/test_cbf.py +++ b/tests/datasets/test_cbf.py @@ -76,7 +76,13 @@ def test_already_downloaded(self, dataset: CanadianBuildingFootprints) -> None: def test_plot(self, dataset: CanadianBuildingFootprints) -> None: query = dataset.bounds x = dataset[query] - dataset.plot(x["mask"]) + dataset.plot(x, suptitle="Test") + + def test_plot_prediction(self, dataset: CanadianBuildingFootprints) -> None: + query = dataset.bounds + x = dataset[query] + x["prediction"] = x["mask"].clone() + dataset.plot(x, suptitle="Prediction") def test_not_downloaded(self, tmp_path: Path) -> None: with pytest.raises(RuntimeError, match="Dataset not found or corrupted."): diff --git a/torchgeo/datasets/cbf.py b/torchgeo/datasets/cbf.py index cfabfee60e7..533228ac455 100644 --- a/torchgeo/datasets/cbf.py +++ b/torchgeo/datasets/cbf.py @@ -6,7 +6,9 @@ import os from typing import Any, Callable, Dict, Optional +import matplotlib.pyplot as plt from rasterio.crs import CRS +from torch import Tensor from .geo import VectorDataset from .utils import check_integrity, download_and_extract_archive @@ -120,3 +122,50 @@ def _download(self) -> None: self.root, md5=md5 if self.checksum else None, ) + + def plot( # type: ignore[override] + self, + sample: Dict[str, Tensor], + show_titles: bool = True, + suptitle: Optional[str] = None, + ) -> plt.Figure: + """Plot a sample from the dataset. + + Args: + sample: a sample returned by :meth:`VectorDataset.__getitem__` + show_titles: flag indicating whether to show titles above each panel + suptitle: optional string to use as a suptitle + + Returns: + a matplotlib Figure with the rendered sample + + .. versionadded:: 0.3 + """ + image = sample["mask"].squeeze(0) + ncols = 1 + + showing_prediction = "prediction" in sample + if showing_prediction: + pred = sample["prediction"].squeeze(0) + ncols = 2 + + fig, axs = plt.subplots(nrows=1, ncols=ncols, figsize=(4, 4)) + + if showing_prediction: + axs[0].imshow(image) + axs[0].axis("off") + axs[1].imshow(pred) + axs[1].axis("off") + if show_titles: + axs[0].set_title("Mask") + axs[1].set_title("Prediction") + else: + axs.imshow(image) + axs.axis("off") + if show_titles: + axs.set_title("Mask") + + if suptitle is not None: + plt.suptitle(suptitle) + + return fig From a2923c8679b369854ad0f7ce9197b6f59f680234 Mon Sep 17 00:00:00 2001 From: nilsleh Date: Thu, 17 Feb 2022 16:56:24 +0100 Subject: [PATCH 02/11] clean up data.py --- tests/data/cbf/data.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/data/cbf/data.py b/tests/data/cbf/data.py index efc57827e33..28563ce3968 100644 --- a/tests/data/cbf/data.py +++ b/tests/data/cbf/data.py @@ -6,16 +6,8 @@ import hashlib import json import os -import random import shutil -import numpy as np - -SIZE = 32 - -np.random.seed(0) -random.seed(0) - def create_geojson(): geojson = { From 022db94bb87eae22409eca3b973e0e54f62cffd3 Mon Sep 17 00:00:00 2001 From: nilsleh Date: Tue, 22 Feb 2022 16:20:39 +0100 Subject: [PATCH 03/11] version changed instead of added --- torchgeo/datasets/cbf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torchgeo/datasets/cbf.py b/torchgeo/datasets/cbf.py index 533228ac455..a52673fa175 100644 --- a/torchgeo/datasets/cbf.py +++ b/torchgeo/datasets/cbf.py @@ -139,7 +139,9 @@ def plot( # type: ignore[override] Returns: a matplotlib Figure with the rendered sample - .. versionadded:: 0.3 + .. versionchanged:: 0.3 + Method now takes a sample dict, not a Tensor. Additionally, possible to + show subplot titles and/or use a custom suptitle. """ image = sample["mask"].squeeze(0) ncols = 1 From f85f60f94a3279454e023da3959a5b4b7cca1aa8 Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Wed, 23 Feb 2022 09:34:23 -0800 Subject: [PATCH 04/11] Update cbf.py --- torchgeo/datasets/cbf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchgeo/datasets/cbf.py b/torchgeo/datasets/cbf.py index a52673fa175..ee805a8eb42 100644 --- a/torchgeo/datasets/cbf.py +++ b/torchgeo/datasets/cbf.py @@ -140,8 +140,8 @@ def plot( # type: ignore[override] a matplotlib Figure with the rendered sample .. versionchanged:: 0.3 - Method now takes a sample dict, not a Tensor. Additionally, possible to - show subplot titles and/or use a custom suptitle. + Method now takes a sample dict, not a Tensor. Additionally, it is possible + to show subplot titles and/or use a custom suptitle. """ image = sample["mask"].squeeze(0) ncols = 1 From 531b2fbdbf15c547e777bc78f92ad36dcd4b8cfe Mon Sep 17 00:00:00 2001 From: nilsleh Date: Fri, 25 Feb 2022 17:21:28 +0100 Subject: [PATCH 05/11] Any instead of Tensor --- torchgeo/datasets/cbf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/torchgeo/datasets/cbf.py b/torchgeo/datasets/cbf.py index ee805a8eb42..cbae4ca3a3f 100644 --- a/torchgeo/datasets/cbf.py +++ b/torchgeo/datasets/cbf.py @@ -8,7 +8,6 @@ import matplotlib.pyplot as plt from rasterio.crs import CRS -from torch import Tensor from .geo import VectorDataset from .utils import check_integrity, download_and_extract_archive @@ -125,7 +124,7 @@ def _download(self) -> None: def plot( # type: ignore[override] self, - sample: Dict[str, Tensor], + sample: Dict[str, Any], show_titles: bool = True, suptitle: Optional[str] = None, ) -> plt.Figure: From b7915f115412d374872177f0470aaf16efe9e27e Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sat, 26 Feb 2022 13:04:53 -0600 Subject: [PATCH 06/11] Fix VectorDataset tests --- tests/datasets/test_geo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/datasets/test_geo.py b/tests/datasets/test_geo.py index 4d790de9c3a..3c8c65d2015 100644 --- a/tests/datasets/test_geo.py +++ b/tests/datasets/test_geo.py @@ -4,12 +4,13 @@ import os import pickle from pathlib import Path -from typing import Dict +from typing import Dict, Generator import pytest import torch import torch.nn as nn from _pytest.fixtures import SubRequest +from _pytest.monkeypatch import MonkeyPatch from rasterio.crs import CRS from torch.utils.data import ConcatDataset From 60bab6bd7adc7fb651f99be943485ead26cd363f Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sat, 26 Feb 2022 13:13:35 -0600 Subject: [PATCH 07/11] Plot method in base class no longer needed/tested --- torchgeo/datasets/cbf.py | 2 +- torchgeo/datasets/geo.py | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/torchgeo/datasets/cbf.py b/torchgeo/datasets/cbf.py index cbae4ca3a3f..9781d90ee20 100644 --- a/torchgeo/datasets/cbf.py +++ b/torchgeo/datasets/cbf.py @@ -122,7 +122,7 @@ def _download(self) -> None: md5=md5 if self.checksum else None, ) - def plot( # type: ignore[override] + def plot( self, sample: Dict[str, Any], show_titles: bool = True, diff --git a/torchgeo/datasets/geo.py b/torchgeo/datasets/geo.py index 55a76c4f1b7..88ec2447bbc 100644 --- a/torchgeo/datasets/geo.py +++ b/torchgeo/datasets/geo.py @@ -677,21 +677,6 @@ def __getitem__(self, query: BoundingBox) -> Dict[str, Any]: return sample - def plot(self, data: Tensor) -> None: - """Plot a data sample. - - Args: - data: the data to plot - """ - array = data.squeeze().numpy() - - # Plot the image - ax = plt.axes() - ax.imshow(array) - ax.axis("off") - plt.show() - plt.close() - class VisionDataset(Dataset[Dict[str, Any]], abc.ABC): """Abstract base class for datasets lacking geospatial information. From 46dc0a8684514b8b720f8a382ec00934b27467d5 Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Sun, 20 Mar 2022 17:22:39 +0000 Subject: [PATCH 08/11] Removing unused imports --- tests/datasets/test_geo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/datasets/test_geo.py b/tests/datasets/test_geo.py index 3c8c65d2015..4d790de9c3a 100644 --- a/tests/datasets/test_geo.py +++ b/tests/datasets/test_geo.py @@ -4,13 +4,12 @@ import os import pickle from pathlib import Path -from typing import Dict, Generator +from typing import Dict import pytest import torch import torch.nn as nn from _pytest.fixtures import SubRequest -from _pytest.monkeypatch import MonkeyPatch from rasterio.crs import CRS from torch.utils.data import ConcatDataset From c35e748db4af0c21ecd64225955b655238057e76 Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Sun, 20 Mar 2022 17:53:41 +0000 Subject: [PATCH 09/11] Remove type ignore from openbuildings --- torchgeo/datasets/openbuildings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchgeo/datasets/openbuildings.py b/torchgeo/datasets/openbuildings.py index 2b630f9f8df..18690617cea 100644 --- a/torchgeo/datasets/openbuildings.py +++ b/torchgeo/datasets/openbuildings.py @@ -421,7 +421,7 @@ def _verify(self) -> None: "have manually downloaded the dataset as suggested in the documentation." ) - def plot( # type: ignore[override] + def plot( self, sample: Dict[str, Any], show_titles: bool = True, From f46b77b3754ce49599f415e3e7939b5af507129a Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Sun, 20 Mar 2022 17:58:06 +0000 Subject: [PATCH 10/11] Fix tests --- tests/datasets/test_cbf.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/datasets/test_cbf.py b/tests/datasets/test_cbf.py index c5434813fd4..e214126e716 100644 --- a/tests/datasets/test_cbf.py +++ b/tests/datasets/test_cbf.py @@ -31,22 +31,12 @@ def dataset( self, monkeypatch: MonkeyPatch, tmp_path: Path ) -> CanadianBuildingFootprints: monkeypatch.setattr(torchgeo.datasets.utils, "download_url", download_url) - md5s = [ - "8a4a0a57367f67c69608d1452e30df13", - "1829f4054a9a81bb23871ca797a3895c", - "4358a0076fd43e9a2f436e74348813b0", - "ae3726b1263727d72565ecacfed56fb8", - "6861876d3a3ca7e79b28c61ab5906de4", - "d289c9ea49801bb287ddbde1ea5f31ef", - "3a940288297631b4e6a365266bfb949a", - "6b43b3632b165ff79c1ca0c693a61398", - "36283e0b29088ec281e77c989cbee100", - "773da9d33e3766b7237a1d7db0811832", - "cc833a65137c8a046c8f45bb695092b1", - "067664d066c4152fb96a5c129cbabadf", - "474bc084bc41b124aa4919e7a37a9648", - ] - monkeypatch.setattr(CanadianBuildingFootprints, "md5s", md5s) + monkeypatch.setattr(CanadianBuildingFootprints, "provinces_territories", [ + "Alberta" + ]) + monkeypatch.setattr(CanadianBuildingFootprints, "md5s", [ + "25091d1f051baa30d8f2026545cfb696" + ]) url = os.path.join("tests", "data", "cbf") + os.sep monkeypatch.setattr(CanadianBuildingFootprints, "url", url) monkeypatch.setattr(plt, "show", lambda *args: None) From 70ea7ef9fba7e5ab0a66300f8327fd57c9df4e00 Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Sun, 20 Mar 2022 18:49:29 +0000 Subject: [PATCH 11/11] Black formatting --- tests/datasets/test_cbf.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/datasets/test_cbf.py b/tests/datasets/test_cbf.py index e214126e716..d664d117439 100644 --- a/tests/datasets/test_cbf.py +++ b/tests/datasets/test_cbf.py @@ -31,12 +31,12 @@ def dataset( self, monkeypatch: MonkeyPatch, tmp_path: Path ) -> CanadianBuildingFootprints: monkeypatch.setattr(torchgeo.datasets.utils, "download_url", download_url) - monkeypatch.setattr(CanadianBuildingFootprints, "provinces_territories", [ - "Alberta" - ]) - monkeypatch.setattr(CanadianBuildingFootprints, "md5s", [ - "25091d1f051baa30d8f2026545cfb696" - ]) + monkeypatch.setattr( + CanadianBuildingFootprints, "provinces_territories", ["Alberta"] + ) + monkeypatch.setattr( + CanadianBuildingFootprints, "md5s", ["25091d1f051baa30d8f2026545cfb696"] + ) url = os.path.join("tests", "data", "cbf") + os.sep monkeypatch.setattr(CanadianBuildingFootprints, "url", url) monkeypatch.setattr(plt, "show", lambda *args: None)