Skip to content

Commit

Permalink
Add urban london dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Sep 27, 2024
1 parent 4c3850e commit 35f1997
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
37 changes: 37 additions & 0 deletions data_prep/UrbanLondon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import geopandas as gpd
from deepforest.utilities import read_file
import rasterio as rio
import os
from shapely.geometry import box
import pandas as pd

train_crowns = gpd.read_file("/orange/ewhite/DeepForest/UrbanLondon/crowns/tiles_0.25m_160_20_0_train_crowns.shp")
test_crowns = gpd.read_file("/orange/ewhite/DeepForest/UrbanLondon/crowns/tiles_0.25m_160_20_0_test_crowns.shp")

source = "Zuniga-Gonzalez et al. 2023"

def get_image_annotations(tif_path, crowns):
with rio.open(tif_path) as src:
bounds = src.bounds
bbox = box(bounds.left, bounds.bottom, bounds.right, bounds.top)
intersected = gpd.overlay(crowns, gpd.GeoDataFrame({'geometry': [bbox]}, crs=crowns.crs), how='intersection')
clipped = gpd.clip(intersected, bbox)
if clipped.empty:
return None
clipped["image_path"] = os.path.basename(tif_path)
clipped['label'] = 'Tree'
clipped = read_file(clipped, root_dir=os.path.dirname(tif_path))

return clipped

tif_dir = "/orange/ewhite/DeepForest/UrbanLondon/rgb"
tif_files = [os.path.join(tif_dir, f) for f in os.listdir(tif_dir) if f.endswith('.tif')]

train_annotations = pd.concat([get_image_annotations(tif, train_crowns) for tif in tif_files], ignore_index=True)
test_annotations = pd.concat([get_image_annotations(tif, test_crowns) for tif in tif_files], ignore_index=True)

annotations = pd.concat([train_annotations, test_annotations], ignore_index=True)
annotations['source'] = source
annotations['image_path'] = tif_dir + "/" + annotations['image_path']
annotations["image_path"] = annotations["image_path"].str.replace("tif", "png")
annotations.to_csv("/orange/ewhite/DeepForest/UrbanLondon/annotations.csv", index=False)
3 changes: 2 additions & 1 deletion data_prep/collect_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"/orange/ewhite/DeepForest/Cloutier2023/images/annotations.csv",
"/orange/ewhite/DeepForest/Firoze2023/annotations.csv",
"/orange/ewhite/DeepForest/Wagner_Australia/annotations.csv",
"/orange/ewhite/DeepForest/Alejandro_Chile/alejandro/annotations.csv"
"/orange/ewhite/DeepForest/Alejandro_Chile/alejandro/annotations.csv",
"/orange/ewhite/DeepForest/UrbanLondon/annotations.csv"
]

# Current errors
Expand Down
6 changes: 6 additions & 0 deletions docs/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Location: Southern California, United States

## Polygons

### Zúñiga-González et al. 2023

[https://zenodo.org/records/8113842](https://zenodo.org/records/8113842)

![sample_image](public/Zuniga-Gonzalez_et_al._2023.png)

### Miranda et al. 2024

[Courtesy of Alejandro Miranda](http://www.lepfor.ufro.cl/)
Expand Down
Binary file added docs/public/Zuniga-Gonzalez_et_al._2023.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 35f1997

Please sign in to comment.