Skip to content

Commit

Permalink
radd
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarshak committed Feb 27, 2024
1 parent 97c478d commit 01bd75c
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 47 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ 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.0.8]
## [0.0.9]

## Added
* Test (and fix bugs) in exception handling related to coverage, tile set names available, and keyword arguments.
* Hansen datasets including `treecover 2000`, `gain`, `lossyear` as indicated here: https://data.globalforestwatch.org/documents/941f17325a494ed78c4817f9bb20f33a/explore
* Hansen datasets including `treecover_2000`, `gain`, `lossyear` (these are the tile shortnames). Infomration on these tiles can be found here: https://data.globalforestwatch.org/documents/941f17325a494ed78c4817f9bb20f33a/explore
* RADD Deforestation Alerts from 2022 (with shortname `radd_deforestation_alerts_2022`): https://data.globalforestwatch.org/datasets/gfw::deforestation-alerts-radd/about

## Fixed
* Test (and fix bugs) in exception handling related to tile coverage, tile sets available, and keyword arguments for certain tiles (e.g. year and season).

## [0.0.8]
* Fix typo in `pekel_water_occ_2021` and other instances of misspelled name: `peckel` --> `pekel`
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The datasets supported are:
In [1]: from tile_mate.stitcher import DATASET_SHORTNAMES
In [2]: DATASET_SHORTNAMES
Out[2]: ['pekel_water_occ_2021',
Out[2]: 'pekel_water_occ_2021',
'esa_world_cover_2020',
'esa_world_cover_2021',
'hansen_annual_mosaic',
Expand All @@ -71,7 +71,8 @@ Out[2]: ['pekel_water_occ_2021',
'hansen_treecover_2000',
's1_coherence_2020',
'cop_100_lulc_discrete',
'hand']
'radd_deforestation_alerts_2022',
'hand'
```
These correspond to
+ Pekel: https://global-surface-water.appspot.com/download
Expand Down
193 changes: 152 additions & 41 deletions notebooks/Basic_Demo.ipynb

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions notebooks/tile_creation/6_RADD.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1e2d311e-1c23-419f-82f2-e1074c99ef7a",
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"from tile_mate.tile_model import TILE_SCHEMA\n",
"from tile_mate.stitcher import DATA_DIR\n",
"from dem_stitcher.geojson_io import to_geojson_gzip\n",
"import requests"
]
},
{
"cell_type": "markdown",
"id": "3d7d1196-2f51-4659-b3dd-c034e3663ecf",
"metadata": {},
"source": [
"Source: https://data.globalforestwatch.org/datasets/gfw::deforestation-alerts-radd/about"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ad3c4086-39b6-4d52-8cc2-0f944ff43d59",
"metadata": {},
"outputs": [],
"source": [
"url = 'https://opendata.arcgis.com/api/v3/datasets/d10aed6037844b86bab85d42bb27954a_0/downloads/data?format=geojson&spatialRefId=4326&where=1%3D1'\n",
"resp = requests.get(url)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b88e512c-2351-4f18-adee-62dd9229acd4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>geometry</th>\n",
" <th>tile_id</th>\n",
" <th>download</th>\n",
" <th>ObjectId</th>\n",
" <th>Shape__Area</th>\n",
" <th>Shape__Length</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1...</td>\n",
" <td>00N_000E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>1</td>\n",
" <td>1.245543e+12</td>\n",
" <td>4.464170e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>POLYGON ((10.00000 0.00000, 20.00000 0.00000, ...</td>\n",
" <td>00N_010E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>2</td>\n",
" <td>1.245543e+12</td>\n",
" <td>4.464170e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>POLYGON ((20.00000 0.00000, 30.00000 0.00000, ...</td>\n",
" <td>00N_020E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>3</td>\n",
" <td>1.245543e+12</td>\n",
" <td>4.464170e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>POLYGON ((30.00000 0.00000, 40.00000 0.00000, ...</td>\n",
" <td>00N_030E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>4</td>\n",
" <td>1.245543e+12</td>\n",
" <td>4.464170e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>POLYGON ((40.00000 0.00000, 50.00000 0.00000, ...</td>\n",
" <td>00N_040E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>5</td>\n",
" <td>1.245543e+12</td>\n",
" <td>4.464170e+06</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" geometry tile_id \\\n",
"0 POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1... 00N_000E \n",
"1 POLYGON ((10.00000 0.00000, 20.00000 0.00000, ... 00N_010E \n",
"2 POLYGON ((20.00000 0.00000, 30.00000 0.00000, ... 00N_020E \n",
"3 POLYGON ((30.00000 0.00000, 40.00000 0.00000, ... 00N_030E \n",
"4 POLYGON ((40.00000 0.00000, 50.00000 0.00000, ... 00N_040E \n",
"\n",
" download ObjectId Shape__Area \\\n",
"0 https://data-api.globalforestwatch.org/dataset... 1 1.245543e+12 \n",
"1 https://data-api.globalforestwatch.org/dataset... 2 1.245543e+12 \n",
"2 https://data-api.globalforestwatch.org/dataset... 3 1.245543e+12 \n",
"3 https://data-api.globalforestwatch.org/dataset... 4 1.245543e+12 \n",
"4 https://data-api.globalforestwatch.org/dataset... 5 1.245543e+12 \n",
"\n",
" Shape__Length \n",
"0 4.464170e+06 \n",
"1 4.464170e+06 \n",
"2 4.464170e+06 \n",
"3 4.464170e+06 \n",
"4 4.464170e+06 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = gpd.GeoDataFrame.from_features(resp.json())\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b956f1fa-dc17-429d-b15c-9e765f09fbf3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>tile_id</th>\n",
" <th>url</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>00N_000E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>00N_010E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>POLYGON ((10.00000 0.00000, 20.00000 0.00000, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>00N_020E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>POLYGON ((20.00000 0.00000, 30.00000 0.00000, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>00N_030E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>POLYGON ((30.00000 0.00000, 40.00000 0.00000, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>00N_040E</td>\n",
" <td>https://data-api.globalforestwatch.org/dataset...</td>\n",
" <td>POLYGON ((40.00000 0.00000, 50.00000 0.00000, ...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" tile_id url \\\n",
"0 00N_000E https://data-api.globalforestwatch.org/dataset... \n",
"1 00N_010E https://data-api.globalforestwatch.org/dataset... \n",
"2 00N_020E https://data-api.globalforestwatch.org/dataset... \n",
"3 00N_030E https://data-api.globalforestwatch.org/dataset... \n",
"4 00N_040E https://data-api.globalforestwatch.org/dataset... \n",
"\n",
" geometry \n",
"0 POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1... \n",
"1 POLYGON ((10.00000 0.00000, 20.00000 0.00000, ... \n",
"2 POLYGON ((20.00000 0.00000, 30.00000 0.00000, ... \n",
"3 POLYGON ((30.00000 0.00000, 40.00000 0.00000, ... \n",
"4 POLYGON ((40.00000 0.00000, 50.00000 0.00000, ... "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_formatted = df[['tile_id', 'download', 'geometry']].copy()\n",
"df_formatted = df_formatted.rename(columns={'download': 'url'})\n",
"df_formatted.head()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5c03447e-c6cc-401e-b25e-d3a5338dc79c",
"metadata": {},
"outputs": [],
"source": [
"df_radd = TILE_SCHEMA.validate(df_formatted)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "69047a72-cd48-4308-b09c-f1a34517e656",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/Users/cmarshak/bekaert-team/tile-mate/src/tile_mate/data/radd_deforestation_alerts_2022.geojson.zip'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"to_geojson_gzip(df_radd, str(DATA_DIR / 'radd_deforestation_alerts_2022.geojson.zip'))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "tile-mate",
"language": "python",
"name": "tile-mate"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file not shown.
1 change: 1 addition & 0 deletions src/tile_mate/stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'hansen_treecover_2000': 'hansen_landsat_mosaic_2022.geojson.zip',
's1_coherence_2020': 's1_coherence_2020.geojson.zip',
'cop_100_lulc_discrete': 'cop_100m_lulc_discrete_classes.geojson.zip',
'radd_deforestation_alerts_2022': 'radd_deforestation_alerts_2022.geojson.zip',
'hand': 'asf_hand_2021.geojson.zip',
}
DATASET_SHORTNAMES = list(GEOJSON_DICT.keys())
Expand Down
10 changes: 9 additions & 1 deletion tests/test_stitch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ def test_cop100_dataset(year: int):


@pytest.mark.parametrize(
'dataset_shortname', ['hansen_gain', 'hansen_treecover_2000', 'hansen_lossyear', 'hand', 'pekel_water_occ_2021']
'dataset_shortname',
[
'hansen_gain',
'hansen_treecover_2000',
'hansen_lossyear',
'hand',
'pekel_water_occ_2021',
'radd_deforestation_alerts_2022',
],
)
def test_no_kwarg_datasets(dataset_shortname):
bounds = [-120.45, 34.85, -120.15, 34.95]
Expand Down

0 comments on commit 01bd75c

Please sign in to comment.