Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.11
rev: v0.16.6
hooks:
# Run the linter.
- id: ruff
Expand All @@ -13,7 +13,7 @@ repos:
types_or: [python, pyi]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-ast
- id: check-yaml
Expand All @@ -30,7 +30,7 @@ repos:
- id: requirements-txt-fixer

- repo: https://github.com/asottile/blacken-docs
rev: 1.19.1
rev: 1.20.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.3.0]
Expand All @@ -47,7 +47,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.37.1
rev: v1.38.0
hooks:
- id: yamllint
args: [--format, parsable, --strict]
Expand All @@ -61,12 +61,12 @@ repos:
args: [--width, '120']

- repo: https://github.com/PyCQA/isort
rev: 6.0.1
rev: 9.0.1
hooks:
- id: isort

- repo: https://github.com/PyCQA/bandit
rev: 1.8.3
rev: 1.9.4
hooks:
- id: bandit
args: [-c, pyproject.toml]
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand All @@ -16,7 +15,7 @@

sys.path.insert(0, os.path.abspath("../minerva/"))

import minerva # noqa: E402
import minerva

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

Expand Down
1 change: 0 additions & 1 deletion minerva/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2024 Harry Baker
#
# This program is free software: you can redistribute it and/or modify
Expand Down
21 changes: 10 additions & 11 deletions minerva/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down Expand Up @@ -33,30 +32,30 @@
__license__ = "MIT License"
__copyright__ = "Copyright (C) 2024 Harry Baker"
__all__ = [
"MinervaNonGeoDataset",
"DFC2020",
"GeoSSL4EOS12Sentinel2",
"MinervaConcatDataset",
"MinervaNonGeoDataset",
"MinervaSSL4EO",
"MultiSpectralDataset",
"NAIPChesapeakeCVPR",
"NonGeoSSL4EOS12Sentinel2",
"PairedConcatDataset",
"PairedGeoDataset",
"PairedNonGeoDataset",
"PairedUnionDataset",
"PairedConcatDataset",
"GeoSSL4EOS12Sentinel2",
"NonGeoSSL4EOS12Sentinel2",
"MinervaSSL4EO",
"NAIPChesapeakeCVPR",
"DFC2020",
"MultiSpectralDataset",
"construct_dataloader",
"get_collator",
"get_manifest",
"get_random_sample",
"intersect_datasets",
"load_all_samples",
"make_bounding_box",
"make_dataset",
"make_loaders",
"make_manifest",
"stack_sample_pairs",
"intersect_datasets",
"unionise_datasets",
"get_random_sample",
]

from .collators import get_collator, stack_sample_pairs
Expand Down
1 change: 0 additions & 1 deletion minerva/datasets/__testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down
4 changes: 2 additions & 2 deletions minerva/datasets/collators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down Expand Up @@ -40,7 +39,8 @@
# =====================================================================================================================
# IMPORTS
# =====================================================================================================================
from typing import Any, Callable, Iterable
from collections.abc import Callable, Iterable
from typing import Any

from hydra.utils import get_method
from torchgeo.datasets.utils import stack_samples
Expand Down
20 changes: 10 additions & 10 deletions minerva/datasets/dfc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2024 Harry Baker
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -37,9 +36,10 @@
# =====================================================================================================================
# IMPORTS
# =====================================================================================================================
from collections.abc import Callable
from glob import glob
from pathlib import Path
from typing import Any, Callable, Optional
from typing import Any

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(
use_s2lr=False,
use_s1=False,
labels=False,
transforms: Optional[Callable[..., Any]] = None,
transforms: Callable[..., Any] | None = None,
) -> None:
super().__init__()

Expand Down Expand Up @@ -359,9 +359,9 @@ def __init__(
use_s2lr=False,
use_s1=False,
labels=False,
transforms: Optional[Callable[..., Any]] = None,
transforms: Callable[..., Any] | None = None,
) -> None:
super(DFC2020, self).__init__(
super().__init__(
root,
split,
use_s2hr,
Expand Down Expand Up @@ -396,9 +396,9 @@ def plot(
self,
sample: dict[str, Tensor],
show_titles: bool = True,
suptitle: Optional[str] = None,
classes: Optional[dict[int, str]] = None,
colours: Optional[dict[int, str]] = None,
suptitle: str | None = None,
classes: dict[int, str] | None = None,
colours: dict[int, str] | None = None,
) -> Figure:
"""Plot a sample from the dataset.

Expand Down Expand Up @@ -583,9 +583,9 @@ def __init__(
use_s2lr=False,
use_s1=False,
labels=False,
transforms: Optional[Callable[..., Any]] = None,
transforms: Callable[..., Any] | None = None,
) -> None:
super(SEN12MS, self).__init__(
super().__init__(
root,
split,
use_s2hr,
Expand Down
41 changes: 20 additions & 21 deletions minerva/datasets/factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down Expand Up @@ -34,9 +33,9 @@
__copyright__ = "Copyright (C) 2024 Harry Baker"
__all__ = [
"construct_dataloader",
"get_manifest",
"make_dataset",
"make_loaders",
"get_manifest",
"make_manifest",
]

Expand All @@ -47,10 +46,11 @@
import os
import platform
import re
from collections.abc import Iterable
from copy import deepcopy
from datetime import timedelta
from pathlib import Path
from typing import Any, Iterable, Optional
from typing import Any

import hydra
import numpy as np
Expand Down Expand Up @@ -87,7 +87,7 @@
def create_subdataset(
paths: str | Iterable[str],
subdataset_params: dict[str, Any],
transformations: Optional[Any],
transformations: Any | None,
sample_pairs: bool = False,
) -> GeoDataset | NonGeoDataset:
"""Creates a sub-dataset based on the parameters supplied.
Expand Down Expand Up @@ -140,7 +140,7 @@ def get_subdataset(
data_directory: Iterable[str] | str | Path,
dataset_params: dict[str, Any],
key: str,
transformations: Optional[Any],
transformations: Any | None,
sample_pairs: bool = False,
cache: bool = False,
cache_dir: str | Path = "",
Expand Down Expand Up @@ -174,7 +174,7 @@ def get_subdataset(
sub_dataset_params.get("paths", sub_dataset_params.get("root")),
)

sub_dataset: Optional[GeoDataset | NonGeoDataset]
sub_dataset: GeoDataset | NonGeoDataset | None

if cache or sub_dataset_params.get("cache_dataset"):
this_hash = utils.make_hash(sub_dataset_params)
Expand Down Expand Up @@ -326,7 +326,7 @@ def make_dataset(
multi_datasets_exist = False

auto_norm = False
master_transforms: Optional[Any] = None
master_transforms: Any | None = None

for sub_type_key in type_dataset_params.keys():
# If any of these keys are present, this must be a parameter set for a singular dataset at this level.
Expand Down Expand Up @@ -640,7 +640,7 @@ def make_loaders(
rank: int = 0,
world_size: int = 1,
p_dist: bool = False,
task_name: Optional[str] = None,
task_name: str | None = None,
**params,
) -> tuple[
dict[str, DataLoader[Iterable[Any]]] | DataLoader[Iterable[Any]],
Expand Down Expand Up @@ -736,7 +736,7 @@ def make_loaders(

collator_target = utils.fallback_params("collator", task_params, params, None)

if "sampler" in dataset_params.keys():
if "sampler" in dataset_params:
sampler_params: dict[str, Any] = dataset_params["sampler"]

if not utils.check_substrings_in_string(model_type, "siamese"):
Expand Down Expand Up @@ -778,7 +778,7 @@ def make_loaders(
n_batches = {}
loaders = {}

for mode in dataset_params.keys():
for mode in dataset_params:
mode_sampler_params: dict[str, Any] = dataset_params[mode]["sampler"]

if (
Expand Down Expand Up @@ -861,11 +861,11 @@ def get_data_specs(
manifest_name: str | Path,
classes: dict[int, str],
cmap_dict: dict[int, str],
cache_dir: Optional[str | Path] = None,
data_dir: Optional[str | Path] = None,
dataset_params: Optional[dict[str, Any]] = None,
sampler_params: Optional[dict[str, Any]] = None,
dataloader_params: Optional[dict[str, Any]] = None,
cache_dir: str | Path | None = None,
data_dir: str | Path | None = None,
dataset_params: dict[str, Any] | None = None,
sampler_params: dict[str, Any] | None = None,
dataloader_params: dict[str, Any] | None = None,
collator_target: str = "torchgeo.datasets.stack_samples",
change_detection: bool = False,
elim: bool = True,
Expand Down Expand Up @@ -901,10 +901,10 @@ def get_data_specs(

def get_manifest(
manifest_path: str | Path,
data_dir: Optional[str | Path] = None,
dataset_params: Optional[dict[str, Any]] = None,
sampler_params: Optional[dict[str, Any]] = None,
loader_params: Optional[dict[str, Any]] = None,
data_dir: str | Path | None = None,
dataset_params: dict[str, Any] | None = None,
sampler_params: dict[str, Any] | None = None,
loader_params: dict[str, Any] | None = None,
collator_target: str = "torchgeo.datasets.stack_samples",
change_detection: bool = False,
) -> DataFrame:
Expand Down Expand Up @@ -998,8 +998,7 @@ def delete_transforms(params: dict[str, Any]) -> None:

# Delete the transforms for both imagery and targets.
# This assumes that it is geometric transforms and therefore distort the actual dataset composition.
if "transforms" in params:
del params["transforms"]
params.pop("transforms", None)

_sampler_params = deepcopy(sampler_params)
if OmegaConf.is_config(_sampler_params):
Expand Down
12 changes: 6 additions & 6 deletions minerva/datasets/multispectral.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down Expand Up @@ -38,8 +37,9 @@
# IMPORTS
# =====================================================================================================================
import os
from collections.abc import Callable
from functools import partial
from typing import Any, Callable, Dict, List, Optional
from typing import Any

import numpy as np
import tifffile
Expand All @@ -62,8 +62,8 @@ class MultiSpectralDataset(VisionDataset, MinervaNonGeoDataset):
def __init__(
self,
root: str,
transforms: Optional[Callable[..., Any]] = None,
bands: Optional[tuple[str, ...]] = None,
transforms: Callable[..., Any] | None = None,
bands: tuple[str, ...] | None = None,
as_type=np.float32,
) -> None:
super().__init__(root, transform=transforms, target_transform=None)
Expand All @@ -76,7 +76,7 @@ def __init__(
self.as_type = as_type
self.samples = self.make_dataset()

def make_dataset(self) -> List[str]:
def make_dataset(self) -> list[str]:
directory = os.path.expanduser(self.root)

dirs = set()
Expand All @@ -86,7 +86,7 @@ def make_dataset(self) -> List[str]:
dirs.add(root)
return sorted(list(dirs))

def __getitem__(self, index: int) -> Dict[str, Any]:
def __getitem__(self, index: int) -> dict[str, Any]:
path = self.samples[index]

images = []
Expand Down
1 change: 0 additions & 1 deletion minerva/datasets/naip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# MIT License

# Copyright (c) 2024 Harry Baker
Expand Down
Loading
Loading