Skip to content

Commit

Permalink
Merge pull request #51 from Guts/compliance/apply-isort-to-existing-c…
Browse files Browse the repository at this point in the history
…odebase

Applique isort au code existant
  • Loading branch information
Dolite authored Aug 30, 2023
2 parents 6e18415 + 965496a commit a22019b
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 148 deletions.
3 changes: 2 additions & 1 deletion src/rok4/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class StorageType(Enum):
HTTPS = "https://"
S3 = "s3://"


class ColorFormat(Enum):
"""A color format enumeration.
Except from "BIT", the member's name matches
Expand All @@ -36,4 +37,4 @@ class ColorFormat(Enum):

BIT = 1
UINT8 = 8
FLOAT32 = 32
FLOAT32 = 32
8 changes: 4 additions & 4 deletions src/rok4/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
- `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.enums import PyramidType
from rok4.exceptions import *
from rok4.pyramid import Pyramid
from rok4.tile_matrix_set import TileMatrixSet
from rok4.storage import *
from rok4.tile_matrix_set import TileMatrixSet
from rok4.utils import *
from rok4.enums import PyramidType


class Layer:
Expand Down
32 changes: 14 additions & 18 deletions src/rok4/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
- `Level` - Level of a pyramid
"""

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

import mapbox_vector_tile
import numpy
from PIL import Image

from rok4.enums import PyramidType, SlabType, StorageType
from rok4.exceptions import *
from rok4.tile_matrix_set import TileMatrixSet, TileMatrix
from rok4.storage import *
from rok4.tile_matrix_set import TileMatrix, TileMatrixSet
from rok4.utils import *
from rok4.enums import PyramidType, SlabType, StorageType

ROK4_IMAGE_HEADER_SIZE = 2048
"""Slab's header size, 2048 bytes"""
Expand Down Expand Up @@ -535,11 +536,8 @@ 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 @@ -656,7 +654,6 @@ def format(self) -> str:

@property
def tile_extension(self) -> str:

if self.__format in [
"TIFF_RAW_UINT8",
"TIFF_LZW_UINT8",
Expand Down Expand Up @@ -732,7 +729,7 @@ def list_generator(self) -> Iterator[Tuple[Tuple[SlabType, str, int, int], Dict]
S3 stored descriptor
from rok4.pyramid import Pyramid
try:
pyramid = Pyramid.from_descriptor("s3://bucket_name/path/to/descriptor.json")
Expand All @@ -756,7 +753,7 @@ 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
Expand All @@ -774,7 +771,7 @@ def list_generator(self) -> Iterator[Tuple[Tuple[SlabType, str, int, int], Dict]
roots = {}
s3_cluster = self.storage_s3_cluster

with open(list_file, "r") as listin:
with open(list_file) as listin:
# Lecture des racines
for line in listin:
line = line.rstrip()
Expand Down Expand Up @@ -1170,7 +1167,6 @@ 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 @@ -1368,10 +1364,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
7 changes: 3 additions & 4 deletions src/rok4/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import copy
import json
import re

from typing import Dict, Tuple

from osgeo import gdal, ogr

from rok4.enums import ColorFormat
from rok4.storage import exists, get_osgeo_path, put_data_str
from rok4.utils import compute_bbox, compute_format
from rok4.enums import ColorFormat

# Enable GDAL/OGR exceptions
ogr.UseExceptions()
Expand Down Expand Up @@ -239,7 +238,7 @@ def from_list(cls, path: str, srs: str) -> "RasterSet":

local_list_path = get_osgeo_path(path)
image_list = []
with open(file=local_list_path, mode="r") as list_file:
with open(file=local_list_path) as list_file:
for line in list_file:
image_path = line.strip(" \t\n\r")
image_list.append(image_path)
Expand Down Expand Up @@ -298,7 +297,7 @@ def from_descriptor(cls, path: str) -> "RasterSet":
"""
self = cls()
descriptor_path = get_osgeo_path(path)
with open(file=descriptor_path, mode="r") as file_handle:
with open(file=descriptor_path) as file_handle:
raw_content = file_handle.read()
serialization = json.loads(raw_content)
self.srs = serialization["srs"]
Expand Down
Loading

0 comments on commit a22019b

Please sign in to comment.