diff --git a/.github/workflows/linux-test.yml b/.github/workflows/linux-test.yml index f1aa9e0..757b4a1 100644 --- a/.github/workflows/linux-test.yml +++ b/.github/workflows/linux-test.yml @@ -19,36 +19,37 @@ jobs: steps: - name: Checkout github repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Create LFS file list + run: git lfs ls-files --long | cut -d ' ' -f1 | sort > .lfs-assets-id - - name: Cache conda - uses: actions/cache@v2 - env: - cache-name: cache-conda-env + - name: LFS Cache + uses: actions/cache@v3 with: - path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('environment.yml') }} + path: .git/lfs/objects + key: ${{ matrix.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} + restore-keys: | + ${{ matrix.os }}-lfs- + - name: Git LFS Pull + run: git lfs pull - - name: Install package dependencies with setup-miniconda@v2 + - name: Setup miniconda uses: conda-incubator/setup-miniconda@v2 with: - python-version: ${{ matrix.python-version }} + auto-update-conda: true miniforge-variant: Mambaforge - channels: conda-forge - channel-priority: true + channels: conda-forge # defaults automatically added + python-version: ${{ matrix.python-version }} activate-environment: geoapis environment-file: environment.yml + use-mamba: true auto-activate-base: false - use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! - - run: | - conda info - conda list - conda config --show-sources - conda config --show - printenv | sort + - name: Conda list + shell: pwsh + run: conda list - name: Install test dependencies run: | @@ -73,4 +74,5 @@ jobs: - name: Run tests with pytest run: | + pip install . pytest diff --git a/environment.yml b/environment.yml index ffa8e30..4430159 100644 --- a/environment.yml +++ b/environment.yml @@ -3,7 +3,6 @@ name: geoapis channels: - conda-forge - - defaults dependencies: - pip - geopandas @@ -12,5 +11,3 @@ dependencies: - python-dotenv - pytest - tqdm - -prefix: C:\ProgramData\Anaconda3\envs\geoapis diff --git a/pyproject.toml b/pyproject.toml index e8abee3..40bd97d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [build-system] requires = [ - "setuptools>=61.0.0", + "setuptools>=64", "wheel" ] build-backend = "setuptools.build_meta" [project] name = "geoapis" -version = "0.3.3" +version = "0.3.4" description = "A package for downloading geospatial data from web APIs." readme = "README.md" authors = [{ name = "Rose pearson", email = "rose.pearson@niwa.co.nz" }] @@ -31,9 +31,6 @@ dependencies = [ ] requires-python = ">=3.6" -[tool.setuptools] -packages = ["geoapis"] - [project.optional-dependencies] dev = ["black", "python-dotenv", "pip-tools", "pytest"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 8ef9667..0000000 --- a/setup.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jun 30 11:22:08 2021 - -@author: pearsonra -""" -import setuptools - -setuptools.setup( - package_dir={"": "src"}, - packages=setuptools.find_packages(where="src"), -) diff --git a/src/geoapis/__init__.py b/src/geoapis/__init__.py index e840111..04838bb 100644 --- a/src/geoapis/__init__.py +++ b/src/geoapis/__init__.py @@ -4,4 +4,4 @@ @author: pearsonra """ -__version__ = "0.3.3" +__version__ = "0.3.4" diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index 3f76e7d..037cb58 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -148,7 +148,22 @@ def run(self, layer: int) -> pathlib.Path: response = requests.post( url=f"{self.base_url}/exports/", headers=headers, json=api_query ) - query_id = response.json()["id"] + json_query = response.json() + if "is_valid" in json_query.keys() and not json_query["is_valid"]: + message = f"Invalid initial query. Check layer {layer} exists and is within bounds." + if "invalid_reasons" in json_query.keys(): + message = ( + message + + f" json_query['invalid_reasons']: {json_query['invalid_reasons']}." + ) + if "items" in json_query.keys(): + message = ( + message + + f" json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + ) + logging.warning(message) + return [] + query_id = json_query["id"] # Check the state of your exports until the triggered raster exports completes logging.info("Check status of download request") @@ -173,7 +188,7 @@ def run(self, layer: int) -> pathlib.Path: logging.warning( f"Could not download raster. Ended with status {element['state']}" ) - return + return [] # Download the completed export logging.info(f"Downloading {element['download_url']} to {self.cache_path}") with requests.get( diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 6e80f19..c303b84 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -72,10 +72,23 @@ def __init__( def _set_up(self): """Ensure the bouding_polygon and CRS are in agreement.""" + error_message = ( + "Either the crs or the bounding_polygon with a CRS mus be specified." + ) + if self.crs is None and self.bounding_polygon is None: + logging.error(error_message) + raise ValueError(error_message) + # Set the crs from the bounding_polygon if it's not been set - if self.crs is None and self.bounding_polygon is not None: - self.crs = self.bounding_polygon.crs.to_epsg() - # Set the bounding_polygon crs from the crs if they differ + if self.bounding_polygon is not None: + if self.crs is None and self.bounding_polygon.crs is not None: + self.crs = self.bounding_polygon.crs.to_epsg() + elif self.crs is not None and self.bounding_polygon.crs is None: + self.bounding_polygon.set_crs(self.crs, inplace=True) + elif self.crs is None and self.bounding_polygon.crs is None: + logging.error(error_message) + raise ValueError(error_message) + # Convert the bounding_polygon crs from the crs if they differ if ( self.bounding_polygon is not None and self.crs != self.bounding_polygon.crs.to_epsg() @@ -153,10 +166,12 @@ def get_json_response_in_bounds(self, layer: int, bounds, geometry_name: str): logging.info( f"Layer: {layer} is not `geometry_name`: {geometry_name}." ) - assert False, ( - f"No geometry types matching that of layer: {layer} tried. The" - " geometry_name's tried are: +{geometry_type_list}" + message = ( + f"No geometry types matching that of layer: {layer}. " + f"The geometry_name's tried are: {self.GEOMETRY_NAMES}." ) + logging.error(message) + raise ValueError(message) def get_features_inside_catchment( self, layer: int, geometry_name: str diff --git a/tests/test_lidar/test_lidar.py b/tests/test_lidar/test_case.py similarity index 99% rename from tests/test_lidar/test_lidar.py rename to tests/test_lidar/test_case.py index 31ffe49..21dab23 100644 --- a/tests/test_lidar/test_lidar.py +++ b/tests/test_lidar/test_case.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTest(unittest.TestCase): diff --git a/tests/test_lidar_by_name/test_lidar_by_name.py b/tests/test_lidar_by_name/test_case.py similarity index 99% rename from tests/test_lidar_by_name/test_lidar_by_name.py rename to tests/test_lidar_by_name/test_case.py index 66fcae1..505faa6 100644 --- a/tests/test_lidar_by_name/test_lidar_by_name.py +++ b/tests/test_lidar_by_name/test_case.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTestByName(unittest.TestCase): diff --git a/tests/test_lidar_subfolders/test_lidar_subfolders.py b/tests/test_lidar_subfolders/test_case.py similarity index 98% rename from tests/test_lidar_subfolders/test_lidar_subfolders.py rename to tests/test_lidar_subfolders/test_case.py index 8a3a596..7a796ed 100644 --- a/tests/test_lidar_subfolders/test_lidar_subfolders.py +++ b/tests/test_lidar_subfolders/test_case.py @@ -13,7 +13,7 @@ import shutil import numpy -from src.geoapis import lidar +from geoapis import lidar class OpenTopographyTestSubfolders(unittest.TestCase): @@ -51,7 +51,7 @@ class OpenTopographyTestSubfolders(unittest.TestCase): f"{DATASETS[3]}_TileIndex.zip": 120930, }, DATASETS[4]: { - f"{DATASETS[4]}_TileIndex.zip": 3389130, + f"{DATASETS[4]}_TileIndex.zip": 4033009, }, } diff --git a/tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py b/tests/test_raster_linz_in_bounds/test_case.py similarity index 99% rename from tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py rename to tests/test_raster_linz_in_bounds/test_case.py index 5a7c2e7..8dbe839 100644 --- a/tests/test_raster_linz_in_bounds/test_raster_linz_in_bounds.py +++ b/tests/test_raster_linz_in_bounds/test_case.py @@ -15,7 +15,7 @@ import os import logging -from src.geoapis import raster +from geoapis import raster class LinzRasterTest(unittest.TestCase): diff --git a/tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py b/tests/test_raster_lris_in_bounds/test_case.py similarity index 99% rename from tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py rename to tests/test_raster_lris_in_bounds/test_case.py index 102d0a2..cc30b1c 100644 --- a/tests/test_raster_lris_in_bounds/test_raster_lris_in_bounds.py +++ b/tests/test_raster_lris_in_bounds/test_case.py @@ -15,7 +15,7 @@ import os import logging -from src.geoapis import raster +from geoapis import raster class LrisRasterTest(unittest.TestCase): diff --git a/tests/test_vector_linz/test_vector_linz.py b/tests/test_vector_linz/test_case.py similarity index 99% rename from tests/test_vector_linz/test_vector_linz.py rename to tests/test_vector_linz/test_case.py index 2c8fd8f..8eef9e2 100644 --- a/tests/test_vector_linz/test_vector_linz.py +++ b/tests/test_vector_linz/test_case.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class LinzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py b/tests/test_vector_linz_in_bounds/test_case.py similarity index 99% rename from tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py rename to tests/test_vector_linz_in_bounds/test_case.py index aba72aa..9636922 100644 --- a/tests/test_vector_linz_in_bounds/test_vector_linz_in_bounds.py +++ b/tests/test_vector_linz_in_bounds/test_case.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class LinzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_lris/test_vector_lris.py b/tests/test_vector_lris/test_case.py similarity index 99% rename from tests/test_vector_lris/test_vector_lris.py rename to tests/test_vector_lris/test_case.py index 33734e5..5576ff2 100644 --- a/tests/test_vector_lris/test_vector_lris.py +++ b/tests/test_vector_lris/test_case.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class LrisVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py b/tests/test_vector_lris_in_bounds/test_case.py similarity index 99% rename from tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py rename to tests/test_vector_lris_in_bounds/test_case.py index 7eae5f3..1d67f86 100644 --- a/tests/test_vector_lris_in_bounds/test_vector_lris_in_bounds.py +++ b/tests/test_vector_lris_in_bounds/test_case.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class LrisVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_stats_nz/test_vector_stats_nz.py b/tests/test_vector_stats_nz/test_case.py similarity index 99% rename from tests/test_vector_stats_nz/test_vector_stats_nz.py rename to tests/test_vector_stats_nz/test_case.py index dda7b8c..7db2421 100644 --- a/tests/test_vector_stats_nz/test_vector_stats_nz.py +++ b/tests/test_vector_stats_nz/test_case.py @@ -13,7 +13,7 @@ import os import geopandas -from src.geoapis import vector +from geoapis import vector class StatsNzVectorsTest(unittest.TestCase): diff --git a/tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py b/tests/test_vector_stats_nz_in_bounds/test_case.py similarity index 99% rename from tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py rename to tests/test_vector_stats_nz_in_bounds/test_case.py index 2cf9a41..9331fd4 100644 --- a/tests/test_vector_stats_nz_in_bounds/test_vector_stats_nz_in_bounds.py +++ b/tests/test_vector_stats_nz_in_bounds/test_case.py @@ -14,7 +14,7 @@ import dotenv import os -from src.geoapis import vector +from geoapis import vector class StatsNzVectorsTest(unittest.TestCase):