-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,181 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Python application | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
python setup.py install | ||
- name: Test with pytest | ||
run: | | ||
cd tests/ | ||
pytest layers.py metrics.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ee | ||
import xee | ||
import xarray as xr | ||
|
||
from .layer import Layer, get_image_collection | ||
|
||
|
||
class AlosDSM(Layer): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def get_data(self, bbox): | ||
dataset = ee.ImageCollection("JAXA/ALOS/AW3D30/V3_2") | ||
alos_dsm = ee.ImageCollection(dataset | ||
.filterBounds(ee.Geometry.BBox(*bbox)) | ||
.select('DSM') | ||
.mean() | ||
) | ||
data = get_image_collection(alos_dsm, bbox, 30, "ALOS DSM").DSM | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ee | ||
import geemap | ||
import pandas as pd | ||
import geopandas as gpd | ||
from shapely.geometry import Polygon, MultiPolygon | ||
|
||
from .layer import Layer | ||
|
||
|
||
class OpenBuildings(Layer): | ||
def __init__(self, country='USA', **kwargs): | ||
super().__init__(**kwargs) | ||
self.country = country | ||
|
||
def get_data(self, bbox): | ||
dataset = ee.FeatureCollection(f"projects/sat-io/open-datasets/VIDA_COMBINED/{self.country}") | ||
open_buildings = dataset.filterBounds(ee.Geometry.BBox(*bbox)) | ||
openbuilds = geemap.ee_to_gdf(open_buildings).reset_index() | ||
|
||
# filter out geom_type GeometryCollection | ||
gc_openbuilds = openbuilds[openbuilds.geom_type == 'GeometryCollection'] | ||
if len(gc_openbuilds) > 0: | ||
# select Polygons and Multipolygons from GeometryCollection | ||
gc_openbuilds['geometries'] = gc_openbuilds.apply(lambda x: [g for g in x.geometry.geoms], axis=1) | ||
gc_openbuilds_polygon = [] | ||
# iterate over each row in gc_openbuilds | ||
for index, row in gc_openbuilds.iterrows(): | ||
for geom in row['geometries']: | ||
# Check if the geometry is a Polygon or MultiPolygon | ||
if isinstance(geom, Polygon) or isinstance(geom, MultiPolygon): | ||
# Create a new row with the same attributes as the original row, but with the Polygon geometry | ||
new_row = row.drop(['geometry', 'geometries']) | ||
new_row['geometry'] = geom | ||
gc_openbuilds_polygon.append(new_row) | ||
if len(gc_openbuilds_polygon) > 0: | ||
# convert list to geodataframe | ||
gc_openbuilds_polygon = gpd.GeoDataFrame(gc_openbuilds_polygon, geometry='geometry') | ||
# replace GeometryCollection with Polygon, merge back to openbuilds | ||
openbuilds = openbuilds[openbuilds.geom_type != 'GeometryCollection'] | ||
openbuilds = pd.concat([openbuilds, gc_openbuilds_polygon], ignore_index=True).reset_index() | ||
else: | ||
openbuilds = openbuilds[openbuilds.geom_type != 'GeometryCollection'].reset_index() | ||
|
||
return openbuilds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from .layer import Layer, get_utm_zone_epsg, get_image_collection | ||
|
||
from dask.diagnostics import ProgressBar | ||
import xarray as xr | ||
import xee | ||
import ee | ||
|
||
|
||
class TreeCanopyHeight(Layer): | ||
|
||
name = "tree_canopy_hight" | ||
|
||
NO_DATA_VALUE = 0 | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def get_data(self, bbox): | ||
canopy_ht = ee.ImageCollection("projects/meta-forest-monitoring-okw37/assets/CanopyHeight") | ||
# aggregate time series into a single image | ||
canopy_ht = canopy_ht.reduce(ee.Reducer.mean()).rename("cover_code") | ||
|
||
|
||
|
||
|
||
data = get_image_collection(ee.ImageCollection(canopy_ht), bbox, 1, "tree canopy hight") | ||
|
||
return data.cover_code | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.