From 59adebc195addea3c34b1ec69753b1245de9749e Mon Sep 17 00:00:00 2001 From: 12rambau Date: Tue, 29 Mar 2022 14:08:34 +0000 Subject: [PATCH 1/3] fix: unproject images in add_raster Fix #434 --- sepal_ui/mapping/mapping.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sepal_ui/mapping/mapping.py b/sepal_ui/mapping/mapping.py index 1dae10f3..6c0f1639 100644 --- a/sepal_ui/mapping/mapping.py +++ b/sepal_ui/mapping/mapping.py @@ -29,6 +29,7 @@ WidgetControl, ZoomControl, ) +from rasterio.crs import CRS from traitlets import Bool, link, observe import ipyvuetify as v import ipyleaflet @@ -405,6 +406,11 @@ def add_raster( # That will also improve performances as the generation of a tile can be done in parallel using Dask. da = da.chunk((1000, 1000)) + # unproject if necessary + epsg_4326 = "EPSG:4326" + if da.rio.crs != CRS.from_string(epsg_4326): + da = da.rio.reproject(epsg_4326) + # Create a named tuple with raster bounds and resolution local_raster = collections.namedtuple( "LocalRaster", @@ -625,7 +631,7 @@ def addLayer( inverted = vis_params.pop("inverted", None) if inverted is not None: - # get the index of the bands taht need to be inverted + # get the index of the bands that need to be inverted index_list = [i for i, v in enumerate(inverted) if v is True] # multiply everything by -1 From c608811c4e59ff85171467267636864e7571f23e Mon Sep 17 00:00:00 2001 From: 12rambau Date: Tue, 29 Mar 2022 14:20:08 +0000 Subject: [PATCH 2/3] build: fix click version https://github.com/psf/black/issues/2964 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index af48d69e..268db1bd 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ def run(self): "keywords": ["UI", "Python", "widget", "sepal"], "python_requires": ">=3.6.9", "install_requires": [ + "click<8.1.0", # https://github.com/psf/black/issues/2964 "haversine", "ipyvue>=1.7.0", # this is the version with the class manager "ipyvuetify", # it will work anyway as the widgets are build on the fly From 203cdb526527eb37e025c65b143d3d7199e6a71d Mon Sep 17 00:00:00 2001 From: 12rambau Date: Tue, 29 Mar 2022 15:38:57 +0000 Subject: [PATCH 3/3] build: fix click deprecation https://github.com/psf/black/issues/2964 --- .github/workflows/unit.yml | 2 +- .pre-commit-config.yaml | 2 +- sepal_ui/scripts/utils.py | 2 +- setup.py | 1 - tests/test_utils.py | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 49d69131..0dc7aeee 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -26,7 +26,7 @@ jobs: - name: Test formatting uses: psf/black@stable with: - version: "21.7b0" + version: "22.3.0" - name: PEP8 rules uses: tonybajan/flake8-check-action@v1.0.0 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c289686..f832e238 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: 'https://github.com/psf/black' - rev: 21.7b0 + rev: 22.3.0 hooks: - id: black stages: [commit] diff --git a/sepal_ui/scripts/utils.py b/sepal_ui/scripts/utils.py index 2cd55df9..d3f0fe85 100644 --- a/sepal_ui/scripts/utils.py +++ b/sepal_ui/scripts/utils.py @@ -139,7 +139,7 @@ def get_file_size(filename): size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(math.floor(math.log(file_size, 1024))) - s = file_size / (1024 ** i) + s = file_size / (1024**i) return "{:.1f} {}".format(s, size_name[i]) diff --git a/setup.py b/setup.py index 268db1bd..af48d69e 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,6 @@ def run(self): "keywords": ["UI", "Python", "widget", "sepal"], "python_requires": ">=3.6.9", "install_requires": [ - "click<8.1.0", # https://github.com/psf/black/issues/2964 "haversine", "ipyvue>=1.7.0", # this is the version with the class manager "ipyvuetify", # it will work anyway as the widgets are build on the fly diff --git a/tests/test_utils.py b/tests/test_utils.py index 05136ab4..4a0ce8b8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -102,7 +102,7 @@ def test_get_file_size(self): # mock every pow of 1024 to YB for i in range(9): with patch("pathlib.Path.stat") as stat: - stat.return_value.st_size = test_value * (1024 ** i) + stat.return_value.st_size = test_value * (1024**i) txt = su.get_file_size("random") assert txt == f"7.5 {size_name[i]}"