Skip to content

Commit 13e3f31

Browse files
committed
fix some ruff and mypy errors
1 parent d679a34 commit 13e3f31

File tree

5 files changed

+8
-28
lines changed

5 files changed

+8
-28
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ quote-style = "single"
7171
[tool.ruff.lint]
7272
extend-select = [
7373
"I", # isort: https://docs.astral.sh/ruff/rules/#isort-i
74+
"UP", # pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up
7475

7576
# TODO: uncomment the following extensions and address their warnings:
76-
#"UP", # pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up
7777
#"D", # pydocstyle: https://docs.astral.sh/ruff/rules/#pydocstyle-d
7878
#"ANN", # annotations: https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
7979
#"PTH", # use-pathlib-pth: https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth

src/hyp3_srg/back_projection.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def back_project(
127127
granule_orbit_pairs.append((granule_path, orbit_path))
128128

129129
if bounds is None:
130-
bounds = unary_union(bboxs).buffer(0.1).bounds
131-
assert bounds is not None # Return type annotation for unary_union is incorrect
130+
bounds = list(unary_union(bboxs).buffer(0.1).bounds)
132131

133132
dem_path = dem.download_dem_for_srg(bounds, work_dir)
134133
utils.create_param_file(dem_path, dem_path.with_suffix('.dem.rsc'), work_dir)

src/hyp3_srg/time_series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ def create_time_series_product_name(
237237
latest_granule = start_dates[-1]
238238

239239
def lat_string(lat):
240-
return ('N' if lat >= 0 else 'S') + f'{("%.1f" % abs(lat)).zfill(4)}'.replace('.', '_')
240+
return ('N' if lat >= 0 else 'S') + f'{("%.1f" % abs(lat)).zfill(4)}'.replace('.', '_') # noqa: UP031
241241

242242
def lon_string(lon):
243-
return ('E' if lon >= 0 else 'W') + f'{("%.1f" % abs(lon)).zfill(5)}'.replace('.', '_')
243+
return ('E' if lon >= 0 else 'W') + f'{("%.1f" % abs(lon)).zfill(5)}'.replace('.', '_') # noqa: UP031
244244

245245
return '_'.join(
246246
[

src/hyp3_srg/utils.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import asf_search
1010
from boto3 import client
1111
from s1_orbits import fetch_for_scene
12-
from shapely.geometry import Polygon, shape
12+
from shapely.geometry import shape
13+
from shapely.geometry.base import BaseGeometry
1314

1415

1516
S3 = client('s3')
@@ -115,7 +116,7 @@ def get_earthdata_credentials() -> tuple[str, str]:
115116
)
116117

117118

118-
def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = False) -> tuple[Path, Polygon]:
119+
def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = False) -> tuple[Path, BaseGeometry]:
119120
"""Download a S1 granule using asf_search. Return its path
120121
and buffered extent.
121122
@@ -155,26 +156,6 @@ def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = Fals
155156
return out_path, bbox
156157

157158

158-
def get_bbox(granule_name: str) -> tuple[Path, Polygon]:
159-
"""Get the buffered extent from asf_search.
160-
161-
Args:
162-
granule_name: Name of the granule to download
163-
164-
Returns:
165-
bbox: the buffered extent polygon
166-
"""
167-
granule_name = granule_name.split('.')[0]
168-
169-
if not granule_name.endswith('-RAW'):
170-
granule_name += '-RAW'
171-
172-
result = asf_search.granule_search([granule_name])[0]
173-
bbox = shape(result.geojson()['geometry'])
174-
175-
return bbox
176-
177-
178159
def download_orbit(granule_name: str, output_dir: Path) -> Path:
179160
"""Download a S1 orbit file. Prefer using the ESA API,
180161
but fallback to ASF if needed.

tests/test_dem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_download_dem_for_srg(monkeypatch):
1313
m.setattr(dem, 'ensure_egm_model_available', mock_ensure_egm_model_available)
1414
mock_call_stanford_module = mock.Mock()
1515
m.setattr(utils, 'call_stanford_module', mock_call_stanford_module)
16-
dem.download_dem_for_srg(box(0, 1, 2, 3).bounds, Path.cwd())
16+
dem.download_dem_for_srg(list(box(0, 1, 2, 3).bounds), Path.cwd())
1717
mock_ensure_egm_model_available.assert_called_once()
1818
mock_call_stanford_module.assert_called_once_with(
1919
'DEM/createDEMcop.py',

0 commit comments

Comments
 (0)