Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23 minor improvements #42

Merged
merged 10 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -73,4 +74,5 @@ jobs:
- name: Run tests with pytest
run: |
pip install .
pytest
3 changes: 0 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
name: geoapis
channels:
- conda-forge
- defaults
dependencies:
- pip
- geopandas
Expand All @@ -12,5 +11,3 @@ dependencies:
- python-dotenv
- pytest
- tqdm

prefix: C:\ProgramData\Anaconda3\envs\geoapis
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }]
Expand All @@ -31,9 +31,6 @@ dependencies = [
]
requires-python = ">=3.6"

[tool.setuptools]
packages = ["geoapis"]

[project.optional-dependencies]
dev = ["black", "python-dotenv", "pip-tools", "pytest"]

Expand Down
12 changes: 0 additions & 12 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/geoapis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
@author: pearsonra
"""
__version__ = "0.3.3"
__version__ = "0.3.4"
19 changes: 17 additions & 2 deletions src/geoapis/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(
Expand Down
27 changes: 21 additions & 6 deletions src/geoapis/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import shutil
import numpy

from src.geoapis import lidar
from geoapis import lidar


class OpenTopographyTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import shutil
import numpy

from src.geoapis import lidar
from geoapis import lidar


class OpenTopographyTestByName(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import shutil
import numpy

from src.geoapis import lidar
from geoapis import lidar


class OpenTopographyTestSubfolders(unittest.TestCase):
Expand Down Expand Up @@ -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,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import logging

from src.geoapis import raster
from geoapis import raster


class LinzRasterTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import logging

from src.geoapis import raster
from geoapis import raster


class LrisRasterTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import geopandas

from src.geoapis import vector
from geoapis import vector


class LinzVectorsTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import dotenv
import os

from src.geoapis import vector
from geoapis import vector


class LinzVectorsTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import geopandas

from src.geoapis import vector
from geoapis import vector


class LrisVectorsTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import dotenv
import os

from src.geoapis import vector
from geoapis import vector


class LrisVectorsTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import geopandas

from src.geoapis import vector
from geoapis import vector


class StatsNzVectorsTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import dotenv
import os

from src.geoapis import vector
from geoapis import vector


class StatsNzVectorsTest(unittest.TestCase):
Expand Down