Skip to content

Commit

Permalink
Ruff: prefer single quotes over double quotes (#2001)
Browse files Browse the repository at this point in the history
* Ruff: prefer single quotes over double quotes

* Apply ruff format
  • Loading branch information
adamjstewart committed May 3, 2024
1 parent bd9c757 commit b09122f
Show file tree
Hide file tree
Showing 377 changed files with 12,339 additions and 12,338 deletions.
112 changes: 56 additions & 56 deletions docs/conf.py
Expand Up @@ -17,16 +17,16 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, os.path.abspath('..'))

import torchgeo # noqa: E402

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

project = "torchgeo"
copyright = "2021, Microsoft Corporation"
project = 'torchgeo'
copyright = '2021, Microsoft Corporation'
author = torchgeo.__author__
version = ".".join(torchgeo.__version__.split(".")[:2])
version = '.'.join(torchgeo.__version__.split('.')[:2])
release = torchgeo.__version__


Expand All @@ -36,97 +36,97 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"nbsphinx",
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'nbsphinx',
]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build"]
exclude_patterns = ['_build']

# Sphinx 3.0+ required for:
# autodoc_typehints_description_target = "documented"
needs_sphinx = "4.0"
needs_sphinx = '4.0'

nitpicky = True
nitpick_ignore = [
# Undocumented classes
("py:class", "fiona.model.Feature"),
("py:class", "kornia.augmentation._2d.intensity.base.IntensityAugmentationBase2D"),
("py:class", "kornia.augmentation.base._AugmentationBase"),
("py:class", "lightning.pytorch.utilities.types.OptimizerLRSchedulerConfig"),
("py:class", "segmentation_models_pytorch.base.model.SegmentationModel"),
("py:class", "timm.models.resnet.ResNet"),
("py:class", "timm.models.vision_transformer.VisionTransformer"),
("py:class", "torch.optim.lr_scheduler.LRScheduler"),
("py:class", "torchvision.models._api.WeightsEnum"),
("py:class", "torchvision.models.resnet.ResNet"),
("py:class", "torchvision.models.swin_transformer.SwinTransformer"),
('py:class', 'fiona.model.Feature'),
('py:class', 'kornia.augmentation._2d.intensity.base.IntensityAugmentationBase2D'),
('py:class', 'kornia.augmentation.base._AugmentationBase'),
('py:class', 'lightning.pytorch.utilities.types.OptimizerLRSchedulerConfig'),
('py:class', 'segmentation_models_pytorch.base.model.SegmentationModel'),
('py:class', 'timm.models.resnet.ResNet'),
('py:class', 'timm.models.vision_transformer.VisionTransformer'),
('py:class', 'torch.optim.lr_scheduler.LRScheduler'),
('py:class', 'torchvision.models._api.WeightsEnum'),
('py:class', 'torchvision.models.resnet.ResNet'),
('py:class', 'torchvision.models.swin_transformer.SwinTransformer'),
]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "pytorch_sphinx_theme"
html_theme = 'pytorch_sphinx_theme'
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"collapse_navigation": False,
"display_version": True,
"logo_only": True,
"pytorch_project": "docs",
"navigation_with_keys": True,
"analytics_id": "UA-209075005-1",
'collapse_navigation': False,
'display_version': True,
'logo_only': True,
'pytorch_project': 'docs',
'navigation_with_keys': True,
'analytics_id': 'UA-209075005-1',
}

html_favicon = os.path.join("..", "logo", "favicon.ico")
html_favicon = os.path.join('..', 'logo', 'favicon.ico')

html_static_path = ["_static"]
html_css_files = ["button-width.css", "notebook-prompt.css", "table-scroll.css"]
html_static_path = ['_static']
html_css_files = ['button-width.css', 'notebook-prompt.css', 'table-scroll.css']

# -- Extension configuration -------------------------------------------------

# sphinx.ext.autodoc
autodoc_default_options = {
"members": True,
"special-members": True,
"show-inheritance": True,
'members': True,
'special-members': True,
'show-inheritance': True,
}
autodoc_member_order = "bysource"
autodoc_typehints = "description"
autodoc_typehints_description_target = "documented"
autodoc_member_order = 'bysource'
autodoc_typehints = 'description'
autodoc_typehints_description_target = 'documented'

# sphinx.ext.intersphinx
intersphinx_mapping = {
"kornia": ("https://kornia.readthedocs.io/en/stable/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"python": ("https://docs.python.org/3", None),
"lightning": ("https://lightning.ai/docs/pytorch/stable/", None),
"pyvista": ("https://docs.pyvista.org/version/stable/", None),
"rasterio": ("https://rasterio.readthedocs.io/en/stable/", None),
"rtree": ("https://rtree.readthedocs.io/en/stable/", None),
"segmentation_models_pytorch": ("https://smp.readthedocs.io/en/stable/", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
"timm": ("https://huggingface.co/docs/timm/main/en/", None),
"torch": ("https://pytorch.org/docs/stable", None),
"torchmetrics": ("https://lightning.ai/docs/torchmetrics/stable/", None),
"torchvision": ("https://pytorch.org/vision/stable", None),
'kornia': ('https://kornia.readthedocs.io/en/stable/', None),
'matplotlib': ('https://matplotlib.org/stable/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'python': ('https://docs.python.org/3', None),
'lightning': ('https://lightning.ai/docs/pytorch/stable/', None),
'pyvista': ('https://docs.pyvista.org/version/stable/', None),
'rasterio': ('https://rasterio.readthedocs.io/en/stable/', None),
'rtree': ('https://rtree.readthedocs.io/en/stable/', None),
'segmentation_models_pytorch': ('https://smp.readthedocs.io/en/stable/', None),
'sklearn': ('https://scikit-learn.org/stable/', None),
'timm': ('https://huggingface.co/docs/timm/main/en/', None),
'torch': ('https://pytorch.org/docs/stable', None),
'torchmetrics': ('https://lightning.ai/docs/torchmetrics/stable/', None),
'torchvision': ('https://pytorch.org/vision/stable', None),
}

# nbsphinx
nbsphinx_execute = "never"
nbsphinx_execute = 'never'
# TODO: branch/tag should change depending on which version of docs you look at
# TODO: width option of image directive is broken, see:
# https://github.com/pytorch/pytorch_sphinx_theme/issues/140
Expand Down Expand Up @@ -165,4 +165,4 @@
# Disables requirejs in nbsphinx to enable compatibility with the pytorch_sphinx_theme
# See more information here https://github.com/spatialaudio/nbsphinx/issues/599
# NOTE: This will likely break nbsphinx widgets
nbsphinx_requirejs_path = ""
nbsphinx_requirejs_path = ''
36 changes: 18 additions & 18 deletions docs/tutorials/custom_raster_dataset.ipynb
Expand Up @@ -131,7 +131,7 @@
"from torchgeo.samplers import RandomGeoSampler\n",
"\n",
"%matplotlib inline\n",
"plt.rcParams[\"figure.figsize\"] = (12, 12)"
"plt.rcParams['figure.figsize'] = (12, 12)"
]
},
{
Expand Down Expand Up @@ -248,18 +248,18 @@
},
"outputs": [],
"source": [
"root = os.path.join(tempfile.gettempdir(), \"sentinel\")\n",
"root = os.path.join(tempfile.gettempdir(), 'sentinel')\n",
"item_urls = [\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20220902T090559_R050_T40XDH_20220902T181115\",\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20220718T084609_R107_T40XEJ_20220718T175008\",\n",
" 'https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20220902T090559_R050_T40XDH_20220902T181115',\n",
" 'https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20220718T084609_R107_T40XEJ_20220718T175008',\n",
"]\n",
"\n",
"for item_url in item_urls:\n",
" item = pystac.Item.from_file(item_url)\n",
" signed_item = planetary_computer.sign(item)\n",
" for band in [\"B02\", \"B03\", \"B04\", \"B08\"]:\n",
" for band in ['B02', 'B03', 'B04', 'B08']:\n",
" asset_href = signed_item.assets[band].href\n",
" filename = urlparse(asset_href).path.split(\"/\")[-1]\n",
" filename = urlparse(asset_href).path.split('/')[-1]\n",
" download_url(asset_href, root, filename)"
]
},
Expand Down Expand Up @@ -360,13 +360,13 @@
"outputs": [],
"source": [
"class Sentinel2(RasterDataset):\n",
" filename_glob = \"T*_B02_10m.tif\"\n",
" filename_regex = r\"^.{6}_(?P<date>\\d{8}T\\d{6})_(?P<band>B0[\\d])\"\n",
" date_format = \"%Y%m%dT%H%M%S\"\n",
" filename_glob = 'T*_B02_10m.tif'\n",
" filename_regex = r'^.{6}_(?P<date>\\d{8}T\\d{6})_(?P<band>B0[\\d])'\n",
" date_format = '%Y%m%dT%H%M%S'\n",
" is_image = True\n",
" separate_files = True\n",
" all_bands = [\"B02\", \"B03\", \"B04\", \"B08\"]\n",
" rgb_bands = [\"B04\", \"B03\", \"B02\"]"
" all_bands = ['B02', 'B03', 'B04', 'B08']\n",
" rgb_bands = ['B04', 'B03', 'B02']"
]
},
{
Expand Down Expand Up @@ -423,13 +423,13 @@
"outputs": [],
"source": [
"class Sentinel2(RasterDataset):\n",
" filename_glob = \"T*_B02_10m.tif\"\n",
" filename_regex = r\"^.{6}_(?P<date>\\d{8}T\\d{6})_(?P<band>B0[\\d])\"\n",
" date_format = \"%Y%m%dT%H%M%S\"\n",
" filename_glob = 'T*_B02_10m.tif'\n",
" filename_regex = r'^.{6}_(?P<date>\\d{8}T\\d{6})_(?P<band>B0[\\d])'\n",
" date_format = '%Y%m%dT%H%M%S'\n",
" is_image = True\n",
" separate_files = True\n",
" all_bands = [\"B02\", \"B03\", \"B04\", \"B08\"]\n",
" rgb_bands = [\"B04\", \"B03\", \"B02\"]\n",
" all_bands = ['B02', 'B03', 'B04', 'B08']\n",
" rgb_bands = ['B04', 'B03', 'B02']\n",
"\n",
" def plot(self, sample):\n",
" # Find the correct band index order\n",
Expand All @@ -438,7 +438,7 @@
" rgb_indices.append(self.all_bands.index(band))\n",
"\n",
" # Reorder and rescale the image\n",
" image = sample[\"image\"][rgb_indices].permute(1, 2, 0)\n",
" image = sample['image'][rgb_indices].permute(1, 2, 0)\n",
" image = torch.clamp(image / 10000, min=0, max=1).numpy()\n",
"\n",
" # Plot the image\n",
Expand Down Expand Up @@ -479,7 +479,7 @@
"for batch in dataloader:\n",
" sample = unbind_samples(batch)[0]\n",
" dataset.plot(sample)\n",
" plt.axis(\"off\")\n",
" plt.axis('off')\n",
" plt.show()"
]
},
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/getting_started.ipynb
Expand Up @@ -149,15 +149,15 @@
},
"outputs": [],
"source": [
"naip_root = os.path.join(tempfile.gettempdir(), \"naip\")\n",
"naip_root = os.path.join(tempfile.gettempdir(), 'naip')\n",
"naip_url = (\n",
" \"https://naipeuwest.blob.core.windows.net/naip/v002/de/2018/de_060cm_2018/38075/\"\n",
" 'https://naipeuwest.blob.core.windows.net/naip/v002/de/2018/de_060cm_2018/38075/'\n",
")\n",
"tiles = [\n",
" \"m_3807511_ne_18_060_20181104.tif\",\n",
" \"m_3807511_se_18_060_20181104.tif\",\n",
" \"m_3807512_nw_18_060_20180815.tif\",\n",
" \"m_3807512_sw_18_060_20180815.tif\",\n",
" 'm_3807511_ne_18_060_20181104.tif',\n",
" 'm_3807511_se_18_060_20181104.tif',\n",
" 'm_3807512_nw_18_060_20180815.tif',\n",
" 'm_3807512_sw_18_060_20180815.tif',\n",
"]\n",
"for tile in tiles:\n",
" download_url(naip_url + tile, naip_root)\n",
Expand Down Expand Up @@ -188,7 +188,7 @@
},
"outputs": [],
"source": [
"chesapeake_root = os.path.join(tempfile.gettempdir(), \"chesapeake\")\n",
"chesapeake_root = os.path.join(tempfile.gettempdir(), 'chesapeake')\n",
"os.makedirs(chesapeake_root, exist_ok=True)\n",
"chesapeake = ChesapeakeDE(chesapeake_root, crs=naip.crs, res=naip.res, download=True)"
]
Expand Down Expand Up @@ -285,8 +285,8 @@
"outputs": [],
"source": [
"for sample in dataloader:\n",
" image = sample[\"image\"]\n",
" target = sample[\"mask\"]"
" image = sample['image']\n",
" target = sample['mask']"
]
}
],
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorials/indices.ipynb
Expand Up @@ -171,7 +171,7 @@
},
"outputs": [],
"source": [
"root = os.path.join(tempfile.gettempdir(), \"eurosat100\")\n",
"root = os.path.join(tempfile.gettempdir(), 'eurosat100')\n",
"ds = EuroSAT100(root, download=True)\n",
"sample = ds[21]"
]
Expand Down Expand Up @@ -247,14 +247,14 @@
"source": [
"# NDVI is appended to channel dimension (dim=0)\n",
"index = AppendNDVI(index_nir=7, index_red=3)\n",
"image = sample[\"image\"]\n",
"image = sample['image']\n",
"image = index(image)[0]\n",
"\n",
"# Normalize from [-1, 1] -> [0, 1] for visualization\n",
"image[-1] = (image[-1] + 1) / 2\n",
"\n",
"plt.imshow(image[-1], cmap=\"RdYlGn\")\n",
"plt.axis(\"off\")\n",
"plt.imshow(image[-1], cmap='RdYlGn')\n",
"plt.axis('off')\n",
"plt.show()\n",
"plt.close()"
]
Expand Down Expand Up @@ -299,8 +299,8 @@
"# Normalize from [-1, 1] -> [0, 1] for visualization\n",
"image[-1] = (image[-1] + 1) / 2\n",
"\n",
"plt.imshow(image[-1], cmap=\"BrBG\")\n",
"plt.axis(\"off\")\n",
"plt.imshow(image[-1], cmap='BrBG')\n",
"plt.axis('off')\n",
"plt.show()\n",
"plt.close()"
]
Expand Down Expand Up @@ -345,8 +345,8 @@
"# Normalize from [-1, 1] -> [0, 1] for visualization\n",
"image[-1] = (image[-1] + 1) / 2\n",
"\n",
"plt.imshow(image[-1], cmap=\"terrain\")\n",
"plt.axis(\"off\")\n",
"plt.imshow(image[-1], cmap='terrain')\n",
"plt.axis('off')\n",
"plt.show()\n",
"plt.close()"
]
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/pretrained_weights.ipynb
Expand Up @@ -133,7 +133,7 @@
},
"outputs": [],
"source": [
"root = os.path.join(tempfile.gettempdir(), \"eurosat100\")\n",
"root = os.path.join(tempfile.gettempdir(), 'eurosat100')\n",
"datamodule = EuroSAT100DataModule(\n",
" root=root, batch_size=batch_size, num_workers=num_workers, download=True\n",
")"
Expand Down Expand Up @@ -199,8 +199,8 @@
"outputs": [],
"source": [
"task = ClassificationTask(\n",
" model=\"resnet18\",\n",
" loss=\"ce\",\n",
" model='resnet18',\n",
" loss='ce',\n",
" weights=weights,\n",
" in_channels=13,\n",
" num_classes=10,\n",
Expand All @@ -226,8 +226,8 @@
},
"outputs": [],
"source": [
"in_chans = weights.meta[\"in_chans\"]\n",
"model = timm.create_model(\"resnet18\", in_chans=in_chans, num_classes=10)\n",
"in_chans = weights.meta['in_chans']\n",
"model = timm.create_model('resnet18', in_chans=in_chans, num_classes=10)\n",
"model.load_state_dict(weights.get_state_dict(progress=True), strict=False)"
]
},
Expand All @@ -250,8 +250,8 @@
},
"outputs": [],
"source": [
"accelerator = \"gpu\" if torch.cuda.is_available() else \"cpu\"\n",
"default_root_dir = os.path.join(tempfile.gettempdir(), \"experiments\")"
"accelerator = 'gpu' if torch.cuda.is_available() else 'cpu'\n",
"default_root_dir = os.path.join(tempfile.gettempdir(), 'experiments')"
]
},
{
Expand Down

0 comments on commit b09122f

Please sign in to comment.