Skip to content

Commit

Permalink
Merge branch 'develop' into compliance/rename-files-to-comply-pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolite authored Jul 18, 2023
2 parents 3fd1c93 + bc67460 commit d2f4985
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 359 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ repos:
rev: 23.3.0
hooks:
- id: black
args: ["--target-version=py38"]


- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- "--py38-plus"
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Documentation interne
* Tests unitaires pour la classe RasterSet
* Classe Raster : constructeur à partir des paramètres

* Pyramid
* Fonction de calcul de la taille d'une pyramide
* Générateur de lecture de la liste du contenu
Expand Down Expand Up @@ -75,7 +75,7 @@ Lecture par système de fichier virtuel avec GDAL
* Utils
* Meilleure gestion de reprojection par `reproject_bbox` : on détecte des systèmes identiques en entrée ou quand seul l'ordre des axes changent, pour éviter le calcul
* Ajout de la fonction de reprojection d'un point `reproject_point` : on détecte des systèmes identiques en entrée ou quand seul l'ordre des axes changent, pour éviter le calcul

### [Changed]

* Utils :
Expand All @@ -98,8 +98,8 @@ Ajout de fonctionnalités de lecture de donnée d'une pyramide et suivi des reco
* Storage :
* Fonction de lecture binaire, complète ou partielle, d'un fichier ou objet S3 ou CEPH
* Exceptions : NotImplementedError permet de préciser qu'une fonctionnalité n'a pas été implémentée pour tous les cas. Ici, on ne gère pas la décompression des données raster pour les compressions packbit et LZW
* Ajout de la publication PyPI dans la CI GitHub

* Ajout de la publication PyPI dans la CI GitHub

### [Changed]

Expand Down Expand Up @@ -181,4 +181,4 @@ Initialisation des librairies Python utilisées par les outils python à venir d
* Librairie de gestion d'un descripteur de pyramide
* chargement depuis un descripteur ou par clone (avec changement de stockage)
* écriture du descripteur
* Tests unitaires couvrant ces librairies
* Tests unitaires couvrant ces librairies
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ L'environnement d'exécution doit avoir accès aux librairies système. Dans le
## Utiliser la librairie

```python
from rok4.TileMatrixSet import TileMatrixSet
from rok4.tile_matrix_set import TileMatrixSet

try:
tms = TileMatrixSet("file:///path/to/tms.json")
Expand All @@ -34,7 +34,7 @@ Plus d'exemple dans la documentation développeur.
* Installer les dépendances de développement :

```sh
python3 -m pip install -e[dev]
python3 -m pip install -e .[dev]
```

* Consulter les [directives de contribution](./CONTRIBUTING.md)
Expand Down
2 changes: 1 addition & 1 deletion README.pypi.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `rok4` package is available on :
## Usage

```python
from rok4.TileMatrixSet import TileMatrixSet
from rok4.tile_matrix_set import TileMatrixSet

try:
tms = TileMatrixSet("file:///path/to/tms.json")
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ doc = [

dev = [
"black",
"isort >= 5.12.0",
"pre-commit >3,<4"
]

Expand Down
39 changes: 39 additions & 0 deletions src/rok4/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! python3 # noqa: E265

# standard lib
from enum import Enum


class PyramidType(Enum):
"""Pyramid's data type"""

RASTER = "RASTER"
VECTOR = "VECTOR"


class SlabType(Enum):
"""Slab's type"""

DATA = "DATA" # Slab of data, raster or vector
MASK = "MASK" # Slab of mask, only for raster pyramid, image with one band : 0 is nodata, other values are data


class StorageType(Enum):
"""Storage type and path's protocol"""

CEPH = "ceph://"
FILE = "file://"
HTTP = "http://"
HTTPS = "https://"
S3 = "s3://"

class ColorFormat(Enum):
"""A color format enumeration.
Except from "BIT", the member's name matches
a common variable format name. The member's value is
the allocated bit size associated to this format.
"""

BIT = 1
UINT8 = 8
FLOAT32 = 32
11 changes: 6 additions & 5 deletions src/rok4/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
import re

from rok4.exceptions import *
from rok4.pyramid import Pyramid, PyramidType
from rok4.pyramid import Pyramid
from rok4.tile_matrix_set import TileMatrixSet
from rok4.storage import *
from rok4.utils import *
from rok4.enums import PyramidType


class Layer:
"""A data layer, raster or vector
Attributes:
__name (str): layer's technical name
__pyramids (Dict[str, Union[rok4.Pyramid.Pyramid,str,str]]): used pyramids
__pyramids (Dict[str, Union[rok4.pyramid.Pyramid,str,str]]): used pyramids
__format (str): pyramid's list path
__tms (rok4.TileMatrixSet.TileMatrixSet): Used grid
__tms (rok4.tile_matrix_set.TileMatrixSet): Used grid
__keywords (List[str]): Keywords
__levels (Dict[str, rok4.Pyramid.Level]): Used pyramids' levels
__best_level (rok4.Pyramid.Level): Used pyramids best level
__levels (Dict[str, rok4.pyramid.Level]): Used pyramids' levels
__best_level (rok4.pyramid.Level): Used pyramids best level
__resampling (str): Interpolation to use fot resampling
__bbox (Tuple[float, float, float, float]): data bounding box, TMS coordinates system
__geobbox (Tuple[float, float, float, float]): data bounding box, EPSG:4326
Expand Down
61 changes: 29 additions & 32 deletions src/rok4/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@
from rok4.tile_matrix_set import TileMatrixSet, TileMatrix
from rok4.storage import *
from rok4.utils import *


class PyramidType(Enum):
"""Pyramid's data type"""

RASTER = "RASTER"
VECTOR = "VECTOR"


class SlabType(Enum):
"""Slab's type"""

DATA = "DATA" # Slab of data, raster or vector
MASK = "MASK" # Slab of mask, only for raster pyramid, image with one band : 0 is nodata, other values are data

from rok4.enums import PyramidType, SlabType, StorageType

ROK4_IMAGE_HEADER_SIZE = 2048
"""Slab's header size, 2048 bytes"""
Expand Down Expand Up @@ -372,10 +358,10 @@ class Pyramid:
__name (str): pyramid's name
__descriptor (str): pyramid's descriptor path
__list (str): pyramid's list path
__tms (rok4.TileMatrixSet.TileMatrixSet): Used grid
__tms (rok4.tile_matrix_set.TileMatrixSet): Used grid
__levels (Dict[str, Level]): Pyramid's levels
__format (str): Data format
__storage (Dict[str, Union[rok4.Storage.StorageType,str,int]]): Pyramid's storage informations (type, root and depth if FILE storage)
__storage (Dict[str, Union[rok4.storage.StorageType,str,int]]): Pyramid's storage informations (type, root and depth if FILE storage)
__raster_specifications (Dict): If raster pyramid, raster specifications
__content (Dict): Loading status (loaded) and list content (cache).
Expand Down Expand Up @@ -412,7 +398,7 @@ def from_descriptor(cls, descriptor: str) -> "Pyramid":
S3 stored descriptor
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand Down Expand Up @@ -549,8 +535,11 @@ def serializable(self) -> Dict:
Returns:
Dict: descriptor structured object description
"""

serialization = {"tile_matrix_set": self.__tms.name, "format": self.__format}

serialization = {
"tile_matrix_set": self.__tms.name,
"format": self.__format
}

serialization["levels"] = []
sorted_levels = sorted(self.__levels.values(), key=lambda l: l.resolution, reverse=True)
Expand Down Expand Up @@ -667,6 +656,7 @@ def format(self) -> str:

@property
def tile_extension(self) -> str:

if self.__format in [
"TIFF_RAW_UINT8",
"TIFF_LZW_UINT8",
Expand Down Expand Up @@ -741,8 +731,8 @@ def list_generator(self) -> Iterator[Tuple[Tuple[SlabType, str, int, int], Dict]
S3 stored descriptor
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand All @@ -766,7 +756,10 @@ def list_generator(self) -> Iterator[Tuple[Tuple[SlabType, str, int, int], Dict]
'slab': 'DATA_18_5424_7526'
}
)
Raises:
StorageError: Unhandled pyramid storage to copy list
MissingEnvironmentError: Missing object storage informations
"""
if self.__content["loaded"]:
for slab, infos in self.__content["cache"].items():
Expand Down Expand Up @@ -848,7 +841,7 @@ def get_levels(self, bottom_id: str = None, top_id: str = None) -> List[Level]:
All levels
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand All @@ -859,7 +852,7 @@ def get_levels(self, bottom_id: str = None, top_id: str = None) -> List[Level]:
From pyramid's bottom to provided top (level 5)
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand Down Expand Up @@ -930,7 +923,7 @@ def get_infos_from_slab_path(self, path: str) -> Tuple[SlabType, str, int, int]:
FILE stored pyramid
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("/path/to/descriptor.json")
Expand All @@ -941,7 +934,7 @@ def get_infos_from_slab_path(self, path: str) -> Tuple[SlabType, str, int, int]:
S3 stored pyramid
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/pyramid.json")
Expand Down Expand Up @@ -1035,7 +1028,7 @@ def get_tile_data_binary(self, level: str, column: int, row: int) -> str:
FILE stored raster pyramid, to extract a tile containing a point and save it as independent image
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("/data/pyramids/SCAN1000.json")
Expand Down Expand Up @@ -1147,7 +1140,7 @@ def get_tile_data_raster(self, level: str, column: int, row: int) -> numpy.ndarr
FILE stored DTM (raster) pyramid, to get the altitude value at a point in the best level
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("/data/pyramids/RGEALTI.json")
Expand Down Expand Up @@ -1177,6 +1170,7 @@ def get_tile_data_raster(self, level: str, column: int, row: int) -> numpy.ndarr
level_object = self.get_level(level)

if self.__format == "TIFF_JPG_UINT8" or self.__format == "TIFF_JPG90_UINT8":

try:
img = Image.open(io.BytesIO(binary_tile))
except Exception as e:
Expand Down Expand Up @@ -1258,7 +1252,8 @@ def get_tile_data_vector(self, level: str, column: int, row: int) -> Dict:
S3 stored vector pyramid, to print a tile as GeoJSON
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
import json
try:
Expand Down Expand Up @@ -1319,7 +1314,7 @@ def get_tile_indices(
FILE stored DTM (raster) pyramid, to get the altitude value at a point in the best level
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("/data/pyramids/RGEALTI.json")
Expand Down Expand Up @@ -1361,7 +1356,7 @@ def size(self) -> int:
Examples:
from rok4.Pyramid import Pyramid
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand All @@ -1373,8 +1368,10 @@ def size(self) -> int:
Returns:
int: size of the pyramid
"""

if not hasattr(self, "_Pyramid__size"):
self.__size = size_path(
get_path_from_infos(self.__storage["type"], self.__storage["root"], self.__name)
)

return self.__size
Loading

0 comments on commit d2f4985

Please sign in to comment.