aletrn commited on
Commit
c8c2cad
β€’
1 Parent(s): eaace17

[refactor] renamed backend package to samgis

Browse files
Files changed (36) hide show
  1. .coveragerc +2 -2
  2. README.md +2 -2
  3. dockerfiles/dockerfile-fastapi-samgeo +0 -38
  4. dockerfiles/dockerfile-lambda-fastsam-api +3 -3
  5. docs/modules.rst +3 -3
  6. docs/{src.io.rst β†’ samgis.io.rst} +23 -15
  7. docs/{src.prediction_api.rst β†’ samgis.prediction_api.rst} +9 -9
  8. docs/{src.rst β†’ samgis.rst} +6 -17
  9. docs/{src.utilities.rst β†’ samgis.utilities.rst} +15 -15
  10. pyproject.toml +30 -0
  11. pytest.ini +2 -2
  12. requirements_dev.txt +3 -2
  13. {src β†’ samgis}/__init__.py +2 -2
  14. {src β†’ samgis}/io/__init__.py +0 -0
  15. {src β†’ samgis}/io/coordinates_pixel_conversion.py +4 -4
  16. {src β†’ samgis}/io/geo_helpers.py +2 -2
  17. {src β†’ samgis}/io/lambda_helpers.py +6 -6
  18. {src β†’ samgis}/io/lambda_wrapper.py +3 -3
  19. {src β†’ samgis}/io/tms2geotiff.py +6 -6
  20. {src β†’ samgis}/prediction_api/__init__.py +0 -0
  21. {src β†’ samgis}/prediction_api/predictors.py +6 -6
  22. {src β†’ samgis}/prediction_api/sam_onnx.py +1 -1
  23. {src β†’ samgis}/utilities/__init__.py +0 -0
  24. {src β†’ samgis}/utilities/constants.py +0 -0
  25. {src β†’ samgis}/utilities/serialize.py +2 -2
  26. {src β†’ samgis}/utilities/type_hints.py +1 -1
  27. {src β†’ samgis}/utilities/utilities.py +2 -2
  28. tests/__init__.py +1 -1
  29. tests/io/test_coordinates_pixel_conversion.py +2 -2
  30. tests/io/test_geo_helpers.py +3 -3
  31. tests/io/test_lambda_helpers.py +6 -6
  32. tests/io/test_tms2geotiff.py +3 -3
  33. tests/prediction_api/test_predictors.py +2 -2
  34. tests/prediction_api/test_sam_onnx.py +4 -4
  35. tests/test_app.py +7 -7
  36. tests/utilities/test_serialize.py +1 -1
.coveragerc CHANGED
@@ -1,9 +1,9 @@
1
  [run]
2
- source = src
3
  omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
4
 
5
  [report]
6
  omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
7
 
8
  exclude_lines =
9
- if __name__ == .__main__.:
 
1
  [run]
2
+ source = samgis
3
  omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
4
 
5
  [report]
6
  omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
7
 
8
  exclude_lines =
9
+ if __name__ == .__main__.:
README.md CHANGED
@@ -66,7 +66,7 @@ there is `Pipfile` (sphinx docs is hosted on Cloudflare Pages).
66
  Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
67
 
68
  ```bash
69
- python -m pytest --cov=src --cov-report=term-missing && coverage html
70
  ```
71
 
72
  ## Update the static documentation with sphinx
@@ -81,7 +81,7 @@ Run the command from the project root:
81
  cd docs && sphinx-quickstart -p SamGIS -a "alessandro trinca tornidor" -r 1.0.0 -l python --master index
82
 
83
  # update docs folder (from project root)
84
- sphinx-apidoc -f -o docs src
85
  ```
86
 
87
  Then it's possible to generate the HTML pages
 
66
  Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
67
 
68
  ```bash
69
+ python -m pytest --cov=samgis --cov-report=term-missing && coverage html
70
  ```
71
 
72
  ## Update the static documentation with sphinx
 
81
  cd docs && sphinx-quickstart -p SamGIS -a "alessandro trinca tornidor" -r 1.0.0 -l python --master index
82
 
83
  # update docs folder (from project root)
84
+ sphinx-apidoc -f -o docs samgis
85
  ```
86
 
87
  Then it's possible to generate the HTML pages
dockerfiles/dockerfile-fastapi-samgeo DELETED
@@ -1,38 +0,0 @@
1
- FROM ghcr.io/osgeo/gdal:ubuntu-small-3.7.2
2
-
3
- WORKDIR /code
4
- COPY ./requirements_dockerfile.txt /code/requirements_dockerfile.txt
5
- COPY ./requirements_pip.txt /code/requirements_pip.txt
6
-
7
- RUN apt update && apt install -y g++ make cmake unzip libcurl4-openssl-dev python3-pip
8
-
9
- # avoid segment-geospatial exception caused by missing libGL.so.1 library
10
- RUN apt install -y libgl1 curl
11
- RUN ls -ld /usr/lib/x86_64-linux-gnu/libGL.so* || echo "libGL.so* not found..."
12
-
13
- RUN which python
14
- RUN python --version
15
- RUN python -m pip install --no-cache-dir --upgrade -r /code/requirements_pip.txt
16
- RUN python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
17
- RUN python -m pip install --no-cache-dir -r /code/requirements_dockerfile.txt
18
-
19
- RUN useradd -m -u 1000 user
20
-
21
- USER user
22
-
23
- ENV HOME=/home/user \
24
- PATH=/home/user/.local/bin:$PATH
25
-
26
- WORKDIR $HOME/app
27
-
28
- RUN curl -o ${HOME}/sam_vit_h_4b8939.pth https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
29
- RUN ls -l ${HOME}/
30
- COPY --chown=user . $HOME/app
31
-
32
- RUN echo $HOME/app
33
- RUN echo $HOME/
34
-
35
- RUN ls -l $HOME/app
36
- RUN ls -l $HOME/
37
-
38
- CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dockerfiles/dockerfile-lambda-fastsam-api CHANGED
@@ -6,7 +6,7 @@ ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-pa
6
 
7
  # Set working directory to function root directory
8
  WORKDIR ${LAMBDA_TASK_ROOT}
9
- COPY ./src ${LAMBDA_TASK_ROOT}/src
10
  COPY ./machine_learning_models ${LAMBDA_TASK_ROOT}/machine_learning_models
11
 
12
  RUN ls -l /usr/bin/which
@@ -28,7 +28,7 @@ RUN python -m pip list
28
  RUN python -m pip freeze
29
  RUN df -h
30
  RUN ls -l /lambda-entrypoint.sh
31
- RUN ls -l ${LAMBDA_TASK_ROOT}/src/
32
 
33
  # ENTRYPOINT ["/lambda-entrypoint.sh"]
34
- CMD [ "src.io.lambda_wrapper.lambda_handler" ]
 
6
 
7
  # Set working directory to function root directory
8
  WORKDIR ${LAMBDA_TASK_ROOT}
9
+ COPY ./samgis ${LAMBDA_TASK_ROOT}/samgis
10
  COPY ./machine_learning_models ${LAMBDA_TASK_ROOT}/machine_learning_models
11
 
12
  RUN ls -l /usr/bin/which
 
28
  RUN python -m pip freeze
29
  RUN df -h
30
  RUN ls -l /lambda-entrypoint.sh
31
+ RUN ls -l ${LAMBDA_TASK_ROOT}/samgis/
32
 
33
  # ENTRYPOINT ["/lambda-entrypoint.sh"]
34
+ CMD [ "samgis.io.lambda_wrapper.lambda_handler" ]
docs/modules.rst CHANGED
@@ -1,7 +1,7 @@
1
- src
2
- ===
3
 
4
  .. toctree::
5
  :maxdepth: 4
6
 
7
- src
 
1
+ samgis
2
+ ======
3
 
4
  .. toctree::
5
  :maxdepth: 4
6
 
7
+ samgis
docs/{src.io.rst β†’ samgis.io.rst} RENAMED
@@ -1,37 +1,45 @@
1
- src.io package
2
- ==============
3
 
4
  Submodules
5
  ----------
6
 
7
- src.io.coordinates\_pixel\_conversion module
8
- --------------------------------------------
9
 
10
- .. automodule:: src.io.coordinates_pixel_conversion
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
- src.io.geo\_helpers module
16
- --------------------------
17
 
18
- .. automodule:: src.io.geo_helpers
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
- src.io.lambda\_helpers module
24
- -----------------------------
 
 
 
 
 
 
 
 
25
 
26
- .. automodule:: src.io.lambda_helpers
27
  :members:
28
  :undoc-members:
29
  :show-inheritance:
30
 
31
- src.io.tms2geotiff module
32
- -------------------------
33
 
34
- .. automodule:: src.io.tms2geotiff
35
  :members:
36
  :undoc-members:
37
  :show-inheritance:
@@ -39,7 +47,7 @@ src.io.tms2geotiff module
39
  Module contents
40
  ---------------
41
 
42
- .. automodule:: src.io
43
  :members:
44
  :undoc-members:
45
  :show-inheritance:
 
1
+ samgis.io package
2
+ =================
3
 
4
  Submodules
5
  ----------
6
 
7
+ samgis.io.coordinates\_pixel\_conversion module
8
+ -----------------------------------------------
9
 
10
+ .. automodule:: samgis.io.coordinates_pixel_conversion
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
+ samgis.io.geo\_helpers module
16
+ -----------------------------
17
 
18
+ .. automodule:: samgis.io.geo_helpers
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
+ samgis.io.lambda\_helpers module
24
+ --------------------------------
25
+
26
+ .. automodule:: samgis.io.lambda_helpers
27
+ :members:
28
+ :undoc-members:
29
+ :show-inheritance:
30
+
31
+ samgis.io.lambda\_wrapper module
32
+ --------------------------------
33
 
34
+ .. automodule:: samgis.io.lambda_wrapper
35
  :members:
36
  :undoc-members:
37
  :show-inheritance:
38
 
39
+ samgis.io.tms2geotiff module
40
+ ----------------------------
41
 
42
+ .. automodule:: samgis.io.tms2geotiff
43
  :members:
44
  :undoc-members:
45
  :show-inheritance:
 
47
  Module contents
48
  ---------------
49
 
50
+ .. automodule:: samgis.io
51
  :members:
52
  :undoc-members:
53
  :show-inheritance:
docs/{src.prediction_api.rst β†’ samgis.prediction_api.rst} RENAMED
@@ -1,21 +1,21 @@
1
- src.prediction\_api package
2
- ===========================
3
 
4
  Submodules
5
  ----------
6
 
7
- src.prediction\_api.predictors module
8
- -------------------------------------
9
 
10
- .. automodule:: src.prediction_api.predictors
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
- src.prediction\_api.sam\_onnx module
16
- ------------------------------------
17
 
18
- .. automodule:: src.prediction_api.sam_onnx
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
@@ -23,7 +23,7 @@ src.prediction\_api.sam\_onnx module
23
  Module contents
24
  ---------------
25
 
26
- .. automodule:: src.prediction_api
27
  :members:
28
  :undoc-members:
29
  :show-inheritance:
 
1
+ samgis.prediction\_api package
2
+ ==============================
3
 
4
  Submodules
5
  ----------
6
 
7
+ samgis.prediction\_api.predictors module
8
+ ----------------------------------------
9
 
10
+ .. automodule:: samgis.prediction_api.predictors
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
+ samgis.prediction\_api.sam\_onnx module
16
+ ---------------------------------------
17
 
18
+ .. automodule:: samgis.prediction_api.sam_onnx
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
 
23
  Module contents
24
  ---------------
25
 
26
+ .. automodule:: samgis.prediction_api
27
  :members:
28
  :undoc-members:
29
  :show-inheritance:
docs/{src.rst β†’ samgis.rst} RENAMED
@@ -1,5 +1,5 @@
1
- src package
2
- ===========
3
 
4
  Subpackages
5
  -----------
@@ -7,25 +7,14 @@ Subpackages
7
  .. toctree::
8
  :maxdepth: 4
9
 
10
- src.io
11
- src.prediction_api
12
- src.utilities
13
-
14
- Submodules
15
- ----------
16
-
17
- src.app module
18
- --------------
19
-
20
- .. automodule:: src.app
21
- :members:
22
- :undoc-members:
23
- :show-inheritance:
24
 
25
  Module contents
26
  ---------------
27
 
28
- .. automodule:: src
29
  :members:
30
  :undoc-members:
31
  :show-inheritance:
 
1
+ samgis package
2
+ ==============
3
 
4
  Subpackages
5
  -----------
 
7
  .. toctree::
8
  :maxdepth: 4
9
 
10
+ samgis.io
11
+ samgis.prediction_api
12
+ samgis.utilities
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  Module contents
15
  ---------------
16
 
17
+ .. automodule:: samgis
18
  :members:
19
  :undoc-members:
20
  :show-inheritance:
docs/{src.utilities.rst β†’ samgis.utilities.rst} RENAMED
@@ -1,37 +1,37 @@
1
- src.utilities package
2
- =====================
3
 
4
  Submodules
5
  ----------
6
 
7
- src.utilities.constants module
8
- ------------------------------
9
 
10
- .. automodule:: src.utilities.constants
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
- src.utilities.serialize module
16
- ------------------------------
17
 
18
- .. automodule:: src.utilities.serialize
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
- src.utilities.type\_hints module
24
- --------------------------------
25
 
26
- .. automodule:: src.utilities.type_hints
27
  :members:
28
  :undoc-members:
29
  :show-inheritance:
30
 
31
- src.utilities.utilities module
32
- ------------------------------
33
 
34
- .. automodule:: src.utilities.utilities
35
  :members:
36
  :undoc-members:
37
  :show-inheritance:
@@ -39,7 +39,7 @@ src.utilities.utilities module
39
  Module contents
40
  ---------------
41
 
42
- .. automodule:: src.utilities
43
  :members:
44
  :undoc-members:
45
  :show-inheritance:
 
1
+ samgis.utilities package
2
+ ========================
3
 
4
  Submodules
5
  ----------
6
 
7
+ samgis.utilities.constants module
8
+ ---------------------------------
9
 
10
+ .. automodule:: samgis.utilities.constants
11
  :members:
12
  :undoc-members:
13
  :show-inheritance:
14
 
15
+ samgis.utilities.serialize module
16
+ ---------------------------------
17
 
18
+ .. automodule:: samgis.utilities.serialize
19
  :members:
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
+ samgis.utilities.type\_hints module
24
+ -----------------------------------
25
 
26
+ .. automodule:: samgis.utilities.type_hints
27
  :members:
28
  :undoc-members:
29
  :show-inheritance:
30
 
31
+ samgis.utilities.utilities module
32
+ ---------------------------------
33
 
34
+ .. automodule:: samgis.utilities.utilities
35
  :members:
36
  :undoc-members:
37
  :show-inheritance:
 
39
  Module contents
40
  ---------------
41
 
42
+ .. automodule:: samgis.utilities
43
  :members:
44
  :undoc-members:
45
  :show-inheritance:
pyproject.toml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-requirements-txt"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "samgis"
7
+ version = "1.0.0"
8
+ authors = [
9
+ { name="Alessandro Trinca Tornidor", email="alessandro@trinca.tornidor.com" },
10
+ ]
11
+ description = "A backend for machine learning instance segmentation on geospatial data even without dedicated graphics cards."
12
+ readme = "README.md"
13
+ requires-python = ">=3.11"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dynamic = ["dependencies", "optional-dependencies"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/trincadev/samgis-be"
23
+ Issues = "https://github.com/trincadev/samgis-be/issues"
24
+
25
+ [tool.hatch.metadata.hooks.requirements_txt]
26
+ files = ["requirements_dockerfile.txt"]
27
+
28
+ [tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
29
+ dev = ["requirements_dev.txt"]
30
+ docs = ["requirements.txt"]
pytest.ini CHANGED
@@ -3,5 +3,5 @@ env_override_existing_values = 1
3
  env_files =
4
  test/.test.env
5
  [path]
6
- source = src
7
- omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
 
3
  env_files =
4
  test/.test.env
5
  [path]
6
+ source = samgis
7
+ omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
requirements_dev.txt CHANGED
@@ -1,12 +1,13 @@
1
  aws-lambda-powertools
2
  awslambdaric
3
  bson
 
4
  geopandas
5
  jmespath
6
- matplotlib
7
  numpy
8
  onnxruntime
9
- opencv-python
10
  pillow
11
  pydantic>=2.0.3
12
  pytest
 
1
  aws-lambda-powertools
2
  awslambdaric
3
  bson
4
+ contextily
5
  geopandas
6
  jmespath
7
+ myst-parser
8
  numpy
9
  onnxruntime
10
+ opencv-python-headless
11
  pillow
12
  pydantic>=2.0.3
13
  pytest
{src β†’ samgis}/__init__.py RENAMED
@@ -1,10 +1,10 @@
1
  """Get machine learning predictions from geodata raster images"""
2
  from aws_lambda_powertools import Logger
3
- # not used here but contextily_tile is imported in src.io.tms2geotiff
4
  from contextily import tile as contextily_tile
5
  from pathlib import Path
6
 
7
- from src.utilities.constants import SERVICE_NAME
8
 
9
 
10
  PROJECT_ROOT_FOLDER = Path(globals().get("__file__", "./_")).absolute().parent.parent
 
1
  """Get machine learning predictions from geodata raster images"""
2
  from aws_lambda_powertools import Logger
3
+ # not used here but contextily_tile is imported in samgis.io.tms2geotiff
4
  from contextily import tile as contextily_tile
5
  from pathlib import Path
6
 
7
+ from samgis.utilities.constants import SERVICE_NAME
8
 
9
 
10
  PROJECT_ROOT_FOLDER = Path(globals().get("__file__", "./_")).absolute().parent.parent
{src β†’ samgis}/io/__init__.py RENAMED
File without changes
{src β†’ samgis}/io/coordinates_pixel_conversion.py RENAMED
@@ -1,8 +1,8 @@
1
  """functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
2
- from src import app_logger
3
- from src.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
4
- from src.utilities.type_hints import ImagePixelCoordinates, tuple_float, tuple_float_any
5
- from src.utilities.type_hints import LatLngDict
6
 
7
 
8
  def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
 
1
  """functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
2
+ from samgis import app_logger
3
+ from samgis.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
4
+ from samgis.utilities.type_hints import ImagePixelCoordinates, tuple_float, tuple_float_any
5
+ from samgis.utilities.type_hints import LatLngDict
6
 
7
 
8
  def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
{src β†’ samgis}/io/geo_helpers.py RENAMED
@@ -2,8 +2,8 @@
2
  from affine import Affine
3
  from numpy import ndarray as np_ndarray
4
 
5
- from src import app_logger
6
- from src.utilities.type_hints import list_float, tuple_float, dict_str_int
7
 
8
 
9
  def load_affine_transformation_from_matrix(matrix_source_coefficients: list_float) -> Affine:
 
2
  from affine import Affine
3
  from numpy import ndarray as np_ndarray
4
 
5
+ from samgis import app_logger
6
+ from samgis.utilities.type_hints import list_float, tuple_float, dict_str_int
7
 
8
 
9
  def load_affine_transformation_from_matrix(matrix_source_coefficients: list_float) -> Affine:
{src β†’ samgis}/io/lambda_helpers.py RENAMED
@@ -3,11 +3,11 @@ from typing import Dict
3
  from xyzservices import providers
4
  from aws_lambda_powertools.event_handler import content_types
5
 
6
- from src import app_logger
7
- from src.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
8
- from src.utilities.constants import CUSTOM_RESPONSE_MESSAGES
9
- from src.utilities.type_hints import ApiRequestBody
10
- from src.utilities.utilities import base64_decode
11
 
12
 
13
  def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
@@ -154,7 +154,7 @@ def get_parsed_request_body(event: Dict or str) -> ApiRequestBody:
154
 
155
 
156
  def get_url_tile(source_type: str):
157
- from src.utilities.constants import DEFAULT_TMS_NAME, DEFAULT_TMS_NAME_SHORT
158
 
159
  if source_type.lower() == DEFAULT_TMS_NAME_SHORT:
160
  return providers.query_name(DEFAULT_TMS_NAME)
 
3
  from xyzservices import providers
4
  from aws_lambda_powertools.event_handler import content_types
5
 
6
+ from samgis import app_logger
7
+ from samgis.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
8
+ from samgis.utilities.constants import CUSTOM_RESPONSE_MESSAGES
9
+ from samgis.utilities.type_hints import ApiRequestBody
10
+ from samgis.utilities.utilities import base64_decode
11
 
12
 
13
  def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
 
154
 
155
 
156
  def get_url_tile(source_type: str):
157
+ from samgis.utilities.constants import DEFAULT_TMS_NAME, DEFAULT_TMS_NAME_SHORT
158
 
159
  if source_type.lower() == DEFAULT_TMS_NAME_SHORT:
160
  return providers.query_name(DEFAULT_TMS_NAME)
{src β†’ samgis}/io/lambda_wrapper.py RENAMED
@@ -5,9 +5,9 @@ from typing import Dict
5
  from aws_lambda_powertools.utilities.typing import LambdaContext
6
  from pydantic import ValidationError
7
 
8
- from src import app_logger
9
- from src.io.lambda_helpers import get_parsed_request_body, get_parsed_bbox_points, get_response
10
- from src.prediction_api.predictors import samexporter_predict
11
 
12
 
13
  def lambda_handler(event: Dict, context: LambdaContext) -> str:
 
5
  from aws_lambda_powertools.utilities.typing import LambdaContext
6
  from pydantic import ValidationError
7
 
8
+ from samgis import app_logger
9
+ from samgis.io.lambda_helpers import get_parsed_request_body, get_parsed_bbox_points, get_response
10
+ from samgis.prediction_api.predictors import samexporter_predict
11
 
12
 
13
  def lambda_handler(event: Dict, context: LambdaContext) -> str:
{src β†’ samgis}/io/tms2geotiff.py RENAMED
@@ -2,10 +2,10 @@ import os
2
  from numpy import ndarray
3
  from xyzservices import TileProvider
4
 
5
- from src import app_logger
6
- from src.utilities.constants import (OUTPUT_CRS_STRING, DRIVER_RASTERIO_GTIFF, N_MAX_RETRIES, N_CONNECTION, N_WAIT,
7
- ZOOM_AUTO, BOOL_USE_CACHE)
8
- from src.utilities.type_hints import tuple_ndarray_transform, tuple_float
9
 
10
  bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
11
  n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
@@ -48,8 +48,8 @@ def download_extent(w: float, s: float, e: float, n: float, zoom: int or str = z
48
  parsed request input
49
  """
50
  try:
51
- from src import contextily_tile
52
- from src.io.coordinates_pixel_conversion import _from4326_to3857
53
 
54
  app_logger.info(f"connection number:{n_connections}, type:{type(n_connections)}.")
55
  app_logger.info(f"zoom:{zoom}, type:{type(zoom)}.")
 
2
  from numpy import ndarray
3
  from xyzservices import TileProvider
4
 
5
+ from samgis import app_logger
6
+ from samgis.utilities.constants import (OUTPUT_CRS_STRING, DRIVER_RASTERIO_GTIFF, N_MAX_RETRIES, N_CONNECTION, N_WAIT,
7
+ ZOOM_AUTO, BOOL_USE_CACHE)
8
+ from samgis.utilities.type_hints import tuple_ndarray_transform, tuple_float
9
 
10
  bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
11
  n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
 
48
  parsed request input
49
  """
50
  try:
51
+ from samgis import contextily_tile
52
+ from samgis.io.coordinates_pixel_conversion import _from4326_to3857
53
 
54
  app_logger.info(f"connection number:{n_connections}, type:{type(n_connections)}.")
55
  app_logger.info(f"zoom:{zoom}, type:{type(zoom)}.")
{src β†’ samgis}/prediction_api/__init__.py RENAMED
File without changes
{src β†’ samgis}/prediction_api/predictors.py RENAMED
@@ -1,12 +1,12 @@
1
  """functions using machine learning instance model(s)"""
2
  from numpy import array as np_array, uint8, zeros, ndarray
3
 
4
- from src import app_logger, MODEL_FOLDER
5
- from src.io.geo_helpers import get_vectorized_raster_as_geojson
6
- from src.io.tms2geotiff import download_extent
7
- from src.prediction_api.sam_onnx import SegmentAnythingONNX
8
- from src.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME, DEFAULT_TMS
9
- from src.utilities.type_hints import llist_float, dict_str_int, list_dict, tuple_ndarr_int, PIL_Image
10
 
11
  models_dict = {"fastsam": {"instance": None}}
12
 
 
1
  """functions using machine learning instance model(s)"""
2
  from numpy import array as np_array, uint8, zeros, ndarray
3
 
4
+ from samgis import app_logger, MODEL_FOLDER
5
+ from samgis.io.geo_helpers import get_vectorized_raster_as_geojson
6
+ from samgis.io.tms2geotiff import download_extent
7
+ from samgis.prediction_api.sam_onnx import SegmentAnythingONNX
8
+ from samgis.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME, DEFAULT_TMS
9
+ from samgis.utilities.type_hints import llist_float, dict_str_int, list_dict, tuple_ndarr_int, PIL_Image
10
 
11
  models_dict = {"fastsam": {"instance": None}}
12
 
{src β†’ samgis}/prediction_api/sam_onnx.py RENAMED
@@ -28,7 +28,7 @@ from numpy import array as np_array, concatenate, float32, linalg, matmul, ndarr
28
  from cv2 import INTER_LINEAR, warpAffine
29
  from onnxruntime import get_available_providers, InferenceSession
30
 
31
- from src import app_logger
32
 
33
 
34
  class SegmentAnythingONNX:
 
28
  from cv2 import INTER_LINEAR, warpAffine
29
  from onnxruntime import get_available_providers, InferenceSession
30
 
31
+ from samgis import app_logger
32
 
33
 
34
  class SegmentAnythingONNX:
{src β†’ samgis}/utilities/__init__.py RENAMED
File without changes
{src β†’ samgis}/utilities/constants.py RENAMED
File without changes
{src β†’ samgis}/utilities/serialize.py RENAMED
@@ -1,8 +1,8 @@
1
  """Serialize objects"""
2
  from typing import Mapping
3
 
4
- from src import app_logger
5
- from src.utilities.type_hints import dict_str, dict_str_any
6
 
7
 
8
  def serialize(obj: any, include_none: bool = False):
 
1
  """Serialize objects"""
2
  from typing import Mapping
3
 
4
+ from samgis import app_logger
5
+ from samgis.utilities.type_hints import dict_str, dict_str_any
6
 
7
 
8
  def serialize(obj: any, include_none: bool = False):
{src β†’ samgis}/utilities/type_hints.py RENAMED
@@ -7,7 +7,7 @@ from affine import Affine
7
  from numpy import ndarray
8
  from pydantic import BaseModel
9
 
10
- from src.utilities.constants import DEFAULT_TMS
11
 
12
 
13
  dict_str_int = dict[str, int]
 
7
  from numpy import ndarray
8
  from pydantic import BaseModel
9
 
10
+ from samgis.utilities.constants import DEFAULT_TMS
11
 
12
 
13
  dict_str_int = dict[str, int]
{src β†’ samgis}/utilities/utilities.py RENAMED
@@ -1,6 +1,6 @@
1
  """Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
2
- from src import app_logger
3
- from src.utilities.serialize import serialize
4
 
5
 
6
  def _prepare_base64_input(sb):
 
1
  """Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
2
+ from samgis import app_logger
3
+ from samgis.utilities.serialize import serialize
4
 
5
 
6
  def _prepare_base64_input(sb):
tests/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from src import PROJECT_ROOT_FOLDER
2
 
3
 
4
  TEST_ROOT_FOLDER = PROJECT_ROOT_FOLDER / "tests"
 
1
+ from samgis import PROJECT_ROOT_FOLDER
2
 
3
 
4
  TEST_ROOT_FOLDER = PROJECT_ROOT_FOLDER / "tests"
tests/io/test_coordinates_pixel_conversion.py CHANGED
@@ -1,8 +1,8 @@
1
  import json
2
 
3
- from src.io.coordinates_pixel_conversion import _get_latlng2pixel_projection, _get_point_latlng_to_pixel_coordinates, \
4
  get_latlng_to_pixel_coordinates
5
- from src.utilities.type_hints import LatLngDict
6
  from tests import TEST_EVENTS_FOLDER
7
 
8
 
 
1
  import json
2
 
3
+ from samgis.io.coordinates_pixel_conversion import _get_latlng2pixel_projection, _get_point_latlng_to_pixel_coordinates, \
4
  get_latlng_to_pixel_coordinates
5
+ from samgis.utilities.type_hints import LatLngDict
6
  from tests import TEST_EVENTS_FOLDER
7
 
8
 
tests/io/test_geo_helpers.py CHANGED
@@ -4,7 +4,7 @@ import unittest
4
  import numpy as np
5
  import shapely
6
 
7
- from src.io.geo_helpers import load_affine_transformation_from_matrix
8
  from tests import TEST_EVENTS_FOLDER
9
 
10
 
@@ -64,7 +64,7 @@ class TestGeoHelpers(unittest.TestCase):
64
 
65
  def test_get_vectorized_raster_as_geojson_ok(self):
66
  from rasterio.transform import Affine
67
- from src.io.geo_helpers import get_vectorized_raster_as_geojson
68
 
69
  name_fn = "samexporter_predict"
70
 
@@ -82,7 +82,7 @@ class TestGeoHelpers(unittest.TestCase):
82
  assert shapely.equals_exact(output_geojson, expected_output_geojson, tolerance=0.000006)
83
 
84
  def test_get_vectorized_raster_as_geojson_fail(self):
85
- from src.io.geo_helpers import get_vectorized_raster_as_geojson
86
 
87
  name_fn = "samexporter_predict"
88
 
 
4
  import numpy as np
5
  import shapely
6
 
7
+ from samgis.io.geo_helpers import load_affine_transformation_from_matrix
8
  from tests import TEST_EVENTS_FOLDER
9
 
10
 
 
64
 
65
  def test_get_vectorized_raster_as_geojson_ok(self):
66
  from rasterio.transform import Affine
67
+ from samgis.io.geo_helpers import get_vectorized_raster_as_geojson
68
 
69
  name_fn = "samexporter_predict"
70
 
 
82
  assert shapely.equals_exact(output_geojson, expected_output_geojson, tolerance=0.000006)
83
 
84
  def test_get_vectorized_raster_as_geojson_fail(self):
85
+ from samgis.io.geo_helpers import get_vectorized_raster_as_geojson
86
 
87
  name_fn = "samexporter_predict"
88
 
tests/io/test_lambda_helpers.py CHANGED
@@ -3,10 +3,10 @@ import time
3
  from http import HTTPStatus
4
  from unittest.mock import patch
5
 
6
- from src.io import lambda_helpers
7
- from src.io.lambda_helpers import get_parsed_bbox_points, get_parsed_request_body, get_response
8
- from src.utilities.type_hints import ApiRequestBody
9
- from src.utilities import utilities
10
  from tests import TEST_EVENTS_FOLDER
11
 
12
 
@@ -92,7 +92,7 @@ def test_get_parsed_request_body():
92
  @patch.object(lambda_helpers, "providers")
93
  def test_get_url_tile(providers_mocked):
94
  import xyzservices
95
- from src.io.lambda_helpers import get_url_tile
96
 
97
  from tests import LOCAL_URL_TILE
98
 
@@ -112,7 +112,7 @@ def test_get_url_tile(providers_mocked):
112
 
113
 
114
  def test_get_url_tile_real():
115
- from src.io.lambda_helpers import get_url_tile
116
 
117
  assert get_url_tile("OpenStreetMap") == {
118
  'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19,
 
3
  from http import HTTPStatus
4
  from unittest.mock import patch
5
 
6
+ from samgis.io import lambda_helpers
7
+ from samgis.io.lambda_helpers import get_parsed_bbox_points, get_parsed_request_body, get_response
8
+ from samgis.utilities.type_hints import ApiRequestBody
9
+ from samgis.utilities import utilities
10
  from tests import TEST_EVENTS_FOLDER
11
 
12
 
 
92
  @patch.object(lambda_helpers, "providers")
93
  def test_get_url_tile(providers_mocked):
94
  import xyzservices
95
+ from samgis.io.lambda_helpers import get_url_tile
96
 
97
  from tests import LOCAL_URL_TILE
98
 
 
112
 
113
 
114
  def test_get_url_tile_real():
115
+ from samgis.io.lambda_helpers import get_url_tile
116
 
117
  assert get_url_tile("OpenStreetMap") == {
118
  'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19,
tests/io/test_tms2geotiff.py CHANGED
@@ -2,9 +2,9 @@ import unittest
2
 
3
  import numpy as np
4
 
5
- from src import app_logger
6
- from src.io.tms2geotiff import download_extent
7
- from src.utilities.utilities import hash_calculate
8
  from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
9
 
10
  input_bbox = [[39.036252959636606, 15.040283203125002], [38.302869955150044, 13.634033203125002]]
 
2
 
3
  import numpy as np
4
 
5
+ from samgis import app_logger
6
+ from samgis.io.tms2geotiff import download_extent
7
+ from samgis.utilities.utilities import hash_calculate
8
  from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
9
 
10
  input_bbox = [[39.036252959636606, 15.040283203125002], [38.302869955150044, 13.634033203125002]]
tests/prediction_api/test_predictors.py CHANGED
@@ -3,8 +3,8 @@ from unittest.mock import patch
3
 
4
  import numpy as np
5
 
6
- from src.prediction_api import predictors
7
- from src.prediction_api.predictors import get_raster_inference, samexporter_predict
8
  from tests import TEST_EVENTS_FOLDER
9
 
10
 
 
3
 
4
  import numpy as np
5
 
6
+ from samgis.prediction_api import predictors
7
+ from samgis.prediction_api.predictors import get_raster_inference, samexporter_predict
8
  from tests import TEST_EVENTS_FOLDER
9
 
10
 
tests/prediction_api/test_sam_onnx.py CHANGED
@@ -3,10 +3,10 @@ import unittest
3
 
4
  import numpy as np
5
 
6
- from src import MODEL_FOLDER
7
- from src.prediction_api.sam_onnx import SegmentAnythingONNX
8
- from src.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME
9
- from src.utilities.utilities import hash_calculate
10
  from tests import TEST_EVENTS_FOLDER
11
 
12
 
 
3
 
4
  import numpy as np
5
 
6
+ from samgis import MODEL_FOLDER
7
+ from samgis.prediction_api.sam_onnx import SegmentAnythingONNX
8
+ from samgis.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME
9
+ from samgis.utilities.utilities import hash_calculate
10
  from tests import TEST_EVENTS_FOLDER
11
 
12
 
tests/test_app.py CHANGED
@@ -5,7 +5,7 @@ from unittest.mock import patch
5
 
6
  from awslambdaric.lambda_context import LambdaContext
7
 
8
- from src.io import lambda_helpers, lambda_wrapper
9
  from tests.local_tiles_http_server import LocalTilesHttpServer
10
 
11
 
@@ -21,7 +21,7 @@ class TestAppFailures(unittest.TestCase):
21
  samexporter_predict_mocked,
22
  time_mocked
23
  ):
24
- from src.io.lambda_wrapper import lambda_handler
25
 
26
  time_mocked.return_value = 0
27
  get_parsed_request_body_mocked.value = {}
@@ -44,7 +44,7 @@ class TestAppFailures(unittest.TestCase):
44
  @patch.object(time, "time")
45
  @patch.object(lambda_wrapper, "get_parsed_request_body")
46
  def test_lambda_handler_400(self, get_parsed_request_body_mocked, time_mocked):
47
- from src.io.lambda_wrapper import lambda_handler
48
 
49
  time_mocked.return_value = 0
50
  get_parsed_request_body_mocked.return_value = {}
@@ -64,7 +64,7 @@ class TestAppFailures(unittest.TestCase):
64
 
65
  @patch.object(time, "time")
66
  def test_lambda_handler_422(self, time_mocked):
67
- from src.io.lambda_wrapper import lambda_handler
68
 
69
  time_mocked.return_value = 0
70
  event = {"body": {}, "version": 1.0}
@@ -95,7 +95,7 @@ class TestAppFailures(unittest.TestCase):
95
  samexporter_predict_mocked,
96
  time_mocked
97
  ):
98
- from src.io.lambda_wrapper import lambda_handler
99
  from tests import TEST_EVENTS_FOLDER
100
 
101
  time_mocked.return_value = 0
@@ -145,7 +145,7 @@ class TestAppFailures(unittest.TestCase):
145
  import xyzservices
146
  import shapely
147
 
148
- from src.io.lambda_wrapper import lambda_handler
149
  from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
150
 
151
  local_tile_provider = xyzservices.TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="")
@@ -190,7 +190,7 @@ class TestAppFailures(unittest.TestCase):
190
  assert len(output_geojson.geoms) == expected_response_body["n_shapes_geojson"]
191
 
192
  def test_debug(self):
193
- from src.io.lambda_wrapper import lambda_handler
194
 
195
  input_event = {
196
  'bbox': {
 
5
 
6
  from awslambdaric.lambda_context import LambdaContext
7
 
8
+ from samgis.io import lambda_helpers, lambda_wrapper
9
  from tests.local_tiles_http_server import LocalTilesHttpServer
10
 
11
 
 
21
  samexporter_predict_mocked,
22
  time_mocked
23
  ):
24
+ from samgis.io.lambda_wrapper import lambda_handler
25
 
26
  time_mocked.return_value = 0
27
  get_parsed_request_body_mocked.value = {}
 
44
  @patch.object(time, "time")
45
  @patch.object(lambda_wrapper, "get_parsed_request_body")
46
  def test_lambda_handler_400(self, get_parsed_request_body_mocked, time_mocked):
47
+ from samgis.io.lambda_wrapper import lambda_handler
48
 
49
  time_mocked.return_value = 0
50
  get_parsed_request_body_mocked.return_value = {}
 
64
 
65
  @patch.object(time, "time")
66
  def test_lambda_handler_422(self, time_mocked):
67
+ from samgis.io.lambda_wrapper import lambda_handler
68
 
69
  time_mocked.return_value = 0
70
  event = {"body": {}, "version": 1.0}
 
95
  samexporter_predict_mocked,
96
  time_mocked
97
  ):
98
+ from samgis.io.lambda_wrapper import lambda_handler
99
  from tests import TEST_EVENTS_FOLDER
100
 
101
  time_mocked.return_value = 0
 
145
  import xyzservices
146
  import shapely
147
 
148
+ from samgis.io.lambda_wrapper import lambda_handler
149
  from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
150
 
151
  local_tile_provider = xyzservices.TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="")
 
190
  assert len(output_geojson.geoms) == expected_response_body["n_shapes_geojson"]
191
 
192
  def test_debug(self):
193
+ from samgis.io.lambda_wrapper import lambda_handler
194
 
195
  input_event = {
196
  'bbox': {
tests/utilities/test_serialize.py CHANGED
@@ -2,7 +2,7 @@ import unittest
2
 
3
  import numpy as np
4
 
5
- from src.utilities.serialize import serialize
6
 
7
  test_dict_list_dict = {
8
  "type": "FeatureCollection",
 
2
 
3
  import numpy as np
4
 
5
+ from samgis.utilities.serialize import serialize
6
 
7
  test_dict_list_dict = {
8
  "type": "FeatureCollection",