From 2ce6e9338df90ed0a13a659e661c010f4c405f24 Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 1 Aug 2024 11:18:37 +0200 Subject: [PATCH] Formatting with black and flake8 --- importer/handlers/apps.py | 4 ---- importer/handlers/gpkg/tests.py | 1 - .../handlers/remote/tests/test_3dtiles.py | 4 ++-- importer/handlers/tiles3d/handler.py | 4 ++-- importer/handlers/tiles3d/tests.py | 4 +--- importer/handlers/tiles3d/utils.py | 23 +++++++++++-------- importer/settings.py | 2 +- importer/tests/end2end/test_end2end.py | 3 --- importer/tests/unit/test_dastore.py | 5 +--- 9 files changed, 20 insertions(+), 30 deletions(-) diff --git a/importer/handlers/apps.py b/importer/handlers/apps.py index f2ef1ee..729a15d 100644 --- a/importer/handlers/apps.py +++ b/importer/handlers/apps.py @@ -1,8 +1,4 @@ -from glob import iglob -from importlib import import_module import logging -import sys -from importer import project_dir from django.apps import AppConfig from django.conf import settings from django.utils.module_loading import import_string diff --git a/importer/handlers/gpkg/tests.py b/importer/handlers/gpkg/tests.py index 4374099..1d7842b 100644 --- a/importer/handlers/gpkg/tests.py +++ b/importer/handlers/gpkg/tests.py @@ -1,4 +1,3 @@ -import os import shutil from django.test import TestCase, override_settings from importer.handlers.gpkg.exceptions import InvalidGeopackageException diff --git a/importer/handlers/remote/tests/test_3dtiles.py b/importer/handlers/remote/tests/test_3dtiles.py index bb5c569..263639b 100644 --- a/importer/handlers/remote/tests/test_3dtiles.py +++ b/importer/handlers/remote/tests/test_3dtiles.py @@ -117,7 +117,7 @@ def test_import_resource_should_work(self, patch_upload): ExecutionRequest.objects.filter(exec_id=exec_id).delete() def test_create_geonode_resource_raise_error_if_url_is_not_reachabel(self): - with self.assertRaises(Invalid3DTilesException) as error: + with self.assertRaises(Invalid3DTilesException): exec_id = orchestrator.create_execution_request( user=self.owner, func_name="funct1", @@ -129,7 +129,7 @@ def test_create_geonode_resource_raise_error_if_url_is_not_reachabel(self): }, ) - resource = self.handler.create_geonode_resource( + self.handler.create_geonode_resource( "layername", "layeralternate", execution_id=exec_id, diff --git a/importer/handlers/tiles3d/handler.py b/importer/handlers/tiles3d/handler.py index 7889ddd..d93fd9a 100755 --- a/importer/handlers/tiles3d/handler.py +++ b/importer/handlers/tiles3d/handler.py @@ -291,7 +291,7 @@ def set_bbox_from_boundingVolume(self, js_file, resource): ) return resource - + def set_bbox_from_boundingVolume_sphere(self, js_file, resource): transform_raw = js_file.get("root", {}).get("transform", []) sphere_raw = js_file.get("root", {}).get("boundingVolume", {}).get("sphere", None) @@ -317,6 +317,6 @@ def set_bbox_from_boundingVolume_sphere(self, js_file, resource): def _has_region(self, js_file): return js_file.get("root", {}).get("boundingVolume", {}).get("region", None) - + def _has_sphere(self, js_file): return js_file.get("root", {}).get("boundingVolume", {}).get("sphere", None) diff --git a/importer/handlers/tiles3d/tests.py b/importer/handlers/tiles3d/tests.py index cf5666f..8817b86 100755 --- a/importer/handlers/tiles3d/tests.py +++ b/importer/handlers/tiles3d/tests.py @@ -441,8 +441,7 @@ def test_set_bbox_from_bounding_volume_sphere_without_transform(self): self.assertEqual(resource.bbox_y1, 86.8110610157489) os.remove("/tmp/tileset.json") - - + def test_set_bbox_from_bounding_volume_sphere_with_center_zero_without_transform(self): # https://github.com/geosolutions-it/MapStore2/blob/master/web/client/api/__tests__/ThreeDTiles-test.js#L53C4-L79C8 # This test should not extract bbox from boundingVolume sphere with center 0, 0, 0 @@ -476,7 +475,6 @@ def test_set_bbox_from_bounding_volume_sphere_with_center_zero_without_transform self.assertTrue(resource.bbox == self.default_bbox) os.remove("/tmp/tileset.json") - def _generate_execid_asset(self): exec_id = orchestrator.create_execution_request( diff --git a/importer/handlers/tiles3d/utils.py b/importer/handlers/tiles3d/utils.py index a544b4b..aad851e 100644 --- a/importer/handlers/tiles3d/utils.py +++ b/importer/handlers/tiles3d/utils.py @@ -127,6 +127,7 @@ def fromCartesian(cartesian): return {"longitude": longitude, "latitude": latitude, "height": height} + def getScale(matrix): ''' Cesium.Matrix4.getScale() @@ -135,17 +136,18 @@ def getScale(matrix): ''' # check the type of the matrix - if isinstance(matrix, np.ndarray)!=True: + if not isinstance(matrix, np.ndarray): print('Please define a NumPy array object') x = np.linalg.norm([matrix[0][0], matrix[0][1], matrix[0][2]]) y = np.linalg.norm([matrix[1][0], matrix[1][1], matrix[1][2]]) z = np.linalg.norm([matrix[2][0], matrix[2][1], matrix[2][2]]) - + result = np.array([x, y, z]) return result + def box_to_wgs84(box_raw, transform_raw): box = box_raw transform_raw = transform_raw or [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] @@ -190,33 +192,34 @@ def box_to_wgs84(box_raw, transform_raw): "maxy": lat + radiusDegrees, } + def sphere_to_wgs84(sphere_raw, transform_raw): - + transform_raw = transform_raw or [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - + transform = np.array([ transform_raw[0:4], transform_raw[4:8], transform_raw[8:12], transform_raw[12:16], ]) - + centerPoint = np.array([sphere_raw[0], sphere_raw[1], sphere_raw[2], 1]) radius = sphere_raw[3] - + # Sphere center after the transformation - center = centerPoint.dot(transform) # Cesium.Matrix4.multiplyByPoint + center = centerPoint.dot(transform) # Cesium.Matrix4.multiplyByPoint scale = getScale(transform) uniformScale = np.max(scale) - radiusDegrees = (radius * uniformScale) / 111194.87428468118 # degrees of one meter + radiusDegrees = (radius * uniformScale) / 111194.87428468118 # degrees of one meter cartographic = fromCartesian(center) - + if not cartographic: return None - + lng = math.degrees(cartographic['longitude']) lat = math.degrees(cartographic['latitude']) diff --git a/importer/settings.py b/importer/settings.py index 5354469..1996d16 100644 --- a/importer/settings.py +++ b/importer/settings.py @@ -21,4 +21,4 @@ 'importer.handlers.sld.handler.SLDFileHandler', 'importer.handlers.tiles3d.handler.Tiles3DFileHandler', 'importer.handlers.remote.tiles3d.RemoteTiles3DResourceHandler', -] \ No newline at end of file +] diff --git a/importer/tests/end2end/test_end2end.py b/importer/tests/end2end/test_end2end.py index ee7aee1..060029f 100644 --- a/importer/tests/end2end/test_end2end.py +++ b/importer/tests/end2end/test_end2end.py @@ -1,8 +1,6 @@ import ast import os import time -from uuid import uuid4 - import mock from django.conf import settings from django.contrib.auth import get_user_model @@ -19,7 +17,6 @@ from geonode.base.populate_test_data import create_single_dataset from django.db.models import Q from geonode.base.models import ResourceBase -from geonode.resource.manager import resource_manager geourl = settings.GEODATABASE_URL diff --git a/importer/tests/unit/test_dastore.py b/importer/tests/unit/test_dastore.py index f6466e9..afc4f7f 100644 --- a/importer/tests/unit/test_dastore.py +++ b/importer/tests/unit/test_dastore.py @@ -1,13 +1,10 @@ -import os from django.test import TestCase -from mock import patch from importer import project_dir from importer.orchestrator import orchestrator from importer.datastore import DataStoreManager -from importer.publisher import DataPublisher -from unittest.mock import MagicMock from django.contrib.auth import get_user_model + class TestDataStoreManager(TestCase): """ """