From 5cfbd6512dd1438190388a99d411caca7651eeb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 21:35:27 +0000 Subject: [PATCH] Bump ruff from 0.4.4 to 0.4.5 in /requirements (#2080) * Bump ruff from 0.4.4 to 0.4.5 in /requirements Bumps [ruff](https://github.com/astral-sh/ruff) from 0.4.4 to 0.4.5. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/v0.4.4...v0.4.5) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * min version of numpy now supports type hints * pre-commit: update ruff --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Adam J. Stewart --- .pre-commit-config.yaml | 2 +- experiments/ssl4eo/landsat/chip_landsat_benchmark.py | 2 +- requirements/style.txt | 2 +- tests/datasets/test_utils.py | 4 ++-- torchgeo/datasets/advance.py | 2 +- torchgeo/datasets/bigearthnet.py | 2 +- torchgeo/datasets/biomassters.py | 2 +- torchgeo/datasets/cloud_cover.py | 4 ++-- torchgeo/datasets/cowc.py | 2 +- torchgeo/datasets/cv4a_kenya_crop_type.py | 4 ++-- torchgeo/datasets/cyclone.py | 2 +- torchgeo/datasets/deepglobelandcover.py | 4 ++-- torchgeo/datasets/dfc2022.py | 4 ++-- torchgeo/datasets/etci2021.py | 4 ++-- torchgeo/datasets/eurocrops.py | 2 +- torchgeo/datasets/fair1m.py | 2 +- torchgeo/datasets/forestdamage.py | 2 +- torchgeo/datasets/geo.py | 2 +- torchgeo/datasets/gid15.py | 4 ++-- torchgeo/datasets/idtrees.py | 4 ++-- torchgeo/datasets/landcoverai.py | 4 ++-- torchgeo/datasets/levircd.py | 4 ++-- torchgeo/datasets/loveda.py | 4 ++-- torchgeo/datasets/mapinwild.py | 2 +- torchgeo/datasets/millionaid.py | 2 +- torchgeo/datasets/oscd.py | 8 ++++---- torchgeo/datasets/potsdam.py | 2 +- torchgeo/datasets/reforestree.py | 2 +- torchgeo/datasets/so2sat.py | 4 ++-- torchgeo/datasets/spacenet.py | 2 +- torchgeo/datasets/usavars.py | 2 +- torchgeo/datasets/vaihingen.py | 4 ++-- torchgeo/datasets/vhr10.py | 2 +- torchgeo/datasets/xview.py | 4 ++-- torchgeo/models/rcf.py | 2 +- 35 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d768ae04..164803fb8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.7 + rev: v0.4.5 hooks: - id: ruff types_or: diff --git a/experiments/ssl4eo/landsat/chip_landsat_benchmark.py b/experiments/ssl4eo/landsat/chip_landsat_benchmark.py index 93fd16b02..b02015201 100755 --- a/experiments/ssl4eo/landsat/chip_landsat_benchmark.py +++ b/experiments/ssl4eo/landsat/chip_landsat_benchmark.py @@ -29,7 +29,7 @@ def retrieve_mask_chip( mask array """ out_shape = (1, *img_src.shape) - mask_chip: 'np.typing.NDArray[np.uint8]' = mask_src.read( + mask_chip: np.typing.NDArray[np.uint8] = mask_src.read( out_shape=out_shape, window=from_bounds(*img_src.bounds, mask_src.transform) ) diff --git a/requirements/style.txt b/requirements/style.txt index 0b493757d..a38126a71 100644 --- a/requirements/style.txt +++ b/requirements/style.txt @@ -1,3 +1,3 @@ # style mypy==1.10.0 -ruff==0.4.4 +ruff==0.4.5 diff --git a/tests/datasets/test_utils.py b/tests/datasets/test_utils.py index be8ddf667..c53bfbed0 100644 --- a/tests/datasets/test_utils.py +++ b/tests/datasets/test_utils.py @@ -561,7 +561,7 @@ def test_nonexisting_directory(tmp_path: Path) -> None: def test_percentile_normalization() -> None: - img: 'np.typing.NDArray[np.int_]' = np.array([[1, 2], [98, 100]]) + img: np.typing.NDArray[np.int_] = np.array([[1, 2], [98, 100]]) img = percentile_normalization(img, 2, 98) assert img.min() == 0 @@ -573,7 +573,7 @@ def test_percentile_normalization() -> None: [np.uint8, np.uint16, np.uint32, np.int8, np.int16, np.int32, np.int64], ) def test_array_to_tensor(array_dtype: 'np.typing.DTypeLike') -> None: - array: 'np.typing.NDArray[Any]' = np.zeros((2,), dtype=array_dtype) + array: np.typing.NDArray[Any] = np.zeros((2,), dtype=array_dtype) array[0] = np.iinfo(array.dtype).min array[1] = np.iinfo(array.dtype).max tensor = array_to_tensor(array) diff --git a/torchgeo/datasets/advance.py b/torchgeo/datasets/advance.py index 0cc025447..be0e5996b 100644 --- a/torchgeo/datasets/advance.py +++ b/torchgeo/datasets/advance.py @@ -179,7 +179,7 @@ class ADVANCE(NonGeoDataset): the image """ with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/bigearthnet.py b/torchgeo/datasets/bigearthnet.py index eb091720a..075af0897 100644 --- a/torchgeo/datasets/bigearthnet.py +++ b/torchgeo/datasets/bigearthnet.py @@ -403,7 +403,7 @@ class BigEarthNet(NonGeoDataset): resampling=Resampling.bilinear, ) images.append(array) - arrays: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0) + arrays: np.typing.NDArray[np.int_] = np.stack(images, axis=0) tensor = torch.from_numpy(arrays).float() return tensor diff --git a/torchgeo/datasets/biomassters.py b/torchgeo/datasets/biomassters.py index 5f72caf63..bb975c800 100644 --- a/torchgeo/datasets/biomassters.py +++ b/torchgeo/datasets/biomassters.py @@ -196,7 +196,7 @@ class BioMassters(NonGeoDataset): target mask """ with rasterio.open(os.path.join(self.root, 'train_agbm', filename), 'r') as src: - arr: 'np.typing.NDArray[np.float_]' = src.read() + arr: np.typing.NDArray[np.float_] = src.read() target = torch.from_numpy(arr).float() return target diff --git a/torchgeo/datasets/cloud_cover.py b/torchgeo/datasets/cloud_cover.py index 64afd875b..2aeea01c5 100644 --- a/torchgeo/datasets/cloud_cover.py +++ b/torchgeo/datasets/cloud_cover.py @@ -183,7 +183,7 @@ class CloudCoverDetection(NonGeoDataset): with rasterio.open(path) as image_data: image_array = image_data.read(1).astype(np.int32) images.append(image_array) - image_stack: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0) + image_stack: np.typing.NDArray[np.int_] = np.stack(images, axis=0) image_tensor = torch.from_numpy(image_stack) return image_tensor @@ -200,7 +200,7 @@ class CloudCoverDetection(NonGeoDataset): with rasterio.open(label_asset_path) as target_data: target_img = target_data.read(1).astype(np.int32) - target_array: 'np.typing.NDArray[np.int_]' = np.array(target_img) + target_array: np.typing.NDArray[np.int_] = np.array(target_img) target_tensor = torch.from_numpy(target_array) return target_tensor diff --git a/torchgeo/datasets/cowc.py b/torchgeo/datasets/cowc.py index f70afbbb1..838123d39 100644 --- a/torchgeo/datasets/cowc.py +++ b/torchgeo/datasets/cowc.py @@ -145,7 +145,7 @@ class COWC(NonGeoDataset, abc.ABC): """ filename = os.path.join(self.root, self.images[index]) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/cv4a_kenya_crop_type.py b/torchgeo/datasets/cv4a_kenya_crop_type.py index eb232ad10..a532c1539 100644 --- a/torchgeo/datasets/cv4a_kenya_crop_type.py +++ b/torchgeo/datasets/cv4a_kenya_crop_type.py @@ -235,7 +235,7 @@ class CV4AKenyaCropType(NonGeoDataset): ) with Image.open(os.path.join(directory, 'labels.tif')) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) labels = torch.from_numpy(array) with Image.open(os.path.join(directory, 'field_ids.tif')) as img: @@ -332,7 +332,7 @@ class CV4AKenyaCropType(NonGeoDataset): f'{band_name}.tif', ) with Image.open(filepath) as band_img: - array: 'np.typing.NDArray[np.int_]' = np.array(band_img) + array: np.typing.NDArray[np.int_] = np.array(band_img) img[band_index] = torch.from_numpy(array) return img diff --git a/torchgeo/datasets/cyclone.py b/torchgeo/datasets/cyclone.py index fb559c06a..eccca9d73 100644 --- a/torchgeo/datasets/cyclone.py +++ b/torchgeo/datasets/cyclone.py @@ -159,7 +159,7 @@ class TropicalCyclone(NonGeoDataset): except AttributeError: resample = Image.BILINEAR # type: ignore[attr-defined] img = img.resize(size=(self.size, self.size), resample=resample) - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) tensor = tensor.permute((2, 0, 1)).float() return tensor diff --git a/torchgeo/datasets/deepglobelandcover.py b/torchgeo/datasets/deepglobelandcover.py index b578374b9..a986e43d3 100644 --- a/torchgeo/datasets/deepglobelandcover.py +++ b/torchgeo/datasets/deepglobelandcover.py @@ -184,7 +184,7 @@ class DeepGlobeLandCover(NonGeoDataset): path = self.image_fns[index] with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)).to(torch.float32) @@ -201,7 +201,7 @@ class DeepGlobeLandCover(NonGeoDataset): """ path = self.mask_fns[index] with Image.open(path) as img: - array: 'np.typing.NDArray[np.uint8]' = np.array(img) + array: np.typing.NDArray[np.uint8] = np.array(img) array = rgb_to_mask(array, self.colormap) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW diff --git a/torchgeo/datasets/dfc2022.py b/torchgeo/datasets/dfc2022.py index b9917c834..697ddeb0f 100644 --- a/torchgeo/datasets/dfc2022.py +++ b/torchgeo/datasets/dfc2022.py @@ -235,7 +235,7 @@ class DFC2022(NonGeoDataset): the image """ with rasterio.open(path) as f: - array: 'np.typing.NDArray[np.float_]' = f.read( + array: np.typing.NDArray[np.float_] = f.read( out_shape=shape, out_dtype='float32', resampling=Resampling.bilinear ) tensor = torch.from_numpy(array) @@ -251,7 +251,7 @@ class DFC2022(NonGeoDataset): the target mask """ with rasterio.open(path) as f: - array: 'np.typing.NDArray[np.int_]' = f.read( + array: np.typing.NDArray[np.int_] = f.read( indexes=1, out_dtype='int32', resampling=Resampling.bilinear ) tensor = torch.from_numpy(array) diff --git a/torchgeo/datasets/etci2021.py b/torchgeo/datasets/etci2021.py index 74f996302..44ab7007f 100644 --- a/torchgeo/datasets/etci2021.py +++ b/torchgeo/datasets/etci2021.py @@ -204,7 +204,7 @@ class ETCI2021(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) @@ -221,7 +221,7 @@ class ETCI2021(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = torch.clamp(tensor, min=0, max=1) tensor = tensor.to(torch.long) diff --git a/torchgeo/datasets/eurocrops.py b/torchgeo/datasets/eurocrops.py index 76db13197..daa1987e3 100644 --- a/torchgeo/datasets/eurocrops.py +++ b/torchgeo/datasets/eurocrops.py @@ -246,7 +246,7 @@ class EuroCrops(VectorDataset): def apply_cmap(arr: 'np.typing.NDArray[Any]') -> 'np.typing.NDArray[np.float_]': # Color 0 as black, while applying default color map for the class indices. cmap = plt.get_cmap('viridis') - im: 'np.typing.NDArray[np.float_]' = cmap(arr / len(self.class_map)) + im: np.typing.NDArray[np.float_] = cmap(arr / len(self.class_map)) im[arr == 0] = 0 return im diff --git a/torchgeo/datasets/fair1m.py b/torchgeo/datasets/fair1m.py index 3025711a8..e3476c971 100644 --- a/torchgeo/datasets/fair1m.py +++ b/torchgeo/datasets/fair1m.py @@ -308,7 +308,7 @@ class FAIR1M(NonGeoDataset): the image """ with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/forestdamage.py b/torchgeo/datasets/forestdamage.py index 2bb7c4b1b..1cbae17f9 100644 --- a/torchgeo/datasets/forestdamage.py +++ b/torchgeo/datasets/forestdamage.py @@ -197,7 +197,7 @@ class ForestDamage(NonGeoDataset): the image """ with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor: Tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/geo.py b/torchgeo/datasets/geo.py index 9ee33356a..157d66195 100644 --- a/torchgeo/datasets/geo.py +++ b/torchgeo/datasets/geo.py @@ -904,7 +904,7 @@ class NonGeoClassificationDataset(NonGeoDataset, ImageFolder): # type: ignore[m the image and class label """ img, label = ImageFolder.__getitem__(self, index) - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/gid15.py b/torchgeo/datasets/gid15.py index 464b3c2ce..329d488e9 100644 --- a/torchgeo/datasets/gid15.py +++ b/torchgeo/datasets/gid15.py @@ -189,7 +189,7 @@ class GID15(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)).float() @@ -206,7 +206,7 @@ class GID15(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = tensor.to(torch.long) return tensor diff --git a/torchgeo/datasets/idtrees.py b/torchgeo/datasets/idtrees.py index 6ddc0c966..4dd067244 100644 --- a/torchgeo/datasets/idtrees.py +++ b/torchgeo/datasets/idtrees.py @@ -265,7 +265,7 @@ class IDTReeS(NonGeoDataset): """ laspy = lazy_import('laspy') las = laspy.read(path) - array: 'np.typing.NDArray[np.int_]' = np.stack([las.x, las.y, las.z], axis=0) + array: np.typing.NDArray[np.int_] = np.stack([las.x, las.y, las.z], axis=0) tensor = torch.from_numpy(array) return tensor @@ -570,7 +570,7 @@ class IDTReeS(NonGeoDataset): path = self.images[index] path = path.replace('RGB', 'LAS').replace('.tif', '.las') las = laspy.read(path) - points: 'np.typing.NDArray[np.int_]' = np.stack( + points: np.typing.NDArray[np.int_] = np.stack( [las.x, las.y, las.z], axis=0 ).transpose((1, 0)) point_cloud = pyvista.PolyData(points) diff --git a/torchgeo/datasets/landcoverai.py b/torchgeo/datasets/landcoverai.py index dece1cd7e..970a45eb1 100644 --- a/torchgeo/datasets/landcoverai.py +++ b/torchgeo/datasets/landcoverai.py @@ -360,7 +360,7 @@ class LandCoverAI(LandCoverAIBase, NonGeoDataset): """ filename = os.path.join(self.root, 'output', id_ + '.jpg') with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) @@ -378,7 +378,7 @@ class LandCoverAI(LandCoverAIBase, NonGeoDataset): """ filename = os.path.join(self.root, 'output', id_ + '_m.png') with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array).long() return tensor diff --git a/torchgeo/datasets/levircd.py b/torchgeo/datasets/levircd.py index 4fcf75350..67209f603 100644 --- a/torchgeo/datasets/levircd.py +++ b/torchgeo/datasets/levircd.py @@ -105,7 +105,7 @@ class LEVIRCDBase(NonGeoDataset, abc.ABC): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) @@ -122,7 +122,7 @@ class LEVIRCDBase(NonGeoDataset, abc.ABC): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = torch.clamp(tensor, min=0, max=1) tensor = tensor.to(torch.long) diff --git a/torchgeo/datasets/loveda.py b/torchgeo/datasets/loveda.py index 4f55c2824..58f3876a0 100644 --- a/torchgeo/datasets/loveda.py +++ b/torchgeo/datasets/loveda.py @@ -208,7 +208,7 @@ class LoveDA(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array).float() # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) @@ -225,7 +225,7 @@ class LoveDA(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = tensor.to(torch.long) return tensor diff --git a/torchgeo/datasets/mapinwild.py b/torchgeo/datasets/mapinwild.py index d4f0a01d6..882ec260f 100644 --- a/torchgeo/datasets/mapinwild.py +++ b/torchgeo/datasets/mapinwild.py @@ -217,7 +217,7 @@ class MapInWild(NonGeoDataset): """ with rasterio.open(os.path.join(self.root, source, f'{filename}.tif')) as f: raw_array = f.read() - array: 'np.typing.NDArray[np.int_]' = np.stack(raw_array, axis=0) + array: np.typing.NDArray[np.int_] = np.stack(raw_array, axis=0) if array.dtype == np.uint16: array = array.astype(np.int32) tensor = torch.from_numpy(array).float() diff --git a/torchgeo/datasets/millionaid.py b/torchgeo/datasets/millionaid.py index 7b5a9ca0e..46eabbe19 100644 --- a/torchgeo/datasets/millionaid.py +++ b/torchgeo/datasets/millionaid.py @@ -305,7 +305,7 @@ class MillionAID(NonGeoDataset): the image """ with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor: Tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/oscd.py b/torchgeo/datasets/oscd.py index 8ff2a52a3..b2ad8aef2 100644 --- a/torchgeo/datasets/oscd.py +++ b/torchgeo/datasets/oscd.py @@ -216,11 +216,11 @@ class OSCD(NonGeoDataset): Returns: the image """ - images: list['np.typing.NDArray[np.int_]'] = [] + images: list[np.typing.NDArray[np.int_]] = [] for path in paths: with Image.open(path) as img: images.append(np.array(img)) - array: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0).astype(np.int_) + array: np.typing.NDArray[np.int_] = np.stack(images, axis=0).astype(np.int_) tensor = torch.from_numpy(array).float() return tensor @@ -235,7 +235,7 @@ class OSCD(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = torch.clamp(tensor, min=0, max=1) tensor = tensor.to(torch.long) @@ -314,7 +314,7 @@ class OSCD(NonGeoDataset): rgb_img = (np.clip((rgb_img - per02) / (per98 - per02), 0, 1) * 255).astype( np.uint8 ) - array: 'np.typing.NDArray[np.uint8]' = draw_semantic_segmentation_masks( + array: np.typing.NDArray[np.uint8] = draw_semantic_segmentation_masks( torch.from_numpy(rgb_img), sample['mask'], alpha=alpha, diff --git a/torchgeo/datasets/potsdam.py b/torchgeo/datasets/potsdam.py index 0496e1feb..943a48921 100644 --- a/torchgeo/datasets/potsdam.py +++ b/torchgeo/datasets/potsdam.py @@ -206,7 +206,7 @@ class Potsdam2D(NonGeoDataset): """ path = self.files[index]['mask'] with Image.open(path) as img: - array: 'np.typing.NDArray[np.uint8]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.uint8] = np.array(img.convert('RGB')) array = rgb_to_mask(array, self.colormap) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW diff --git a/torchgeo/datasets/reforestree.py b/torchgeo/datasets/reforestree.py index 83e4b5701..28c1d0135 100644 --- a/torchgeo/datasets/reforestree.py +++ b/torchgeo/datasets/reforestree.py @@ -147,7 +147,7 @@ class ReforesTree(NonGeoDataset): the image """ with Image.open(path) as img: - array: 'np.typing.NDArray[np.uint8]' = np.array(img) + array: np.typing.NDArray[np.uint8] = np.array(img) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) diff --git a/torchgeo/datasets/so2sat.py b/torchgeo/datasets/so2sat.py index ee6f14354..300303139 100644 --- a/torchgeo/datasets/so2sat.py +++ b/torchgeo/datasets/so2sat.py @@ -230,7 +230,7 @@ class So2Sat(NonGeoDataset): assert split in self.filenames_by_version[version] self._validate_bands(bands) - self.s1_band_indices: 'np.typing.NDArray[np.int_]' = np.array( + self.s1_band_indices: np.typing.NDArray[np.int_] = np.array( [ self.all_s1_band_names.index(b) for b in bands @@ -240,7 +240,7 @@ class So2Sat(NonGeoDataset): self.s1_band_names = [self.all_s1_band_names[i] for i in self.s1_band_indices] - self.s2_band_indices: 'np.typing.NDArray[np.int_]' = np.array( + self.s2_band_indices: np.typing.NDArray[np.int_] = np.array( [ self.all_s2_band_names.index(b) for b in bands diff --git a/torchgeo/datasets/spacenet.py b/torchgeo/datasets/spacenet.py index 7bae1dbb8..2a5283dfb 100644 --- a/torchgeo/datasets/spacenet.py +++ b/torchgeo/datasets/spacenet.py @@ -686,7 +686,7 @@ class SpaceNet3(SpaceNet): max_speed_bin = 65 speed_arr_bin = np.arange(min_speed_bin, max_speed_bin + 1) bin_size_mph = 10.0 - speed_cls_arr: 'np.typing.NDArray[np.int_]' = np.array( + speed_cls_arr: np.typing.NDArray[np.int_] = np.array( [math.ceil(s / bin_size_mph) for s in speed_arr_bin] ) diff --git a/torchgeo/datasets/usavars.py b/torchgeo/datasets/usavars.py index 4870c715a..b955e8ded 100644 --- a/torchgeo/datasets/usavars.py +++ b/torchgeo/datasets/usavars.py @@ -180,7 +180,7 @@ class USAVars(NonGeoDataset): the image """ with rasterio.open(path) as f: - array: 'np.typing.NDArray[np.int_]' = f.read() + array: np.typing.NDArray[np.int_] = f.read() tensor = torch.from_numpy(array).float() return tensor diff --git a/torchgeo/datasets/vaihingen.py b/torchgeo/datasets/vaihingen.py index dd3232296..6276dcb87 100644 --- a/torchgeo/datasets/vaihingen.py +++ b/torchgeo/datasets/vaihingen.py @@ -190,7 +190,7 @@ class Vaihingen2D(NonGeoDataset): """ path = self.files[index]['image'] with Image.open(path) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)).float() @@ -207,7 +207,7 @@ class Vaihingen2D(NonGeoDataset): """ path = self.files[index]['mask'] with Image.open(path) as img: - array: 'np.typing.NDArray[np.uint8]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.uint8] = np.array(img.convert('RGB')) array = rgb_to_mask(array, self.colormap) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW diff --git a/torchgeo/datasets/vhr10.py b/torchgeo/datasets/vhr10.py index 7f77b2951..30ea07c90 100644 --- a/torchgeo/datasets/vhr10.py +++ b/torchgeo/datasets/vhr10.py @@ -285,7 +285,7 @@ class VHR10(NonGeoDataset): f'{id_:03d}.jpg', ) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img) + array: np.typing.NDArray[np.int_] = np.array(img) tensor = torch.from_numpy(array) tensor = tensor.float() # Convert from HxWxC to CxHxW diff --git a/torchgeo/datasets/xview.py b/torchgeo/datasets/xview.py index 17e3b2e15..5716c06f5 100644 --- a/torchgeo/datasets/xview.py +++ b/torchgeo/datasets/xview.py @@ -163,7 +163,7 @@ class XView2(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB')) tensor = torch.from_numpy(array) # Convert from HxWxC to CxHxW tensor = tensor.permute((2, 0, 1)) @@ -180,7 +180,7 @@ class XView2(NonGeoDataset): """ filename = os.path.join(path) with Image.open(filename) as img: - array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L')) + array: np.typing.NDArray[np.int_] = np.array(img.convert('L')) tensor = torch.from_numpy(array) tensor = tensor.to(torch.long) return tensor diff --git a/torchgeo/models/rcf.py b/torchgeo/models/rcf.py index 99fd1ae5c..82545afa3 100644 --- a/torchgeo/models/rcf.py +++ b/torchgeo/models/rcf.py @@ -165,7 +165,7 @@ class RCF(Module): sqrt_zca_eigs = np.sqrt(E) inv_sqrt_zca_eigs = np.diag(np.power(sqrt_zca_eigs, -1)) global_ZCA = V.dot(inv_sqrt_zca_eigs).dot(V.T) - patches_normalized: 'np.typing.NDArray[np.float32]' = ( + patches_normalized: np.typing.NDArray[np.float32] = ( (patches).dot(global_ZCA).dot(global_ZCA.T) )