Skip to content

Commit

Permalink
Fixutils microjson light (#14)
Browse files Browse the repository at this point in the history
* created default package with less dependencies

* fix polygons encodings error

---------

Co-authored-by: Bengt Ljungquist <bengt@ljungquist.info>
  • Loading branch information
hamshkhawar and bengtl authored Aug 15, 2024
1 parent f7ce613 commit b28aa36
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/microjson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
from microjson.model import Feature, Properties
from typing import Union
import pydantic
import matplotlib.pyplot as plt

#define conditional imports
try:
from bfio import BioReader
import filepattern as fp
from scipy import ndimage
import vaex
except ImportError as e:
print("""Packages bfio, filepattern, scipy, vaex not installed
please install using pip install microjson[all]""")
raise e


#define conditional imports
try:
Expand Down Expand Up @@ -94,6 +107,7 @@ def _tile_read(self) -> None:
image = self.br[y:y_max, x:x_max, z : z + 1]

unique_labels = len(np.unique(image))

if unique_labels >= self.max_unique_labels:
if unique_labels == self.max_unique_labels:
msg = f"Binary image detected : tile {i}"
Expand All @@ -113,6 +127,7 @@ def _tile_read(self) -> None:
)
if as_completed(future): # type: ignore
label, coordinates = future.result()

if len(label) and len(coordinates) > 0:
label = [i + idx for i in range(
1, len(label) + 1)]
Expand Down Expand Up @@ -328,9 +343,10 @@ def polygons_to_microjson( # noqa: PLR0915
if self.polygon_type == "rectangle":
cor_value = list(ast.literal_eval(cor))
else:
cor_value = cor
cor_value = cor + [cor[0]]

geometry = GeometryClass(type=row["geometry_type"], coordinates=[cor_value])


# create a new properties object dynamically
properties = mj.Properties(numeric=numeric_dict)
Expand Down

0 comments on commit b28aa36

Please sign in to comment.