Commit 860e580d authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added type hints. Changed a default value. Fixed deployment order to PyPi, Anaconda.

parent 97139899
Pipeline #3374 failed
......@@ -126,6 +126,7 @@ deploy_anaconda:
stage: deploy
dependencies:
- test_py_tools_ds
- deploy_pypi
script:
- source /root/miniconda3/bin/activate
- conda install -y -q conda-build anaconda-client
......
......@@ -2,7 +2,8 @@
import numpy as np
from shapely.geometry import box
from typing import Tuple # noqa F401 # flake8 issue
from shapely.geometry import Polygon # noqa F401 # flake8 issue
from typing import Sequence, Tuple, Union # noqa F401 # flake8 issue
from ..numeric.vector import find_nearest
from .coord_calc import get_corner_coordinates
......@@ -11,12 +12,16 @@ __author__ = "Daniel Scheffler"
def get_coord_grid(ULxy, LRxy, out_resXY):
# type: (Sequence[float, float], Sequence[float, float], Sequence[float, float]) -> np.ndarray
X_vec = np.arange(ULxy[0], LRxy[0], out_resXY[0])
Y_vec = np.arange(ULxy[1], LRxy[1], out_resXY[1])
# noinspection PyTypeChecker
return np.meshgrid(X_vec, Y_vec)
def snap_bounds_to_pixGrid(bounds, gt, roundAlg='auto'):
# type: (Sequence[float], Sequence[float], str) -> Tuple[float, float, float, float]
"""Snaps the given bounds to the given grid (defined by gt) under the use of the given round algorithm.
NOTE: asserts equal projections of source and target grid
......@@ -32,10 +37,12 @@ def snap_bounds_to_pixGrid(bounds, gt, roundAlg='auto'):
ymax = find_nearest(ygrid, in_ymax, roundAlg, extrapolate=True)
xmax = find_nearest(xgrid, in_xmax, roundAlg, extrapolate=True)
ymin = find_nearest(ygrid, in_ymin, roundAlg, extrapolate=True)
return xmin, ymin, xmax, ymax
def is_coord_grid_equal(gt, xgrid, ygrid, tolerance=0.):
# type: (Sequence[float], Sequence[float], Sequence[float], float) -> bool
"""Checks if a given GeoTransform exactly matches the given X/Y grid.
:param gt: GDAL GeoTransform
......@@ -54,7 +61,7 @@ def is_coord_grid_equal(gt, xgrid, ygrid, tolerance=0.):
def is_point_on_grid(pointXY, xgrid, ygrid, tolerance=0.):
# type: (tuple, np.array, np.array, float) -> bool
# type: (Sequence[float, float], Sequence[float], Sequence[float], float) -> bool
"""Checks if a given point is exactly on the given coordinate grid.
:param pointXY: (X,Y) coordinates of the point to check
......@@ -70,6 +77,7 @@ def is_point_on_grid(pointXY, xgrid, ygrid, tolerance=0.):
def find_nearest_grid_coord(valXY, gt, rows, cols, direction='NW', extrapolate=True):
# type: (Sequence[float, float], Sequence[float], int, int, str, bool) -> Tuple[float, float]
UL, LL, LR, UR = get_corner_coordinates(gt=gt, rows=rows, cols=cols) # (x,y) tuples
round_x = {'NW': 'off', 'NO': 'on', 'SW': 'off', 'SE': 'on'}[direction]
round_y = {'NW': 'on', 'NO': 'on', 'SW': 'off', 'SE': 'off'}[direction]
......@@ -77,13 +85,15 @@ def find_nearest_grid_coord(valXY, gt, rows, cols, direction='NW', extrapolate=T
tgt_ygrid = np.arange(LL[1], UL[1] + abs(gt[5]), abs(gt[5]))
tgt_x = find_nearest(tgt_xgrid, valXY[0], roundAlg=round_x, extrapolate=extrapolate)
tgt_y = find_nearest(tgt_ygrid, valXY[1], roundAlg=round_y, extrapolate=extrapolate)
return tgt_x, tgt_y
def move_shapelyPoly_to_image_grid(shapelyPoly, gt, rows, cols, moving_dir='NW', extrapolate=True):
def move_shapelyPoly_to_image_grid(shapelyPoly, gt, rows, cols, moving_dir='NW'):
# type: (Union[Polygon, box], Sequence[float], int, int, str) -> box
polyULxy = (min(shapelyPoly.exterior.coords.xy[0]), max(shapelyPoly.exterior.coords.xy[1]))
polyLRxy = (max(shapelyPoly.exterior.coords.xy[0]), min(shapelyPoly.exterior.coords.xy[1]))
UL, LL, LR, UR = get_corner_coordinates(gt=gt, rows=rows, cols=cols) # type: Tuple[Tuple] # (x,y)
UL, LL, LR, UR = get_corner_coordinates(gt=gt, rows=rows, cols=cols) # (x,y)
round_x = {'NW': 'off', 'NO': 'on', 'SW': 'off', 'SE': 'on'}[moving_dir]
round_y = {'NW': 'on', 'NO': 'on', 'SW': 'off', 'SE': 'off'}[moving_dir]
tgt_xgrid = np.arange(UL[0], UR[0] + gt[1], gt[1])
......@@ -92,4 +102,5 @@ def move_shapelyPoly_to_image_grid(shapelyPoly, gt, rows, cols, moving_dir='NW',
tgt_xmax = find_nearest(tgt_xgrid, polyLRxy[0], roundAlg=round_x, extrapolate=True)
tgt_ymin = find_nearest(tgt_ygrid, polyLRxy[1], roundAlg=round_y, extrapolate=True)
tgt_ymax = find_nearest(tgt_ygrid, polyULxy[1], roundAlg=round_y, extrapolate=True)
return box(tgt_xmin, tgt_ymin, tgt_xmax, tgt_ymax)
......@@ -5,7 +5,7 @@ import warnings
import multiprocessing
import os
from tempfile import TemporaryDirectory
from typing import Union, Tuple, List # noqa: F401
from typing import Union, Tuple, List, Any, Iterable # noqa: F401
# custom
try:
......@@ -498,7 +498,7 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
class SensorMapGeometryTransformer(object):
def __init__(self, data, lons, lats, resamp_alg='nearest', radius_of_influence=30, **opts):
# type: (np.ndarray, np.ndarray, np.ndarray, str, int, dict) -> None
# type: (np.ndarray, np.ndarray, np.ndarray, str, int, Any) -> None
"""Get an instance of SensorMapGeometryTransformer.
:param data: numpy array to be warped to sensor or map geometry
......@@ -567,12 +567,13 @@ class SensorMapGeometryTransformer(object):
return tgt_extent
def compute_output_shape(self, tgt_prj, tgt_extent, tgt_res=None):
# type: (Union[int, str], List[float, float, float, float], Tuple[float, float]) -> (int, int, tuple, str, ...)
def compute_output_shape(self, tgt_prj, tgt_extent=None, tgt_res=None):
# type: (Union[int, str], Iterable[float, float, float, float], Tuple[float, float]) -> (int, int, tuple, ...)
"""Estimates the map geometry output shape of a sensor geometry array resampled to map geometry.
:param tgt_prj: target projection (WKT or 'epsg:1234' or <EPSG_int>)
:param tgt_extent: extent coordinates of output map geometry array (LL_x, LL_y, UR_x, UR_y) in the tgt_prj
(automatically computed from the corner positions of the coordinate arrays)
:param tgt_res: target X/Y resolution (e.g., (30, 30))
:return:
"""
......@@ -693,7 +694,7 @@ class SensorMapGeometryTransformer(object):
return result
def to_map_geometry(self, tgt_prj, tgt_extent=None, tgt_res=None):
# type: (Union[str, int], List[float, float, float, float], Tuple[float, float]) -> (np.ndarray, tuple, str)
# type: (Union[str, int], Iterable[float, float, float, float], Tuple[float, float]) -> (np.ndarray, tuple, str)
"""Transform the input sensor geometry array into map geometry.
:param tgt_prj: target projection (WKT or 'epsg:1234' or <EPSG_int>)
......
__version__ = '0.14.0'
__versionalias__ = '20181212_01'
__version__ = '0.14.1'
__versionalias__ = '20181213_01'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment