alessandro trinca tornidor
commited on
Commit
•
6126322
1
Parent(s):
49ff57f
[doc] use new typing hints from samgis_core
Browse files
docs/external_links_md.md
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
- My [SamGIS demo website](https://ml-trinca.tornidor.com)
|
|
|
|
|
2 |
- My [personal website](https://trinca.tornidor.com)
|
|
|
1 |
- My [SamGIS demo website](https://ml-trinca.tornidor.com)
|
2 |
+
- My [HuggingFace SamGIS demo](https://huggingface.co/spaces/aletrn/samgis)
|
3 |
+
- My [HuggingFace SamGIS - LISA on CUDA demo](https://huggingface.co/spaces/aletrn/samgis-lisa-on-cuda)
|
4 |
- My [personal website](https://trinca.tornidor.com)
|
samgis/io/coordinates_pixel_conversion.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
"""functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
|
2 |
-
from samgis_core.utilities.type_hints import
|
3 |
|
4 |
from samgis import app_logger
|
5 |
from samgis.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
|
@@ -82,7 +82,7 @@ def get_latlng_to_pixel_coordinates(
|
|
82 |
return point
|
83 |
|
84 |
|
85 |
-
def _from4326_to3857(lat: float, lon: float) ->
|
86 |
from math import radians, log, tan
|
87 |
|
88 |
x_tile: float = radians(lon) * EARTH_EQUATORIAL_RADIUS
|
|
|
1 |
"""functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
|
2 |
+
from samgis_core.utilities.type_hints import TupleFloat, TupleFloatAny
|
3 |
|
4 |
from samgis import app_logger
|
5 |
from samgis.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
|
|
|
82 |
return point
|
83 |
|
84 |
|
85 |
+
def _from4326_to3857(lat: float, lon: float) -> TupleFloat or TupleFloatAny:
|
86 |
from math import radians, log, tan
|
87 |
|
88 |
x_tile: float = radians(lon) * EARTH_EQUATORIAL_RADIUS
|
samgis/io/geo_helpers.py
CHANGED
@@ -2,11 +2,11 @@
|
|
2 |
from affine import Affine
|
3 |
from numpy import ndarray as np_ndarray
|
4 |
|
5 |
-
from samgis_core.utilities.type_hints import
|
6 |
from samgis import app_logger
|
7 |
|
8 |
|
9 |
-
def load_affine_transformation_from_matrix(matrix_source_coefficients:
|
10 |
"""
|
11 |
Wrapper for rasterio.Affine.from_gdal() method
|
12 |
|
@@ -32,7 +32,7 @@ def load_affine_transformation_from_matrix(matrix_source_coefficients: list_floa
|
|
32 |
raise e
|
33 |
|
34 |
|
35 |
-
def get_affine_transform_from_gdal(matrix_source_coefficients:
|
36 |
"""wrapper for rasterio Affine from_gdal method
|
37 |
|
38 |
Args:
|
@@ -44,7 +44,7 @@ def get_affine_transform_from_gdal(matrix_source_coefficients: list_float or tup
|
|
44 |
return Affine.from_gdal(*matrix_source_coefficients)
|
45 |
|
46 |
|
47 |
-
def get_vectorized_raster_as_geojson(mask: np_ndarray, transform:
|
48 |
"""
|
49 |
Get shapes and values of connected regions in a dataset or array
|
50 |
|
|
|
2 |
from affine import Affine
|
3 |
from numpy import ndarray as np_ndarray
|
4 |
|
5 |
+
from samgis_core.utilities.type_hints import ListFloat, DictStrInt, TupleFloat
|
6 |
from samgis import app_logger
|
7 |
|
8 |
|
9 |
+
def load_affine_transformation_from_matrix(matrix_source_coefficients: ListFloat) -> Affine:
|
10 |
"""
|
11 |
Wrapper for rasterio.Affine.from_gdal() method
|
12 |
|
|
|
32 |
raise e
|
33 |
|
34 |
|
35 |
+
def get_affine_transform_from_gdal(matrix_source_coefficients: ListFloat or TupleFloat) -> Affine:
|
36 |
"""wrapper for rasterio Affine from_gdal method
|
37 |
|
38 |
Args:
|
|
|
44 |
return Affine.from_gdal(*matrix_source_coefficients)
|
45 |
|
46 |
|
47 |
+
def get_vectorized_raster_as_geojson(mask: np_ndarray, transform: TupleFloat) -> DictStrInt:
|
48 |
"""
|
49 |
Get shapes and values of connected regions in a dataset or array
|
50 |
|
samgis/io/tms2geotiff.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
|
3 |
from numpy import ndarray
|
4 |
-
from samgis_core.utilities.type_hints import
|
5 |
from xyzservices import TileProvider
|
6 |
|
7 |
from samgis import app_logger
|
@@ -70,7 +70,7 @@ def download_extent(w: float, s: float, e: float, n: float, zoom: int or str = z
|
|
70 |
raise e_download_extent
|
71 |
|
72 |
|
73 |
-
def crop_raster(w: float, s: float, e: float, n: float, raster: ndarray, raster_bbox:
|
74 |
crs: str = OUTPUT_CRS_STRING, driver: str = DRIVER_RASTERIO_GTIFF) -> tuple_ndarray_transform:
|
75 |
"""
|
76 |
Crop a raster using given bounding box (w, s, e, n) values
|
@@ -134,7 +134,7 @@ def crop_raster(w: float, s: float, e: float, n: float, raster: ndarray, raster_
|
|
134 |
raise e_crop_raster
|
135 |
|
136 |
|
137 |
-
def get_transform_raster(raster: ndarray, raster_bbox:
|
138 |
"""
|
139 |
Convert the input raster image to RGB and extract the Affine
|
140 |
|
|
|
1 |
import os
|
2 |
|
3 |
from numpy import ndarray
|
4 |
+
from samgis_core.utilities.type_hints import TupleFloat
|
5 |
from xyzservices import TileProvider
|
6 |
|
7 |
from samgis import app_logger
|
|
|
70 |
raise e_download_extent
|
71 |
|
72 |
|
73 |
+
def crop_raster(w: float, s: float, e: float, n: float, raster: ndarray, raster_bbox: TupleFloat,
|
74 |
crs: str = OUTPUT_CRS_STRING, driver: str = DRIVER_RASTERIO_GTIFF) -> tuple_ndarray_transform:
|
75 |
"""
|
76 |
Crop a raster using given bounding box (w, s, e, n) values
|
|
|
134 |
raise e_crop_raster
|
135 |
|
136 |
|
137 |
+
def get_transform_raster(raster: ndarray, raster_bbox: TupleFloat) -> tuple_ndarray_transform:
|
138 |
"""
|
139 |
Convert the input raster image to RGB and extract the Affine
|
140 |
|
samgis/prediction_api/predictors.py
CHANGED
@@ -8,7 +8,7 @@ from samgis.utilities.constants import DEFAULT_URL_TILES, SLOPE_CELLSIZE
|
|
8 |
from samgis_core.prediction_api.sam_onnx import SegmentAnythingONNX
|
9 |
from samgis_core.prediction_api.sam_onnx import get_raster_inference, get_raster_inference_with_embedding_from_dict
|
10 |
from samgis_core.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME, DEFAULT_INPUT_SHAPE
|
11 |
-
from samgis_core.utilities.type_hints import
|
12 |
|
13 |
|
14 |
models_dict = {"fastsam": {"instance": None}}
|
@@ -16,13 +16,13 @@ embedding_dict = {}
|
|
16 |
|
17 |
|
18 |
def samexporter_predict(
|
19 |
-
bbox:
|
20 |
-
prompt:
|
21 |
zoom: float,
|
22 |
model_name: str = "fastsam",
|
23 |
source: str = DEFAULT_URL_TILES,
|
24 |
source_name: str = None
|
25 |
-
) ->
|
26 |
"""
|
27 |
Return predictions as a geojson from a geo-referenced image using the given input prompt.
|
28 |
|
|
|
8 |
from samgis_core.prediction_api.sam_onnx import SegmentAnythingONNX
|
9 |
from samgis_core.prediction_api.sam_onnx import get_raster_inference, get_raster_inference_with_embedding_from_dict
|
10 |
from samgis_core.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME, DEFAULT_INPUT_SHAPE
|
11 |
+
from samgis_core.utilities.type_hints import LlistFloat, DictStrInt, ListDict
|
12 |
|
13 |
|
14 |
models_dict = {"fastsam": {"instance": None}}
|
|
|
16 |
|
17 |
|
18 |
def samexporter_predict(
|
19 |
+
bbox: LlistFloat,
|
20 |
+
prompt: ListDict,
|
21 |
zoom: float,
|
22 |
model_name: str = "fastsam",
|
23 |
source: str = DEFAULT_URL_TILES,
|
24 |
source_name: str = None
|
25 |
+
) -> DictStrInt:
|
26 |
"""
|
27 |
Return predictions as a geojson from a geo-referenced image using the given input prompt.
|
28 |
|