Skip to content

Commit

Permalink
Merge branch 'Guts-compliance/rename-files-to-comply-pep8' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolite committed Jul 18, 2023
2 parents 899ef88 + 48fb66a commit d1e38fc
Show file tree
Hide file tree
Showing 19 changed files with 1,724 additions and 378 deletions.
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
79 changes: 48 additions & 31 deletions src/rok4/Pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@
- `Level` - Level of a pyramid
"""

import io
from typing import Dict, List, Tuple, Union, Iterator
import json
from json.decoder import JSONDecodeError
import os
import re
import numpy
import zlib
from json.decoder import JSONDecodeError
from typing import Dict, Iterator, List, Tuple, Union

import io
import mapbox_vector_tile
import numpy
from PIL import Image

from rok4.Exceptions import *
from rok4.Storage import *
from rok4.TileMatrixSet import TileMatrix, TileMatrixSet
from rok4.Utils import *
from rok4.enums import PyramidType, SlabType, StorageType
from rok4.tile_matrix_set import TileMatrixSet, TileMatrix
from rok4.storage import *
from rok4.utils import *
from rok4.enums import StorageType


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


ROK4_IMAGE_HEADER_SIZE = 2048
Expand Down Expand Up @@ -360,10 +373,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 @@ -400,7 +413,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 @@ -537,8 +550,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 @@ -605,7 +621,7 @@ def storage_root(self) -> str:
Returns:
str: Pyramid's storage root
"""

return self.__storage["root"].split("@", 1)[
0
] # Suppression de l'éventuel hôte de spécification du cluster S3
Expand Down Expand Up @@ -655,6 +671,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 @@ -729,7 +746,7 @@ 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 Down Expand Up @@ -769,7 +786,7 @@ def list_generator(self) -> Iterator[Tuple[Tuple[SlabType, str, int, int], Dict]
roots = {}
s3_cluster = self.storage_s3_cluster

with open(list_file) as listin:
with open(list_file, "r") as listin:
# Lecture des racines
for line in listin:
line = line.rstrip()
Expand Down Expand Up @@ -819,7 +836,7 @@ def get_level(self, level_id: str) -> "Level":
Returns:
The corresponding pyramid's level, None if not present
"""

return self.__levels.get(level_id, None)

def get_levels(self, bottom_id: str = None, top_id: str = None) -> List[Level]:
Expand All @@ -836,7 +853,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 @@ -847,7 +864,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 @@ -918,7 +935,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 @@ -929,7 +946,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 @@ -1003,6 +1020,7 @@ def get_slab_path_from_infos(
else:
return slab_path


def get_tile_data_binary(self, level: str, column: int, row: int) -> str:
"""Get a pyramid's tile as binary string
Expand All @@ -1023,7 +1041,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 @@ -1135,7 +1153,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 @@ -1165,6 +1183,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 @@ -1246,7 +1265,7 @@ 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 @@ -1307,7 +1326,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 @@ -1349,7 +1368,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 @@ -1361,8 +1380,6 @@ 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)
)
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
13 changes: 12 additions & 1 deletion src/rok4/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ class SlabType(Enum):


class StorageType(Enum):
"""Matrice de correspondance entre type de stockage et protocole."""
"""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
File renamed without changes.
22 changes: 11 additions & 11 deletions src/rok4/Layer.py → src/rok4/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
- `Layer` - Descriptor to broadcast pyramids' data
"""

from typing import Dict, List, Tuple, Union
import json
from json.decoder import JSONDecodeError
import os
import re
from json.decoder import JSONDecodeError
from typing import Dict, List, Tuple, Union

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


Expand All @@ -24,12 +24,12 @@ class Layer:
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
Loading

0 comments on commit d1e38fc

Please sign in to comment.