Skip to content

Commit

Permalink
Merge branch 'feature/v0.2.2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Feb 3, 2023
2 parents f59d055 + 7369a28 commit ed66836
Show file tree
Hide file tree
Showing 31 changed files with 1,539 additions and 1,620 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

20 changes: 4 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/ikamensh/flynt/
rev: '0.77'
hooks:
- id: flynt
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.239'
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
Expand All @@ -18,14 +17,3 @@ repos:
hooks:
- id: blackdoc
language_version: python3.9
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
args:
- --convention=numpy
- --add-ignore=D104,D200,D202,D205,D301,D400
5 changes: 2 additions & 3 deletions colour_datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- utilities: Various utilities.
"""

import contextlib
import numpy as np
import os
import subprocess # nosec
Expand Down Expand Up @@ -77,7 +78,5 @@
del _version

# TODO: Remove legacy printing support when deemed appropriate.
try:
with contextlib.suppress(TypeError):
np.set_printoptions(legacy="1.13")
except TypeError:
pass
13 changes: 5 additions & 8 deletions colour_datasets/loaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys

from colour.hints import Any, Union
from colour.hints import Any
from colour.utilities import CanonicalMapping, warning

from colour_datasets.records import datasets
Expand Down Expand Up @@ -105,22 +105,19 @@
Dataset loaders ids and callables.
"""

from .kuopio import DATASET_LOADERS_KUOPIO_UNIVERSITY # noqa
from .kuopio import DATASET_LOADERS_KUOPIO_UNIVERSITY # noqa: E402

DATASET_LOADERS.update(DATASET_LOADERS_KUOPIO_UNIVERSITY)

from . import kuopio # noqa
from . import kuopio # noqa: E402

_module = sys.modules["colour_datasets.loaders"]

for _export in kuopio.__all__:
if _export.startswith("DatasetLoader_") or _export.startswith("build_"):

setattr(_module, _export, getattr(kuopio, _export))

__all__ += [
_export,
]
__all__ += [_export] # noqa: PLE0604

del _module, _export

Expand All @@ -133,7 +130,7 @@
"""


def load(dataset: Union[int, str]) -> Any:
def load(dataset: int | str) -> Any:
"""
Load given dataset: The dataset is pulled locally, i.e. synced if required
and then its data is loaded.
Expand Down
8 changes: 3 additions & 5 deletions colour_datasets/loaders/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from abc import ABC, abstractmethod

from colour.hints import Any, Optional
from colour.hints import Any

from colour_datasets.records import Record

Expand Down Expand Up @@ -63,7 +63,7 @@ class AbstractDatasetLoader(ABC):

def __init__(self, record: Record) -> None:
self._record: Record = record
self._content: Optional[Any] = None
self._content: Any | None = None

@property
def record(self) -> Record:
Expand All @@ -79,7 +79,7 @@ def record(self) -> Record:
return self._record

@property
def id(self) -> str:
def id(self) -> str: # noqa: A003
"""
Getter property for the dataset id.
Expand Down Expand Up @@ -122,8 +122,6 @@ def load(self) -> Any:
when they implement it, e.g. ``super().sync()``.
"""

pass

def sync(self):
"""
Sync the dataset content, i.e. checks whether it is synced and pulls
Expand Down
26 changes: 12 additions & 14 deletions colour_datasets/loaders/asano2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
XYZ_ColourMatchingFunctions,
LMS_ConeFundamentals,
)
from colour.hints import Dict, NDArrayFloat, Optional
from colour.hints import Dict, NDArrayFloat
from colour.utilities import as_float_array, tstack

from colour_datasets.loaders import AbstractDatasetLoader
Expand All @@ -52,7 +52,7 @@ class Specification_Asano2015(
"Specification_Asano2015",
("XYZ_2", "XYZ_10", "LMS_2", "LMS_10", "parameters", "others"),
)
): # noqa: D405,D407,D410,D411
):
"""
Define the *Asano (2015)* specification for an observer.
Expand All @@ -74,7 +74,7 @@ class Specification_Asano2015(
References
----------
:cite:`Asano2015`
"""
""" # noqa: D405, D407, D410, D411

def __new__(
cls,
Expand All @@ -83,7 +83,7 @@ def __new__(
LMS_2: LMS_ConeFundamentals,
LMS_10: LMS_ConeFundamentals,
parameters: NDArrayFloat,
others: Optional[Dict] = None,
others: Dict | None = None,
):
"""
Return a new instance of the
Expand Down Expand Up @@ -122,7 +122,7 @@ class DatasetLoader_Asano2015(AbstractDatasetLoader):
def __init__(self) -> None:
super().__init__(datasets()[DatasetLoader_Asano2015.ID])

def load(self) -> Dict[str, Specification_Asano2015]:
def load(self) -> Dict[str, Dict[int, Specification_Asano2015]]:
"""
Sync, parse, convert and return the *Asano (2015)*
*Observer Function Database* dataset content.
Expand All @@ -145,12 +145,10 @@ def load(self) -> Dict[str, Specification_Asano2015]:

super().sync()

self._content = dict(
[
("Categorical Observers", dict()),
("Colour Normal Observers", dict()),
]
)
self._content = {
"Categorical Observers": {},
"Colour Normal Observers": {},
}

# Categorical Observers
workbook_path = os.path.join(
Expand Down Expand Up @@ -247,7 +245,7 @@ def parse_workbook_Asano2015(

shape = SpectralShape(390, 780, 5)
wavelengths = shape.range()
data: Dict = dict()
data: Dict = {}

for i, cmfs in enumerate(
[
Expand Down Expand Up @@ -276,7 +274,7 @@ def parse_workbook_Asano2015(
observer = k + 1
rgb = tstack([x[k], y[k], z[k]])
if data.get(observer) is None:
data[observer] = dict()
data[observer] = {}

key = f"{cmfs[1]}_{degree[0]}"
data[observer][key] = cmfs[0](
Expand Down Expand Up @@ -310,7 +308,7 @@ def parse_workbook_Asano2015(
return data


_DATASET_LOADER_ASANO2015: Optional[DatasetLoader_Asano2015] = None
_DATASET_LOADER_ASANO2015: DatasetLoader_Asano2015 | None = None
"""
Singleton instance of the *Asano (2015)* *Observer Function Database* dataset
loader.
Expand Down
6 changes: 3 additions & 3 deletions colour_datasets/loaders/brendel2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os

from colour import LinearInterpolator, SpectralShape, SpectralDistribution
from colour.hints import Dict, Optional
from colour.hints import Dict
from colour.utilities import as_int

from colour_datasets.loaders import AbstractDatasetLoader
Expand Down Expand Up @@ -87,7 +87,7 @@ def load(self) -> Dict[str, SpectralDistribution]:

super().sync()

self._content = dict()
self._content = {}

wavelengths = SpectralShape(350, 700, 2).range()

Expand All @@ -108,7 +108,7 @@ def load(self) -> Dict[str, SpectralDistribution]:
return self._content


_DATASET_LOADER_BRENDEL2020: Optional[DatasetLoader_Brendel2020] = None
_DATASET_LOADER_BRENDEL2020: DatasetLoader_Brendel2020 | None = None
"""
Singleton instance of the *Brendel (2020)* *Measured Commercial LED Spectra*
dataset loader.
Expand Down
Loading

0 comments on commit ed66836

Please sign in to comment.