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

Dem development #7

Merged
merged 48 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
604bdcc
working dem stitcher in geoid heights
abradley60 Jan 7, 2025
bc9a345
renaming dem test file
abradley60 Jan 8, 2025
92a9482
working geoid removal
abradley60 Jan 8, 2025
ba3b47e
working over water where dems missing
abradley60 Jan 8, 2025
037d259
update geoid path, clean comments
abradley60 Jan 8, 2025
85b7f23
returning array + profile for antimeridian case
abradley60 Jan 8, 2025
da3ed2a
fix bounds split test
abradley60 Jan 8, 2025
37528cc
uncomment test in main
abradley60 Jan 8, 2025
7bb12e5
Merge pull request #5 from GeoscienceAustralia/main
abradley60 Jan 9, 2025
4a5dcb4
adding rasterio and pyproj
abradley60 Jan 9, 2025
583e8ef
moving dem test to right folder
abradley60 Jan 9, 2025
812755e
fixing bug, only expand in direction when needed
abradley60 Jan 10, 2025
8481bd0
new test for AM crs
abradley60 Jan 10, 2025
5ae89e6
adding spatial utils
abradley60 Jan 10, 2025
6f74602
bugfix for filling dem, clean and generalise for AM
abradley60 Jan 10, 2025
e598598
adding geopandas
abradley60 Jan 13, 2025
dda29d0
adding profile test
abradley60 Jan 13, 2025
a7d55e0
geoid docstrings
abradley60 Jan 13, 2025
c01f721
docstrings and gpkg dem tile search
abradley60 Jan 13, 2025
2ef86d4
simplification with vrt
abradley60 Jan 13, 2025
38db7ad
remove gpkg
abradley60 Jan 13, 2025
faa7c52
docstrings and clean
abradley60 Jan 13, 2025
a215b6c
adding pixel buffer to ensure bounds are covered
abradley60 Jan 14, 2025
eea1e45
cleanup merge function
abradley60 Jan 14, 2025
3b8de0e
adding test data
abradley60 Jan 15, 2025
425713b
ensure full bounds read
abradley60 Jan 15, 2025
1638160
bounds expand bugfix
abradley60 Jan 15, 2025
b29feb1
include test data
abradley60 Jan 15, 2025
3f1d031
setting nodata to np.nan
abradley60 Jan 15, 2025
793ec10
path handling and var rename
abradley60 Jan 15, 2025
e08f0ea
path handling and main function testing
abradley60 Jan 15, 2025
9844490
adding warning rather than expanding bounds
abradley60 Jan 15, 2025
4d92590
cleanup tests
abradley60 Jan 15, 2025
1778b36
Add module to create VRT with hardcoded paths for Copernicus glo30 DEM
caitlinadams Jan 15, 2025
cee1e39
Merge branch 'main' into dem-development
caitlinadams Jan 15, 2025
56e4d8f
adding geoid file
abradley60 Jan 15, 2025
ef0a3ac
Merge branch 'dem-development' of https://github.com/GeoscienceAustra…
abradley60 Jan 15, 2025
4409b2c
fixing dem/geoid test paths
abradley60 Jan 15, 2025
5cc97fd
Split functions to support tests
caitlinadams Jan 15, 2025
1d8aded
Add flag to run build vrt step
caitlinadams Jan 15, 2025
5cb7e5f
Add function to build tile index
caitlinadams Jan 16, 2025
33428e5
Merge branch 'dem-development' into create-vrt
caitlinadams Jan 16, 2025
6162e11
ensure antimeridian reads correct files
abradley60 Jan 16, 2025
bf5629c
Add tests for creating vrt and tile index
caitlinadams Jan 16, 2025
8e090cd
fixes for utilising tile index, not vrt
abradley60 Jan 16, 2025
85cf580
Merge pull request #8 from GeoscienceAustralia/create-vrt
abradley60 Jan 16, 2025
79fdbb3
fix empty dem generation
abradley60 Jan 16, 2025
52b1099
tests for new logic
abradley60 Jan 16, 2025
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: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ credentials
__pycache__

build
*.egg-info
*.egg-info
.*cache
*.tif
*.vrt
data

# include test data files
!tests/sar_antarctica/data/**/*.tif
!tests/sar_antarctica/data/**/*.vrt
26 changes: 23 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ name: sar-antarctica
dependencies:
- _libgcc_mutex=0.1
- _openmp_mutex=4.5
- affine=2.4.0
- aom=3.9.1
- attrs=24.3.0
- blosc=1.21.6
- bzip2=1.0.8
- c-ares=1.34.4
- ca-certificates=2024.12.14
- certifi=2024.12.14
- click=8.1.8
- click-plugins=1.1.1
- cligj=0.7.2
- dav1d=1.2.1
- freexl=2.0.0
- gdal=3.10.0
Expand Down Expand Up @@ -67,23 +73,37 @@ dependencies:
- pcre2=10.44
- pip=24.3.1
- proj=9.5.1
- pyparsing=3.2.1
- python=3.10.16
- python_abi=3.10
- rasterio=1.4.3
- rav1e=0.6.6
- readline=8.2
- setuptools=75.6.0
- shapely=2.0.6
- snappy=1.2.1
- snuggs=1.4.7
- sqlite=3.47.2
- svt-av1=2.3.0
- tk=8.6.13
- tzdata=2024b
- uriparser=0.9.8
- wheel=0.45.1
- x265=3.5
- xerces-c=3.2.5
- zlib=1.3.1
- zstd=1.5.6
- pip:
- click==8.1.8
- pytest==8.3.4
- exceptiongroup==1.2.2
- geopandas==1.0.1
- iniconfig==2.0.0
- packaging==24.2
- pandas==2.2.3
- pluggy==1.5.0
- pyogrio==0.10.0
- pyproj==3.7.0
- pytest==8.3.4
- python-dateutil==2.9.0.post0
- pytz==2024.2
- six==1.17.0
- tomli==2.2.1
- tzdata==2024.2
81 changes: 81 additions & 0 deletions sar_antarctica/nci/preparation/create_dem_vrt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
from pathlib import Path
from typing import Generator

def find_tiles(source_dir: Path, pattern: str) -> Generator[Path, None, None]:
"""_summary_

Parameters
----------
source_dir : Path
The directory to search for files
pattern : str
The pattern to search for
e.g. DEM_folder/*.tif

Returns
-------
Generator[Path, None, None]
A generator that yeilds `Path` objects for all files matching the pattern
e.g. /path/to/DEM_folder/DEM_file.tif
"""

tiles = source_dir.rglob(pattern)

return tiles

def build_vrt(tiles: Generator[Path, None, None] | list[Path], vrt_path: str | os.PathLike, run: bool = True):
"""Generic function for building a VRT from a generator of tile paths

Parameters
----------
tiles : Generator[Path, None, None] | list[Path]
A generator (or list) that provides `Path` objects for tiles
e.g. /path/to/DEM_folder/DEM_file.tif
vrt_path : str | os.PathLike
Where to write the VRT to, ending in .vrt
run : bool, optional
Whether to run the step to create the VRT, by default True
Can use False to generate the temporary file and check
"""
with open("temp.txt", "w") as f:
f.writelines(f"{tile}\n" for tile in tiles)

if run:
os.system(f'gdalbuildvrt -input_file_list temp.txt {vrt_path}')

os.remove("temp.txt")

def build_tileindex(tiles: Generator[Path, None, None], tindex_path: str | os.PathLike, run: bool = True):
"""Generic function for building a tile index from a generator of tile paths

Parameters
----------
tiles : Generator[Path, None, None]
A generator that yeilds `Path` objects for tiles
e.g. /path/to/DEM_folder/DEM_file.tif
vrt_path : str | os.PathLike
Where to write the tile index to, ending in .gpkg
run : bool, optional
Whether to run the step to create the tile index, by default True
Can use False to generate the temporary file and check
"""
with open("temp.txt", "w") as f:
f.writelines(f"{tile}\n" for tile in tiles)

if run:
os.system(f'gdaltindex {tindex_path} --optfile temp.txt')

os.remove("temp.txt")

def create_glo30_dem_south_vrt():
"""Create a VRT for the Copernicus Global 30m DEM on NCI
"""

SOURCE_DIR = Path("/g/data/v10/eoancillarydata-2/elevation/copernicus_30m_world")
PATTERN = "Copernicus_DSM_COG_10_S??_00_????_00_DEM/*.tif"
VRT_PATH = Path("/g/data/yp75/projects/ancillary/dem/copdem_south.vrt")

tiles = find_tiles(SOURCE_DIR, PATTERN)

build_vrt(tiles, VRT_PATH)
Loading
Loading