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

Release 0.7.0 #226

Merged
merged 63 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6ce6f12
Bump pypa/gh-action-pypi-publish from 1.8.10 to 1.8.11
dependabot[bot] Nov 29, 2023
e0d59ea
Merge pull request #217 from ASFHyP3/dependabot/github_actions/pypa/g…
jhkennedy Nov 29, 2023
4e0e439
Bump actions/setup-python from 4 to 5
dependabot[bot] Dec 6, 2023
5cb723e
Merge pull request #219 from ASFHyP3/dependabot/github_actions/action…
jtherrmann Jan 13, 2024
ab4e511
osm water mask creation
AndrewPlayer3 Feb 21, 2024
8eb65f0
added function for removing temp files
AndrewPlayer3 Feb 21, 2024
e67e03d
updated the dependencies
AndrewPlayer3 Feb 21, 2024
662ec27
worldcover code
AndrewPlayer3 Feb 21, 2024
4b5e8b5
added entrypoints for watermasking
AndrewPlayer3 Feb 26, 2024
6614f36
refactor and print statements
AndrewPlayer3 Feb 26, 2024
9980a72
added script for filling polar regions
AndrewPlayer3 Feb 26, 2024
afe6f12
gdal expects lower left corner at these lats
AndrewPlayer3 Feb 26, 2024
023728e
added entrypoint for filling missing tiles
AndrewPlayer3 Feb 26, 2024
aeeff8d
refactoring
AndrewPlayer3 Feb 26, 2024
64d5ed5
refactoring
AndrewPlayer3 Feb 26, 2024
ce58908
functionality to fill missing worldcover tiles
AndrewPlayer3 Feb 27, 2024
b7ed7d3
Bump pypa/gh-action-pypi-publish from 1.8.11 to 1.8.12
dependabot[bot] Feb 27, 2024
9367218
refactor
AndrewPlayer3 Feb 28, 2024
2314c80
refactor
AndrewPlayer3 Feb 28, 2024
5308f75
refactor
AndrewPlayer3 Feb 28, 2024
4543ee9
added setup_directories to utils
AndrewPlayer3 Feb 28, 2024
7964963
refactor
AndrewPlayer3 Feb 28, 2024
29ea0cd
refactoring
AndrewPlayer3 Feb 28, 2024
e0b8bfd
making flake8 happy
AndrewPlayer3 Feb 28, 2024
22d646b
making flake8 happy
AndrewPlayer3 Feb 28, 2024
2ed5362
making flake8 happy
AndrewPlayer3 Feb 28, 2024
45e55c9
restructured lambda
AndrewPlayer3 Feb 28, 2024
be30e48
remove blind exceptions
AndrewPlayer3 Feb 28, 2024
49ce330
basic instructions for the watermask scripts
AndrewPlayer3 Feb 28, 2024
0acf55b
refactor
AndrewPlayer3 Feb 28, 2024
fc904ed
refactor
AndrewPlayer3 Feb 28, 2024
17f1f5e
better entrypoint names
AndrewPlayer3 Feb 28, 2024
12c1e16
Don't verify PyPI distributions
jhkennedy Feb 28, 2024
91e7bcc
added filter by longitude
AndrewPlayer3 Feb 28, 2024
6a779ea
Merge pull request #225 from ASFHyP3/jhkennedy-patch-1
jtherrmann Feb 28, 2024
2768eb2
fixes for wc generation
AndrewPlayer3 Feb 28, 2024
18cbed2
added dependencies
AndrewPlayer3 Feb 28, 2024
6ac972a
remove whitespace
AndrewPlayer3 Feb 28, 2024
f91b2fa
remove =None before del
AndrewPlayer3 Feb 28, 2024
95c291f
updated changelog
AndrewPlayer3 Feb 28, 2024
c08ed40
Merge pull request #224 from ASFHyP3/dependabot/github_actions/pypa/g…
jtherrmann Feb 29, 2024
3801c66
replaced system with subprocess
AndrewPlayer3 Feb 29, 2024
4b3c9bd
refactoring
AndrewPlayer3 Feb 29, 2024
71bae1d
switch to subprocess
AndrewPlayer3 Feb 29, 2024
be67b70
added gdal.UseExceptions
AndrewPlayer3 Feb 29, 2024
129cd03
instructions for worldcover
AndrewPlayer3 Feb 29, 2024
8c735c0
typo
AndrewPlayer3 Feb 29, 2024
63b4f6b
removed quotes around polygon
AndrewPlayer3 Feb 29, 2024
47ead4d
fix line length
AndrewPlayer3 Feb 29, 2024
d762ba9
replaced system with subprocess
AndrewPlayer3 Feb 29, 2024
ed5f543
clarifying comments
AndrewPlayer3 Feb 29, 2024
7a6be8b
expanded filter
AndrewPlayer3 Feb 29, 2024
f47f7af
flake8
AndrewPlayer3 Feb 29, 2024
478b7f8
better filters
AndrewPlayer3 Feb 29, 2024
9b2e13c
uncommented line
AndrewPlayer3 Feb 29, 2024
8712676
removed whitespace
AndrewPlayer3 Feb 29, 2024
5765450
final touches
AndrewPlayer3 Feb 29, 2024
fa54a43
flake8
AndrewPlayer3 Feb 29, 2024
9981861
fix pathing issue
forrestfwilliams Mar 1, 2024
2352660
Update README.MD
forrestfwilliams Mar 1, 2024
3022127
Update README.MD
forrestfwilliams Mar 1, 2024
12d959b
attriberror to keyerror and typo fix
AndrewPlayer3 Mar 1, 2024
b030f1e
Merge pull request #223 from ASFHyP3/watermasking
AndrewPlayer3 Mar 1, 2024
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
21 changes: 1 addition & 20 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,7 @@ jobs:
python -m build

- name: upload to PyPI.org
uses: pypa/[email protected].10
uses: pypa/[email protected].12
with:
user: __token__
password: ${{ secrets.TOOLS_PYPI_PAK }}

verify-distribution:
runs-on: ubuntu-latest
needs:
- call-version-info-workflow
- distribute
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml

- name: Ensure asf_tools v${{ needs.call-version-info-workflow.outputs.version }}} is pip installable
run: |
python -m pip install asf_tools==${{ needs.call-version-info-workflow.outputs.version_tag }}
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0]

## Added
* Scripts and entrypoints for generating our global watermasking dataset added to `watermasking`.


## [0.6.0]

Expand Down
3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ dependencies:
- boto3
- fiona
- gdal>=3.7
- geopandas
- numpy
- osmium-tool
- pyogrio
- pysheds>=0.3
- rasterio
- scikit-fuzzy
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ dependencies = [
"astropy",
"fiona",
"gdal>=3.3",
"geopandas",
"numpy",
"pyogrio",
"pysheds>=0.3",
"rasterio",
"scikit-fuzzy",
"scikit-image",
"scipy",
"shapely",
"tqdm",
"shapely"
]
dynamic = ["version"]

Expand All @@ -41,6 +42,9 @@ make_composite = "asf_tools.composite:main"
water_map = "asf_tools.hydrosar.water_map:main"
calculate_hand = "asf_tools.hydrosar.hand.calculate:main"
flood_map = "asf_tools.hydrosar.flood_map:main"
generate_osm_dataset = "asf_tools.watermasking.generate_osm_tiles:main"
generate_worldcover_dataset = "asf_tools.watermasking.generate_worldcover_tiles:main"
fill_missing_tiles = "asf_tools.watermasking.fill_missing_tiles:main"

[project.entry-points.hyp3]
water_map = "asf_tools.hydrosar.water_map:hyp3"
Expand Down
18 changes: 18 additions & 0 deletions src/asf_tools/watermasking/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
These scripts are for creating a global (or regional) water mask dataset based off of OpenStreetMaps, and optionally augmented by ESA WorldCover.

For the OSM water mask dataset, follow these steps to replicate our dataset:

1. Download the "Latest Weekly Planet PBF File" file from here: "https://planet.openstreetmap.org/".
2. Download the WGS84 water polygons shapefile from: "https://osmdata.openstreetmap.de/data/water-polygons.html".
3. The files should be unzipped and you should have something like `planet.osm.pbf` or `planet.pbf` and `water_polygons.shp` (and the support files for `water_polygons.shp`).
4. Run ```generate_osm_dataset --planet-file-path [path-to-planet.pbf] --ocean-polygons-path [path-to-water-polygons.shp] --lat-begin -85 --lat-end 85 --lon-begin -180 --lon-end 180 --tile-width 5 --tile-height 5```
5. Run ```fill_missing_tiles --fill-value 0 --lat-begin -90 --lat-end -85 --lon-begin -180 --lon-end 180 --tile-width 5 --tile-height 5```
6. Run ```fill_missing_tiles --fill-value 1 --lat-begin 85 --lat-end 90 --lon-begin -180 --lon-end 180 --tile-width 5 --tile-height 5```

For the WorldCover water mask dataset, follow these steps:

1. Download the portions of the dataset for the areas you would like to cover from here: "https://worldcover2020.esa.int/downloader"
2. Extract the contents into a folder. Note, if you download multiple portions of the dataset, extract them all into the same folder.
3. Run ```generate_worldcover_dataset --worldcover-tiles-dir [path-to-worldcover-data] --lat-begin 55 --lat-end 80 --lon-begin -180 --lon-end 180 --tile-width 5 --tile-height 5```

Note that we only use WorldCover data over Alaska, Canada, and Russia for our dataset.
75 changes: 75 additions & 0 deletions src/asf_tools/watermasking/fill_missing_tiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import argparse
import os
import subprocess

import numpy as np
from osgeo import gdal, osr

from asf_tools.watermasking.utils import lat_lon_to_tile_string


gdal.UseExceptions()


def main():

parser = argparse.ArgumentParser(
prog='fill_missing_tiles.py',
description='Script for creating filled tifs in areas with missing tiles.'
)

parser.add_argument('--fill-value', help='The value to fill the data array with.', default=0)
parser.add_argument('--lat-begin', help='The minimum latitude of the dataset in EPSG:4326.', default=-85)
parser.add_argument('--lat-end', help='The maximum latitude of the dataset in EPSG:4326.', default=85)
parser.add_argument('--lon-begin', help='The minimum longitude of the dataset in EPSG:4326.', default=-180)
parser.add_argument('--lon-end', help='The maximum longitude of the dataset in EPSG:4326.', default=180)
parser.add_argument('--tile-width', help='The desired width of the tile in degrees.', default=5)
parser.add_argument('--tile-height', help='The desired height of the tile in degrees.', default=5)

args = parser.parse_args()

fill_value = int(args.fill_value)
lat_begin = int(args.lat_begin)
lat_end = int(args.lat_end)
lon_begin = int(args.lon_begin)
lon_end = int(args.lon_end)
tile_width = int(args.tile_width)
tile_height = int(args.tile_height)

lat_range = range(lat_begin, lat_end, tile_height)
lon_range = range(lon_begin, lon_end, tile_width)

for lat in lat_range:
for lon in lon_range:

tile = lat_lon_to_tile_string(lat, lon, is_worldcover=False, postfix='')
tile_tif = 'tiles/' + tile + '.tif'
tile_cog = 'tiles/cogs/' + tile + '.tif'

print(f'Processing: {tile}')

xmin, ymin = lon, lat
pixel_size_x = 0.00009009009
pixel_size_y = 0.00009009009

# All images in the dataset should be this size.
data = np.empty((55500, 55500))
data.fill(fill_value)

driver = gdal.GetDriverByName('GTiff')
dst_ds = driver.Create(tile_tif, xsize=data.shape[0], ysize=data.shape[1], bands=1, eType=gdal.GDT_Byte)
dst_ds.SetGeoTransform([xmin, pixel_size_x, 0, ymin, 0, pixel_size_y])
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
dst_ds.SetProjection(srs.ExportToWkt())
dst_band = dst_ds.GetRasterBand(1)
dst_band.WriteArray(data)
del dst_ds

command = f'gdal_translate -of COG -co NUM_THREADS=all_cpus {tile_tif} {tile_cog}'.split(' ')
subprocess.run(command)
os.remove(tile_tif)


if __name__ == '__main__':
main()
Loading
Loading