Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.9"]
python-version: ["3.13", "3.9"]
name: pixi tests
steps:
- uses: actions/checkout@v4
Expand All @@ -22,9 +22,9 @@ jobs:
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Run tests
uses: prefix-dev/setup-pixi@v0.9.2
uses: prefix-dev/setup-pixi@v0.10.1
with:
pixi-version: v0.59.0
pixi-version: v0.77.1
cache: true
- run: pixi run test
- name: Run Coverage
Expand All @@ -42,6 +42,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Lint
uses: psf/black@stable
uses: psf/black@26.5.1
with:
options: "--check --verbose"
options: "--check --verbose --target-version py39 --target-version py313"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ build
.pixi
*.egg-info

# ignore .env files
.env

# ignore the version file made by setuptools_scm
dem_handler/_version.py
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files", "--skip", ".pixi"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
- id: black
args: ["--exclude", ".pixi"]
language_version: python3.13
- repo: local
hooks:
Expand Down
5 changes: 3 additions & 2 deletions dem_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dem_handler._version import __version__
from pathlib import Path
import typing
from pathlib import Path

from dem_handler._version import __version__

DATA_DIR = Path(__file__).parent / Path("data")
REMA_GPKG_PATH = DATA_DIR / Path("REMA_Mosaic_Index_v2.gpkg")
Expand Down
37 changes: 19 additions & 18 deletions dem_handler/dem/cop_glo30.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
from __future__ import annotations
from affine import Affine

import logging
import math
from pathlib import Path, PurePath

import geopandas as gpd
import numpy as np
from rasterio.crs import CRS
import rasterio
import rasterio.mask
import geopandas as gpd
import numpy as np
from osgeo import gdal
from pathlib import Path, PurePath
import shapely.geometry
import logging
from affine import Affine
from osgeo import gdal
from rasterio.crs import CRS

from dem_handler.dem.geoid import apply_geoid
from dem_handler.download.aws import download_cop_glo30_tiles, download_egm_08_geoid
from dem_handler.utils.logging import log_timing
from dem_handler.utils.raster import (
adjust_pixel_coordinate_from_point_to_area,
expand_bounding_box_to_pixel_edges,
merge_arrays_with_geometadata,
reproject_raster,
)
from dem_handler.utils.spatial import (
BoundingBox,
adjust_bounds_at_high_lat,
check_bounds_likely_cross_antimeridian,
crop_datasets_to_bounds,
get_target_antimeridian_projection,
split_bounds_at_antimeridian,
adjust_bounds_at_high_lat,
crop_datasets_to_bounds,
)
from dem_handler.utils.raster import (
reproject_raster,
merge_arrays_with_geometadata,
adjust_pixel_coordinate_from_point_to_area,
expand_bounding_box_to_pixel_edges,
)
from dem_handler.utils.general import log_timing
from dem_handler.dem.geoid import apply_geoid
from dem_handler.download.aws import download_cop_glo30_tiles, download_egm_08_geoid

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion dem_handler/dem/geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
inspired by https://github.com/ACCESS-Cloud-Based-InSAR/dem-stitcher/blob/dev/src/dem_stitcher/geoid.py
"""

import logging
import os
from pathlib import Path
import logging
from typing import Literal

import numpy as np
import rasterio
import rasterio.transform
import shapely.geometry

from dem_handler.utils.raster import read_raster_with_bounds
from dem_handler.utils.rio_tools import reproject_arr_to_match_profile
from dem_handler.utils.spatial import transform_polygon
Expand Down
74 changes: 57 additions & 17 deletions dem_handler/dem/rema.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
from __future__ import annotations

import glob
import logging
import math
import os
import zipfile
from pathlib import Path
import shapely
from shapely import box
from urllib.request import urlretrieve

import geopandas as gpd
import rasterio
from rasterio.profiles import Profile
from rasterio.crs import CRS
import numpy as np
import math
import logging
import pooch
import rasterio
import shapely
from affine import Affine

from dem_handler.utils.spatial import (
BoundingBox,
transform_polygon,
crop_datasets_to_bounds,
)
from dem_handler.utils.general import log_timing
from dem_handler.download.aws import download_rema_tiles, extract_s3_path
from pooch import Unzip
from rasterio.crs import CRS
from rasterio.profiles import Profile
from shapely import box

from dem_handler.dem.geoid import apply_geoid
from dem_handler.download.aws import download_egm_08_geoid
from dem_handler.download.aws import (
download_egm_08_geoid,
download_rema_tiles,
extract_s3_path,
)
from dem_handler.utils.logging import log_timing
from dem_handler.utils.raster import reproject_and_merge_rasters
from dem_handler.utils.spatial import (
BoundingBox,
check_bounds_likely_cross_antimeridian,
crop_datasets_to_bounds,
split_antimeridian_shape_into_east_west_bounds,
transform_polygon,
)
from dem_handler.utils.raster import reproject_and_merge_rasters

# Create a custom type that allows use of BoundingBox or tuple(left, bottom, right, top)
BBox = BoundingBox | tuple[float | int, float | int, float | int, float | int]
Expand Down Expand Up @@ -481,3 +489,35 @@ def make_empty_rema_profile_for_bounds(
}

return dem_profile


def get_rema_index_file(
Comment thread
arcisad marked this conversation as resolved.
Resolved
rema_index_url: str = "https://data.pgc.umn.edu/elev/dem/setsm/REMA/indexes/REMA_Mosaic_Index_latest_gpkg.zip",
rema_index_hash: str = "b0e1fd8236d5e2858ab66aa54a5e73a43828aacc56bc37d58fc88afde4c02c9f",
) -> Path:
"""Retrieves REMA DEMs index file.
Parameters
----------
rema_index_url : str, optional
URL to the REMA index file, by default "https://data.pgc.umn.edu/elev/dem/setsm/REMA/indexes/REMA_Mosaic_Index_latest_gpkg.zip"
rema_index_hash : str, optional
SHA256 hash of the REMA index file, by default "b0e1fd8236d5e2858ab66aa54a5e73a43828aacc56bc37d58fc88afde4c02c9f"

Returns
-------
Path
Local path to the index file.
"""

rema_index_filename = os.path.basename(rema_index_url)
# download and store locally

zip_save_paths = pooch.retrieve(
url=rema_index_url,
known_hash=f"sha256:{rema_index_hash}",
fname=rema_index_filename,
path=pooch.os_cache("dem_handler"),
progressbar=True,
processor=Unzip(),
)
return Path(zip_save_paths[0])
Loading
Loading