Skip to content

Commit

Permalink
Ruff: enable ruff-specific rules
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart committed Aug 12, 2024
1 parent e973c1e commit 8ae31ae
Show file tree
Hide file tree
Showing 60 changed files with 204 additions and 199 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))

import torchgeo # noqa: E402
import torchgeo

# -- Project information -----------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion experiments/ssl4eo/download_ssl4eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def filter_collection(

if filtered.size().getInfo() == 0:
raise ee.EEException(
f'ImageCollection.filter: No suitable images found in ({coords[1]:.4f}, {coords[0]:.4f}) between {period[0]} and {period[1]}.' # noqa: E501
f'ImageCollection.filter: No suitable images found in ({coords[1]:.4f}, {coords[0]:.4f}) between {period[0]} and {period[1]}.'
)
return filtered

Expand Down
2 changes: 1 addition & 1 deletion experiments/ssl4eo/sample_ssl4eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
def get_world_cities(
download_root: str = 'world_cities', size: int = 10000
) -> pd.DataFrame:
url = 'https://simplemaps.com/static/data/world-cities/basic/simplemaps_worldcities_basicv1.71.zip' # noqa: E501
url = 'https://simplemaps.com/static/data/world-cities/basic/simplemaps_worldcities_basicv1.71.zip'
filename = 'worldcities.csv'
download_and_extract_archive(url, download_root)
cols = ['city', 'lat', 'lng', 'population']
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ quote-style = "single"
skip-magic-trailing-comma = true

[tool.ruff.lint]
extend-select = ["ANN", "D", "I", "NPY201", "UP"]
ignore = ["ANN101", "ANN102", "ANN401"]
extend-select = ["ANN", "D", "I", "NPY201", "RUF", "UP"]
ignore = ["ANN101", "ANN102", "ANN401", "RUF012"]

[tool.ruff.lint.per-file-ignores]
"docs/**" = ["ANN", "D"]
Expand Down
28 changes: 14 additions & 14 deletions tests/data/dfc2022/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@

train_set = [
{
'image': 'labeled_train/Nantes_Saint-Nazaire/BDORTHO/44-2013-0295-6713-LA93-0M50-E080.tif', # noqa: E501
'dem': 'labeled_train/Nantes_Saint-Nazaire/RGEALTI/44-2013-0295-6713-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'target': 'labeled_train/Nantes_Saint-Nazaire/UrbanAtlas/44-2013-0295-6713-LA93-0M50-E080_UA2012.tif', # noqa: E501
'image': 'labeled_train/Nantes_Saint-Nazaire/BDORTHO/44-2013-0295-6713-LA93-0M50-E080.tif',
'dem': 'labeled_train/Nantes_Saint-Nazaire/RGEALTI/44-2013-0295-6713-LA93-0M50-E080_RGEALTI.tif',
'target': 'labeled_train/Nantes_Saint-Nazaire/UrbanAtlas/44-2013-0295-6713-LA93-0M50-E080_UA2012.tif',
},
{
'image': 'labeled_train/Nice/BDORTHO/06-2014-1007-6318-LA93-0M50-E080.tif', # noqa: E501
'dem': 'labeled_train/Nice/RGEALTI/06-2014-1007-6318-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'target': 'labeled_train/Nice/UrbanAtlas/06-2014-1007-6318-LA93-0M50-E080_UA2012.tif', # noqa: E501
'image': 'labeled_train/Nice/BDORTHO/06-2014-1007-6318-LA93-0M50-E080.tif',
'dem': 'labeled_train/Nice/RGEALTI/06-2014-1007-6318-LA93-0M50-E080_RGEALTI.tif',
'target': 'labeled_train/Nice/UrbanAtlas/06-2014-1007-6318-LA93-0M50-E080_UA2012.tif',
},
]

unlabeled_set = [
{
'image': 'unlabeled_train/Calais_Dunkerque/BDORTHO/59-2012-0650-7077-LA93-0M50-E080.tif', # noqa: E501
'dem': 'unlabeled_train/Calais_Dunkerque/RGEALTI/59-2012-0650-7077-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'image': 'unlabeled_train/Calais_Dunkerque/BDORTHO/59-2012-0650-7077-LA93-0M50-E080.tif',
'dem': 'unlabeled_train/Calais_Dunkerque/RGEALTI/59-2012-0650-7077-LA93-0M50-E080_RGEALTI.tif',
},
{
'image': 'unlabeled_train/LeMans/BDORTHO/72-2013-0469-6789-LA93-0M50-E080.tif', # noqa: E501
'dem': 'unlabeled_train/LeMans/RGEALTI/72-2013-0469-6789-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'image': 'unlabeled_train/LeMans/BDORTHO/72-2013-0469-6789-LA93-0M50-E080.tif',
'dem': 'unlabeled_train/LeMans/RGEALTI/72-2013-0469-6789-LA93-0M50-E080_RGEALTI.tif',
},
]

val_set = [
{
'image': 'val/Marseille_Martigues/BDORTHO/13-2014-0900-6268-LA93-0M50-E080.tif', # noqa: E501
'dem': 'val/Marseille_Martigues/RGEALTI/13-2014-0900-6268-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'image': 'val/Marseille_Martigues/BDORTHO/13-2014-0900-6268-LA93-0M50-E080.tif',
'dem': 'val/Marseille_Martigues/RGEALTI/13-2014-0900-6268-LA93-0M50-E080_RGEALTI.tif',
},
{
'image': 'val/Clermont-Ferrand/BDORTHO/63-2013-0711-6530-LA93-0M50-E080.tif', # noqa: E501
'dem': 'val/Clermont-Ferrand/RGEALTI/63-2013-0711-6530-LA93-0M50-E080_RGEALTI.tif', # noqa: E501
'image': 'val/Clermont-Ferrand/BDORTHO/63-2013-0711-6530-LA93-0M50-E080.tif',
'dem': 'val/Clermont-Ferrand/RGEALTI/63-2013-0711-6530-LA93-0M50-E080_RGEALTI.tif',
},
]

Expand Down
6 changes: 3 additions & 3 deletions tests/data/seasonet/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
# Compute checksums
with open(archive, 'rb') as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f'{season}: {repr(md5)}')
print(f'{season}: {md5!r}')

# Write meta.csv
with open('meta.csv', 'w') as f:
Expand All @@ -121,7 +121,7 @@
# Compute checksums
with open('meta.csv', 'rb') as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f'meta.csv: {repr(md5)}')
print(f'meta.csv: {md5!r}')

os.makedirs('splits', exist_ok=True)

Expand All @@ -138,4 +138,4 @@
# Compute checksums
with open('splits.zip', 'rb') as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f'splits: {repr(md5)}')
print(f'splits: {md5!r}')
2 changes: 1 addition & 1 deletion tests/trainers/test_byol.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])

@pytest.fixture
def weights(self) -> WeightsEnum:
Expand Down
12 changes: 6 additions & 6 deletions tests/trainers/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down Expand Up @@ -262,13 +262,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down
6 changes: 3 additions & 3 deletions tests/trainers/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down
6 changes: 3 additions & 3 deletions tests/trainers/test_iobench.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def test_trainer(self, name: str, fast_dev_run: bool) -> None:
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass
2 changes: 1 addition & 1 deletion tests/trainers/test_moco.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])

def test_version_warnings(self) -> None:
with pytest.warns(UserWarning, match='MoCo v1 uses a memory bank'):
Expand Down
12 changes: 6 additions & 6 deletions tests/trainers/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down Expand Up @@ -240,13 +240,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down
6 changes: 3 additions & 3 deletions tests/trainers/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])
try:
main(['test'] + args)
main(['test', *args])
except MisconfigurationException:
pass
try:
main(['predict'] + args)
main(['predict', *args])
except MisconfigurationException:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_simclr.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_trainer(
'1',
]

main(['fit'] + args)
main(['fit', *args])

def test_version_warnings(self) -> None:
with pytest.warns(UserWarning, match='SimCLR v1 only uses 2 layers'):
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datamodules/seco.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
seasons = kwargs.get('seasons', 1)

# Normalization only available for RGB dataset, defined here:
# https://github.com/ServiceNow/seasonal-contrast/blob/8285173ec205b64bc3e53b880344dd6c3f79fa7a/datasets/seco_dataset.py # noqa: E501
# https://github.com/ServiceNow/seasonal-contrast/blob/8285173ec205b64bc3e53b880344dd6c3f79fa7a/datasets/seco_dataset.py
if bands == SeasonalContrastS2.rgb_bands:
_min = torch.tensor([3, 2, 0])
_max = torch.tensor([88, 103, 129])
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datamodules/ssl4eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SSL4EOS12DataModule(NonGeoDataModule):
.. versionadded:: 0.5
"""

# https://github.com/zhu-xlab/SSL4EO-S12/blob/d2868adfada65e40910bfcedfc49bc3b20df2248/src/benchmark/transfer_classification/datasets/EuroSat/eurosat_dataset.py#L97 # noqa: E501
# https://github.com/zhu-xlab/SSL4EO-S12/blob/d2868adfada65e40910bfcedfc49bc3b20df2248/src/benchmark/transfer_classification/datasets/EuroSat/eurosat_dataset.py#L97
mean = torch.tensor(0)
std = torch.tensor(10000)

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/agb_live_woody_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AbovegroundLiveWoodyBiomassDensity(RasterDataset):

is_image = False

url = 'https://opendata.arcgis.com/api/v3/datasets/e4bdbe8d6d8d4e32ace7d36a4aec7b93_0/downloads/data?format=geojson&spatialRefId=4326' # noqa: E501
url = 'https://opendata.arcgis.com/api/v3/datasets/e4bdbe8d6d8d4e32ace7d36a4aec7b93_0/downloads/data?format=geojson&spatialRefId=4326'

base_filename = 'Aboveground_Live_Woody_Biomass_Density.geojson'

Expand Down
10 changes: 6 additions & 4 deletions torchgeo/datasets/benin_cashews.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ def __init__(

# Calculate the indices that we will use over all tiles
self.chips_metadata = []
for y in list(range(0, self.tile_height - self.chip_size, stride)) + [
self.tile_height - self.chip_size
for y in [
*list(range(0, self.tile_height - self.chip_size, stride)),
self.tile_height - self.chip_size,
]:
for x in list(range(0, self.tile_width - self.chip_size, stride)) + [
self.tile_width - self.chip_size
for x in [
*list(range(0, self.tile_width - self.chip_size, stride)),
self.tile_width - self.chip_size,
]:
self.chips_metadata.append((y, x))

Expand Down
8 changes: 4 additions & 4 deletions torchgeo/datasets/bigearthnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class BigEarthNet(NonGeoDataset):
* https://doi.org/10.1109/IGARSS.2019.8900532
""" # noqa: E501
"""

class_sets = {
19: [
Expand Down Expand Up @@ -234,17 +234,17 @@ class BigEarthNet(NonGeoDataset):

splits_metadata = {
'train': {
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/train.csv?inline=false', # noqa: E501
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/train.csv?inline=false',
'filename': 'bigearthnet-train.csv',
'md5': '623e501b38ab7b12fe44f0083c00986d',
},
'val': {
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/val.csv?inline=false', # noqa: E501
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/val.csv?inline=false',
'filename': 'bigearthnet-val.csv',
'md5': '22efe8ed9cbd71fa10742ff7df2b7978',
},
'test': {
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/test.csv?inline=false', # noqa: E501
'url': 'https://git.tu-berlin.de/rsim/BigEarthNet-MM_19-classes_models/-/raw/9a5be07346ab0884b2d9517475c27ef9db9b5104/splits/test.csv?inline=false',
'filename': 'bigearthnet-test.csv',
'md5': '697fb90677e30571b9ac7699b7e5b432',
},
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/cdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CDL(RasterDataset):
If you use this dataset in your research, please cite it using the following format:
* https://www.nass.usda.gov/Research_and_Science/Cropland/sarsfaqs2.php#Section1_14.0
""" # noqa: E501
"""

filename_glob = '*_30m_cdls.tif'
filename_regex = r"""
Expand All @@ -49,7 +49,7 @@ class CDL(RasterDataset):
date_format = '%Y'
is_image = False

url = 'https://www.nass.usda.gov/Research_and_Science/Cropland/Release/datasets/{}_30m_cdls.zip' # noqa: E501
url = 'https://www.nass.usda.gov/Research_and_Science/Cropland/Release/datasets/{}_30m_cdls.zip'
md5s = {
2023: '8c7685d6278d50c554f934b16a6076b7',
2022: '754cf50670cdfee511937554785de3e6',
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/chabud.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ChaBuD(NonGeoDataset):
]
rgb_bands = ['B04', 'B03', 'B02']
folds = {'train': [1, 2, 3, 4], 'val': [0]}
url = 'https://hf.co/datasets/chabud-team/chabud-ecml-pkdd2023/resolve/de222d434e26379aa3d4f3dd1b2caf502427a8b2/train_eval.hdf5' # noqa: E501
url = 'https://hf.co/datasets/chabud-team/chabud-ecml-pkdd2023/resolve/de222d434e26379aa3d4f3dd1b2caf502427a8b2/train_eval.hdf5'
filename = 'train_eval.hdf5'
md5 = '15d78fb825f9a81dad600db828d22c08'

Expand Down
12 changes: 6 additions & 6 deletions torchgeo/datasets/chesapeake.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ class ChesapeakeCVPR(GeoDataset):

subdatasets = ['base', 'prior_extension']
urls = {
'base': 'https://lilablobssc.blob.core.windows.net/lcmcvpr2019/cvpr_chesapeake_landcover.zip', # noqa: E501
'prior_extension': 'https://zenodo.org/record/5866525/files/cvpr_chesapeake_landcover_prior_extension.zip?download=1', # noqa: E501
'base': 'https://lilablobssc.blob.core.windows.net/lcmcvpr2019/cvpr_chesapeake_landcover.zip',
'prior_extension': 'https://zenodo.org/record/5866525/files/cvpr_chesapeake_landcover_prior_extension.zip?download=1',
}
filenames = {
'base': 'cvpr_chesapeake_landcover.zip',
Expand Down Expand Up @@ -489,13 +489,13 @@ class ChesapeakeCVPR(GeoDataset):
'wv_1m_2014_extended-debuffered-train_tiles',
'wv_1m_2014_extended-debuffered-val_tiles',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_buildings.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_landsat-leaf-off.tif', # noqa: E501
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_landsat-leaf-on.tif', # noqa: E501
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_landsat-leaf-off.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_landsat-leaf-on.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_lc.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_naip-new.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_naip-old.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_nlcd.tif',
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_prior_from_cooccurrences_101_31_no_osm_no_buildings.tif', # noqa: E501
'wv_1m_2014_extended-debuffered-val_tiles/m_3708035_ne_17_1_prior_from_cooccurrences_101_31_no_osm_no_buildings.tif',
'spatial_index.geojson',
]

Expand Down Expand Up @@ -588,7 +588,7 @@ def __init__(
'lc': row['properties']['lc'],
'nlcd': row['properties']['nlcd'],
'buildings': row['properties']['buildings'],
'prior_from_cooccurrences_101_31_no_osm_no_buildings': prior_fn, # noqa: E501
'prior_from_cooccurrences_101_31_no_osm_no_buildings': prior_fn,
},
)

Expand Down
Loading

0 comments on commit 8ae31ae

Please sign in to comment.